Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Todo list; move components and models into their own modules and folders
- Loading branch information
Ryan Scott Lewis
committed
Jul 14, 2015
1 parent
ae0a8ca
commit 6d46e3a
Showing
14 changed files
with
244 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module TodoList | ||
module Component | ||
|
||
class Header < Cura::Component::Pack | ||
|
||
attr_reader :create_list_textbox | ||
|
||
def initialize(attributes={}) | ||
attributes = { orientation: :horizontal }.merge(attributes) | ||
|
||
super(attributes) | ||
|
||
add_children( | ||
Cura::Component::Label.new(text: "Todo", bold: true, margin: { right: 3 }), | ||
Cura::Component::Label.new(text: "^-C to exit", margin: { right: 3 }), | ||
Cura::Component::Label.new(text: "^-E to edit item", margin: { right: 3 }), | ||
Cura::Component::Label.new(text: "^-D to delete item", margin: { right: 3 }), | ||
Cura::Component::Label.new(text: "^-F to move focus forwards", margin: { right: 3 }), | ||
Cura::Component::Label.new(text: "^-B to move focus backwards", margin: { right: 3 }) | ||
) | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module TodoList | ||
module Component | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
module TodoList | ||
module Component | ||
|
||
class ListItems < Cura::Component::Pack | ||
|
||
attr_reader :create_list_item_textbox | ||
attr_reader :listbox | ||
attr_reader :list | ||
|
||
def initialize(attributes={}) | ||
attributes = { fill: true, padding: { top: 1, bottom: 1 } }.merge(attributes) | ||
|
||
super(attributes) | ||
|
||
create_form_pack = Cura::Component::Pack.new(orientation: :horizontal) | ||
add_child(create_form_pack) | ||
|
||
@create_list_item_textbox = Cura::Component::Textbox.new(width: width - 21, padding: { left: 1, right: 1 }, margin: { right: 1 }) | ||
@create_list_item_textbox.on_event(:key_down, self) { |event, model_list| model_list.create_list_item if event.name == :enter } | ||
create_form_pack.add_child(@create_list_item_textbox) | ||
|
||
@create_list_item_button = Cura::Component::Button.new(text: "Create List Item", padding: { left: 1, right: 1 }) | ||
@create_list_item_button.on_event(:click, self) { |_event| model_list.create_list_item } | ||
create_form_pack.add_child(@create_list_item_button) | ||
|
||
@listbox_header_label = Cura::Component::Label.new(text: " " * width, bold: true, underline: true, margin: { top: 1 }) | ||
add_child(@listbox_header_label) | ||
|
||
@listbox = Cura::Component::Listbox.new(width: @width) | ||
|
||
@listbox.on_event(:key_down, self) do |event, model_list| | ||
if event.target == self && event.control? && event.name == :D && !selected_object.nil? | ||
selected_object.destroy | ||
|
||
previous_selected_index = @selected_index | ||
model_list.fill_listbox | ||
self.selected_index = [previous_selected_index, count - 1].min | ||
end | ||
|
||
if event.target == self && event.control? && event.name == :E | ||
selected_child.focusable = true | ||
selected_child.focus | ||
end | ||
end | ||
|
||
add_child(@listbox) | ||
|
||
|
||
end | ||
|
||
def create_list_item | ||
text = @create_list_item_textbox.text | ||
|
||
Model::ListItem.create(list_id: @list.id, text: text) | ||
|
||
fill_listbox | ||
|
||
@create_list_item_textbox.clear | ||
@create_list_item_textbox.focus | ||
end | ||
|
||
def fill_listbox | ||
@listbox.delete_children | ||
|
||
return nil if @list.nil? | ||
|
||
@list.list_items.each do |list_item| | ||
list_item_textbox = Cura::Component::Textbox.new(text: list_item.text, width: @listbox.width, background: :inherit, foreground: Cura::Color.white, focusable: false) | ||
list_item_textbox.on_event(:key_down, @listbox) do |event, listbox| | ||
if event.name == :enter | ||
list_item.text = text | ||
|
||
list_item.save | ||
|
||
self.focusable = false | ||
listbox.focus | ||
end | ||
end | ||
|
||
@listbox.add_child(list_item_textbox, list_item) | ||
end | ||
end | ||
|
||
def list=(list) | ||
@list = list | ||
@listbox_header_label.text = @list.name | ||
@listbox_header_label.text << " " * (width - @list.name.length) unless @list.name.length >= width | ||
|
||
fill_listbox | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
module TodoList | ||
module Component | ||
|
||
class Lists < Cura::Component::Pack | ||
|
||
attr_reader :create_list_textbox | ||
attr_reader :listbox | ||
|
||
|
||
def initialize(attributes={}) | ||
attributes = { fill: true, padding: { top: 1, bottom: 1 } }.merge(attributes) | ||
|
||
super(attributes) | ||
|
||
create_form_pack = Cura::Component::Pack.new(orientation: :horizontal) | ||
add_child(create_form_pack) | ||
|
||
@create_list_textbox = Cura::Component::Textbox.new(width: width - 16, padding: { left: 1, right: 1 }, margin: { right: 1 }) | ||
@create_list_textbox.on_event(:key_down, self) { |event, model_list| model_list.create_list if event.name == :enter } | ||
create_form_pack.add_child(@create_list_textbox) | ||
|
||
@create_list_button = Cura::Component::Button.new(text: "Create List", padding: { left: 1, right: 1 }) | ||
@create_list_button.on_event(:click, self) { |_event, model_list| model_list.create_list } | ||
create_form_pack.add_child(@create_list_button) | ||
|
||
@listbox_header_label = Cura::Component::Label.new(text: "Lists" + " " * (width - 5), bold: true, underline: true, margin: { top: 1 }) | ||
add_child(@listbox_header_label) | ||
|
||
@listbox = Cura::Component::Listbox.new(width: @width) | ||
@listbox.on_event(:selected) { |_event| application.list_items.list = selected_object unless selected_object.nil? } | ||
@listbox.on_event(:key_down, self) do |event, model_list| | ||
if event.target == self && event.control? && event.name == :D && !selected_object.nil? | ||
selected_object.destroy | ||
|
||
previous_selected_index = @selected_index | ||
model_list.fill_listbox | ||
self.selected_index = [previous_selected_index, count - 1].min | ||
end | ||
|
||
if event.target == self && event.control? && event.name == :E | ||
selected_child.focusable = true | ||
selected_child.focus | ||
end | ||
end | ||
|
||
add_child(@listbox) | ||
|
||
fill_listbox | ||
end | ||
|
||
def create_list | ||
name = @create_list_textbox.text | ||
|
||
Model::List.create(name: name) | ||
|
||
fill_listbox | ||
|
||
@create_list_textbox.clear | ||
@create_list_textbox.focus | ||
end | ||
|
||
def fill_listbox | ||
@listbox.delete_children | ||
|
||
Model::List.all.each do |list| | ||
list_textbox = Cura::Component::Textbox.new(text: list.name, width: @listbox.width, background: :inherit, foreground: Cura::Color.white, focusable: false) | ||
list_textbox.on_event(:key_down, @listbox) do |event, listbox| | ||
if event.name == :enter | ||
list.name = text | ||
|
||
list.save | ||
|
||
self.focusable = false | ||
listbox.focus | ||
end | ||
end | ||
|
||
@listbox.add_child(list_textbox, list) | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.