Skip to content

Commit 5749246

Browse files
committed
feat: add dirty icon if file is modified and show popup to save before closing
1 parent 2738ae8 commit 5749246

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/extensionsIntegrated/TabBar/main.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ define(function (require, exports, module) {
66
const PreferencesManager = require("preferences/PreferencesManager");
77
const CommandManager = require("command/CommandManager");
88
const Commands = require("command/Commands");
9+
const DocumentManager = require("document/DocumentManager");
910

1011

1112
const Helper = require("./helper");
@@ -101,7 +102,7 @@ define(function (require, exports, module) {
101102
// Create the tab element with the structure we need
102103
// tab name is written as a separate div because it may include directory info which we style differently
103104
const $tab = $(
104-
`<div class="tab ${isActive ? 'active' : ''}"
105+
`<div class="tab ${isActive ? 'active' : ''} ${isDirty ? 'dirty' : ''}"
105106
data-path="${entry.path}"
106107
title="${entry.path}">
107108
<div class="tab-icon"></div>
@@ -353,7 +354,6 @@ define(function (require, exports, module) {
353354
MainViewManager.off("activePaneChange paneCreate paneDestroy paneLayoutChange", createTabBar);
354355
MainViewManager.on("activePaneChange paneCreate paneDestroy paneLayoutChange", createTabBar);
355356

356-
357357
// editor handlers
358358
EditorManager.off("activeEditorChange", createTabBar);
359359
EditorManager.on("activeEditorChange", createTabBar);
@@ -362,6 +362,13 @@ define(function (require, exports, module) {
362362
MainViewManager.on("workingSetAdd", workingSetChanged);
363363
MainViewManager.on("workingSetRemove", workingSetChanged);
364364
MainViewManager.on("workingSetSort", workingSetChanged);
365+
366+
// file dirty flag change handler
367+
DocumentManager.on("dirtyFlagChange", function (event, doc) {
368+
const filePath = doc.file.fullPath;
369+
const $tab = $tabBar.find(`.tab[data-path="${filePath}"]`);
370+
$tab.toggleClass('dirty', doc.isDirty);
371+
});
365372
}
366373

367374

src/styles/Extn-TabBar.less

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@
8787
color: #8D8D8E;
8888
font-size: 26px;
8989
margin-right: 4px;
90-
margin-top: -8px;
9190
position: absolute;
92-
left: 4px;
93-
top: 8px;
91+
left: 5px;
92+
top: 4px;
9493
}
9594

9695
.tab.dirty .tab-icon {

0 commit comments

Comments
 (0)