void SettingsDialog::showPage(Id categoryId, Id pageId) { // handle the case of "show last page" Id initialCategory = categoryId; Id initialPage = pageId; if (!initialCategory.isValid() && !initialPage.isValid()) { QSettings *settings = ICore::settings(); initialCategory = Id::fromSetting(settings->value(QLatin1String(categoryKeyC))); initialPage = Id::fromSetting(settings->value(QLatin1String(pageKeyC))); } int initialCategoryIndex = -1; int initialPageIndex = -1; const QList<Category*> &categories = m_model->categories(); for (int i = 0; i < categories.size(); ++i) { Category *category = categories.at(i); if (category->id == initialCategory) { initialCategoryIndex = i; for (int j = 0; j < category->pages.size(); ++j) { IOptionsPage *page = category->pages.at(j); if (page->id() == initialPage) initialPageIndex = j; } } } if (initialCategoryIndex != -1) { const QModelIndex modelIndex = m_proxyModel->mapFromSource(m_model->index(initialCategoryIndex)); m_categoryList->setCurrentIndex(modelIndex); if (initialPageIndex != -1) categories.at(initialCategoryIndex)->tabWidget->setCurrentIndex(initialPageIndex); } }
void SettingsDialog::showPage(const Id pageId) { // handle the case of "show last page" Id initialPageId = pageId; if (!initialPageId.isValid()) { QSettings *settings = ICore::settings(); initialPageId = Id::fromSetting(settings->value(QLatin1String(pageKeyC))); } int initialCategoryIndex = -1; int initialPageIndex = -1; const QList<Category*> &categories = m_model->categories(); if (initialPageId.isValid()) { // First try categories without lazy items. for (int i = 0; i < categories.size(); ++i) { Category *category = categories.at(i); if (category->providers.isEmpty()) { // no providers ensureCategoryWidget(category); if (category->findPageById(initialPageId, &initialPageIndex)) { initialCategoryIndex = i; break; } } } if (initialPageIndex == -1) { // On failure, expand the remaining items. for (int i = 0; i < categories.size(); ++i) { Category *category = categories.at(i); if (!category->providers.isEmpty()) { // has providers ensureCategoryWidget(category); if (category->findPageById(initialPageId, &initialPageIndex)) { initialCategoryIndex = i; break; } } } } } if (initialPageId.isValid() && initialPageIndex == -1) return; // Unknown settings page, probably due to missing plugin. if (initialCategoryIndex != -1) { const QModelIndex modelIndex = m_proxyModel->mapFromSource(m_model->index(initialCategoryIndex)); m_categoryList->setCurrentIndex(modelIndex); if (initialPageIndex != -1) categories.at(initialCategoryIndex)->tabWidget->setCurrentIndex(initialPageIndex); } }
TextDocument::TextDocument(Id id) : d(new TextDocumentPrivate) { QObject::connect(&d->m_document, &QTextDocument::modificationChanged, [this](bool modified) { // we only want to update the block revisions when going back to the saved version, // e.g. with undo if (!modified) d->updateRevisions(); emit changed(); }); connect(&d->m_document, &QTextDocument::contentsChanged, this, &Core::IDocument::contentsChanged); connect(&d->m_document, &QTextDocument::contentsChange, this, &TextDocument::contentsChangedWithPosition); // set new document layout QTextOption opt = d->m_document.defaultTextOption(); opt.setTextDirection(Qt::LeftToRight); opt.setFlags(opt.flags() | QTextOption::IncludeTrailingSpaces | QTextOption::AddSpaceForLineAndParagraphSeparators ); d->m_document.setDefaultTextOption(opt); d->m_document.setDocumentLayout(new TextDocumentLayout(&d->m_document)); if (id.isValid()) setId(id); setSuspendAllowed(true); }
void SettingsDialog::showPage(Id categoryId, Id pageId) { // handle the case of "show last page" Id initialCategory = categoryId; Id initialPage = pageId; if (!initialCategory.isValid() && !initialPage.isValid()) { QSettings *settings = ICore::settings(); initialCategory = Id::fromSetting(settings->value(QLatin1String(categoryKeyC))); initialPage = Id::fromSetting(settings->value(QLatin1String(pageKeyC))); } if (!initialCategory.isValid()) // no category given and no old setting return; int initialCategoryIndex = -1; int initialPageIndex = -1; const QList<Category*> &categories = m_model->categories(); for (int i = 0; i < categories.size(); ++i) { Category *category = categories.at(i); if (category->id == initialCategory) { initialCategoryIndex = i; if (initialPage.isValid()) { ensureCategoryWidget(category); for (int j = 0; j < category->pages.size(); ++j) { IOptionsPage *page = category->pages.at(j); if (page->id() == initialPage) initialPageIndex = j; } } break; } } QTC_ASSERT(initialCategoryIndex != -1, qDebug("Unknown category: %s", initialCategory.name().constData()); return); QTC_ASSERT(!initialPage.isValid() || initialPageIndex != -1, qDebug("Unknown page: %s", initialPage.name().constData())); if (initialCategoryIndex != -1) { const QModelIndex modelIndex = m_proxyModel->mapFromSource(m_model->index(initialCategoryIndex)); m_categoryList->setCurrentIndex(modelIndex); if (initialPageIndex != -1) categories.at(initialCategoryIndex)->tabWidget->setCurrentIndex(initialPageIndex); } }
void MainWindow::openFileWith() { foreach (const QString &fileName, EditorManager::getOpenFileNames()) { bool isExternal; const Id editorId = EditorManagerPrivate::getOpenWithEditorId(fileName, &isExternal); if (!editorId.isValid()) continue; if (isExternal) EditorManager::openExternalEditor(fileName, editorId); else EditorManagerPrivate::openEditorWith(fileName, editorId); }
void ProjectFileWizardExtension::applyCodeStyle(GeneratedFile *file) const { if (file->isBinary() || file->contents().isEmpty()) return; // nothing to do MimeType mt = MimeDatabase::findByFile(QFileInfo(file->path())); Id languageId = TextEditorSettings::languageId(mt.type()); if (!languageId.isValid()) return; // don't modify files like *.ui *.pro FolderNode *folder = m_context->page->currentNode(); Project *baseProject = SessionManager::projectForNode(folder); ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(languageId); Indenter *indenter = 0; if (factory) indenter = factory->createIndenter(); if (!indenter) indenter = new NormalIndenter(); ICodeStylePreferences *codeStylePrefs = codeStylePreferences(baseProject, languageId); indenter->setCodeStylePreferences(codeStylePrefs); QTextDocument doc(file->contents()); QTextCursor cursor(&doc); cursor.select(QTextCursor::Document); indenter->indent(&doc, cursor, QChar::Null, codeStylePrefs->currentTabSettings()); delete indenter; if (TextEditorSettings::storageSettings().m_cleanWhitespace) { QTextBlock block = doc.firstBlock(); while (block.isValid()) { codeStylePrefs->currentTabSettings().removeTrailingWhitespace(cursor, block); block = block.next(); } } file->setContents(doc.toPlainText()); }
TextDocument::TextDocument(Id id) : d(new TextDocumentPrivate) { connect(&d->m_document, &QTextDocument::modificationChanged, this, &TextDocument::modificationChanged); connect(&d->m_document, &QTextDocument::contentsChanged, this, &Core::IDocument::contentsChanged); connect(&d->m_document, &QTextDocument::contentsChange, this, &TextDocument::contentsChangedWithPosition); // set new document layout QTextOption opt = d->m_document.defaultTextOption(); opt.setTextDirection(Qt::LeftToRight); opt.setFlags(opt.flags() | QTextOption::IncludeTrailingSpaces | QTextOption::AddSpaceForLineAndParagraphSeparators ); d->m_document.setDefaultTextOption(opt); d->m_document.setDocumentLayout(new TextDocumentLayout(&d->m_document)); if (id.isValid()) setId(id); setSuspendAllowed(true); }