void QmlEngine::gotoLocation(const Location &location) { const QString fileName = location.fileName(); if (QUrl(fileName).isLocalFile()) { // internal file from source files -> show generated .js QTC_ASSERT(m_sourceDocuments.contains(fileName), return); QString titlePattern = tr("JS Source for %1").arg(fileName); //Check if there are open documents with the same title foreach (Core::IDocument *document, Core::EditorManager::documentModel()->openedDocuments()) { if (document->displayName() == titlePattern) { Core::EditorManager::activateEditorForDocument(document); return; } } Core::IEditor *editor = Core::EditorManager::openEditorWithContents( QmlJSEditor::Constants::C_QMLJSEDITOR_ID, &titlePattern); if (editor) { editor->document()->setProperty(Constants::OPENED_BY_DEBUGGER, true); QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(editor->widget()); if (plainTextEdit) plainTextEdit->setReadOnly(true); updateDocument(editor->document(), m_sourceDocuments.value(fileName)); } } else {
void TabbedEditorWidget::handleDocumentChanged() { if (!tabWidget) return; Core::IEditor *editor = this->getEditor(tabWidget->currentIndex()); if (!editor) return; QString title = editor->document()->displayName(); if (editor->document()->isModified()) title += QString::fromUtf8("*"); tabWidget->setTabText(tabWidget->currentIndex(), title); }
Core::IDocument *FormEditorFactory::open(const QString &fileName) { Core::IEditor *iface = Core::EditorManager::openEditor(fileName, id()); if (!iface) return 0; if (qobject_cast<FormWindowEditor *>(iface)) { Core::InfoBarEntry info(QLatin1String(Constants::INFO_READ_ONLY), tr("This file can only be edited in <b>Design</b> mode.")); info.setCustomButtonInfo(tr("Switch mode"), this, SLOT(designerModeClicked())); iface->document()->infoBar()->addInfo(info); } return iface->document(); }
void Internal::TextEditorPlugin::testBlockSelectionTransformation() { // fetch test data QFETCH(QString, input); QFETCH(QString, transformedText); QFETCH(TestBlockSelection, selection); QFETCH(TransFormationType, type); // open editor Core::IEditor *editor = Core::EditorManager::openEditorWithContents( Core::Constants::K_DEFAULT_TEXT_EDITOR_ID, 0, input.toLatin1()); QVERIFY(editor); if (BaseTextEditor *textEditor = qobject_cast<BaseTextEditor*>(editor)) { TextEditorWidget *editorWidget = textEditor->editorWidget(); editorWidget->setBlockSelection(selection.positionBlock, selection.positionColumn, selection.anchorBlock, selection.anchorColumn); editorWidget->update(); // transform blockselection switch (type) { case Uppercase: editorWidget->uppercaseSelection(); break; case Lowercase: editorWidget->lowercaseSelection(); break; } QCOMPARE(textEditor->textDocument()->plainText(), transformedText); } Core::EditorManager::closeDocument(editor->document(), false); }
Core::IDocument *DiffEditorController::findOrCreateDocument(const QString &vcsId, const QString &displayName) { QString preferredDisplayName = displayName; Core::IEditor *editor = Core::EditorManager::openEditorWithContents( Constants::DIFF_EDITOR_ID, &preferredDisplayName, QByteArray(), vcsId); return editor ? editor->document() : 0; }
Core::IDocument *GLSLEditorFactory::open(const QString &fileName) { Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id()); if (!iface) { qWarning() << "QmlEditorFactory::open: openEditor failed for " << fileName; return 0; } return iface->document(); }
void Manager::gotoLocations(const QList<QVariant> &list) { QSet<SymbolLocation> locations = Utils::roleToLocations(list); if (locations.count() == 0) return; QString fileName; int line = 0; int column = 0; bool currentPositionAvailable = false; // what is open now? Core::IEditor *editor = Core::EditorManager::instance()->currentEditor(); if (editor) { // get current file name Core::IDocument *document = editor->document(); if (document) fileName = document->fileName(); // if text file - what is current position? TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor); if (textEditor) { // there is open currently text editor int position = textEditor->position(); textEditor->convertPosition(position, &line, &column); currentPositionAvailable = true; } } // if there is something open - try to check, is it currently activated symbol? if (currentPositionAvailable) { SymbolLocation current(fileName, line, column); QSet<SymbolLocation>::const_iterator it = locations.find(current); QSet<SymbolLocation>::const_iterator end = locations.constEnd(); // is it known location? if (it != end) { // found - do one additional step ++it; if (it == end) it = locations.begin(); const SymbolLocation &found = *it; gotoLocation(found.fileName(), found.line(), found.column()); return; } } // no success - open first item in the list const SymbolLocation loc = *locations.constBegin(); gotoLocation(loc.fileName(), loc.line(), loc.column()); }
void TabBar::contextMenuEvent(QContextMenuEvent *event) { const int index = tabAt(event->pos()); if (index == -1) return; QScopedPointer<QMenu> menu(new QMenu()); Core::IEditor *editor = m_editors[index]; Core::DocumentModel::Entry *entry = Core::DocumentModel::entryForDocument(editor->document()); Core::EditorManager::addSaveAndCloseEditorActions(menu.data(), entry, editor); menu->addSeparator(); Core::EditorManager::addNativeDirAndOpenWithActions(menu.data(), entry); menu->exec(mapToGlobal(event->pos())); }
void Internal::TextEditorPlugin::testBlockSelectionCopy() { // fetch test data QFETCH(QString, copiedText); QFETCH(TestBlockSelection, selection); // open editor Core::IEditor *editor = Core::EditorManager::openEditorWithContents( Core::Constants::K_DEFAULT_TEXT_EDITOR_ID, 0, text); QVERIFY(editor); if (BaseTextEditor *textEditor = qobject_cast<BaseTextEditor*>(editor)) { TextEditorWidget *editorWidget = textEditor->editorWidget(); editorWidget->setBlockSelection(selection.positionBlock, selection.positionColumn, selection.anchorBlock, selection.anchorColumn); editorWidget->update(); editorWidget->copy(); QCOMPARE(qApp->clipboard()->text(), copiedText); } Core::EditorManager::closeDocument(editor->document(), false); }
Core::IDocument *PlainTextEditorFactory::open(const QString &fileName) { Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id()); return iface ? iface->document() : 0; }