Class: Swat::TodoWindow

Inherits:
Object
  • Object
show all
Includes:
ListHelper
Defined in:
lib/todo_window.rb

Defined Under Namespace

Classes: TreeItem

Constant Summary collapse

@@todo_file_location =
nil
@@meta_data_file =
nil
@@wish_list =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ TodoWindow

Returns a new instance of TodoWindow.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/todo_window.rb', line 61

def initialize path
  @glade = GladeXML.new(path) { |handler| method(handler) }
  @list_view = @glade.get_widget("todo_view")
  @todo_window = @glade.get_widget("todo_window")
  window_icon = Gdk::Pixbuf.new("#{SWAT_APP}/resources/todo.png")
  @todo_window.icon_list = [window_icon]
  @todo_window.title = "Your TaskList"
  @todo_selection = @list_view.selection
  @todo_selection.mode = Gtk::SELECTION_SINGLE

  @meta_data = SwatMetaData.new(@@meta_data_file)
  layout_statbar
  @todo_data = TodoData.new(@@todo_file_location)
  @model = create_model
  load_available_lists
  add_columns
  connect_custom_signals
  layout_wishlist
  layout_done_view
  @list_view.expand_all
  @todo_window.hide
end

Instance Attribute Details

#gladeObject

Returns the value of attribute glade.



4
5
6
# File 'lib/todo_window.rb', line 4

def glade
  @glade
end

#todo_dataObject

Returns the value of attribute todo_data.



4
5
6
# File 'lib/todo_window.rb', line 4

def todo_data
  @todo_data
end

#todo_windowObject

Returns the value of attribute todo_window.



4
5
6
# File 'lib/todo_window.rb', line 4

def todo_window
  @todo_window
end

Class Method Details

.meta_data_file=(file) ⇒ Object



11
# File 'lib/todo_window.rb', line 11

def self. (file); @@meta_data_file = file; end

.todo_file_location=(filename) ⇒ Object



12
# File 'lib/todo_window.rb', line 12

def self.todo_file_location= (filename); @@todo_file_location = filename; end

.wishlist=(filename) ⇒ Object



13
# File 'lib/todo_window.rb', line 13

def self.wishlist= (filename); @@wishlist = filename; end

Instance Method Details

#add_to_tasklist(category, todo, priority) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/todo_window.rb', line 28

def add_to_tasklist(category,todo,priority)
  @todo_data.insert(category,todo,priority.to_i)
  @meta_data.todo_added
  @meta_data.dump
  @todo_data.dump
  reload_view
  @stat_vbox.update_today_label(@meta_data)
end

#connect_custom_signalsObject



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/todo_window.rb', line 106

def connect_custom_signals
  @todo_context_menu = TodoContextMenu.new
  @todo_context_menu.append(" Mark As Done ") { mark_as_done }
  @todo_context_menu.append(" Mark As Wishlist ") { mark_as_wishlist }
  @todo_context_menu.show

  @list_view.signal_connect("button_press_event") do |widget,event|
    if event.kind_of? Gdk::EventButton and event.button == 3
      @todo_context_menu.todo_menu.popup(nil, nil, event.button, event.time)
    end
  end
  @list_view.signal_connect("popup_menu") { @todo_context_menu.todo_menu.popup(nil, nil, 0, Gdk::Event::CURRENT_TIME) }

  # FIXME: implement fold and unfold of blocks
  @list_view.signal_connect("key-press-event") do |widget,event|
    if event.kind_of? Gdk::EventKey
      key_str = Gdk::Keyval.to_name(event.keyval)
      if key_str =~ /Left/i
        # fold the block
      elsif key_str =~ /Right/i
        # unfold the block
      end
    end
  end
end

#hide_windowObject



167
# File 'lib/todo_window.rb', line 167

def hide_window; @todo_window.hide; end

#layout_done_viewObject



101
102
103
104
# File 'lib/todo_window.rb', line 101

def layout_done_view
  done_view = @glade.get_widget("done_view")
  @done_tab = CompletedView.new(done_view,self)
end

#layout_statbarObject

