Skip to content

Commit 39129e8

Browse files
committed
Add AfterSavingNotifyAddOn
1 parent e8b1a5a commit 39129e8

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

src/plugins/coreplugin/internal/CorePlugin.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include <coreplugin/CoreInterface.h>
4545
#include <coreplugin/HomeWindowInterface.h>
46+
#include <coreplugin/internal/AfterSavingNotifyAddOn.h>
4647
#include <coreplugin/internal/AppearancePage.h>
4748
#include <coreplugin/internal/BehaviorPreference.h>
4849
#include <coreplugin/internal/ColorSchemeCollection.h>
@@ -377,6 +378,7 @@ namespace Core::Internal {
377378
ProjectWindowInterfaceRegistry::instance()->attach<MetadataAddOn>();
378379
HomeWindowInterfaceRegistry::instance()->attach<ProjectWindowNavigatorAddOn>();
379380
ProjectWindowInterfaceRegistry::instance()->attach<ProjectWindowNavigatorAddOn>();
381+
ProjectWindowInterfaceRegistry::instance()->attach<AfterSavingNotifyAddOn>();
380382
}
381383

382384
void CorePlugin::initializeBehaviorPreference() {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "AfterSavingNotifyAddOn.h"
2+
3+
#include <CoreApi/filelocker.h>
4+
5+
#include <coreplugin/NotificationMessage.h>
6+
#include <coreplugin/ProjectWindowInterface.h>
7+
#include <coreplugin/ProjectDocumentContext.h>
8+
9+
namespace Core::Internal {
10+
11+
AfterSavingNotifyAddOn::AfterSavingNotifyAddOn(QObject *parent) : WindowInterfaceAddOn(parent) {
12+
}
13+
14+
AfterSavingNotifyAddOn::~AfterSavingNotifyAddOn() = default;
15+
16+
void AfterSavingNotifyAddOn::initialize() {
17+
auto windowInterface = windowHandle()->cast<ProjectWindowInterface>();
18+
m_message = new NotificationMessage(windowInterface->window());
19+
m_message->setIcon(SVS::SVSCraft::Information);
20+
m_message->setAllowDoNotShowAgain(false);
21+
connect(windowInterface->projectDocumentContext(), &ProjectDocumentContext::saved, this, [=, this] {
22+
m_message->close();
23+
if (!windowInterface->projectDocumentContext()->fileLocker())
24+
return;
25+
auto path = windowInterface->projectDocumentContext()->fileLocker()->path();
26+
if (path.isEmpty())
27+
return;
28+
m_message->setTitle(tr("The file has been saved to %1").arg(path));
29+
windowInterface->sendNotification(m_message, ProjectWindowInterface::DoNotShowBubble);
30+
});
31+
}
32+
33+
void AfterSavingNotifyAddOn::extensionsInitialized() {
34+
}
35+
36+
bool AfterSavingNotifyAddOn::delayedInitialize() {
37+
return WindowInterfaceAddOn::delayedInitialize();
38+
}
39+
40+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef DIFFSCOPE_COREPLUGIN_AFTERSAVINGNOTIFYADDON_H
2+
#define DIFFSCOPE_COREPLUGIN_AFTERSAVINGNOTIFYADDON_H
3+
4+
#include <CoreApi/windowinterface.h>
5+
6+
namespace Core {
7+
class NotificationMessage;
8+
}
9+
10+
namespace Core::Internal {
11+
12+
class AfterSavingNotifyAddOn : public WindowInterfaceAddOn {
13+
Q_OBJECT
14+
public:
15+
explicit AfterSavingNotifyAddOn(QObject *parent = nullptr);
16+
~AfterSavingNotifyAddOn() override;
17+
18+
void initialize() override;
19+
void extensionsInitialized() override;
20+
bool delayedInitialize() override;
21+
22+
private:
23+
NotificationMessage *m_message{};
24+
};
25+
26+
}
27+
28+
#endif //DIFFSCOPE_COREPLUGIN_AFTERSAVINGNOTIFYADDON_H

src/plugins/coreplugin/project/ProjectDocumentContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ namespace Core {
4949
}
5050

5151
void ProjectDocumentContextPrivate::markSaved() {
52+
Q_Q(ProjectDocumentContext);
5253
// TODO
54+
Q_EMIT q->saved();
5355
}
5456

5557
QByteArray ProjectDocumentContextPrivate::serializeDocument() const {

src/plugins/coreplugin/project/ProjectDocumentContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ namespace Core {
4242
bool saveAs(const QString &filePath);
4343
bool saveCopy(const QString &filePath);
4444

45+
Q_SIGNALS:
46+
void saved();
47+
4548
private:
4649
QScopedPointer<ProjectDocumentContextPrivate> d_ptr;
4750
};

0 commit comments

Comments
 (0)