Skip to content

Instantly share code, notes, and snippets.

@seanlilmateus
Forked from alloy/status_bar_view.rb
Created March 30, 2011 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanlilmateus/894748 to your computer and use it in GitHub Desktop.
Save seanlilmateus/894748 to your computer and use it in GitHub Desktop.
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