Skip to content

Instantly share code, notes, and snippets.

@danielwestendorf
Created June 17, 2011 17:07
Show Gist options
  • Save danielwestendorf/1031813 to your computer and use it in GitHub Desktop.
Save danielwestendorf/1031813 to your computer and use it in GitHub Desktop.
class SimpleModal
attr_accessor :window, :modal, :outlets
def initialize(window, modal)
@window = window
@modal = modal
@outlets = []
end
def show
NSApp.beginSheet(@modal,
modalForWindow:@window,
modalDelegate:self,
didEndSelector:nil,
contextInfo:nil)
end
def add_outlet(sending_object, exit_on_finish=true, &block)
@outlets << ModalOutlet.new(self, sending_object, exit_on_finish, &block)
end
def close(sender)
NSApp.endSheet(@modal)
@modal.orderOut(sender)
end
end
class ModalOutlet
def initialize(simple_modal, sending_object, exit_on_finish, &block)
@sending_object = sending_object
@sending_object.setTarget(self)
@sending_object.setAction("fire:")
@block = block
@simple_modal = simple_modal
@exit_on_finish = exit_on_finish
end
def fire(sender)
@block.call
if @exit_on_finish
NSApp.endSheet(@simple_modal.modal)
@simple_modal.modal.orderOut(sender)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment