Class: Alexandria::UI::SmartLibraryRuleBox
- Inherits:
-
Object
- Object
- Alexandria::UI::SmartLibraryRuleBox
- Defined in:
- lib/alexandria/ui/smart_library_rule_box.rb
Instance Attribute Summary collapse
-
#add_button ⇒ Object
Returns the value of attribute add_button.
-
#date_entry ⇒ Object
Returns the value of attribute date_entry.
-
#entry_label ⇒ Object
Returns the value of attribute entry_label.
-
#left_operand_combo ⇒ Object
Returns the value of attribute left_operand_combo.
-
#operator_combo ⇒ Object
Returns the value of attribute operator_combo.
-
#remove_button ⇒ Object
Returns the value of attribute remove_button.
-
#rule_box ⇒ Object
Returns the value of attribute rule_box.
-
#value_entry ⇒ Object
Returns the value of attribute value_entry.
Instance Method Summary collapse
- #handle_left_operand_changed ⇒ Object
- #handle_operator_changed ⇒ Object
-
#initialize(parent) ⇒ SmartLibraryRuleBox
constructor
A new instance of SmartLibraryRuleBox.
- #operands ⇒ Object
Constructor Details
#initialize(parent) ⇒ SmartLibraryRuleBox
Returns a new instance of SmartLibraryRuleBox.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 15 def initialize(parent) @parent = parent self.rule_box = Gtk::Box.new :horizontal rule_box.spacing = 8 self.left_operand_combo = Gtk::ComboBoxText.new self.operator_combo = Gtk::ComboBoxText.new self.value_entry = Gtk::Entry.new self.date_entry = Gtk::Entry.new.tap do |entry| entry.primary_icon_name = Gtk::Stock::EDIT entry.primary_icon_activatable = true entry.signal_connect("icon-press") do |, primary, icon| @parent.handle_date_icon_press(, primary, icon) end end self.entry_label = Gtk::Label.new("") self. = Gtk::Button.new(label: "").tap do || .remove(.children.first) << Gtk::Image.new(stock: Gtk::Stock::ADD, size: Gtk::IconSize::BUTTON) .signal_connect("clicked") { @parent.handle_add_rule_clicked } end self. = Gtk::Button.new(label: "") .remove(.children.first) << Gtk::Image.new(stock: Gtk::Stock::REMOVE, size: Gtk::IconSize::BUTTON) .signal_connect("clicked") do || @parent.handle_remove_rule_clicked(self) end operands.each do |operand| left_operand_combo.append_text(operand.name) end operator_combo.signal_connect("changed") do handle_operator_changed end left_operand_combo.signal_connect("changed") do handle_left_operand_changed end rule_box.pack_start(left_operand_combo, expand: false, fill: false) rule_box.pack_start(operator_combo, expand: false, fill: false) rule_box.pack_start(value_entry) rule_box.pack_start(date_entry) rule_box.pack_start(entry_label, expand: false, fill: false) rule_box.pack_end(, expand: false, fill: false) rule_box.pack_end(, expand: false, fill: false) value_entry.visible = date_entry.visible = entry_label.visible = false end |
Instance Attribute Details
#add_button ⇒ Object
Returns the value of attribute add_button.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def @add_button end |
#date_entry ⇒ Object
Returns the value of attribute date_entry.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def date_entry @date_entry end |
#entry_label ⇒ Object
Returns the value of attribute entry_label.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def entry_label @entry_label end |
#left_operand_combo ⇒ Object
Returns the value of attribute left_operand_combo.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def left_operand_combo @left_operand_combo end |
#operator_combo ⇒ Object
Returns the value of attribute operator_combo.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def operator_combo @operator_combo end |
#remove_button ⇒ Object
Returns the value of attribute remove_button.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def @remove_button end |
#rule_box ⇒ Object
Returns the value of attribute rule_box.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def rule_box @rule_box end |
#value_entry ⇒ Object
Returns the value of attribute value_entry.
10 11 12 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 10 def value_entry @value_entry end |
Instance Method Details
#handle_left_operand_changed ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 105 def handle_left_operand_changed operand = operands[left_operand_combo.active] operator_combo.freeze_notify do operator_combo.remove_all operations = SmartLibrary::Rule.operations_for_operand(operand) operations.each do |operation| operator = operation.first operator_combo.append_text(operator.name) end operator_combo.active = 0 end end |
#handle_operator_changed ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 81 def handle_operator_changed operand = operands[left_operand_combo.active] operations = SmartLibrary::Rule.operations_for_operand(operand) operation = operations[operator_combo.active] value_entry.visible = date_entry.visible = entry_label.visible = false right_operand = operation.last unless right_operand.nil? entry = case right_operand.klass.name when "Time" date_entry else value_entry end entry.visible = true unless right_operand.name.nil? entry_label.text = right_operand.name entry_label.visible = true end end @parent.apply_smart_rule_for_rule_box(rule_box, operand, operation) end |
#operands ⇒ Object
77 78 79 |
# File 'lib/alexandria/ui/smart_library_rule_box.rb', line 77 def operands SmartLibrary::Rule::Operands::LEFT end |