Skip to content

Initial implementation of Xi-Mac status bar#183

Merged
cmyr merged 31 commits intoxi-editor:masterfrom
nangtrongvuon:statusbar
Jun 24, 2018
Merged

Initial implementation of Xi-Mac status bar#183
cmyr merged 31 commits intoxi-editor:masterfrom
nangtrongvuon:statusbar

Conversation

@nangtrongvuon
Copy link
Copy Markdown
Member

@nangtrongvuon nangtrongvuon commented May 28, 2018

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

@googlebot
Copy link
Copy Markdown

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

1 similar comment
@googlebot
Copy link
Copy Markdown

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@nangtrongvuon nangtrongvuon changed the title Initial implementation of Xi-Mac statusbar Initial implementation of Xi-Mac status bar May 28, 2018
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@cmyr
Copy link
Copy Markdown
Member

cmyr commented May 28, 2018

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?

@nangtrongvuon
Copy link
Copy Markdown
Member Author

@cmyr Will do shortly.

Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some preliminary feedback.

Comment thread XiEditor/Client.swift Outdated
/// A notification containing an alert message to be shown the user.
func alert(text: String);

// Status bar notifications
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would follow the documentation style of the rest of this file; three /// (for doc comments) and a description of the specific command.

Comment thread XiEditor/StatusBar.swift
@@ -0,0 +1,140 @@
//

This comment was marked as resolved.

Comment thread XiEditor/StatusBar.swift Outdated

