class PasteHistoryView(PidaView): key = 'pastebin.history' label_text = _('Paste History') icon_name = gtk.STOCK_PASTE #glade_file_name = 'paste-history.glade' def create_ui(self): self.history_tree = ObjectList( [Column('markup', use_markup=True, expand=True)]) self.history_tree.set_headers_visible(False) self.add_main_widget(self.history_tree) self.x11_clipboard = gtk.Clipboard(selection="PRIMARY") self.gnome_clipboard = gtk.Clipboard(selection="CLIPBOARD") self.history_tree.connect('item-right-clicked', self.on_paste_rclick) self.__pulse_bar = gtk.ProgressBar() self.add_main_widget(self.__pulse_bar, expand=False) # only show pulse bar if working self.__pulse_bar.hide() self.__pulse_bar.set_size_request(-1, 12) self.__pulse_bar.set_pulse_step(0.01) self.history_tree.show_all() @property def tree_selected(self): return self.history_tree.selected_item def set(self, pastes): '''Sets the paste list to the tree view. First reset it, then rebuild it. ''' self.history_tree.clear() self.history_tree.expand(pastes) self.tree_selected = None def add_paste(self, item): self.history_tree.append(item) def copy_current_paste(self): '''Callback function bound to the toolbar button view that copies the selected paste''' if self.tree_selected != None: self.x11_clipboard.set_text(self.tree_selected.get_url()) self.gnome_clipboard.set_text(self.tree_selected.get_url()) def view_current_paste(self): '''Callback function bound to the toolbar button view that shows the selected paste''' if self.tree_selected != None: self.service.boss.call_command('pastemanager', 'view_paste', paste=self.tree_selected) else: print _("ERROR: No paste selected") def remove_current_paste(self): '''Callback function bound to the toolbar button delete that removes the selected paste''' if self.tree_selected != None: self.service.boss.call_command('pastemanager', 'delete_paste', paste=self.tree_selected) else: print _("ERROR: No paste selected") def cb_paste_db_clicked(self, ol, item): """ Callback function called when an item is double clicked, and copy it to the gnome/gtk clipboard """ if item is not None: self.svc.boss.cmd('browseweb', 'browse', url=item.url) # self.__gnome_clipboard.set_text(self.__tree_selected.get_url()) # aa: view the paste def cb_paste_m_clicked(self, paste, tree_item): '''Callback function called when an item is middle clicked, and copy it to the mouse buffer clipboard''' if self.__tree_selected != None: self.__x11_clipboard.set_text(self.__tree_selected.get_url()) def cb_paste_r_clicked(self, paste, tree_item, event): menu = gtk.Menu() sensitives = (tree_item is not None) for action in [ 'pastemanager+new_paste', None, 'pastemanager+remove_paste', 'pastemanager+view_paste', None, 'pastemanager+copy_url_to_clipboard' ]: if action is None: menu.append(gtk.SeparatorMenuItem()) else: act = self.service.action_group.get_action(action) if 'new_paste' not in action: act.set_sensitive(sensitives) mi = gtk.ImageMenuItem() act.connect_proxy(mi) mi.show() menu.append(mi) menu.show_all() menu.popup(None, None, None, event.button, event.time) def on_paste_rclick(self, ol, item, event): self.svc.boss.cmd('contexts', 'popup_menu', context='url-menu', url=item.url, event=event) def start_pulse(self): '''Starts the pulse''' self._pulsing = True self.__pulse_bar.show() gobject.timeout_add(100, self._pulse) def stop_pulse(self): self.__pulse_bar.hide() self._pulsing = False def _pulse(self): self.__pulse_bar.pulse() return self._pulsing def can_be_closed(self): self.svc.get_action('show_pastes').set_active(False)