void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor) { PlainTextEditor *editorEditable = qobject_cast<PlainTextEditor *>(editor); if (editorEditable) { BaseTextDocument *file = qobject_cast<BaseTextDocument *>(editor->document()); if (!file) return; PlainTextEditorWidget *textEditor = static_cast<PlainTextEditorWidget *>(editorEditable->editorWidget()); const QString infoSyntaxDefinition = QLatin1String(Constants::INFO_SYNTAX_DEFINITION); if (textEditor->isMissingSyntaxDefinition() && !textEditor->ignoreMissingSyntaxDefinition() && TextEditorSettings::instance()->highlighterSettings().alertWhenNoDefinition()) { if (file->hasHighlightWarning()) return; Core::InfoBarEntry info(infoSyntaxDefinition, tr("A highlight definition was not found for this file. " "Would you like to try to find one?")); info.setCustomButtonInfo(tr("Show highlighter options..."), textEditor, SLOT(acceptMissingSyntaxDefinitionInfo())); info.setCancelButtonInfo(textEditor, SLOT(ignoreMissingSyntaxDefinitionInfo())); file->infoBar()->addInfo(info); file->setHighlightWarning(true); return; } if (!file->hasHighlightWarning()) return; file->infoBar()->removeInfo(infoSyntaxDefinition); file->setHighlightWarning(false); } }
Core::IEditor *PlainTextEditorEditable::duplicate(QWidget *parent) { PlainTextEditor *newEditor = new PlainTextEditor(parent); newEditor->duplicateFrom(editor()); TextEditorPlugin::instance()->initializeEditor(newEditor); return newEditor->editableInterface(); }
void MainUI::wrapLines(bool wrap){ settings->setValue("wrapLines",wrap); for(int i=0; i<ui->tabWidget->count(); i++){ PlainTextEditor *edit = static_cast<PlainTextEditor*>(ui->tabWidget->widget(i)); edit->setLineWrapMode( wrap ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap); } }
void BlackMilordTests::check_PlainTextEditor_blockCount() { PlainTextEditor *editor = Gui::plainTextEditor(); QString testString = "test\ntest"; editor->setPlainText(testString); QVERIFY(editor->blockCount() == 2); }
void MainUI::showLineNumbers(bool show){ settings->setValue("showLineNumbers",show); for(int i=0; i<ui->tabWidget->count(); i++){ PlainTextEditor *edit = static_cast<PlainTextEditor*>(ui->tabWidget->widget(i)); edit->showLineNumbers(show); } }
void BlackMilordTests::check_PlainTextEditor_typing() { PlainTextEditor *editor = Gui::plainTextEditor(); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_A); QVERIFY(editor->toPlainText() == "a"); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_B); QVERIFY(editor->toPlainText() == "ab"); }
void BlackMilordTests::check_PlainTextEditor_visibleBlocks() { PlainTextEditor *editor = Gui::plainTextEditor(); QString testString = "test\ntest"; editor->setPlainText(testString); QVERIFY(editor->firstVisibleBlock() == 0); QVERIFY(editor->lastVisibleBlock() == 1); }
void MainUI::openReplace(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } ui->groupReplace->setVisible(true); ui->line_find->setText( cur->textCursor().selectedText() ); ui->line_replace->setText(""); ui->line_replace->setFocus(); }
void MainUI::tabChanged(){ //update the buttons/menus based on the current widget PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } //should never happen though bool changes = cur->hasChange(); ui->actionSave_File->setEnabled(changes); this->setWindowTitle( ui->tabWidget->tabText( ui->tabWidget->currentIndex() ) ); if(!ui->line_find->hasFocus() && !ui->line_replace->hasFocus()){ ui->tabWidget->currentWidget()->setFocus(); } }
void MainUI::tabClosed(int tab){ PlainTextEditor *edit = static_cast<PlainTextEditor*>(ui->tabWidget->widget(tab)); if(edit==0){ return; } //should never happen if(edit->hasChange()){ //Verify if the user wants to lose any unsaved changes } ui->tabWidget->removeTab(tab); edit->deleteLater(); }
void MainUI::findPrev(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively | QTextDocument::FindBackward : QTextDocument::FindBackward ); if(!found){ //Try starting back at the bottom of the file cur->moveCursor(QTextCursor::End); cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively | QTextDocument::FindBackward : QTextDocument::FindBackward ); } }
void MainUI::findNext(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); if(!found){ //Try starting back at the top of the file cur->moveCursor(QTextCursor::Start); cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); } }
QString MainUI::currentFileDir(){ PlainTextEditor* cur = currentEditor(); QString dir; if(cur!=0){ if(cur->currentFile().startsWith("/")){ dir = cur->currentFile().section("/",0,-2); } } return dir; }
void BlackMilordTests::check_PlainTextEditor_setTextgetText() { PlainTextEditor *editor = Gui::plainTextEditor(); QString testString = "test"; editor->setPlainText(testString); QVERIFY(editor->toPlainText() == testString); testString = "test\ntest"; editor->setPlainText(testString); QVERIFY(editor->toPlainText() == testString); }
void BlackMilordTests::check_PlainTextEditor_getCursorPosition() { PlainTextEditor *editor = Gui::plainTextEditor(); QVERIFY(editor->getCursorPosition() == 0); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_A); QVERIFY(editor->getCursorPosition() == 1); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_B); QVERIFY(editor->getCursorPosition() == 2); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_Enter); QVERIFY(editor->getCursorPosition() == 3); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_A); QVERIFY(editor->getCursorPosition() == 4); }
void MainUI::UpdateHighlighting(QAction *act){ if(act!=0){ //Single-editor change PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } cur->LoadSyntaxRule(act->text()); }else{ //Have every editor reload the syntax rules (color changes) for(int i=0; i<ui->tabWidget->count(); i++){ static_cast<PlainTextEditor*>(ui->tabWidget->widget(i))->updateSyntaxColors(); } } }
void MainUI::replaceOne(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } //See if the current selection matches the find field first bool done = false; if(cur->textCursor().selectedText()==ui->line_find->text()){ cur->insertPlainText(ui->line_replace->text()); //done = true; }//else{ //Find/replace the next occurance of the string bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); //if(found){ cur->insertPlainText(ui->line_replace->text()); done = true;} //} /*if(done){ //Re-highlight the newly-inserted text cur->find( ui->line_replace->text(), QTextDocument::FindCaseSensitively | QTextDocument::FindBackward); }*/ }
void MainUI::updateTab(QString file){ PlainTextEditor *cur = 0; int index = -1; for(int i=0; i<ui->tabWidget->count(); i++){ PlainTextEditor *tmp = static_cast<PlainTextEditor*>(ui->tabWidget->widget(i)); if(tmp->currentFile()==file){ cur = tmp; index = i; break; } } if(cur==0){ return; } //should never happen bool changes = cur->hasChange(); //qDebug() << "Update Tab:" << file << cur << changes; ui->tabWidget->setTabText(index,(changes ? "*" : "") + file.section("/",-1)); ui->actionSave_File->setEnabled(changes); this->setWindowTitle( ui->tabWidget->tabText( ui->tabWidget->currentIndex() ) ); }
void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor) { PlainTextEditor *editorEditable = qobject_cast<PlainTextEditor *>(editor); if (editorEditable) { PlainTextEditorWidget *textEditor = static_cast<PlainTextEditorWidget *>(editorEditable->editorWidget()); if (textEditor->isMissingSyntaxDefinition() && !textEditor->ignoreMissingSyntaxDefinition() && TextEditorSettings::instance()->highlighterSettings().alertWhenNoDefinition()) { Core::EditorManager::instance()->showEditorInfoBar( Constants::INFO_SYNTAX_DEFINITION, tr("A highlight definition was not found for this file. " "Would you like to try to find one?"), tr("Show highlighter options"), textEditor, SLOT(acceptMissingSyntaxDefinitionInfo()), SLOT(ignoreMissingSyntaxDefinitionInfo())); return; } } Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_SYNTAX_DEFINITION); }
void MainUI::OpenFile(QString file){ QStringList files; if(file.isEmpty()){ //Prompt for a file to open files = QFileDialog::getOpenFileNames(this, tr("Open File(s)"), currentFileDir(), tr("Text Files (*)") ); if(files.isEmpty()){ return; } //cancelled }else{ files << file; } for(int i=0; i<files.length(); i++){ PlainTextEditor *edit = new PlainTextEditor(settings, this); connect(edit, SIGNAL(FileLoaded(QString)), this, SLOT(updateTab(QString)) ); connect(edit, SIGNAL(UnsavedChanges(QString)), this, SLOT(updateTab(QString)) ); ui->tabWidget->addTab(edit, files[i].section("/",-1)); edit->showLineNumbers(ui->actionLine_Numbers->isChecked()); edit->setLineWrapMode( ui->actionWrap_Lines->isChecked() ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap); edit->setFocusPolicy(Qt::ClickFocus); //no "tabbing" into this widget ui->tabWidget->setCurrentWidget(edit); edit->LoadFile(files[i]); edit->setFocus(); QApplication::processEvents(); //to catch the fileLoaded() signal } }
void BlackMilordTests::check_PlainTextEditor_setCursorPosition() { PlainTextEditor *editor = Gui::plainTextEditor(); QString testString = "testtest"; editor->setPlainText(testString); QVERIFY(editor->getCursorPosition() == 8); editor->setCursorPosition(4); QVERIFY(editor->getCursorPosition() == 4); editor->setCursorPosition(0); QVERIFY(editor->getCursorPosition() == 0); editor->setCursorPositionToEnd(); QVERIFY(editor->getCursorPosition() == 8); editor->setCursorPositionToStart(); QVERIFY(editor->getCursorPosition() == 0); }
void MainUI::SaveFileAs(){ PlainTextEditor *cur = currentEditor(); if(cur==0){ return; } cur->SaveFile(true); }
void BlackMilordTests::check_PlainTextEditor_redoUndoAvailability() { PlainTextEditor *editor = Gui::plainTextEditor(); QVERIFY(!editor->canRedo()); QVERIFY(!editor->canUndo()); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_A); QVERIFY(!editor->canRedo()); QVERIFY(editor->canUndo()); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_Enter); QVERIFY(!editor->canRedo()); QVERIFY(editor->canUndo()); QTest::keyEvent(QTest::Click, editor->asWidget(), Qt::Key_A); QVERIFY(!editor->canRedo()); QVERIFY(editor->canUndo()); editor->undo(); QVERIFY(editor->canRedo()); QVERIFY(editor->canUndo()); editor->undo(); QVERIFY(editor->canRedo()); QVERIFY(!editor->canUndo()); editor->redo(); QVERIFY(editor->canRedo()); QVERIFY(editor->canUndo()); editor->redo(); QVERIFY(!editor->canRedo()); QVERIFY(editor->canUndo()); }
void BlackMilordTests::check_PlainTextEditor_selection() { PlainTextEditor *editor = Gui::plainTextEditor(); QString testString = "testtest"; editor->setPlainText(testString); QVERIFY(editor->hasSelection() == false); QVERIFY(editor->getSelectionStart() == editor->getSelectionEnd()); QVERIFY(editor->getSelectionStart() == editor->getCursorPosition()); editor->setSelection(0, 4); QVERIFY(editor->hasSelection() == true); QVERIFY(editor->getSelectionStart() == 0); QVERIFY(editor->getSelectionEnd() == 4); QVERIFY(editor->getSelectedText() == "test"); editor->clearSelection(); QVERIFY(editor->hasSelection() == false); QVERIFY(editor->getSelectionStart() == editor->getSelectionEnd()); QVERIFY(editor->getSelectionStart() == editor->getCursorPosition()); }
Core::IEditor *PlainTextEditorFactory::createEditor(QWidget *parent) { PlainTextEditor *rc = new PlainTextEditor(parent); TextEditorPlugin::instance()->initializeEditor(rc); return rc->editableInterface(); }
//Find/Replace functions void MainUI::closeFindReplace(){ ui->groupReplace->setVisible(false); PlainTextEditor *cur = currentEditor(); if(cur!=0){ cur->setFocus(); } }