-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Display current project name in main window #7789
Conversation
@le717 This code is better: $(ProjectManager).on("projectOpen", function (e, projectRoot) {
_projectName = projectRoot.name;
updateTitle();
}); |
@SAplayer That worked! After looking more closely at it, I found out The only thing left now would be this split-second display of However, because it appears for such a short time, it might be acceptable. @peterflynn Any chance this could get in Release 40? |
I guess initializing You could probably try this: _projectName = _projectName.replace(/^\s*(-|\u2014)/, "").trim(); |
@SAplayer I tried setting it to an empty string, but then I got that blank dash in front of Brackets (which you regex would fix). I'm just trying to think where the regex would go in the code if the |
Probably like this: $(ProjectManager).on("projectOpen", function (e, projectRoot) {
_projectName = projectRoot.name;
_projectName = _projectName.replace(/^\s*[\-\u2014]\s*/, "");
updateTitle();
}); |
Forget what I said. if (_projectName === "") {
windowTitle = windowTitle.replace(/^\s*[\-\u2014]\s*/, "");
}
window.document.title = windowTitle; Tested. |
@SAplayer Oh, come on! I had that exact same code (save the regex) in place before, but I removed it long before I committed (wasn't sure if it was what @peterflynn was talking about). I didn't think that code snippet from last night was what was needed, but I know this new one would work even is you had not tested it. I'll make the change ASAP (on mobile right now). |
/** @type {string} String template for window title. Use emdash on mac only. */ | ||
var WINDOW_TITLE_STRING = (brackets.platform !== "mac") ? "{0} - {1}" : "{0} \u2014 {1}"; | ||
/** @type {string} The current project name; displayed in window title */ | ||
var _projectName = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set it to ""
in order to make the code below work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*facepalm* Fixed.
This PR should (hopefully) finally be complete, with all tests passing. @peterflynn Ready for review again. Thanks for all the help, @SAplayer. I probably wouldn't have been able to finish this until later if it were not for you. :) |
Changed Milestone to Release 41. |
@peterflynn Do you still want to review this? I just rebased it and merged with master, so it's all ready to pull. If I need, I will try to fix the whitespace changes. That was from a force-of-habit keyboard shortcut action when I started this. |
@peterflynn Is this feature still wanted in Brackets? I can post a quick screenshot of the final version if needed. |
@le717 Would you mind updating the screenshot? That would be great. |
@ingorichter Quick check, what screenshot do you refer to? Yes, I'll get this PR ready to be merged again, no problem there. |
Is that what you meant? EDIT: Updated, ready to be merged, Travis build is clean. |
* String template for window title when a file is open. Use emdash on mac only. | ||
* @type {string} | ||
*/ | ||
var WINDOW_TITLE_STRING_DOC = (brackets.platform !== "mac") ? "{0} ({1}) - {2}" : "{0} \u2014 {2}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the new format should be available for the Mac too. Currently it's missing and the tests are failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do OS differentiation like this:
var osDash = brackets.platform === "mac" ? "\u2014" : "-";
var WINDOW_TITLE_STRING_NO_DOC = "{0} " + osDash + " {1}";
var WINDOW_TITLE_STRING_DOC = "{0} ({1}) " + osDash + " {2}";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh shoot, I didn't realize this was not occurring on Mac.
Before I update, my question would be why different dashes are used on Win and Mac. OS app convention/requirement? Why not use the same dash on Win, Mac, and Linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. But what I heart is, that \2014
is the default delimiter on OSX and -
for all other platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we can't use \2014
on all platforms then. It's just a tad longer than -
. *sigh* Will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@le717 We decided originally we want to match each platform's standard separator, so can you please keep the split? \u2014
looks weird on Windows (doesn't match any other app), and -
looks weird on Mac (same reason). We want to feel as much like native code editors as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fully understand that native app feeling. Just trying to understand the reasoning behind the difference. I was going to keep the split dashes anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -135,7 +147,7 @@ define(function (require, exports, module) { | |||
function _updateTitle() { | |||
var currentDoc = DocumentManager.getCurrentDocument(), | |||
currentlyViewedPath = MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE), | |||
windowTitle = brackets.config.app_title; | |||
windowTitle = StringUtils.format(WINDOW_TITLE_STRING_NO_DOC, _projectName, brackets.config.app_title); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be cleaner to move this initializer down into an else
with the other case below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@ingorichter @peterflynn @marcelgerber Changes pushed. Project title should now work on Mac (with appropriate dashes), refactoring completed, and |
} else { | ||
// hide dirty dot if there is no document | ||
_$dirtydot.css("visibility", "hidden"); | ||
// Application loading/no project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can never get here -- if ProjectManager.getProjectRoot()
is null, we'll crash up on line 149 before getting this far. We should either remove this else
or move the projectName
var down inside the if (projectRoot)
block here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of moving it into if (projectRoot)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never ended up in the else branch. Perhaps you can initialize windowTitle
with brackets.config.app_title
before the if (projectRoot)
statement and get rid of the else branch entirely (only to initialize it with something valid).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ingorichter Sounds good. It looks like it was that way in case projectRoot
was undefined or null
, but initializing it as brackets.config.app_title
is a better method.
@peterflynn Changes pushed. |
windowTitle = (currentDoc.isDirty) ? "• " + windowTitle : windowTitle; | ||
var projectRoot = ProjectManager.getProjectRoot(); | ||
if (projectRoot) { | ||
var projectName = ProjectManager.getProjectRoot().name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can reuse projectRoot
here instead of calling ProjectManager.getProjectRoot
again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
JSHint:
|
@marcelgerber Fixed just as you posted that. |
Changes pushed, ready for another look. |
@le717 Just needs a merge with master so you're in sync with the new way of registering event listeners, and then I think this is good to go! And actually if you could squash/rebase after doing your merge with master, that would be ideal -- there are a lot of commits here and many of them are redundant merge commits. |
@peterflynn Certainly for both merge and squash. Will get that ready ASAP. :) |
@peterflynn Merged and rebased. Travis is running right now. Unless it reports something, this is ready to be merged. :D |
Great, all set! Thanks for the typo/spelling fixes too btw :-) |
Display current project name in window titlebar
@@ -194,7 +208,7 @@ define(function (require, exports, module) { | |||
*/ | |||
function _shortTitleForDocument(doc) { | |||
var fullPath = doc.file.fullPath; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh! All of the unnecessary whitespace changes in this file (and others) are making my life difficult. I'm trying to keep my promises-upgrade branch up-to-date and every one of these whitespace changes that coincide with any change in my branch causes a phantom merge conflict that needs to be manually resolved. Please stop doing this! Brackets has no convention for whitespace in empty lines -- it's left to the authors discretion to have none or match indent level of previous/next line of code, so there's nothing to "fix".
Sorry @le717 I don't mean to single you out -- I'm just using your code as an example. This comment is meant for everyone: contributors and committers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I felt bad about these whitespaces things when this was finally merged. This was my first PR, and the whitespace was removed automatically. I kept considering adding it back, but it was mentioned or asked for. If someone had asked for it to be restored, I would have gladly done so. I've been trying to watch whitespace removal since this.
It's fine, I know how it is to be frustrated by changes like this. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The team has gone back and forth about whether to accept these changes, but I think this is a good reason to no longer accept them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@redmunds Pro Tip: Use git merge -X ignore-all-space
Source: http://stackoverflow.com/a/9784089/3455922 (haven't tested it, though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcelgerber Thanks for the tip! I'll try to remember that one.
Supersedes #6878.
This implements #2281, displaying the project name in the Brackets window title.