示例#1
0
QMap<QString, QString> TextDocument::openedTextDocumentContents()
{
    QMap<QString, QString> workingCopy;
    foreach (IDocument *document, DocumentModel::openedDocuments()) {
        TextDocument *textEditorDocument = qobject_cast<TextDocument *>(document);
        if (!textEditorDocument)
            continue;
        QString fileName = textEditorDocument->filePath().toString();
        workingCopy[fileName] = textEditorDocument->plainText();
    }
示例#2
0
void DocManager::gotoTextLine( const KURL &url, int line )
{
	TextDocument * doc = dynamic_cast<TextDocument*>( openURL(url) );
	TextView * tv = doc ? doc->textView() : 0;
	
	if ( !tv ) return;
	
	tv->gotoLine(line);
	tv->setFocus();
}
TEST (test_case, your_test)
{
	TextDocument *text = new TextDocument();
	ASSERT_TRUE(text->GetGraphic() == NULL);
	text->Insert(new ImageProxy("virtual_proxy_pattern.cpp"));

	Graphic *graph = text->GetGraphic();//image object is not yet instantiated
	ASSERT_TRUE(graph != NULL);
	ASSERT_TRUE(graph->GetExtent() == Point(0, 0));
	Point pt(10, 5);
	graph->Draw(pt);
	Point pt2 = graph->GetExtent();
	ASSERT_TRUE(pt2 == pt);

	delete text;
}
/// This method test the undo functionality of the text
void ReplaceSelectionCommandTest::testUndo()
{
    TextEditorWidget* widget = new TextEditorWidget();
    TextEditorController* ctrl = widget->controller();
    TextDocument *doc = widget->textDocument();
    TextBuffer* buf = doc->buffer();

    // check if we can set the txt  
    ctrl->replaceSelection("test");
    testEqual( buf->text(), "test" );

    // test basic, undo/redo
        ctrl->undo();
        testEqual( buf->text(), "" );

        // test coalesce
        ctrl->replaceSelection("emma");
        ctrl->replaceSelection(" sarah",true);
        ctrl->replaceSelection(" david",true);
        testEqual( buf->text(), "emma sarah david" );
        ctrl->undo();
        testEqual( buf->text(), "emma" );

        ctrl->redo();
        testEqual( buf->text(), "emma sarah david");

    // test ranged replacement
        doc->textUndoStack()->clear();
        buf->setText("Blommers");

        testEqual( buf->text(), "Blommers" );

        // now replace 'mm' by nothing
        TextRangeSet sel( doc );
        sel.addRange(3,5);
        ctrl->replaceRangeSet( sel, "" );
        testEqual( buf->text(), "Bloers" );

        ctrl->undo();
        testEqual( buf->text(), "Blommers" );
        ctrl->redo();
        testEqual( buf->text(), "Bloers" );



        delete widget;
}
示例#5
0
TextDocument *DocManager::openTextFile( const KURL &url, ViewArea *viewArea )
{
	TextDocument *document = TextDocument::constructTextDocument( url.fileName().remove(url.directory()) );
	
	if (!document)
		return 0;
	
	if ( !document->openURL(url) )
	{
		KMessageBox::sorry( 0, i18n("Could not open text file \"%1\"").arg(url.prettyURL()) );
		document->deleteLater();
		return 0;
	}
	
	handleNewDocument( document, viewArea );
	emit fileOpened(url);
	return document;
}
TextDocument* TextDocument::clone()
{
    if (d.dirty > 0)
        flush();

    TextDocument* doc = new TextDocument(d.buffer);
    doc->setDefaultStyleSheet(defaultStyleSheet());
    QTextCursor(doc).insertFragment(QTextDocumentFragment(this));
    doc->rootFrame()->setFrameFormat(rootFrame()->frameFormat());

    // TODO:
    doc->d.uc = d.uc;
    doc->d.css = d.css;
    doc->d.lowlight = d.lowlight;
    doc->d.buffer = d.buffer;
    doc->d.highlights = d.highlights;
    doc->d.timeStampFormat = d.timeStampFormat;
    doc->d.clone = true;

    return doc;
}
示例#7
0
void TextMarkRegistry::documentRenamed(IDocument *document, const
                                           QString &oldName, const QString &newName)
{
    TextDocument *baseTextDocument = qobject_cast<TextDocument *>(document);
    if (!document)
        return;
    FileName oldFileName = FileName::fromString(oldName);
    FileName newFileName = FileName::fromString(newName);
    if (!m_marks.contains(oldFileName))
        return;

    QSet<TextMark *> toBeMoved;
    foreach (TextMark *mark, baseTextDocument->marks())
        toBeMoved.insert(mark);

    m_marks[oldFileName].subtract(toBeMoved);
    m_marks[newFileName].unite(toBeMoved);

    foreach (TextMark *mark, toBeMoved)
        mark->updateFileName(newName);
}
BOOL CFileBasedProjectTemplateItem::CreateMainFile(LPCTSTR lpszTargetPath, LPCTSTR lpszCrLf)
{
	CStringW text;
	TextDocument doc;

	bool result = doc.Read(m_strPath,text);

	if (result)
	{
		const CStringW lineendings(L"\r\n");
		int index = text.FindOneOf(lineendings);

		if (index != -1)
		{
			CStringW line = text.Left(index);
			const CStringW strKey(L"%DESCRIPTION: ");
			CStringW strStartOfLine = line.Left(strKey.GetLength());

			strStartOfLine.MakeUpper();

			if (strKey == strStartOfLine) 
			{
				text.Delete(0,index);
				text.TrimLeft(lineendings + L' ');
			}
		}

		LPCWSTR le = GetLineEnding(static_cast<LPCWSTR>(text),text.GetLength());

		USES_CONVERSION;

		if (std::wcscmp(le,T2CW(lpszCrLf)) != 0) // Line endings not equal
			text.Replace(le,lpszCrLf);

		result = doc.Write(lpszTargetPath,text);
	}

	return result;
}
BOOL CEmptyProjectTemplateItem::CreateMainFile(LPCTSTR lpszTargetPath, LPCTSTR lpszCrLf)
{
	// create empty main file
	TextDocument doc;
	return doc.Write(lpszTargetPath,lpszCrLf);
}
示例#10
0
void TextUndoStackTest::testMultiCaretUndoIssue196()
{
    TextEditorWidget widget;
    TextDocument* doc = widget.textDocument();
    TextEditorController* controller = widget.controller();
//    TextUndoStack* undoStack = doc->textUndoStack();

    controller->replace(0,0,"1a2b3c4d",0);                  // 1a|2b|3c4d
    controller->moveCaretToOffset(2,false);
    controller->addCaretAtOffset(4);

    testEqual( doc->text(), "1a2b3c4d" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2,4>4");

    RemoveCommand del( RemoveCommand::RemoveChar, RemoveCommand::Right );

    del.execute(controller);
    testEqual( doc->text(), "1abc4d" );                          // 1a|b|c4d
    testEqual( controller->textSelection()->rangesAsString(), "2>2,3>3");

    del.execute(controller);
    testEqual( controller->textSelection()->rangesAsString(), "2>2");
    testEqual( doc->text(), "1a4d" );                       // 1a||4d



    del.execute(controller);
    testEqual( doc->text(), "1ad" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2");

    del.execute(controller);
    testEqual( doc->text(), "1a" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2");

    del.execute(controller);
    testEqual( doc->text(), "1a" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2");

//qlog_info() << "STACK: ---------------------------------------";
//qlog_info() << doc->textUndoStack()->dumpStack();
//qlog_info() << "----------------------------------------------";

    controller->undo();

    testEqual( doc->text(), "1a2b3c4d" );
    testEqual( controller->textSelection()->rangesAsString(), "2>2,4>4");


/*


==== after 1 delete ===

  1a|2b|3c4d =>  1a|b|c4d


 UndoStack
 =====================
 "-|Complex::TextChangeGroup(3/3)
 - 0: SelectionTextChange
 - 1: SingleTextChange:2:0:2
 - 2: SingleTextChange:3:0:3

==== after 2 deletes ===

  1a|b|c4d =>  1a|4d


UndoStack
=====================
"-|Complex::TextChangeGroup(3/3)
 - 0: SelectionTextChange
 - 1: SingleTextChange:2:0:2b         (2b en 3c is verwijderd... Dit is nog goed!)
 - 2: SingleTextChange:2:0:3c

 ==== after 3 deletes ===

  1a|4d =>  1a|d

  // NEW STACK ITEM REQUIRED!!!!

 UndoStack
 =====================
 "-|Complex::TextChangeGroup(3/3)
 - 0: SelectionTextChange
 - 1: SingleTextChange:2:0:2b4
 - 2: SingleTextChange:1:0:3c          <= hier zou de 4 achter moeten staan!!! (Dit is nooit te bepalen, omdat je niet weet welke carets verdwenen zijn)

*/


}
示例#11
0
/// execute the given selection command
/// @param controller the controller to execute the selection for
void SelectionCommand::execute( TextEditorController* controller )
{
    // save the selection state
    TextDocument* document = controller->textDocument();
    TextRangeSet* currentSelection = dynamic_cast<TextRangeSet*>( controller->textSelection() );
    TextRangeSet* sel = new TextRangeSet(*currentSelection);  // start with the current selection

    bool resetAnchors = !keepSelection_;

    // handle the select operation
    switch( unit_ ) {
        // character movement
        case MoveCaretByCharacter:
            sel->moveCarets(amount_);
            break;

        // This results in clearing the selection if a selection is present or it results in a movement of the caret.
        // When clearing a selection the caret is placed next to the selection (which side depends on the direction)
        case MoveCaretsOrDeselect:
            if( keepSelection_ ) {
                sel->moveCarets(amount_);
            } else {
                sel->moveCaretsOrDeselect(amount_);
            }
            break;

        case MoveCaretByWord:
            sel->moveCaretsByCharGroup(amount_, document->config()->whitespaceWithoutNewline(), document->config()->charGroups() );
            break;

        case MoveCaretByLine:
            TextSelection::moveCaretsByLine( controller, sel, amount_ );
            break;

        case MoveCaretToLineBoundary:
            sel->moveCaretsToLineBoundary( amount_, document->config()->whitespaceWithoutNewline() );
            break;

        case MoveCaretToDocumentBegin:
            sel->toSingleRange();
            sel->range(0).setCaret(0);
            break;

        case MoveCaretToDocumentEnd:
            sel->toSingleRange();
            sel->range(0).setCaret( controller->textDocument()->length() );
            break;

        case MoveCaretByPage:
        {
            // make sure the first line of the window is scrolled
            TextRenderer* renderer   = controller->textRenderer();
            TextEditorWidget* widget = controller->widget();
            int firstVisibleLine = renderer->firstVisibleLine();
            int linesPerPage     = renderer->viewHeightInLines();

            sel->beginChanges();
            TextSelection::moveCaretsByPage( controller, sel, amount_ );
            if( !keepSelection_ ) {
                sel->resetAnchors();    // we must reset anchors here because de process-changes will merge carets
            }
            sel->endChanges();

            firstVisibleLine += linesPerPage * amount_;
            widget->scrollTopToLine( firstVisibleLine );

            break;
        }
        case MoveCaretToExactOffset:
            sel->toSingleRange();
            sel->range(0).setCaret(amount_);
            break;

        case SelectAll:
            sel->toSingleRange();
            sel->setRange(0, document->buffer()->length() );
            resetAnchors = false;   // do not reset the anchors
            break;

        case SelectWord:
            sel->expandToWords(document->config()->whitespaces(), document->config()->charGroups());
            resetAnchors = false;   // do not reset the anchors
            break;

        case SelectWordAt:
            sel->selectWordAt( amount_, document->config()->whitespaces(), document->config()->charGroups() );
            resetAnchors = false;
            break;

        case ToggleWordSelectionAt:
            sel->toggleWordSelectionAt( amount_, document->config()->whitespaces(), document->config()->charGroups() );
            resetAnchors = false;
            break;

        case SelectFullLine:
            sel->expandToFullLines( amount_);
            resetAnchors = false;
            break;

        case AddCaretAtOffset:
            sel->addRange( amount_, amount_ );
            resetAnchors = false;   // do not reset the anchors
            break;

        case AddCaretByLine:
            TextSelection::addRangesByLine( controller, sel, amount_ );
            break;

        case ResetSelection:

            // when there's a selection ESCAPE clears the selection
            if( sel->hasSelection() ) {
                sel->clearSelection();
            } else if( sel->rangeCount() > 1 ) {
                sel->toSingleRange();
            }
            resetAnchors = false;   // keep selection
            break;
    }

    if( resetAnchors ) {
        sel->resetAnchors();
    }

    // no change?
    if( currentSelection->equals( *sel ) ) {
        delete sel;
        return; // 0
    }

    controller->changeAndGiveTextSelection( sel, commandId() );
}
示例#12
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();
}
示例#13
0
TextDocument::TextDocument(const TextDocument& orig) : Document(orig) {
    text = auto_ptr< string > (new string(*orig.getText()));
}