diff options
Diffstat (limited to 'src/plugins/coreplugin')
-rw-r--r-- | src/plugins/coreplugin/editormanager/documentmodel.cpp | 59 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/documentmodel.h | 6 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/documentmodel_p.h | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/editorview.cpp | 7 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/openeditorsview.cpp | 11 | ||||
-rw-r--r-- | src/plugins/coreplugin/editortoolbar.cpp | 15 | ||||
-rw-r--r-- | src/plugins/coreplugin/find/findtoolbar.cpp | 8 | ||||
-rw-r--r-- | src/plugins/coreplugin/helpmanager.cpp | 4 | ||||
-rw-r--r-- | src/plugins/coreplugin/manhattanstyle.cpp | 12 | ||||
-rw-r--r-- | src/plugins/coreplugin/menubarfilter.h | 1 |
10 files changed, 77 insertions, 50 deletions
diff --git a/src/plugins/coreplugin/editormanager/documentmodel.cpp b/src/plugins/coreplugin/editormanager/documentmodel.cpp index fb6bf68949..fae56815ca 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel.cpp +++ b/src/plugins/coreplugin/editormanager/documentmodel.cpp @@ -76,9 +76,8 @@ void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry) fixedPath = DocumentManager::filePathKey(fileName.toString(), DocumentManager::ResolveLinks); // replace a non-loaded entry (aka 'suspended') if possible - int previousIndex = indexOfFilePath(fileName); - if (previousIndex >= 0) { - DocumentModel::Entry *previousEntry = m_entries.at(previousIndex); + DocumentModel::Entry *previousEntry = DocumentModel::entryForFilePath(fileName); + if (previousEntry) { const bool replace = !entry->isSuspended && previousEntry->isSuspended; if (replace) { previousEntry->isSuspended = false; @@ -180,13 +179,16 @@ QIcon DocumentModelPrivate::lockedIcon() return icon; } -int DocumentModelPrivate::indexOfFilePath(const Utils::FileName &filePath) const +Utils::optional<int> DocumentModelPrivate::indexOfFilePath(const Utils::FileName &filePath) const { if (filePath.isEmpty()) - return -1; + return Utils::nullopt; const QString fixedPath = DocumentManager::filePathKey(filePath.toString(), DocumentManager::ResolveLinks); - return m_entries.indexOf(m_entryByFixedPath.value(fixedPath)); + const int index = m_entries.indexOf(m_entryByFixedPath.value(fixedPath)); + if (index < 0) + return Utils::nullopt; + return index; } void DocumentModelPrivate::removeDocument(int idx) @@ -210,11 +212,14 @@ void DocumentModelPrivate::removeDocument(int idx) delete entry; } -int DocumentModelPrivate::indexOfDocument(IDocument *document) const +Utils::optional<int> DocumentModelPrivate::indexOfDocument(IDocument *document) const { - return Utils::indexOf(m_entries, [&document](DocumentModel::Entry *entry) { + const int index = Utils::indexOf(m_entries, [&document](DocumentModel::Entry *entry) { return entry->document == document; }); + if (index < 0) + return Utils::nullopt; + return index; } Qt::ItemFlags DocumentModelPrivate::flags(const QModelIndex &index) const @@ -292,14 +297,14 @@ void DocumentModelPrivate::itemChanged() { IDocument *document = qobject_cast<IDocument *>(sender()); - int idx = indexOfDocument(document); - if (idx < 0) + const Utils::optional<int> idx = indexOfDocument(document); + if (!idx) return; const QString fileName = document->filePath().toString(); QString fixedPath; if (!fileName.isEmpty()) fixedPath = DocumentManager::filePathKey(fileName, DocumentManager::ResolveLinks); - DocumentModel::Entry *entry = m_entries.at(idx); + DocumentModel::Entry *entry = m_entries.at(idx.value()); bool found = false; // The entry's fileName might have changed, so find the previous fileName that was associated // with it and remove it, then add the new fileName. @@ -316,8 +321,8 @@ void DocumentModelPrivate::itemChanged() } if (!found && !fixedPath.isEmpty()) m_entryByFixedPath[fixedPath] = entry; - if (!disambiguateDisplayNames(m_entries.at(idx))) { - QModelIndex mindex = index(idx + 1/*<no document>*/, 0); + if (!disambiguateDisplayNames(m_entries.at(idx.value()))) { + QModelIndex mindex = index(idx.value() + 1/*<no document>*/, 0); emit dataChanged(mindex, mindex); } } @@ -507,11 +512,16 @@ QList<IEditor *> DocumentModel::editorsForDocuments(const QList<IDocument *> &do return result; } -int DocumentModel::indexOfDocument(IDocument *document) +Utils::optional<int> DocumentModel::indexOfDocument(IDocument *document) { return d->indexOfDocument(document); } +Utils::optional<int> DocumentModel::indexOfFilePath(const Utils::FileName &filePath) +{ + return d->indexOfFilePath(filePath); +} + DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document) { return Utils::findOrDefault(d->m_entries, @@ -520,10 +530,10 @@ DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document) DocumentModel::Entry *DocumentModel::entryForFilePath(const Utils::FileName &filePath) { - const int index = d->indexOfFilePath(filePath); - if (index < 0) + const Utils::optional<int> index = d->indexOfFilePath(filePath); + if (!index) return nullptr; - return d->m_entries.at(index); + return d->m_entries.at(index.value()); } QList<IDocument *> DocumentModel::openedDocuments() @@ -533,10 +543,10 @@ QList<IDocument *> DocumentModel::openedDocuments() IDocument *DocumentModel::documentForFilePath(const QString &filePath) { - const int index = d->indexOfFilePath(Utils::FileName::fromString(filePath)); - if (index < 0) - return 0; - return d->m_entries.at(index)->document; + const Utils::optional<int> index = d->indexOfFilePath(Utils::FileName::fromString(filePath)); + if (!index) + return nullptr; + return d->m_entries.at(index.value())->document; } QList<IEditor *> DocumentModel::editorsForFilePath(const QString &filePath) @@ -560,11 +570,14 @@ int DocumentModel::entryCount() return d->m_entries.count(); } -int DocumentModel::rowOfDocument(IDocument *document) +Utils::optional<int> DocumentModel::rowOfDocument(IDocument *document) { if (!document) return 0 /*<no document>*/; - return indexOfDocument(document) + 1/*<no document>*/; + const Utils::optional<int> index = indexOfDocument(document); + if (index) + return index.value() + 1/*correction for <no document>*/; + return Utils::nullopt; } QList<DocumentModel::Entry *> DocumentModel::entries() diff --git a/src/plugins/coreplugin/editormanager/documentmodel.h b/src/plugins/coreplugin/editormanager/documentmodel.h index e0b14ed3aa..09bb465272 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel.h +++ b/src/plugins/coreplugin/editormanager/documentmodel.h @@ -29,6 +29,7 @@ #include "../id.h" #include <utils/fileutils.h> +#include <utils/optional.h> QT_BEGIN_NAMESPACE class QAbstractItemModel; @@ -63,11 +64,12 @@ public: }; static Entry *entryAtRow(int row); - static int rowOfDocument(IDocument *document); + static Utils::optional<int> rowOfDocument(IDocument *document); static int entryCount(); static QList<Entry *> entries(); - static int indexOfDocument(IDocument *document); + static Utils::optional<int> indexOfDocument(IDocument *document); + static Utils::optional<int> indexOfFilePath(const Utils::FileName &filePath); static Entry *entryForDocument(IDocument *document); static Entry *entryForFilePath(const Utils::FileName &filePath); static QList<IDocument *> openedDocuments(); diff --git a/src/plugins/coreplugin/editormanager/documentmodel_p.h b/src/plugins/coreplugin/editormanager/documentmodel_p.h index 98223e63ed..ae6ff016fa 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel_p.h +++ b/src/plugins/coreplugin/editormanager/documentmodel_p.h @@ -58,8 +58,8 @@ public: void addEntry(DocumentModel::Entry *entry); void removeDocument(int idx); - int indexOfFilePath(const Utils::FileName &filePath) const; - int indexOfDocument(IDocument *document) const; + Utils::optional<int> indexOfFilePath(const Utils::FileName &filePath) const; + Utils::optional<int> indexOfDocument(IDocument *document) const; bool disambiguateDisplayNames(DocumentModel::Entry *entry); diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index b46c71f772..4d6dc67623 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -268,11 +268,10 @@ void EditorView::updateEditorHistory(IEditor *editor, QList<EditLocation> &histo location.state = QVariant(state); for (int i = 0; i < history.size(); ++i) { - if (history.at(i).document == 0 - || history.at(i).document == document - ){ + const EditLocation &item = history.at(i); + if (item.document == document + || !DocumentModel::indexOfFilePath(FileName::fromString(item.fileName))) { history.removeAt(i--); - continue; } } history.prepend(location); diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp index 72622a4a75..1a7e0d618c 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp @@ -30,6 +30,7 @@ #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/command.h> +#include <utils/qtcassert.h> #include <QApplication> #include <QMenu> @@ -70,15 +71,15 @@ OpenEditorsWidget::~OpenEditorsWidget() void OpenEditorsWidget::updateCurrentItem(IEditor *editor) { - IDocument *document = editor ? editor->document() : 0; - QModelIndex index = m_model->index(DocumentModel::indexOfDocument(document), 0); - if (!index.isValid()) { + if (!editor) { clearSelection(); return; } - setCurrentIndex(index); + const Utils::optional<int> index = DocumentModel::indexOfDocument(editor->document()); + if (QTC_GUARD(index)) + setCurrentIndex(m_model->index(index.value(), 0)); selectionModel()->select(currentIndex(), - QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); scrollTo(currentIndex()); } diff --git a/src/plugins/coreplugin/editortoolbar.cpp b/src/plugins/coreplugin/editortoolbar.cpp index b41245cd25..3383325e4c 100644 --- a/src/plugins/coreplugin/editortoolbar.cpp +++ b/src/plugins/coreplugin/editortoolbar.cpp @@ -320,7 +320,9 @@ void EditorToolBar::setMenuProvider(const EditorToolBar::MenuProvider &provider) void EditorToolBar::setCurrentEditor(IEditor *editor) { IDocument *document = editor ? editor->document() : 0; - d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document)); + const Utils::optional<int> index = DocumentModel::rowOfDocument(document); + if (QTC_GUARD(index)) + d->m_editorList->setCurrentIndex(index.value()); // If we never added the toolbar from the editor, we will never change // the editor, so there's no need to update the toolbar either. @@ -332,8 +334,11 @@ void EditorToolBar::setCurrentEditor(IEditor *editor) void EditorToolBar::updateEditorListSelection(IEditor *newSelection) { - if (newSelection) - d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(newSelection->document())); + if (newSelection) { + const Utils::optional<int> index = DocumentModel::rowOfDocument(newSelection->document()); + if (QTC_GUARD(index)) + d->m_editorList->setCurrentIndex(index.value()); + } } void EditorToolBar::changeActiveEditor(int row) @@ -403,7 +408,9 @@ void EditorToolBar::updateDocumentStatus(IDocument *document) return; } - d->m_editorList->setCurrentIndex(DocumentModel::rowOfDocument(document)); + const Utils::optional<int> index = DocumentModel::rowOfDocument(document); + if (QTC_GUARD(index)) + d->m_editorList->setCurrentIndex(index.value()); if (document->filePath().isEmpty()) { d->m_lockButton->setIcon(QIcon()); diff --git a/src/plugins/coreplugin/find/findtoolbar.cpp b/src/plugins/coreplugin/find/findtoolbar.cpp index 5ca9833343..793b2990f8 100644 --- a/src/plugins/coreplugin/find/findtoolbar.cpp +++ b/src/plugins/coreplugin/find/findtoolbar.cpp @@ -973,16 +973,12 @@ void FindToolBar::setBackward(bool backward) void FindToolBar::setLightColoredIcon(bool lightColored) { if (lightColored) { - m_ui.findNextButton->setIcon(QIcon()); - m_ui.findNextButton->setArrowType(Qt::RightArrow); - m_ui.findPreviousButton->setIcon(QIcon()); - m_ui.findPreviousButton->setArrowType(Qt::LeftArrow); + m_ui.findNextButton->setIcon(Utils::Icons::NEXT.icon()); + m_ui.findPreviousButton->setIcon(Utils::Icons::PREV.icon()); m_ui.close->setIcon(Utils::Icons::CLOSE_FOREGROUND.icon()); } else { m_ui.findNextButton->setIcon(Utils::Icons::NEXT_TOOLBAR.icon()); - m_ui.findNextButton->setArrowType(Qt::NoArrow); m_ui.findPreviousButton->setIcon(Utils::Icons::PREV_TOOLBAR.icon()); - m_ui.findPreviousButton->setArrowType(Qt::NoArrow); m_ui.close->setIcon(Utils::Icons::CLOSE_TOOLBAR.icon()); } } diff --git a/src/plugins/coreplugin/helpmanager.cpp b/src/plugins/coreplugin/helpmanager.cpp index 76d5aa787f..438314e7a1 100644 --- a/src/plugins/coreplugin/helpmanager.cpp +++ b/src/plugins/coreplugin/helpmanager.cpp @@ -157,6 +157,7 @@ void HelpManager::registerDocumentationNow(QFutureInterface<bool> &futureInterfa QHelpEngineCore helpEngine(collectionFilePath()); bool docsChanged = false; + QStringList nameSpaces = d->m_helpEngine->registeredDocumentations(); for (const QString &file : files) { if (futureInterface.isCanceled()) break; @@ -164,8 +165,9 @@ void HelpManager::registerDocumentationNow(QFutureInterface<bool> &futureInterfa const QString &nameSpace = helpEngine.namespaceName(file); if (nameSpace.isEmpty()) continue; - if (!helpEngine.registeredDocumentations().contains(nameSpace)) { + if (!nameSpaces.contains(nameSpace)) { if (helpEngine.registerDocumentation(file)) { + nameSpaces.append(nameSpace); docsChanged = true; } else { qWarning() << "Error registering namespace '" << nameSpace diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp index 4a68fa4110..add7b8c753 100644 --- a/src/plugins/coreplugin/manhattanstyle.cpp +++ b/src/plugins/coreplugin/manhattanstyle.cpp @@ -288,6 +288,12 @@ void ManhattanStyle::polish(QWidget *widget) } else if (qobject_cast<QStatusBar*>(widget)) { widget->setFixedHeight(StyleHelper::navigationWidgetHeight() + 2); } else if (qobject_cast<QComboBox*>(widget)) { + const bool isLightColored = lightColored(widget); + QPalette palette = panelPalette(widget->palette(), isLightColored); + if (!isLightColored) + palette.setBrush(QPalette::All, QPalette::Foreground, + creatorTheme()->color(Theme::ComboBoxTextColor)); + widget->setPalette(palette); widget->setMaximumHeight(StyleHelper::navigationWidgetHeight() - 2); widget->setAttribute(Qt::WA_Hover); } @@ -730,9 +736,9 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt painter->setPen(StyleHelper::toolBarDropShadowColor()); painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text); } - painter->setPen(creatorTheme()->color((option->state & State_Enabled) - ? Theme::ComboBoxTextColor - : Theme::IconsDisabledColor)); + painter->setPen((option->state & State_Enabled) + ? option->palette.color(QPalette::Foreground) + : creatorTheme()->color(Theme::IconsDisabledColor)); painter->drawText(editRect.adjusted(1, 0, -1, 0), Qt::AlignLeft | Qt::AlignVCenter, text); painter->restore(); diff --git a/src/plugins/coreplugin/menubarfilter.h b/src/plugins/coreplugin/menubarfilter.h index 9251df7da2..c7b137e6a9 100644 --- a/src/plugins/coreplugin/menubarfilter.h +++ b/src/plugins/coreplugin/menubarfilter.h @@ -37,6 +37,7 @@ namespace Internal { class MenuBarFilter : public ILocatorFilter { + Q_OBJECT public: MenuBarFilter(); |