Class: GNetvibes::Icon
- Inherits:
-
Gtk::StatusIcon
- Object
- Gtk::StatusIcon
- GNetvibes::Icon
- Defined in:
- lib/gnetvibes/icon.rb
Instance Attribute Summary collapse
-
#buf ⇒ Object
readonly
Returns the value of attribute buf.
Instance Method Summary collapse
- #add(obj, tab) ⇒ Object
- #build_menu ⇒ Object
- #edit(obj, mod) ⇒ Object
-
#initialize(api) ⇒ Icon
constructor
A new instance of Icon.
- #refresh(*args) ⇒ Object
Constructor Details
#initialize(api) ⇒ Icon
Returns a new instance of Icon.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gnetvibes/icon.rb', line 6 def initialize(api) @api = api super() self.pixbuf = ICON self.signal_connect('popup-menu') do |w, , time| unless @menu.nil? @menu.popup(nil, nil, , time) do self.(@menu) end end end end |
Instance Attribute Details
#buf ⇒ Object (readonly)
Returns the value of attribute buf.
4 5 6 |
# File 'lib/gnetvibes/icon.rb', line 4 def buf @buf end |
Instance Method Details
#add(obj, tab) ⇒ Object
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/gnetvibes/icon.rb', line 153 def add(obj, tab) dlg = EditDialog.new(:postit) res = dlg.run if res == Gtk::Dialog::RESPONSE_ACCEPT @api.add(tab, :postit, :title => dlg.buf.text[/^[^\n]*/], :text => dlg.buf.text[/\n.*$/m].strip) refresh end dlg.destroy end |
#build_menu ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gnetvibes/icon.rb', line 21 def if @menu @menu_items.to_a.each {|i| i.destroy} @menu.destroy end @menu_items = [] @menu = Gtk::Menu.new @menu_items << Gtk::SeparatorMenuItem.new @menu.append(@menu_items.last) @menu_items << Gtk::ImageMenuItem.new(Gtk::Stock::REFRESH) @menu_items.last.signal_connect("activate", true, &method(:refresh)) @menu.append(@menu_items.last) @menu_items << Gtk::ImageMenuItem.new(Gtk::Stock::QUIT) @menu_items.last.signal_connect("activate") do Gtk.main_quit end @menu.append(@menu_items.last) @menu.show_all end |
#edit(obj, mod) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/gnetvibes/icon.rb', line 122 def edit(obj, mod) mod = @api.modules[mod.to_i] dlg = EditDialog.new(mod) begin res = dlg.run if res == Gtk::Dialog::RESPONSE_ACCEPT @api.save(mod['id'], :title => dlg.buf.text[/^[^\n]*/], :text => dlg.buf.text[/\n.*$/m].strip) refresh dlg.destroy elsif res == Gtk::Dialog::RESPONSE_APPLY confirm = Gtk::MessageDialog.new(dlg, Gtk::Dialog::MODAL, Gtk::MessageDialog::QUESTION, Gtk::MessageDialog::BUTTONS_YES_NO, "Are you sure ?") if confirm.run == Gtk::Dialog::RESPONSE_YES @api.delete(mod['id']) refresh dlg.destroy confirm.destroy else confirm.destroy raise 'Retry' end else dlg.destroy end rescue RuntimeError retry end end |
#refresh(*args) ⇒ Object
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/gnetvibes/icon.rb', line 43 def refresh(*args) self.tooltip = "#{NAME} refreshing..."; @api.refresh @api.tabs.each do |id, tab| # Title = Gtk::ImageMenuItem.new(tab['title']) if not tab['icon'].strip.empty? .image = Gtk::Image.new(@api.download(tab['icon'])) end = Gtk::Menu.new # Add item @menu_items << Gtk::ImageMenuItem.new(Gtk::Stock::ADD) @menu_items.last.signal_connect("activate", id, &method(:add)) .append(@menu_items.last) # Separator if @api.tab_has?(id, :postit) @menu_items << Gtk::SeparatorMenuItem.new .append(@menu_items.last) end # Postit @api.each_postit_in_tab(id) do |postit| @menu_items << Gtk::ImageMenuItem.new(postit['title']) @menu_items.last.image = Gtk::Image.new(ICON_POSTIT) @menu_items.last.signal_connect("activate", postit['id'], &method(:edit)) .append(@menu_items.last) end # TodoLists @api.each_todo_list_in_tab(id) do |todolist| title = todolist['data']['title'] || todolist['title'] @menu_items << Gtk::ImageMenuItem.new(title) @menu_items.last.image = Gtk::Image.new(ICON_TODOLIST) @menu_items.last.signal_connect("activate", todolist['id'], &method(:edit)) .append(@menu_items.last) end # Feeds items = [] @api.each_feed_in_tab(id) do |feed| next if feed['unread'].zero? if feed['unread'] > 0 items << feed['title'] + " (#{feed['unread']})" else items << feed['title'] end end if not items.empty? # Separator if @api.tab_has?(id, :feed) @menu_items << Gtk::SeparatorMenuItem.new .append(@menu_items.last) end items.each do |title| @menu_items << Gtk::ImageMenuItem.new(title) @menu_items.last.image = Gtk::Image.new(ICON_FEED) .append(@menu_items.last) end end . = @menu_items << @menu_items << @menu.prepend() end @menu.show_all self.tooltip = NAME; GC.start end |