Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add activities with an enter keypress

  • Loading branch information...
commit c5e564e0efffa4756e065c227bae4e4cd34e46c1 1 parent 1109406
@PragTob authored
Showing with 19 additions and 7 deletions.
  1. +19 −7 lib/pomodoro_tracker/tabs/activity_inventory_tab.rb
View
26 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
@@ -13,7 +14,7 @@ def content
@activity_inventory.each{ |activity| new_activity(activity) }
end
- add_activity
+ add_activity_section
end
private
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.