示例#1
0
void ProcessChain::slotFinishedCompile(Language *language)
{
	ProcessOptions options = language->processOptions();
	
	if ( options.b_addToProject && ProjectManager::self()->currentProject() )
		ProjectManager::self()->currentProject()->addFile( KUrl(options.targetFile()) );
	
	ProcessOptions::ProcessPath::MediaType typeTo = ProcessOptions::ProcessPath::to( m_processOptions.processPath() );
	
	TextDocument * editor = 0l;
	if ( KTLConfig::reuseSameViewForOutput() )
	{
		editor = options.textOutputTarget();
		if ( editor && (!editor->url().isEmpty() || editor->isModified()) )
			editor = 0l;
	}
	
	switch (typeTo)
	{
		case ProcessOptions::ProcessPath::AssemblyAbsolute:
		case ProcessOptions::ProcessPath::AssemblyRelocatable:
		case ProcessOptions::ProcessPath::C:
		case ProcessOptions::ProcessPath::Disassembly:
		case ProcessOptions::ProcessPath::Library:
		case ProcessOptions::ProcessPath::Microbe:
		case ProcessOptions::ProcessPath::Object:
		case ProcessOptions::ProcessPath::Program:
		{
			switch ( options.method() )
			{
				case ProcessOptions::Method::LoadAsNew:
				{
					if ( !editor )
						editor = DocManager::self()->createTextDocument();
					
					if ( !editor )
						break;
				
					QString text;
					QFile f( options.targetFile() );
					if ( !f.open( QIODevice::ReadOnly ) )
					{
						editor->deleteLater();
						editor = 0l;
						break;
					}
				
					QTextStream stream(&f);
				
					while ( !stream.atEnd() )
						text += stream.readLine()+'\n';
				
					f.close();
	
					editor->setText( text, true );
					break;
				}
			
				case ProcessOptions::Method::Load:
				{
					editor = dynamic_cast<TextDocument*>( DocManager::self()->openURL(options.targetFile()) );
					break;
				}
			
				case ProcessOptions::Method::Forget:
					break;
			}
		}
			
		case ProcessOptions::ProcessPath::FlowCode:
		case ProcessOptions::ProcessPath::Pic:
		case ProcessOptions::ProcessPath::Unknown:
			break;
	}
	
	
	if (editor)
	{
		switch (typeTo)
		{
			case ProcessOptions::ProcessPath::AssemblyAbsolute:
			case ProcessOptions::ProcessPath::AssemblyRelocatable:
			{
				if ( KTLConfig::autoFormatMBOutput() )
					editor->formatAssembly();
				editor->slotInitLanguage( TextDocument::ct_asm );
				break;
			}
		
			case ProcessOptions::ProcessPath::C:
				editor->slotInitLanguage( TextDocument::ct_c );
				break;
			
			case ProcessOptions::ProcessPath::Disassembly:
				break;
			
			case ProcessOptions::ProcessPath::Library:
			case ProcessOptions::ProcessPath::Object:
			case ProcessOptions::ProcessPath::Program:
				editor->slotInitLanguage( TextDocument::ct_hex );
				break;
			
			case ProcessOptions::ProcessPath::Microbe:
				editor->slotInitLanguage( TextDocument::ct_microbe );
				break;
			
			case ProcessOptions::ProcessPath::FlowCode:
			case ProcessOptions::ProcessPath::Pic:
			case ProcessOptions::ProcessPath::Unknown:
				break;
		}
		
		DocManager::self()->giveDocumentFocus( editor );
	}
	
	options.setTextOutputtedTo( editor );

	emit successful(options);
	emit successful();
}