class PPCurses::Application

noinspection RubyClassVariableUsageInspection

Attributes

content_view[RW]

Any object of type PPCurses:View

main_menu[RW]

Public Class Methods

new() click to toggle source
# File lib/ppcurses/application.rb, line 137
def initialize
  @screen = PPCurses::Screen.new

  @main_menu = create_default_menubar
  @next_responder = @main_menu

  @@shared_app = self
  @terminated = false
end
sharedApplication() click to toggle source
# File lib/ppcurses/application.rb, line 226
def Application.sharedApplication
  @@shared_app
end

Public Instance Methods

content_view=(value) click to toggle source
# File lib/ppcurses/application.rb, line 148
def content_view=(value)
  
  if @content_view != nil then
    # Clear current content_view before reassignment
    frame = @content_view.frame
    x = frame.origin.x
    y = frame.origin.y
    height = frame.size.height
    
    for i in y..y+height-1
      @screen.setpos( i, x )        
      @screen.clrtoeol  ## TODO use width !!!
    end
    
  end
  
  @content_view=value
  @main_menu.next_responder=@content_view
end
create_default_menubar() click to toggle source
# File lib/ppcurses/application.rb, line 168
def create_default_menubar
  menubar = PPCurses::MenuBar.new

  quit_item = PPCurses::MenuBarItem.new('q', 'Quit')
  quit_item.action = method(:terminate)
  menubar.add_menu_item(quit_item)

  menubar
end
launch() click to toggle source
# File lib/ppcurses/application.rb, line 190
def launch
  @screen.setup_curses
  if @delegate.respond_to?(:applicationDidFinishLaunching)
    @delegate.applicationDidFinishLaunching(self)
  end

  until @terminated
    # TODO - switch show to display?
    @main_menu.show(@screen) unless @main_menu.nil?

    # TODO -- pass a subview of the screen.
    @content_view.display(@screen) unless @content_view.nil?

    c = @screen.get_ch
    key_down(c)
  end

  @screen.shutdown_curses

end
set_delegate(delegate) click to toggle source

Informal protocol A delegate receives notifications if and only if a method is defined

applicationDidFinishLaunching applicationShouldTerminate

# File lib/ppcurses/application.rb, line 185
def set_delegate (delegate)
  @delegate = delegate
end
terminate() click to toggle source
# File lib/ppcurses/application.rb, line 211
def terminate

  # Cocoa returns an NSApplicationTerminateReply which can
  # be a cancel, now or later response.  Simply support a boolean
  # for now.
  if @delegate.respond_to?(:applicationShouldTerminate)
    should_terminate = @delegate.applicationShouldTerminate(self)
    unless should_terminate
      return
    end
  end

  @terminated = true
end