ui: Added option to show file directory in code view title (issue #556)
* relative to project file if shorter * checkbox in preferences * not enabled by default
This commit is contained in:
+2
-1
@@ -55,7 +55,8 @@
|
||||
.ycm_extra_conf.py
|
||||
.ycm_extra_conf.pyc
|
||||
|
||||
sourcetrail.srctrlprj
|
||||
Sourcetrail.srctrlprj
|
||||
Sourcetrail_dev.srctrlprj
|
||||
|
||||
Makefile
|
||||
CMakeLists.txt.user*
|
||||
|
||||
@@ -146,11 +146,21 @@ Application::~Application()
|
||||
}
|
||||
}
|
||||
|
||||
const std::shared_ptr<Project> Application::getCurrentProject()
|
||||
const std::shared_ptr<Project> 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)
|
||||
|
||||
@@ -48,7 +48,8 @@ public:
|
||||
|
||||
~Application();
|
||||
|
||||
const std::shared_ptr<Project> getCurrentProject();
|
||||
const std::shared_ptr<Project> getCurrentProject() const;
|
||||
FilePath getCurrentProjectPath() const;
|
||||
bool isProjectLoaded() const;
|
||||
|
||||
bool hasGUI();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,16 @@ void ApplicationSettings::setShowBuiltinTypesInGraph(bool showBuiltinTypes)
|
||||
setValue<bool>("application/builtin_types_in_graph", showBuiltinTypes);
|
||||
}
|
||||
|
||||
bool ApplicationSettings::getShowDirectoryInCodeFileTitle() const
|
||||
{
|
||||
return getValue<bool>("application/directory_in_code_title", false);
|
||||
}
|
||||
|
||||
void ApplicationSettings::setShowDirectoryInCodeFileTitle(bool showDirectory)
|
||||
{
|
||||
setValue<bool>("application/directory_in_code_title", showDirectory);
|
||||
}
|
||||
|
||||
std::wstring ApplicationSettings::getColorSchemeName() const
|
||||
{
|
||||
return getValue<std::wstring>("application/color_scheme", L"bright");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
#include "QtSelfRefreshIconButton.h"
|
||||
|
||||
#include <QResizeEvent>
|
||||
|
||||
#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));
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define QT_SELF_REFRESH_ICON_BUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
|
||||
#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
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
#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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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",
|
||||
"<p>Enable display of referenced built-in types in the graph view.</p>", layout, row);
|
||||
|
||||
// directory in code
|
||||
m_showDirectoryInCode = addCheckBox("Directory in File Title", "Show directory of file in code title",
|
||||
"<p>Enable display of the parent directory of a code file relative to the project file.</p>", 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)
|
||||
{
|
||||
|
||||
@@ -91,6 +91,7 @@ private:
|
||||
|
||||
QCheckBox* m_useAnimations;
|
||||
QCheckBox* m_showBuiltinTypes;
|
||||
QCheckBox* m_showDirectoryInCode;
|
||||
|
||||
QComboBox* m_screenAutoScaling;
|
||||
QLabel* m_screenAutoScalingInfoLabel;
|
||||
|
||||
Reference in New Issue
Block a user