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:
Eberhard Graether
2019-07-22 14:25:46 +02:00
parent 293ddffb46
commit cd144a979f
12 changed files with 114 additions and 13 deletions
@@ -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);