lib/Context/Context.rb in context-0.0.16 vs lib/Context/Context.rb in context-0.0.22
- old
+ new
@@ -1,7 +1,5 @@
-require 'Context/KeyMap'
-require 'Context/ExecutionProxy'
module Context
# The Context is the Presenter in the Model, View, Presentor (MVP)
# model. It is an object that holds the logic for the UI
@@ -16,21 +14,21 @@
#
# Note that views are usually only instantiated in createViews, which
# is called on enter(), not on Context creation. However, there is
# no requirement for this.
class Context
- attr_reader :parent, :mainView
+ attr_reader :parent, :mainView, :viewBridge
attr_writer :mainView
# Create a new Context. Takes a Bridge that is used to
# create the View s in using the correct namespace.
def initialize(viewBridge)
@parent = nil
@mainView = nil
@viewBridge = viewBridge
- @keyMap = KeyMap.new
@entered = false
+ @onExitBlock = nil
end
# Creates the views for the context. This method is called
# automatically by enter() and probably should not be called otherwise.
# This method should be overriden by the concrete class. It
@@ -93,10 +91,19 @@
# Returns false if the context has never been entered, or if
# it has been entered and then exited.
def isEntered?
@entered
end
+
+ # Set a block to be called when the context exits.
+ # Often a context is exited by the result of some UI activity
+ # at some unknown point in the future. The caller of the context
+ # may want to do something after the context exits. This block
+ # will be called at the end of the exit method.
+ def onExit(&block)
+ @onExitBlock = block
+ end
# Exits the Context. After it is called, the context is no longer
# active and can't be interacted with. This method automatically
# removes the mainView from the parent's view and calls destroyViews().
#
@@ -107,40 +114,12 @@
@entered = false
if !@parent.nil? && !@parent.mainView.nil?
@parent.mainView.removeView(@mainView) unless @mainView.nil?
end
destroyViews
+ if !@onExitBlock.nil?
+ @onExitBlock.call
+ end
end
- # Sets a binding for a key.
- # Whenever a key is pressed, the context is notified. This
- # sets up a binding between the key and the block passed in.
- # After that point, the block will be called everytime the
- # key is pressed.
- #
- # Warning: This key binding mechanism is likely to be
- # depracated, or at least heavily modified soon.
- def setKeyBinding(key, &binding)
- a = KeyAssignment.new(key, &binding)
- @keyMap.add(a)
- end
-
- # Returns the existing binding for a key.
- #
- # Warning: This key binding mechanism is likely to be
- # depracated, or at least heavily modified soon.
- def getKeyBinding(key)
- a = @keyMap.findKey(key)
- a.unless_nil.action
- end
-
- # Called by the view to indicated that a key has been pressed.
- # Runs the binding in the keymap, or returns nil if there
- # isn't one.
- #
- # Warning: This key binding mechanism is likely to be
- # depracated, or at least heavily modified soon.
- def notifyKey(view, key)
- @keyMap.unless_nil do press(key) end
- end
end
end