forked from qt-creator/qt-creator
QmlDesigner: Indicate if a file is modified
Task-number: QDS-12361 Change-Id: I7a6c5f112b0f193f5bb975a331e2f0d44d19ddc2 Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
@@ -190,6 +190,26 @@ Rectangle {
|
|||||||
onActivated: backend.openFileByIndex(index)
|
onActivated: backend.openFileByIndex(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
parent:currentFile.contentItem
|
||||||
|
visible: backend.isDocumentDirty
|
||||||
|
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.rightMargin: parent.width - metric.textWidth - 18
|
||||||
|
color: StudioTheme.Values.themeTextColor
|
||||||
|
text: StudioTheme.Constants.wildcard
|
||||||
|
font.family: StudioTheme.Constants.iconFont.family
|
||||||
|
font.pixelSize: StudioTheme.Values.smallIconFont
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
anchors.verticalCenterOffset: -4
|
||||||
|
|
||||||
|
FontMetrics {
|
||||||
|
id: metric
|
||||||
|
font: currentFile.font
|
||||||
|
property int textWidth: metric.boundingRect(currentFile.currentText).width
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ToolbarButton {
|
ToolbarButton {
|
||||||
id: backButton
|
id: backButton
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
@@ -21,6 +21,9 @@
|
|||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/modemanager.h>
|
#include <coreplugin/modemanager.h>
|
||||||
|
|
||||||
|
#include <texteditor/textdocument.h>
|
||||||
|
|
||||||
#include <projectexplorer/kitmanager.h>
|
#include <projectexplorer/kitmanager.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
@@ -302,6 +305,20 @@ ToolBarBackend::ToolBarBackend(QObject *parent)
|
|||||||
this,
|
this,
|
||||||
&ToolBarBackend::documentIndexChanged);
|
&ToolBarBackend::documentIndexChanged);
|
||||||
|
|
||||||
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, this, [this]() {
|
||||||
|
static QMetaObject::Connection *lastConnection = nullptr;
|
||||||
|
delete lastConnection;
|
||||||
|
|
||||||
|
if (auto textDocument = qobject_cast<TextEditor::TextDocument *>(
|
||||||
|
Core::EditorManager::currentDocument())) {
|
||||||
|
connect(textDocument->document(),
|
||||||
|
&QTextDocument::modificationChanged,
|
||||||
|
this,
|
||||||
|
&ToolBarBackend::isDocumentDirtyChanged);
|
||||||
|
emit isDocumentDirtyChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
connect(Core::EditorManager::instance(),
|
connect(Core::EditorManager::instance(),
|
||||||
&Core::EditorManager::currentEditorChanged,
|
&Core::EditorManager::currentEditorChanged,
|
||||||
this,
|
this,
|
||||||
@@ -740,6 +757,12 @@ bool ToolBarBackend::isSharingEnabled()
|
|||||||
return QmlDesigner::checkEnterpriseLicense();
|
return QmlDesigner::checkEnterpriseLicense();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ToolBarBackend::isDocumentDirty() const
|
||||||
|
{
|
||||||
|
return Core::EditorManager::currentDocument()
|
||||||
|
&& Core::EditorManager::currentDocument()->isModified();
|
||||||
|
}
|
||||||
|
|
||||||
void ToolBarBackend::launchGlobalAnnotations()
|
void ToolBarBackend::launchGlobalAnnotations()
|
||||||
{
|
{
|
||||||
QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_TOOLBAR_EDIT_GLOBAL_ANNOTATION);
|
QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_TOOLBAR_EDIT_GLOBAL_ANNOTATION);
|
||||||
|
@@ -97,6 +97,7 @@ class ToolBarBackend : public QObject
|
|||||||
Q_PROPERTY(bool isMCUs READ isMCUs NOTIFY isMCUsChanged)
|
Q_PROPERTY(bool isMCUs READ isMCUs NOTIFY isMCUsChanged)
|
||||||
Q_PROPERTY(bool projectOpened READ projectOpened NOTIFY projectOpenedChanged)
|
Q_PROPERTY(bool projectOpened READ projectOpened NOTIFY projectOpenedChanged)
|
||||||
Q_PROPERTY(bool isSharingEnabled READ isSharingEnabled NOTIFY isSharingEnabledChanged)
|
Q_PROPERTY(bool isSharingEnabled READ isSharingEnabled NOTIFY isSharingEnabledChanged)
|
||||||
|
Q_PROPERTY(bool isDocumentDirty READ isDocumentDirty NOTIFY isDocumentDirtyChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ToolBarBackend(QObject *parent = nullptr);
|
ToolBarBackend(QObject *parent = nullptr);
|
||||||
@@ -147,6 +148,8 @@ public:
|
|||||||
|
|
||||||
bool isSharingEnabled();
|
bool isSharingEnabled();
|
||||||
|
|
||||||
|
bool isDocumentDirty() const;
|
||||||
|
|
||||||
static void launchGlobalAnnotations();
|
static void launchGlobalAnnotations();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -167,6 +170,7 @@ signals:
|
|||||||
void isMCUsChanged();
|
void isMCUsChanged();
|
||||||
void projectOpenedChanged();
|
void projectOpenedChanged();
|
||||||
void isSharingEnabledChanged();
|
void isSharingEnabledChanged();
|
||||||
|
void isDocumentDirtyChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupWorkspaces();
|
void setupWorkspaces();
|
||||||
|
Reference in New Issue
Block a user