diff --git a/.gitignore b/.gitignore index 3de6104d..590690fe 100644 --- a/.gitignore +++ b/.gitignore @@ -55,7 +55,8 @@ .ycm_extra_conf.py .ycm_extra_conf.pyc -sourcetrail.srctrlprj +Sourcetrail.srctrlprj +Sourcetrail_dev.srctrlprj Makefile CMakeLists.txt.user* diff --git a/src/lib/app/Application.cpp b/src/lib/app/Application.cpp index ed653cfb..7a9e9bed 100644 --- a/src/lib/app/Application.cpp +++ b/src/lib/app/Application.cpp @@ -146,11 +146,21 @@ Application::~Application() } } -const std::shared_ptr Application::getCurrentProject() +const std::shared_ptr Application::getCurrentProject() const { return m_project; } +FilePath Application::getCurrentProjectPath() const +{ + if (m_project) + { + return m_project->getProjectSettingsFilePath(); + } + + return FilePath(); +} + bool Application::isProjectLoaded() const { if (m_project) diff --git a/src/lib/app/Application.h b/src/lib/app/Application.h index 7d788215..c9d61403 100644 --- a/src/lib/app/Application.h +++ b/src/lib/app/Application.h @@ -48,7 +48,8 @@ public: ~Application(); - const std::shared_ptr getCurrentProject(); + const std::shared_ptr getCurrentProject() const; + FilePath getCurrentProjectPath() const; bool isProjectLoaded() const; bool hasGUI(); diff --git a/src/lib/component/view/helper/CodeSnippetParams.cpp b/src/lib/component/view/helper/CodeSnippetParams.cpp index 584717df..be05fa89 100644 --- a/src/lib/component/view/helper/CodeSnippetParams.cpp +++ b/src/lib/component/view/helper/CodeSnippetParams.cpp @@ -62,7 +62,7 @@ bool CodeSnippetParams::sort(const CodeSnippetParams& a, const CodeSnippetParams // alphabetical filepath without extension else { - return aFilePath.withoutExtension().fileName() < bFilePath.withoutExtension().fileName(); + return aFilePath.withoutExtension() < bFilePath.withoutExtension(); } } diff --git a/src/lib/settings/ApplicationSettings.cpp b/src/lib/settings/ApplicationSettings.cpp index 66c617e1..7f11f583 100644 --- a/src/lib/settings/ApplicationSettings.cpp +++ b/src/lib/settings/ApplicationSettings.cpp @@ -182,6 +182,16 @@ void ApplicationSettings::setShowBuiltinTypesInGraph(bool showBuiltinTypes) setValue("application/builtin_types_in_graph", showBuiltinTypes); } +bool ApplicationSettings::getShowDirectoryInCodeFileTitle() const +{ + return getValue("application/directory_in_code_title", false); +} + +void ApplicationSettings::setShowDirectoryInCodeFileTitle(bool showDirectory) +{ + setValue("application/directory_in_code_title", showDirectory); +} + std::wstring ApplicationSettings::getColorSchemeName() const { return getValue("application/color_scheme", L"bright"); diff --git a/src/lib/settings/ApplicationSettings.h b/src/lib/settings/ApplicationSettings.h index ad8279d3..48d1bdb5 100644 --- a/src/lib/settings/ApplicationSettings.h +++ b/src/lib/settings/ApplicationSettings.h @@ -54,6 +54,9 @@ public: bool getShowBuiltinTypesInGraph() const; void setShowBuiltinTypesInGraph(bool showBuiltinTypes); + bool getShowDirectoryInCodeFileTitle() const; + void setShowDirectoryInCodeFileTitle(bool showDirectory); + int getWindowBaseWidth() const; int getWindowBaseHeight() const; diff --git a/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.cpp b/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.cpp index 63505ece..93276f96 100644 --- a/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.cpp +++ b/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.cpp @@ -1,16 +1,33 @@ #include "QtSelfRefreshIconButton.h" +#include + #include "utilityQt.h" QtSelfRefreshIconButton::QtSelfRefreshIconButton( const QString& text, const FilePath& iconPath, const std::string& buttonKey, QWidget* parent ) : QPushButton(text, parent) + , m_text(text) , m_iconPath(iconPath) , m_buttonKey(buttonKey) { setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac refresh(); + + m_timer.setSingleShot(true); + connect(&m_timer, &QTimer::timeout, [this](){ updateText(width()); }); +} + +void QtSelfRefreshIconButton::setText(const QString& text) +{ + m_text = text; + QPushButton::setText(text); + + if (m_autoElide) + { + m_timer.start(25); + } } void QtSelfRefreshIconButton::setIconPath(const FilePath& iconPath) @@ -22,6 +39,11 @@ void QtSelfRefreshIconButton::setIconPath(const FilePath& iconPath) } } +void QtSelfRefreshIconButton::setAutoElide(bool autoElide) +{ + m_autoElide = autoElide; +} + void QtSelfRefreshIconButton::handleMessage(MessageRefreshUI* message) { m_onQtThread([this]() @@ -37,3 +59,20 @@ void QtSelfRefreshIconButton::refresh() setIcon(utility::createButtonIcon(m_iconPath, m_buttonKey)); } } + +void QtSelfRefreshIconButton::resizeEvent(QResizeEvent *event) +{ + if (m_autoElide) + { + m_timer.stop(); + updateText(event->size().width()); + } + + QPushButton::resizeEvent(event); +} + +void QtSelfRefreshIconButton::updateText(int width) +{ + QPushButton::setText( + fontMetrics().elidedText(m_text, Qt::ElideLeft, width - iconSize().width() - 22)); +} diff --git a/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.h b/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.h index bad73266..159e6f3d 100644 --- a/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.h +++ b/src/lib_gui/qt/element/button/QtSelfRefreshIconButton.h @@ -2,6 +2,7 @@ #define QT_SELF_REFRESH_ICON_BUTTON_H #include +#include #include "FilePath.h" #include "MessageListener.h" @@ -17,18 +18,29 @@ public: const QString& text, const FilePath& iconPath, const std::string& buttonKey, QWidget* parent = nullptr); ~QtSelfRefreshIconButton() = default; + void setText(const QString& text); void setIconPath(const FilePath& iconPath); + void setAutoElide(bool autoElide); + protected: void handleMessage(MessageRefreshUI* message) override; virtual void refresh(); + void resizeEvent(QResizeEvent *event) override; + private: + void updateText(int width); + QtThreadedLambdaFunctor m_onQtThread; + QString m_text; FilePath m_iconPath; const std::string m_buttonKey; + + bool m_autoElide = false; + QTimer m_timer; }; #endif // QT_SELF_REFRESH_ICON_BUTTON_H diff --git a/src/lib_gui/qt/element/code/QtCodeFileTitleButton.cpp b/src/lib_gui/qt/element/code/QtCodeFileTitleButton.cpp index d363212f..c815046d 100644 --- a/src/lib_gui/qt/element/code/QtCodeFileTitleButton.cpp +++ b/src/lib_gui/qt/element/code/QtCodeFileTitleButton.cpp @@ -2,6 +2,8 @@ #include +#include "Application.h" +#include "ApplicationSettings.h" #include "FileSystem.h" #include "MessageActivateFile.h" #include "MessageProjectEdit.h" @@ -36,10 +38,6 @@ QtCodeFileTitleButton::QtCodeFileTitleButton(QWidget* parent) connect(m_openInTabAction, &QAction::triggered, this, &QtCodeFileTitleButton::openInTab); } -QtCodeFileTitleButton::~QtCodeFileTitleButton() -{ -} - const FilePath& QtCodeFileTitleButton::getFilePath() const { return m_filePath; @@ -135,6 +133,28 @@ void QtCodeFileTitleButton::updateTexts() toolTip = L"out-of-date " + toolTip; } + if (ApplicationSettings::getInstance()->getShowDirectoryInCodeFileTitle()) + { + setAutoElide(true); + + FilePath directoryPath = m_filePath.getParentDirectory(); + std::wstring directory = directoryPath.wstr(); + + FilePath projectPath = Application::getInstance()->getCurrentProjectPath(); + std::wstring directoryRelative = directoryPath.getRelativeTo(projectPath).wstr(); + + if (directoryRelative.size() < directory.size()) + { + directory = directoryRelative; + } + + title = directory + L" - " + title; + } + else + { + setAutoElide(false); + } + setText(QString::fromStdWString(title)); setToolTip(QString::fromStdWString(toolTip)); } @@ -172,13 +192,11 @@ void QtCodeFileTitleButton::contextMenuEvent(QContextMenuEvent* event) FilePath path = m_filePath; if (path.empty()) { - Project* currentProject = Application::getInstance()->getCurrentProject().get(); - if (!currentProject) + path = Application::getInstance()->getCurrentProjectPath(); + if (path.empty()) { return; } - - path = currentProject->getProjectSettingsFilePath(); } m_openInTabAction->setEnabled(!m_filePath.empty()); diff --git a/src/lib_gui/qt/element/code/QtCodeFileTitleButton.h b/src/lib_gui/qt/element/code/QtCodeFileTitleButton.h index f71050f4..6e336271 100644 --- a/src/lib_gui/qt/element/code/QtCodeFileTitleButton.h +++ b/src/lib_gui/qt/element/code/QtCodeFileTitleButton.h @@ -12,7 +12,7 @@ class QtCodeFileTitleButton public: QtCodeFileTitleButton(QWidget* parent = nullptr); - virtual ~QtCodeFileTitleButton(); + virtual ~QtCodeFileTitleButton() = default; const FilePath& getFilePath() const; void setFilePath(const FilePath& filePath); diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp index 4ef3eeb2..981b49ae 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.cpp @@ -103,6 +103,10 @@ void QtProjectWizardContentPreferences::populate(QGridLayout* layout, int& row) m_showBuiltinTypes = addCheckBox("Built-in Types", "Show built-in types in graph when referenced", "

Enable display of referenced built-in types in the graph view.

", layout, row); + // directory in code + m_showDirectoryInCode = addCheckBox("Directory in File Title", "Show directory of file in code title", + "

Enable display of the parent directory of a code file relative to the project file.

", layout, row); + addGap(layout, row); @@ -419,6 +423,7 @@ void QtProjectWizardContentPreferences::load() m_useAnimations->setChecked(appSettings->getUseAnimations()); m_showBuiltinTypes->setChecked(appSettings->getShowBuiltinTypesInGraph()); + m_showDirectoryInCode->setChecked(appSettings->getShowDirectoryInCodeFileTitle()); if (m_screenAutoScaling) { @@ -481,6 +486,7 @@ void QtProjectWizardContentPreferences::save() appSettings->setUseAnimations(m_useAnimations->isChecked()); appSettings->setShowBuiltinTypesInGraph(m_showBuiltinTypes->isChecked()); + appSettings->setShowDirectoryInCodeFileTitle(m_showDirectoryInCode->isChecked()); if (m_screenAutoScaling) { diff --git a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h index ae7af35c..d7ce1ae0 100644 --- a/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h +++ b/src/lib_gui/qt/project_wizard/content/QtProjectWizardContentPreferences.h @@ -91,6 +91,7 @@ private: QCheckBox* m_useAnimations; QCheckBox* m_showBuiltinTypes; + QCheckBox* m_showDirectoryInCode; QComboBox* m_screenAutoScaling; QLabel* m_screenAutoScalingInfoLabel;