Initial implementation of Xi-Mac status bar#183
Conversation
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
1 similar comment
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
|
CLAs look good, thanks! |
1 similar comment
|
CLAs look good, thanks! |
|
Haven't had a chance to take a look at this yet, but it might be a good idea to open a PR in xi-editor with the changes to the API that support this work, and maybe also some changes to the sample plugin to use this api? Or a link to some plugin that does? |
|
@cmyr Will do shortly. |
| /// A notification containing an alert message to be shown the user. | ||
| func alert(text: String); | ||
|
|
||
| // Status bar notifications |
There was a problem hiding this comment.
I would follow the documentation style of the rest of this file; three /// (for doc comments) and a description of the specific command.
| @@ -0,0 +1,140 @@ | |||
| // | |||
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| class StatusItem: NSTextField { | ||
|
|
||
| var key: String = "" |
There was a problem hiding this comment.
perhaps these should be let bindings? In which case you don't need to assign them initial values, if you assign them values in init.
|
|
||
| class StatusBar: NSView { | ||
|
|
||
| private let backgroundColor = NSColor(deviceWhite: 0.9, alpha: 1.0) |
There was a problem hiding this comment.
this can probably change based on theme or other settings (you mentioned this, just noting it again)
| class StatusBar: NSView { | ||
|
|
||
| private let backgroundColor = NSColor(deviceWhite: 0.9, alpha: 1.0) | ||
| private let statusBarHeight: CGFloat = 20 |
There was a problem hiding this comment.
No particular reason, I just thought it looked nice.
| // Adds a status bar item. Only appends status bar items for now. | ||
| func addStatusItem(_ item: StatusItem) { | ||
| // If item exists, update its value | ||
| if let existingItem = currentItems[item.key] { |
There was a problem hiding this comment.
I think trying to add an item that already exists either replaces the exiting item or is an error. Having it just silently update instead seems like an easy way to let people write bugs.
| } | ||
|
|
||
| // Update a status bar item with a new value. | ||
| func updateStatusItem(_ key: String, _ value: String) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| super.draw(dirtyRect) | ||
| let path = NSBezierPath() | ||
| backgroundColor.setFill() | ||
| __NSRectFill(dirtyRect) |
There was a problem hiding this comment.
I... don't think we're supposed to use this function. I think there's just a fill() method on NSRect now?
5edc78b to
06cfa4d
Compare
cmyr
left a comment
There was a problem hiding this comment.
This is getting close, but there's still some logic errors with the layout:
new items are not hidden, if they should be:

in some situations items being 'unhidden' are aligned incorrectly:

When we have the layout logic sorted we should talk about how we actually want things to look, and work on polish.
| } | ||
|
|
||
| func setupStatusBar() { | ||
| if self.unifiedTitlebar == true { |
There was a problem hiding this comment.
we shouldn't need to do styling here. The statusbar should draw itself with the 'default style' (to be determined) by default, and if we're using the unified style we should be updating the statusbar in the same place where we update other elements (which is the unifiedTitlebar's didSet method).
To see the advantage of this approach, notice that if you change the unified_toolbar setting, the statusbar isn't updated.
Similarly, if you select a dark theme the statusbar becomes unreadable.
| willScroll(to: scrollView.contentView.bounds.origin) | ||
| editView.gutterCache = nil | ||
| shadowView.updateShadowColor(newColor: theme.shadow) | ||
| if self.unifiedTitlebar == true { |
There was a problem hiding this comment.
see above; any properties of the statusbar related to this setting should be set in along with other changes related to this setting
|
|
||
| var backgroundColor: NSColor = NSColor.white | ||
| var itemTextColor: NSColor = NSColor.black | ||
| var statusBarPadding: CGFloat = 10 |
| var hiddenItems = [StatusItem]() | ||
| var leftItems = [StatusItem]() | ||
| var rightItems = [StatusItem]() | ||
| var currentItems: [StatusItem] { |
There was a problem hiding this comment.
instead of storing current keys and current items separately, can we just have a dictionary of keys: items?
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
1 similar comment
|
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
a1388fd to
08a3232
Compare
|
CLAs look good, thanks! |
1 similar comment
|
CLAs look good, thanks! |
|
The separator line looks good both on the unified and non-unified versions IMHO. For non-unified I like the 2nd one from the top of the "general design stuff" section. As for font size, I generally like my fonts small, but 10pt might be a bit straining on the eyes in the long run. I currently have iTerm set to 11pt so if the rest of the statusbar can be scaled to that size I'd probably go for that. Unless you want to improve readability (especially on non-retina screens), in which case 12pt is the way to go. |
|
I’ll iron out the remaining bugs. I do agree with the designs with the light gray line and the solid gray as I think the metallic gray should only be reserved for the title bar. It would also help when Mojave hits and people use the dark theme, as the system color used there will get updated as well. |
abe86c7 to
98485da
Compare
|
Awesome, look forward to playing around. I might not have time today, but tomorrow at the latest. 👌 Also there's a merge conflict that will have to get resolved at some point. :) |
cmyr
left a comment
There was a problem hiding this comment.
Just a few little remaining observations, but this looks and feels much better. I suspect we will run across some issues as we start to use the feature, but this feels good for now.
I do have one remaining request, which I think should be a follow-up PR: I think that we should hide the statusbar unless it is showing any items; this lets us keep the default window appearance as minimal as possible.
| currentItems[item.key] = item | ||
| checkItemsFitFor(windowWidth: self.superview!.frame.width) | ||
| self.needsUpdateConstraints = true | ||
| checkItemsFitFor(windowWidth: self.superview!.frame.width) |
There was a problem hiding this comment.
shouldn't self.bounds.width always suffice? our width should be the same as the superview's.
| return currentItems.values.filter { $0.isHidden == false } | ||
| .map({$0.bounds.width}) | ||
| .reduce(CGFloat(currentItems.count - 1) * statusBarPadding, +) | ||
| .reduce(CGFloat(currentItems.count - hiddenItems.count - 1) * statusBarPadding, +) |
There was a problem hiding this comment.
I think this should have braces? Subtraction isn't associative, so (currentItems.count - hiddenItems.count) - 1 != (currentItems.count - (hiddenItems.count - 1)
(I'm sure the expected behaviour is defined in the swift spec, but braces make it easier for the code reviewer)
|
|
||
| NSLayoutConstraint.activate([ | ||
| statusBar.heightAnchor.constraint(equalToConstant: statusBar.statusBarHeight), | ||
| statusBar.widthAnchor.constraint(equalTo: editView.widthAnchor), |
There was a problem hiding this comment.
just noticed this, but the width constraint shouldn't be necessary if you have a leading and trailing.
… status item, refactored names for consistency
…status bar updates, addressed PR comments
…a constraints being created, adjusted padding to match buttons
…ome comments, fixed small bugs when updating constraints
| window.backgroundColor = unifiedTitlebar ? color : nil | ||
|
|
||
|
|
||
| statusBar.updateStatusBarColor(newBackgroundColor: self.theme.background, newTextColor: self.theme.foreground, newUnifiedTitlebar: unifiedTitlebar) |
There was a problem hiding this comment.
Doing one last read through and test, I realize there's a race here: we can receive the theme_changed RPC before our viewDidAppear: is called, which means self.statusBar is nil, and this crashes.
I think there's a fairly simple solution, which is to instantiate the statusbar at init time; i.e. instead of var statusBar: StatusBar! we can just have let statusBar = StatusBar(frame: .zero).
|
@lukakerr If you're interested, you might have an opinion on this? |
cmyr
left a comment
There was a problem hiding this comment.
Okay, I'm happy with this, look forward to starting to play around with it in some plugins.
|
Talked to raph yesterday and he has a bunch on his plate, so we decided it's better to get this in now than to wait for time for a second review. As follow-up, though, I would like to have at least an option for the statusbar to not be shown if it doesn't contain any items. @nangtrongvuon could you open an issue for this? |












This PR adds a initial status bar implementation, which supports the addition, update and deletion of status items.
#180
Part of #176
To be used with xi-editor's #677