-
-
Save seanlilmateus/894748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StatusBarView < NSView | |
attr_reader :progressIndicator, :statusBarItem | |
def initWithStatusBarItem(item) | |
bar = item.statusBar | |
if initWithFrame([[0,0], [bar.thickness, bar.thickness]]) | |
@statusBarItem = item | |
@highlight = false | |
origin, size = frame.origin, frame.size | |
@progressIndicator = NSProgressIndicator.alloc.initWithFrame([[origin.x + 2, origin.x + 2], [size.width - 4, size.height - 4]]) | |
@progressIndicator.style = NSProgressIndicatorSpinningStyle | |
addSubview(@progressIndicator) | |
@menu = NSMenu.alloc.init | |
@menu.delegate = self | |
@menu.addItemWithTitle('Quit App', action: 'terminate:', keyEquivalent: '') | |
@statusBarItem.view = self | |
self | |
end | |
end | |
def menuWillOpen(_) | |
@highlight = true | |
self.needsDisplay = true | |
end | |
def menuDidClose(_) | |
@highlight = false | |
self.needsDisplay = true | |
end | |
def mouseDown(event) | |
@statusBarItem.popUpStatusItemMenu(@menu) | |
end | |
def drawRect(rect) | |
@statusBarItem.drawStatusBarBackgroundInRect(bounds, withHighlight: @highlight) if @statusBarItem | |
end | |
def startAnimation | |
@progressIndicator.startAnimation(self) | |
end | |
def stopAnimation | |
@progressIndicator.stopAnimation(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment