Skip to content

Commit

Permalink
Add activities with an enter keypress
Browse files Browse the repository at this point in the history
  • Loading branch information
PragTob committed Apr 20, 2012
1 parent 1109406 commit c5e564e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/pomodoro_tracker/tabs/activity_inventory_tab.rb
@@ -1,5 +1,6 @@
module PomodoroTracker
class ActivityInventoryTab < SideTab
ENTER = "\n"

def init_data
@today ||= Day.today
Expand All @@ -13,7 +14,7 @@ def content
@activity_inventory.each{ |activity| new_activity(activity) }
end

add_activity
add_activity_section
end

private
Expand Down Expand Up @@ -42,16 +43,27 @@ def new_activity(activity)
end
end

def add_activity
def add_activity_section
stack do
para "Add an activity"
flow do
@edit_line = edit_line
button "Add" do
activity = Activity.new(@edit_line.text)
@activity_inventory.add activity
@activities.append { new_activity(activity) }
end
button "Add" do add_activity end
end
end
keypress_handler
end

def add_activity
activity = Activity.new(@edit_line.text)
@activity_inventory.add activity
@activities.append { new_activity(activity) }
end

def keypress_handler
keypress do |key|
if key == ENTER
add_activity unless @edit_line.text.empty?
end
end
end
Expand Down

0 comments on commit c5e564e

Please sign in to comment.