diff --git a/src/plugins/coreplugin/locator/locator.cpp b/src/plugins/coreplugin/locator/locator.cpp index 55aa984c08d..563a1d6010c 100644 --- a/src/plugins/coreplugin/locator/locator.cpp +++ b/src/plugins/coreplugin/locator/locator.cpp @@ -166,6 +166,7 @@ void Locator::loadSettings() const Settings def; DB::beginGroup(settingsGroup); m_refreshTimer.setInterval(minutes(DB::value("RefreshInterval", 60).toInt())); + m_relativePaths = DB::value("RelativePaths", false).toBool(); m_settings.useCenteredPopup = DB::value(kUseCenteredPopup, def.useCenteredPopup).toBool(); for (ILocatorFilter *filter : std::as_const(m_filters)) { @@ -294,6 +295,7 @@ void Locator::saveSettings() const DB::beginGroup("Locator"); DB::remove(QString()); DB::setValue("RefreshInterval", refreshInterval()); + DB::setValue("RelativePaths", relativePaths()); DB::setValueWithDefault(kUseCenteredPopup, m_settings.useCenteredPopup, def.useCenteredPopup); for (ILocatorFilter *filter : m_filters) { if (!m_customFilters.contains(filter) && filter->id().isValid()) { @@ -363,6 +365,16 @@ void Locator::setRefreshInterval(int interval) m_refreshTimer.start(); } +bool Locator::relativePaths() const +{ + return m_relativePaths; +} + +void Locator::setRelativePaths(bool use) +{ + m_relativePaths = use; +} + bool Locator::useCenteredPopupForShortcut() { return m_instance->m_settings.useCenteredPopup; diff --git a/src/plugins/coreplugin/locator/locator.h b/src/plugins/coreplugin/locator/locator.h index cee26782a6f..6cc69c6f9a6 100644 --- a/src/plugins/coreplugin/locator/locator.h +++ b/src/plugins/coreplugin/locator/locator.h @@ -40,6 +40,8 @@ public: void setCustomFilters(QList f); int refreshInterval() const; void setRefreshInterval(int interval); + bool relativePaths() const; + void setRelativePaths(bool use); static bool useCenteredPopupForShortcut(); static void setUseCenteredPopupForShortcut(bool center); @@ -73,6 +75,7 @@ private: QTimer m_refreshTimer; Tasking::TaskTreeRunner m_taskTreeRunner; QList m_refreshingFilters; + bool m_relativePaths = false; }; } // namespace Internal diff --git a/src/plugins/coreplugin/locator/locatorsettingspage.cpp b/src/plugins/coreplugin/locator/locatorsettingspage.cpp index 8f549cb1138..d379a5c858e 100644 --- a/src/plugins/coreplugin/locator/locatorsettingspage.cpp +++ b/src/plugins/coreplugin/locator/locatorsettingspage.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -273,6 +274,12 @@ public: m_refreshInterval->setSingleStep(5); m_refreshInterval->setValue(60); + auto relativePathsLabel = new QLabel(Tr::tr("Show Paths in Relation to Active Project:")); + relativePathsLabel->setToolTip(Tr::tr("Locator filters show relative paths to the active project when possible.")); + + m_relativePaths = new QCheckBox; + m_relativePaths->setToolTip(relativePathsLabel->toolTip()); + auto filterEdit = new FancyLineEdit; filterEdit->setFiltering(true); @@ -320,7 +327,9 @@ public: m_filterList, buttons, br, - Span(2, Row{refreshIntervalLabel, m_refreshInterval, st})} + Span(2, Row{refreshIntervalLabel, m_refreshInterval, st}), + br, + Span(2, Row{relativePathsLabel, m_relativePaths, st})} .attachTo(this); connect(filterEdit, &FancyLineEdit::filterChanged, this, &LocatorSettingsWidget::setFilter); @@ -355,6 +364,7 @@ public: addButton->setMenu(addMenu); m_refreshInterval->setValue(m_plugin->refreshInterval()); + m_relativePaths->setChecked(m_plugin->relativePaths()); saveFilterStates(); } @@ -376,6 +386,7 @@ private: QPushButton *m_removeButton; QPushButton *m_editButton; QSpinBox *m_refreshInterval; + QCheckBox *m_relativePaths; Locator *m_plugin = nullptr; Utils::TreeModel<> *m_model = nullptr; QSortFilterProxyModel *m_proxyModel = nullptr; @@ -399,6 +410,7 @@ void LocatorSettingsWidget::apply() m_plugin->setFilters(m_filters); m_plugin->setCustomFilters(m_customFilters); m_plugin->setRefreshInterval(m_refreshInterval->value()); + m_plugin->setRelativePaths(m_relativePaths->isChecked()); requestRefresh(); m_plugin->saveSettings(); saveFilterStates(); diff --git a/src/plugins/coreplugin/locator/locatorwidget.cpp b/src/plugins/coreplugin/locator/locatorwidget.cpp index 6b008ccc13a..e6acfee42f7 100644 --- a/src/plugins/coreplugin/locator/locatorwidget.cpp +++ b/src/plugins/coreplugin/locator/locatorwidget.cpp @@ -162,8 +162,13 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const case Qt::DisplayRole: if (index.column() == DisplayNameColumn) return m_entries.at(index.row()).displayName; - else if (index.column() == ExtraInfoColumn) - return m_entries.at(index.row()).extraInfo; + if (index.column() == ExtraInfoColumn) { + if (Locator::instance()->relativePaths()) { + return ICore::pathRelativeToActiveProject(FilePath::fromUserInput(m_entries.at(index.row()).extraInfo)).toUserOutput(); + } else { + return m_entries.at(index.row()).extraInfo; + } + } break; case Qt::ToolTipRole: { const LocatorFilterEntry &entry = m_entries.at(index.row());