class StatusItem: NSTextField {

var key: String = ""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread XiEditor/StatusBar.swift Outdated

class StatusBar: NSView {

private let backgroundColor = NSColor(deviceWhite: 0.9, alpha: 1.0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can probably change based on theme or other settings (you mentioned this, just noting it again)

Comment thread XiEditor/StatusBar.swift Outdated
class StatusBar: NSView {

private let backgroundColor = NSColor(deviceWhite: 0.9, alpha: 1.0)
private let statusBarHeight: CGFloat = 20
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 20? (just curious)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, I just thought it looked nice.

Comment thread XiEditor/StatusBar.swift
// 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] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread XiEditor/StatusBar.swift
}

// Update a status bar item with a new value.
func updateStatusItem(_ key: String, _ value: String) {

This comment was marked as resolved.

Comment thread XiEditor/StatusBar.swift Outdated
super.draw(dirtyRect)
let path = NSBezierPath()
backgroundColor.setFill()
__NSRectFill(dirtyRect)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I... don't think we're supposed to use this function. I think there's just a fill() method on NSRect now?

@nangtrongvuon nangtrongvuon force-pushed the statusbar branch 2 times, most recently from 5edc78b to 06cfa4d Compare May 31, 2018 14:19
Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting close, but there's still some logic errors with the layout:

new items are not hidden, if they should be:
hide-on-insert

in some situations items being 'unhidden' are aligned incorrectly:
unhide-position

When we have the layout logic sorted we should talk about how we actually want things to look, and work on polish.

Comment thread XiEditor/EditViewController.swift Outdated
}

func setupStatusBar() {
if self.unifiedTitlebar == true {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread XiEditor/EditViewController.swift Outdated
willScroll(to: scrollView.contentView.bounds.origin)
editView.gutterCache = nil
shadowView.updateShadowColor(newColor: theme.shadow)
if self.unifiedTitlebar == true {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above; any properties of the statusbar related to this setting should be set in along with other changes related to this setting

Comment thread XiEditor/StatusBar.swift Outdated

var backgroundColor: NSColor = NSColor.white
var itemTextColor: NSColor = NSColor.black
var statusBarPadding: CGFloat = 10
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can maybe be a let binding?

Comment thread XiEditor/StatusBar.swift Outdated
var hiddenItems = [StatusItem]()
var leftItems = [StatusItem]()
var rightItems = [StatusItem]()
var currentItems: [StatusItem] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of storing current keys and current items separately, can we just have a dictionary of keys: items?

@googlebot
Copy link
Copy Markdown

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

1 similar comment
@googlebot
Copy link
Copy Markdown

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.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@nangtrongvuon nangtrongvuon force-pushed the statusbar branch 3 times, most recently from a1388fd to 08a3232 Compare June 5, 2018 04:08
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

@cmyr
Copy link
Copy Markdown
Member

cmyr commented Jun 8, 2018

Getting there! Still some design/layout nits:

buggy stuff:

statusbar-weird-hide

Three things in this example:

  • the 'f' item is initially shown even though it's clipped by the window
  • adding the 'g' item causes the 'f' to be correctly hidden
  • when the z item is added, the 'e' should probably be hidden; they're very close to one another.

Left padding: the left padding of the status bar item should be equal to the left padding of the buttons in the top menu bar.

screen shot 2018-06-08 at 10 14 29 am

typing this sequence causes the 'z' item to be inserted overlapping with the previous item:

screen shot 2018-06-08 at 10 17 59 am

but resizing the view even slightly correctly hides the previous item:

screen shot 2018-06-08 at 10 18 04 am

.. so there's some bug here where we aren't correctly hiding items on one side after adding them on another.

general design stuff:

  • When drawing not-unified, I think there should be a width-0 light gray line separating the statusbar from the main view. For comparison, here are three versions: without line, with line, and gradient with line:
    screen shot 2018-06-08 at 11 34 24 am
    screen shot 2018-06-08 at 11 33 59 am
    screen shot 2018-06-08 at 11 33 18 am

And with the unified toolbar:

screen shot 2018-06-08 at 11 35 26 am
screen shot 2018-06-08 at 11 36 08 am

I think that the decision is less clear with the unified toolbar, but I still maybe prefer the line?

font size:

I think that the default font size may be too big?

12 pt (default)
screen shot 2018-06-08 at 11 47 29 am
11 pt
screen shot 2018-06-08 at 11 46 15 am
10 pt
screen shot 2018-06-08 at 11 47 02 am

I haven't had a chance to go through the code super carefully yet, will have to do that before we can merge. I'd like to get this in by early next week though so we can move on to hover definitions. :)

@jansol
Copy link
Copy Markdown
Contributor

jansol commented Jun 8, 2018

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.

@nangtrongvuon
Copy link
Copy Markdown
Member Author

nangtrongvuon commented Jun 10, 2018

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.

@nangtrongvuon nangtrongvuon force-pushed the statusbar branch 2 times, most recently from abe86c7 to 98485da Compare June 10, 2018 13:52
@cmyr
Copy link
Copy Markdown
Member

cmyr commented Jun 10, 2018

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. :)

Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread XiEditor/StatusBar.swift Outdated
currentItems[item.key] = item
checkItemsFitFor(windowWidth: self.superview!.frame.width)
self.needsUpdateConstraints = true
checkItemsFitFor(windowWidth: self.superview!.frame.width)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't self.bounds.width always suffice? our width should be the same as the superview's.

Comment thread XiEditor/StatusBar.swift Outdated
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, +)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread XiEditor/EditViewController.swift Outdated

NSLayoutConstraint.activate([
statusBar.heightAnchor.constraint(equalToConstant: statusBar.statusBarHeight),
statusBar.widthAnchor.constraint(equalTo: editView.widthAnchor),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed this, but the width constraint shouldn't be necessary if you have a leading and trailing.

… status item, refactored names for consistency
…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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@cmyr
Copy link
Copy Markdown
Member

cmyr commented Jun 13, 2018

@lukakerr If you're interested, you might have an opinion on this?

Copy link
Copy Markdown
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'm happy with this, look forward to starting to play around with it in some plugins.

@cmyr cmyr merged commit 80e6723 into xi-editor:master Jun 24, 2018
@cmyr
Copy link
Copy Markdown
Member

cmyr commented Jun 24, 2018

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants