Class: PPCurses::Application

Inherits:
ResponderManager show all
Defined in:
lib/ppcurses/application.rb

Overview

noinspection RubyClassVariableUsageInspection

Instance Attribute Summary collapse

Attributes inherited from ResponderManager

#first_responder

Attributes inherited from Responder

#next_responder

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ResponderManager

#accepts_first_responder, #make_first_responder

Methods inherited from Responder

#accepts_first_responder, #become_first_responder, isa, #key_down, #resign_first_responder

Constructor Details

#initializeApplication

Returns a new instance of Application.



137
138
139
140
141
142
143
144
145
# 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

Instance Attribute Details

#content_viewObject

Any object of type PPCurses:View



135
136
137
# File 'lib/ppcurses/application.rb', line 135

def content_view
  @content_view
end

Returns the value of attribute main_menu.



132
133
134
# File 'lib/ppcurses/application.rb', line 132

def main_menu
  @main_menu
end

Class Method Details

.sharedApplicationObject



226
227
228
# File 'lib/ppcurses/application.rb', line 226

def Application.sharedApplication
  @@shared_app
end

Instance Method Details

#create_default_menubarObject



168
169
170
171
172
173
174
175
176
# 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

#launchObject



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# 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) ⇒ Object

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

applicationDidFinishLaunching applicationShouldTerminate



185
186
187
# File 'lib/ppcurses/application.rb', line 185

def set_delegate (delegate)
  @delegate = delegate
end

#terminateObject



211
212
213
214
215
216
217
218
219
220
221
222
223
224
# 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