layout statistic bar



85
86
87
88
89
90
91
92
93
94
# File 'lib/todo_window.rb', line 85

def layout_statbar
  @stat_toggle_button = @glade.get_widget("toggle_stat_button")
  @stat_hbox = @glade.get_widget("stat_box")
  @stat_vbox = StatBox.new(@meta_data)

  @stat_hbox.pack_end(@stat_vbox.vbox_container,true)
  button_icon_widget = Gtk::Image.new("#{SWAT_APP}/resources/control_rewind_blue.png")
  @stat_box_status = false
  @stat_toggle_button.image = button_icon_widget
end

#layout_wishlistObject



96
97
98
99
# File 'lib/todo_window.rb', line 96

def layout_wishlist
  wish_list_view = @glade.get_widget("wish_list_view")
  @wish_list_tab = WishList.new(@@wishlist,wish_list_view,self)
end

#mark_as_doneObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/todo_window.rb', line 132

def mark_as_done
  selection = @list_view.selection
  if iter = selection.selected
    selected_category = iter.parent[0]
    task_index = iter[3]
    @todo_data.delete(selected_category,task_index)
    @list_view.model.remove(iter)
    @todo_data.dump
    @meta_data.todo_done
    @meta_data.dump
    @stat_vbox.update_today_label(@meta_data)
    @done_tab.reload_view
  end
end

#mark_as_wishlistObject



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/todo_window.rb', line 147

def mark_as_wishlist
  selection = @list_view.selection
  if iter = selection.selected
    selected_category = iter.parent[0]
    task_index = iter[3]
    priority = todo_data.get_priority(selected_category,task_index)
    task_text = todo_data.get_task(selected_category,task_index)
    @wish_list_tab.add_to_wishlist(selected_category,task_text,priority)
    @todo_data.remove(selected_category,task_index)
    @todo_data.dump
    @list_view.model.remove(iter)
  end
end

#on_add_todo_button_clickedObject



22
23
24
25
26
# File 'lib/todo_window.rb', line 22

def on_add_todo_button_clicked
  AddTodoDialog.new(@todo_data.categories) do |priority,category,todo|
    add_to_tasklist(category,todo,priority)
  end
end

#on_reload_button_clickedObject



55
56
57
58
# File 'lib/todo_window.rb', line 55

def on_reload_button_clicked
  @todo_data = TodoData.new(@@todo_file_location)
  reload_view
end

#on_sync_button_clickedObject



169
170
171
172
# File 'lib/todo_window.rb', line 169

def on_sync_button_clicked
  system("svn up #{@@todo_file_location}")
  system("svn ci #{@@todo_file_location} -m 'foo'")
end

#on_todo_window_delete_eventObject



15
16
17
18
# File 'lib/todo_window.rb', line 15

def on_todo_window_delete_event
  hide_window
  return true
end

#on_todo_window_destroy_eventObject



20
# File 'lib/todo_window.rb', line 20

def on_todo_window_destroy_event; return true; end

#on_todo_window_key_press_event(widget, key) ⇒ Object



51
52
53
# File 'lib/todo_window.rb', line 51

def on_todo_window_key_press_event(widget,key)
  hide_window if Gdk::Keyval.to_name(key.keyval) =~ /Escape/i
end

#on_toggle_stat_button_clickedObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/todo_window.rb', line 37

def on_toggle_stat_button_clicked
  # stat box is hidden
  unless @stat_box_status
    button_icon_widget = Gtk::Image.new("#{SWAT_APP}/resources/control_end_blue.png")
    @stat_vbox.show_all
    # stat box is already shown
  else
    button_icon_widget = Gtk::Image.new("#{SWAT_APP}/resources/control_rewind_blue.png")
    @stat_vbox.hide_all
  end
  @stat_box_status = !@stat_box_status
  @stat_toggle_button.image = button_icon_widget
end

#show_windowObject



161
162
163
164
165
# File 'lib/todo_window.rb', line 161

def show_window
  @todo_window = @glade.get_widget("todo_window")
  @todo_window.present
  @todo_window.show
end