Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 3551e40

Browse files
committed
Merge pull request #3349 from adobe/jasonsanjose/window-title
Use window.document.title instead of HTML toolbar when not inBrowser
2 parents 74a6a86 + 84fc305 commit 3551e40

File tree

2 files changed

+49
-27
lines changed

2 files changed

+49
-27
lines changed

src/document/DocumentCommandHandlers.js

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,39 +61,54 @@ define(function (require, exports, module) {
6161
var _$titleWrapper = null;
6262
/** @type {string} Label shown above editor for current document: filename and potentially some of its path */
6363
var _currentTitlePath = null;
64+
/** @type {string} String template for window title. Use emdash on mac only. */
65+
var WINDOW_TITLE_STRING = (brackets.platform !== "mac") ? "{0} - {1}" : "{0} \u2014 {1}";
6466

6567
/** @type {jQueryObject} Container for _$titleWrapper; if changing title changes this element's height, must kick editor to resize */
6668
var _$titleContainerToolbar = null;
6769
/** @type {Number} Last known height of _$titleContainerToolbar */
6870
var _lastToolbarHeight = null;
6971

7072
function updateTitle() {
71-
var currentDoc = DocumentManager.getCurrentDocument();
72-
if (currentDoc) {
73-
_$title.text(_currentTitlePath);
74-
_$title.attr("title", currentDoc.file.fullPath);
75-
// dirty dot is always in DOM so layout doesn't change, and visibility is toggled
76-
_$dirtydot.css("visibility", (currentDoc.isDirty) ? "visible" : "hidden");
77-
} else {
78-
_$title.text("");
79-
_$title.attr("title", "");
80-
_$dirtydot.css("visibility", "hidden");
81-
}
82-
83-
// Set _$titleWrapper to a fixed width just large enough to accomodate _$title. This seems equivalent to what
84-
// the browser would do automatically, but the CSS trick we use for layout requires _$titleWrapper to have a
85-
// fixed width set on it (see the "#main-toolbar.toolbar" CSS rule for details).
86-
_$titleWrapper.css("width", "");
87-
var newWidth = _$title.width();
88-
_$titleWrapper.css("width", newWidth);
73+
var currentDoc = DocumentManager.getCurrentDocument(),
74+
windowTitle = brackets.config.app_title;
75+
76+
if (brackets.inBrowser) {
77+
if (currentDoc) {
78+
_$title.text(_currentTitlePath);
79+
_$title.attr("title", currentDoc.file.fullPath);
80+
// dirty dot is always in DOM so layout doesn't change, and visibility is toggled
81+
_$dirtydot.css("visibility", (currentDoc.isDirty) ? "visible" : "hidden");
82+
} else {
83+
_$title.text("");
84+
_$title.attr("title", "");
85+
_$dirtydot.css("visibility", "hidden");
86+
}
8987

90-
// Changing the width of the title may cause the toolbar layout to change height, which needs to resize the
91-
// editor beneath it (toolbar changing height due to window resize is already caught by EditorManager).
92-
var newToolbarHeight = _$titleContainerToolbar.height();
93-
if (_lastToolbarHeight !== newToolbarHeight) {
94-
_lastToolbarHeight = newToolbarHeight;
95-
EditorManager.resizeEditor();
88+
// Set _$titleWrapper to a fixed width just large enough to accomodate _$title. This seems equivalent to what
89+
// the browser would do automatically, but the CSS trick we use for layout requires _$titleWrapper to have a
90+
// fixed width set on it (see the "#main-toolbar.toolbar" CSS rule for details).
91+
_$titleWrapper.css("width", "");
92+
var newWidth = _$title.width();
93+
_$titleWrapper.css("width", newWidth);
94+
95+
// Changing the width of the title may cause the toolbar layout to change height, which needs to resize the
96+
// editor beneath it (toolbar changing height due to window resize is already caught by EditorManager).
97+
var newToolbarHeight = _$titleContainerToolbar.height();
98+
if (_lastToolbarHeight !== newToolbarHeight) {
99+
_lastToolbarHeight = newToolbarHeight;
100+
EditorManager.resizeEditor();
101+
}
96102
}
103+
104+
// build shell/browser window title, e.g. "• file.html — Brackets"
105+
if (currentDoc) {
106+
windowTitle = StringUtils.format(WINDOW_TITLE_STRING, _currentTitlePath, windowTitle);
107+
windowTitle = (currentDoc.isDirty) ? "• " + windowTitle : windowTitle;
108+
}
109+
110+
// update shell/browser window title
111+
window.document.title = windowTitle;
97112
}
98113

99114
function updateDocumentTitle() {
@@ -722,7 +737,7 @@ define(function (require, exports, module) {
722737
}
723738
});
724739
}
725-
740+
726741
/**
727742
* @private
728743
* Implementation for abortQuit callback to reset quit sequence settings

test/spec/DocumentCommandHandlers-test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ define(function (require, exports, module) {
7777
waitsForDone(promise, "FILE_CLOSE");
7878
});
7979
runs(function () {
80-
expect(testWindow.$("#main-toolbar .title").text()).toBe("");
80+
expect(testWindow.document.title).toBe(brackets.config.app_title);
8181
});
8282
});
8383

@@ -93,7 +93,7 @@ define(function (require, exports, module) {
9393
waitsForDone(promise, "FILE_CLOSE");
9494
});
9595
runs(function () {
96-
expect(testWindow.$("#main-toolbar .title").text()).toBe("");
96+
expect(testWindow.document.title).toBe(brackets.config.app_title);
9797
});
9898
});
9999
});
@@ -222,6 +222,8 @@ define(function (require, exports, module) {
222222

223223
beforeEach(function () {
224224
var promise;
225+
226+
SpecRunnerUtils.loadProjectInTestWindow(testPath);
225227

226228
runs(function () {
227229
promise = CommandManager.execute(Commands.FILE_OPEN, {fullPath: testPath + "/test.js"});
@@ -232,6 +234,9 @@ define(function (require, exports, module) {
232234
it("should report clean immediately after opening a file", function () {
233235
runs(function () {
234236
expect(DocumentManager.getCurrentDocument().isDirty).toBe(false);
237+
238+
var expectedTitle = (brackets.platform === "mac" ? ("test.js — " + brackets.config.app_title) : ("test.js - " + brackets.config.app_title));
239+
expect(testWindow.document.title).toBe(expectedTitle);
235240
});
236241
});
237242

@@ -244,6 +249,8 @@ define(function (require, exports, module) {
244249

245250
// verify Document dirty status
246251
expect(doc.isDirty).toBe(true);
252+
var expectedTitle = (brackets.platform === "mac" ? ("• test.js — " + brackets.config.app_title) : ("• test.js - " + brackets.config.app_title));
253+
expect(testWindow.document.title).toBe(expectedTitle);
247254
});
248255
});
249256

0 commit comments

Comments
 (0)