def get_file_items(self, window, sel_items): """Adds the 'Add To Audacious Playlist' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the list of selected Audio items""" num_paths = len(sel_items) if num_paths == 0 or num_paths > 2: return uri_raw = sel_items[0].get_uri() if len(uri_raw) < 7: return element_1 = urllib.unquote(uri_raw[7:]) if num_paths == 2: uri_raw = sel_items[1].get_uri() if len(uri_raw) < 7: return element_2 = urllib.unquote(uri_raw[7:]) if os.path.isfile(element_1): if not os.path.isfile(element_2): return element_1 = re.escape(element_1) filetype = subprocess.Popen("file -i %s" % element_1, shell=True, stdout=subprocess.PIPE).communicate()[0] if "text" not in filetype and "xml" not in filetype: return element_2 = re.escape(element_2) filetype = subprocess.Popen("file -i %s" % element_2, shell=True, stdout=subprocess.PIPE).communicate()[0] if "text" not in filetype and "xml" not in filetype: return elif os.path.isdir(element_1): if not os.path.isdir(element_2): return element_1 = re.escape(element_1) element_2 = re.escape(element_2) else: return item = caja.MenuItem('Kdiff3::kdiff3', _('Kdiff3 Compare'), _('Compare the selected Files/Folders using Kdiff3 (Diff and merge tool)') ) item.set_property('icon', 'kdiff3') item.connect('activate', self.run, element_1, element_2) return item, # only one item selected if os.path.isfile(element_1): filetype = subprocess.Popen("file -i %s" % re.escape(element_1), shell=True, stdout=subprocess.PIPE).communicate()[0] if "text" not in filetype and "xml" not in filetype: return # top menuitem top_menuitem = caja.MenuItem('Kdiff3::actions', _('Kdiff3 Actions'), _('Kdiff3 (Diff and merge tool) Actions') ) top_menuitem.set_property('icon', 'kdiff3') # creation of submenus submenu = caja.Menu() top_menuitem.set_submenu(submenu) # submenu items save sub_menuitem_save = caja.MenuItem('Kdiff3::save', _('Save Path for Future Use'), _('Save the Selected File/Dir Path for Future Use') ) sub_menuitem_save.set_property('icon', 'gtk-save') sub_menuitem_save.connect('activate', self.kdiff3_save, element_1) submenu.append_item(sub_menuitem_save) # submenu items compare with saved stored_path = self.mateconf_client.get_string(MATECONF_PATH) if stored_path and stored_path != element_1 and ( (os.path.isfile(stored_path) and os.path.isfile(element_1) ) or (os.path.isdir(stored_path) and os.path.isdir(element_1) ) ): sub_menuitem_compare_saved = caja.MenuItem('Kdiff3::compare_saved', _('Compare with %s' % stored_path.replace("_", " ") ), _('Compare the Selected File/Dir with %s' % stored_path) ) sub_menuitem_compare_saved.set_property('icon', 'gtk-execute') sub_menuitem_compare_saved.connect('activate', self.run, re.escape(element_1), re.escape(stored_path)) submenu.append_item(sub_menuitem_compare_saved) return top_menuitem,
def _buildMenu(self, menus): '''Build one level of a menu''' items = [] if self.files: passcwd = None else: #bg passcwd = self.cwd for menu_info in menus: idstr = '%s::%02d%s' % (idstr_prefix, self.pos, menu_info.hgcmd) self.pos += 1 if menu_info.isSep(): # can not insert a separator till now pass elif menu_info.isSubmenu(): if hasattr(caja, 'Menu'): item = caja.MenuItem(idstr, menu_info.menutext, menu_info.helptext) submenu = caja.Menu() item.set_submenu(submenu) for subitem in self._buildMenu(menu_info.get_menus()): submenu.append_item(subitem) items.append(item) else: #submenu not suported for subitem in self._buildMenu(menu_info.get_menus()): items.append(subitem) else: if menu_info.state: item = caja.MenuItem(idstr, menu_info.menutext, menu_info.helptext, self.icon(menu_info.icon)) item.connect('activate', self.run_dialog, menu_info.hgcmd, passcwd) items.append(item) return items
def get_file_items(self, window, sel_items): """Adds the 'Add To Audacious Playlist' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the list of selected Audio items""" if len(sel_items) == 0: return if sel_items[0].is_directory( ) or sel_items[0].get_uri_scheme() != 'file': return source_path_list = [] for sel_item in sel_items: uri_raw = sel_item.get_uri() if len(uri_raw) < 7: continue source_path = re.escape(urllib.unquote(uri_raw[7:])) filetype = subprocess.Popen( "file -i %s" % source_path, shell=True, stdout=subprocess.PIPE).communicate()[0] if "audio" in filetype\ or "application/ogg" in filetype: source_path_list.append(source_path) if source_path_list: item = caja.MenuItem( 'CajaPython::audacious', _('Add To Audacious Playlist'), _('Add the selected Audio file(s) to the Audacious Playlist')) item.set_property('icon', 'audacious') item.connect('activate', self.run, source_path_list) return item,
def get_background_items(self, window, current_directory): """Adds the 'Open Terminal Geometry' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the current Directory""" item = caja.MenuItem('CajaPython::terminal', _('Open Terminal Here'), _('Open the Terminal on the Current Directory')) item.set_property('icon', 'terminal') item.connect('activate', self.run, current_directory) return item,
def get_background_items(self, window, current_directory): """Adds the 'Replace in Filenames' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the current Directory""" item = caja.MenuItem( 'CajaPython::gtk-find-and-replace', _('Replace in Filenames'), _('Replace in Filenames of the Current Directory')) item.set_property('icon', 'gtk-find-and-replace') item.connect('activate', self.run, current_directory) return item,
def get_file_items(self, window, sel_items): """Adds the 'Open Terminal Geometry' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the selected Directory/File""" if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return item = caja.MenuItem( 'CajaPython::terminal', _('Open Terminal Here'), _('Open the Terminal on the Current/Selected Directory')) item.set_property('icon', 'terminal') item.connect('activate', self.run, sel_items[0]) return item,
def get_file_items(self, window, sel_items): """Adds the 'Replace in Filenames' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the selected Directory/File""" if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return item = caja.MenuItem( 'CajaPython::gtk-find-and-replace', _('Replace in Filenames'), _('Replace in Filenames of the Current/Selected Directory')) item.set_property('icon', 'gtk-find-and-replace') item.connect('activate', self.run, sel_items[0]) return item,
def get_file_items(self, window, sel_items): """Adds the 'Open as Root' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the selected File/Folder""" if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return uri_raw = sel_items[0].get_uri() if len(uri_raw) < 7: return source_path = urllib.unquote(uri_raw[7:]) item = caja.MenuItem('CajaPython::gksu', _('Open as Root'), _('Open the selected File/Folder as Root User')) item.set_property('icon', 'gksu') item.connect('activate', self.run, re.escape(source_path)) return item,
def get_file_items(self, window, sel_items): """Adds the 'Set As Desktop Background' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the list of selected Image item""" if len(sel_items) != 1 or sel_items[0].is_directory( ) or sel_items[0].get_uri_scheme() != 'file': return uri_raw = sel_items[0].get_uri() if len(uri_raw) < 7: return source_path = urllib.unquote(uri_raw[7:]) filetype = subprocess.Popen("file -i %s" % re.escape(source_path), shell=True, stdout=subprocess.PIPE).communicate()[0] if "image" in filetype: item = caja.MenuItem( 'CajaPython::preferences-desktop-wallpaper', _('Set As Desktop Background'), _('Set the selected Image file as Desktop Background')) item.set_property('icon', 'preferences-desktop-wallpaper') item.connect('activate', self.run, source_path) return item,