def get_file_items(self, window, files): """Ensure there are reachable devices""" try: devices = self.get_reachable_devices() except Exception as e: raise Exception("Error while getting reachable devices") """if there is no reacheable devices don't show this on context menu""" if not devices: return """Ensure that user only select files""" for file in files: if file.get_uri_scheme() != 'file' or file.is_directory( ) and os.path.isfile(file): return self.setup_gettext() """If user only select file(s) create menu and sub menu""" menu = Caja.MenuItem(name='KdeConnectSendExtension::KDEConnect_Send', label=_('KDEConnect Send To'), tip=_('send file(s) with kdeconnect'), icon='kdeconnect') sub_menu = Caja.Menu() menu.set_submenu(sub_menu) for device in devices: item = Caja.MenuItem(name="KDEConnectSendExtension::Send_File_To", label=device["name"]) item.connect('activate', self.menu_activate_cb, files, device["id"], device["name"]) sub_menu.append_item(item) return menu,
def get_file_items(self, window, files): if len(files) != 1: return file = files[0] filename = file.get_name() if file.is_directory() or file.get_uri_scheme() != 'file': return encryption_item = Caja.MenuItem( name='CajaPython::ccencrypt_file_item', label=encrypt_loc.get(loc, 'Encrypt') + '...', tip='Encrypt this file using ccencrypt') encryption_item.connect('activate', self.menu_activate_encryption, file) # Check if file is .cpt or otherwise is_encrypted = file.get_name().endswith('.cpt') if not is_encrypted: return encryption_item, # Otherwise, include a decryption option decryption_item = Caja.MenuItem( name='CajaPython::ccdecrypt_file_item', label=decrypt_loc.get(loc, 'Decrypt') + '...', tip='Decrypt this file using ccdecrypt') decryption_item.connect('activate', self.menu_activate_decryption, file) return (encryption_item, decryption_item)
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(name='Meld::meld', label=_('Meld Compare'), tip=_('Compare the selected Files/Folders using Meld (Diff and merge tool)'), icon='meld') 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(name='Meld::actions', label=_('Meld Actions'), tip=_('Meld (Diff and merge tool) Actions'), icon='meld') # creation of submenus submenu = Caja.Menu() top_menuitem.set_submenu(submenu) # submenu items save sub_menuitem_save = Caja.MenuItem(name='Meld::save', label=_('Save Path for Future Use'), tip=_('Save the Selected File/Dir Path for Future Use'), icon='gtk-save') sub_menuitem_save.connect('activate', self.meld_save, element_1) submenu.append_item(sub_menuitem_save) # submenu items compare with saved stored_path = os.environ[NAUPYEXT_MELD] if NAUPYEXT_MELD in os.environ else "" 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(name='Meld::compare_saved', label=_('Compare with %s' % stored_path.replace("_", " ") ), tip=_('Compare the Selected File/Dir with %s' % stored_path), 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 get_file_items(self, window, items_selected): if not items_selected: # No items selected return locale.setlocale(locale.LC_ALL, '') gettext.bindtextdomain('folder-color-switcher') gettext.textdomain('folder-color-switcher') directories = [] directories_selected = [] for item in items_selected: # Only folders if not item.is_directory(): logger.info("A selected item is not a directory, skipping") continue logger.debug('URI "%s" is in selection', item.get_uri()) if item.get_uri_scheme() != 'file': return directory = item.get_location() logger.debug('Valid path selected: "%s"', directory.get_path()) directories.append(directory) directories_selected.append(item) if not directories_selected: return supported_colors = self.theme.get_supported_colors(directories) if supported_colors: logger.debug("At least one color supported: creating menu entry") top_menuitem = Caja.MenuItem(name='ChangeFolderColorMenu::Top', label=_("Change color")) submenu = Caja.Menu() top_menuitem.set_submenu(submenu) for color in supported_colors: name = ''.join(['ChangeFolderColorMenu::"', color, '"']) label = _(color) item = Caja.MenuItem(name=name, label=label, icon='folder-color-switcher-%s' % color.lower()) item.connect('activate', self.menu_activate_cb, color, directories_selected) submenu.append_item(item) # Separator item_sep = Caja.MenuItem(name='ChangeFolderColorMenu::Sep1', label=self.SEPARATOR, sensitive=False) submenu.append_item(item_sep) # Restore item_restore = Caja.MenuItem(name='ChangeFolderColorMenu::Restore', label=_("Default")) item_restore.connect('activate', self.menu_activate_cb, None, directories_selected) submenu.append_item(item_restore) return top_menuitem,
def get_file_items(self, window, items_selected): if not items_selected: # No items selected return locale.setlocale(locale.LC_ALL, '') gettext.bindtextdomain('folder-color-switcher') gettext.textdomain('folder-color-switcher') paths = [] for item in items_selected: # Only folders if not item.is_directory(): logger.info("A selected item is not a directory, exiting") return item_uri = item.get_uri() logger.debug('URI "%s" is in selection', item_uri) uri_tuple = urlparse.urlparse(item_uri) # GNOME can only handle "file" URI scheme # break if the file URI has weired components (such as params) if uri_tuple[0] != 'file' or uri_tuple[1] or uri_tuple[3] or uri_tuple[4] or uri_tuple[5]: logger.info("A selected item as a weired URI, exiting") return path = uri_tuple[2] logger.debug('Valid path selected: "%s"', path) paths.append(path) supported_colors = self.theme.get_supported_colors(paths) if supported_colors: top_menuitem = Caja.MenuItem(name='ChangeFolderColorMenu::Top', label=_("Change color"), tip='', icon='') submenu = Caja.Menu() top_menuitem.set_submenu(submenu) for color in supported_colors: name = ''.join(['ChangeFolderColorMenu::"', color, '"']) label = _(color) item = Caja.MenuItem(name=name, label=label, icon='folder-color-switcher-%s' % color.lower()) item.connect('activate', self.menu_activate_cb, color, items_selected) submenu.append_item(item) # Separator item_sep = Caja.MenuItem(name='ChangeFolderColorMenu::Sep1', label=self.SEPARATOR, sensitive=False) submenu.append_item(item_sep) # Restore item_restore = Caja.MenuItem(name='ChangeFolderColorMenu::Restore', label=_("Default")) item_restore.connect('activate', self.menu_activate_cb, None, items_selected) submenu.append_item(item_restore) return top_menuitem,
def get_background_items(self, window, file): submenu = Caja.Menu() submenu.append_item( Caja.MenuItem(name='ExampleMenuProvider::Bar2', label='Bar2', tip='', icon='')) menuitem = Caja.MenuItem(name='ExampleMenuProvider::Foo2', label='Foo2', tip='', icon='') menuitem.set_submenu(submenu) return menuitem,
def get_background_items(self, window, current_directory): item = Caja.MenuItem(name=name, label=_(label), tip=_(tip), icon=icon) item.connect('activate', self.run, current_directory) return [item]
def get_file_items(self, window, files): top_menuitem = Caja.MenuItem(name='ExampleMenuProvider::Foo', label='Foo', tip='', icon='') submenu = Caja.Menu() top_menuitem.set_submenu(submenu) sub_menuitem = Caja.MenuItem(name='ExampleMenuProvider::Bar', label='Bar', tip='', icon='') submenu.append_item(sub_menuitem) return top_menuitem,
def get_file_items(self, window, sel_items): if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return item = Caja.MenuItem(name=name, label=_(label), tip=_(tip), icon=icon) item.connect('activate', self.run, sel_items[0]) return [item]
def _create_hide_item(self, files, hidden_path, hidden): """Creates the 'Hide file(s)' menu item.""" item = Caja.MenuItem(name="CajaHide::HideFile", label=ngettext("_Hide File", "_Hide Files", len(files)), tip=ngettext("Hide this file", "Hide these files", len(files))) item.connect("activate", self._hide_run, files, hidden_path, hidden) return item
def get_background_items(self, window, current_directory): if not self._is_server_online(): return synced_dirs = _get_synced_dirs(_get_conf()) dir_path = _get_item_path(current_directory) if dir_path in synced_dirs.values(): item = Caja.MenuItem(name='CajaSyncthing::curr_dir_rm', label='Remove Current Directory from Syncthing', tip='Remove current directory from syncthing', icon='emblem-synchronizing') item.connect('activate', self.on_dir_rm, current_directory) else: item = Caja.MenuItem(name='CajaSyncthing::curr_dir_add', label='Add Current Directory to Syncthing', tip='Add current directory to syncthing', icon='emblem-synchronizing') item.connect('activate', self.on_dir_add, current_directory) return [item]
def get_background_items(self, window, file): item = Caja.MenuItem( name='CajaPython::openscanner_directory', label=_('Scan directory for threats...'), tip=_('Scan this directory for threats...'), icon='clamtk') # - the tooltips are not shown any longer in Caja # (the code is kept here in case this changes again for Caja item.connect('activate', self.menu_background_activate_cb, file) return [item]
def get_file_items(self, window, files): """Ensure there are reachable devices""" try: devices = self.get_reachable_devices() except Exception as e: raise Exception("Error while getting reachable devices") """if there is no reacheable devices don't show this on context menu""" if len(devices) == 0: return """Ensure that user only select files""" for file in files: if file.get_uri_scheme() != 'file' or file.is_directory(): return self.setup_gettext() """If user only select file(s) create menu and sub menu""" menu = Caja.MenuItem(name = 'SendViaExtension::SendViaKDEConnect', label = _('KDEConnect Send To'), tip = _('send file(s) with kdeconnect'), icon = 'kdeconnect') sub_menu = Caja.Menu() menu.set_submenu(sub_menu) for deviceId, deviceName in devices.items(): item = Caja.MenuItem(name='SendViaExtension::SendFileTo'+deviceId, label=deviceName) item.connect('activate', self.send_files, files, deviceId, deviceName) sub_menu.append_item(item) if len(devices) > 1: item = Caja.MenuItem(name='SendViaExtension::SendFileToMultipleDevices', label='Multiple Devices') item.connect('activate', self.send_to_multiple_devices, files) sub_menu.append_item(item) return menu,
def get_file_items(self, oWindow, lstItems): if len(lstItems) > 1: oMenuItem = Caja.MenuItem(name='cajarename', label=_('Rename All...'), icon='font') oMenuItem.connect('activate', self.onActivate, lstItems) self.oWindow = oWindow return [oMenuItem]
def get_background_items(self, window, folder): mixed = self._file_has_mixed_name(folder) if not mixed: return [] return [ Caja.MenuItem( name='Mixed::BackgroundMenu', label= 'Mixed: you are browsing a directory with a mixed case name', tip='', icon='') ]
def get_file_items(self, window, sel_items): if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return if not self._is_server_online(): return synced_dirs = _get_synced_dirs(_get_conf()) dir_path = _get_item_path(sel_items[0]) if dir_path in synced_dirs.values(): item = Caja.MenuItem(name='CajaSyncthing::dir_rm', label='Remove Directory from Syncthing', tip='Remove selected directory from syncthing', icon='emblem-synchronizing') item.connect('activate', self.on_dir_rm, sel_items[0]) else: item = Caja.MenuItem(name='CajaSyncthing::dir_add', label='Add Directory to Syncthing', tip='Add selected directory to syncthing', icon='emblem-synchronizing') item.connect('activate', self.on_dir_add, sel_items[0]) return [item]
def get_file_items(self, window, files): # Keep only the files we want (right type and file) files = [ f for f in files if self.is_valid(f)] if len(files) == 0: return item = Caja.MenuItem(name='Caja::download_subtitles', label=_('Find subtitles for this video'), tip=_('Download subtitles for this video'), icon=Gtk.STOCK_FIND_AND_REPLACE) item.connect('activate', self.menu_activate_cb, files) return item,
def make_menu_item(self, item, id_magic): identifier = item.make_magic_id(id_magic) menuitem = Caja.MenuItem(name=identifier, label=item.make_label(), tip=item.tooltip, icon=item.icon) if type(item) is MenuSeparator: item.make_insensitive(menuitem) return menuitem
def get_background_items(self, window, current_directory): """Adds the 'Open VScode Here' menu item to the Caja right-click menu, connects its 'activate' signal to the 'run' method passing the current Directory""" item = Caja.MenuItem( name='CajaPython::vscode', label=_('Open VScode Here'), tip=_( 'Open the Visual Studio code on the Current/Selected Directory' ), icon='code') item.connect('activate', self.run, current_directory) return [item]
def get_file_items(self, window, files): if len(files) != 1: return file = files[0] if not file.is_directory() or file.get_uri_scheme() != 'file': return item = Caja.MenuItem(name='CajaPython::openterminal_file_item', label='Open Terminal' , tip='Open Terminal In %s' % file.get_name()) item.connect('activate', self.menu_activate_cb, file) return [item]
def get_file_items(self, window, sel_items): """Adds the 'Open VScode Here' 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( name='CajaPython::vscode', label=_('Open VScode Here'), tip=_( 'Open the Visual Studio code on the Current/Selected Directory' ), icon='code') 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 FileBrowser right-click menu, connects its 'activate' signal to the 'run' method passing the selected Directory/File""" sel_items = get_files(sel_items) if not len(sel_items) > 0: return item = FileBrowser.MenuItem( name='AntiviralMenuProvider::Gtk-antiviral-tools', label=_('Scan folder'), tip=_('Scan this folder'), icon='Gtk-find-and-replace') item.connect('activate', self.addfolders, sel_items) return item,
def get_file_items(self, window, files): if len(files) != 1: return file = files[0] item = Caja.MenuItem( name='CajaPython::openscanner', label=_('Scan for threats...') , tip=_('Scan %s for threats...') % file.get_name(), icon='clamtk') # - the tooltips are not shown any longer in Caja # (the code is kept here in case this changes again for Caja item.connect('activate', self.menu_activate_cb, file) return [item]
def get_file_items(self, window, cajafiles): menuitems = [] if len(cajafiles) == 1: for cajafile in cajafiles: mixed = cajafile.get_string_attribute('mixed') if mixed: filename = cajafile.get_name() menuitem = Caja.MenuItem( name='Mixed::FileMenu', label='Mixed: %s has a mixed case name' % filename, tip='', icon='') menuitems.append(menuitem) return menuitems
def get_file_items(self, window, files): if len(files) != 1: return fileObj = files[0] if fileObj.get_uri_scheme() != 'file': return if fileObj.is_directory(): return filename = urllib.unquote(fileObj.get_uri())[7:] itemEncrypt = Caja.MenuItem(name='EncryptMenuProvider::Encrypt', label='Зашифровать', tip='Зашифровать файл %s' % filename) itemEncrypt.connect("activate", self.menu_activate_cb, fileObj) return itemEncrypt,
def get_file_items(self, window, files): if len(files) == 0: return # We do not support sending whole directories for f in files: if f.is_directory(): return item = Caja.MenuItem(name='BluemanSendto::blueman_send_files', label='Send files over bluetooth', tip='Sends files over bluetooth with blueman', icon='blueman') item.connect('activate', self.on_menu_activate, files) return [item]
def get_file_items(self, window, files): if len(files) != 1: return fileObj = files[0] if fileObj.get_uri_scheme() != 'file': return if fileObj.is_directory(): return filename = urllib.unquote(fileObj.get_uri())[7:] if filename[-3:] != 'sig': return itemVerify = Caja.MenuItem(name='DettachMenuProvider::Dettach', label='Отсоединить подпись', tip='Отсоединить подпись %s' % filename) itemVerify.connect("activate", self.menu_activate_cb, fileObj) return itemVerify,
def get_file_items(self, window, files): if len(files) != 1: return file = files[0] # We're only going to put ourselves on images context menus if not file.get_mime_type() in SUPPORTED_FORMATS: return # Mate can only handle file: # In the future we might want to copy the file locally if file.get_uri_scheme() != 'file': return item = Caja.MenuItem(name='Caja::set_background_image', label='Use as background image', tip='Set the current image as a background image') item.connect('activate', self.menu_activate_cb, file) return [item]
def get_file_items(self, window, files): if len(files) != 1: return fileObj = files[0] if fileObj.get_uri_scheme() != 'file': return if fileObj.is_directory(): return filename = urllib.unquote(fileObj.get_uri())[7:] if filename[-3:] != 'sig': return if os.path.isfile(filename[:-4]): return itemVerify = Caja.MenuItem(name='VerifyMenuProvider::Verify', label='Проверить ЭЦП', tip='Проверить ЭЦП %s' % filename) itemVerify.connect("activate", self.menu_activate_cb, fileObj) return itemVerify,
def _buildMenu(self, menus, files): '''Build one level of a menu''' items = [] if 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(Nautilus, 'Menu'): item = Nautilus.MenuItem(name=idstr, label=menu_info.menutext, tip=menu_info.helptext) submenu = Nautilus.Menu() item.set_submenu(submenu) for subitem in self._buildMenu(menu_info.get_menus(), files): submenu.append_item(subitem) items.append(item) else: #submenu not suported for subitem in self._buildMenu(menu_info.get_menus(), files): items.append(subitem) else: if menu_info.state: item = Nautilus.MenuItem.new(idstr, menu_info.menutext, menu_info.helptext, self.icon(menu_info.icon)) item.connect('activate', self.run_dialog, menu_info.hgcmd, passcwd, files) items.append(item) return items