Beispiel #1
0
    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():
                return

        self.setup_gettext()
        """If user only select file(s) create menu and sub menu"""
        menu = Caja.MenuItem(name='KdeConnectSendExtension::KDEConnectSend',
                             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::SendFileTo' +
                                 device["id"],
                                 label=device["name"])
            item.connect('activate', self.send_files, files, device["id"],
                         device["name"])
            sub_menu.append_item(item)

        if len(devices) > 1:
            item = Nautilus.MenuItem(
                name='KDEConnectSendExtension::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, window, files):
        if len(files) != 1:
            return

        item = files[0]
        uri = item.get_uri()

        if uri == self.cloud_folder_uri:
            return
        if not self.valid_uri(uri):
            return

        full_path = self.uri_to_full_path(uri)
        uri = self.uri_to_path(uri)

        top_menuitem = Caja.MenuItem.new('MEOCloudMenuProvider::MEOCloud',
                                         'MEO Cloud', '', '')

        submenu = Caja.Menu()
        top_menuitem.set_submenu(submenu)

        link_menuitem = Caja.MenuItem.new('MEOCloudMenuProvider::Copy',
                                          _('Copy Link'), '', '')
        link_menuitem.connect("activate", lambda w: self.share_link(uri))
        submenu.append_item(link_menuitem)

        if not os.path.isfile(full_path):
            share_menuitem = Caja.MenuItem.new(
                'MEOCloudMenuProvider::Share', _('Share Folder'), '', '')
            share_menuitem.connect("activate", lambda w:
                                   self.share_folder(uri))
            submenu.append_item(share_menuitem)

        browser_menuitem = Caja.MenuItem.new(
            'MEOCloudMenuProvider::Browser', _('Open in Browser'), '', '')
        browser_menuitem.connect("activate", lambda w:
                                 self.open_in_browser(uri))
        submenu.append_item(browser_menuitem)

        return top_menuitem,
Beispiel #3
0
    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
Beispiel #4
0
 def attach_submenu(self, menu_node, submenu_list):
     submenu = Caja.Menu()
     menu_node.set_submenu(submenu)
     [submenu.append_item(item) for item in submenu_list]
Beispiel #5
0
 def get_file_items(self, window, sel_items):
     """Adds the 'Replace in Filenames' menu item to the File Manager
     right-click menu, connects its 'activate' signal to the 'run' method
     passing the selected Directory/File"""
     if tools.all_files_are_pdf(sel_items):
         top_menuitem = FileManager.MenuItem(
             name='PdfToolsMenuProvider::Gtk-pdf-tools',
             label=_('Pdf Tools'),
             tip=_('Tools to manipulate pdf files'),
             icon='Gtk-find-and-replace')
         #
         submenu = FileManager.Menu()
         top_menuitem.set_submenu(submenu)
         sub_menus = []
         items = [
             ('01', _('Rotate and flip'), _('rotate_and_flip pdf files'),
              'rotate'),
             ('02', _('Watermark'), _('Watermark pdffiles'), 'watermark'),
             ('03', _('Textmark'), _('Textmark pdf files'), 'textmark'),
             ('04', _('Paginate'), _('Paginate pdf files'), 'paginate'),
             ('05', _('Rotate pages'),
              _('Rotate pages of the document files'), 'rotate pages'),
             ('06', _('Remove pages'),
              _('Remove pages of the document files'), 'remove pages'),
             ('07', _('Extract pages'),
              _('Extract pages of the document files'), 'extract pages'),
             ('08', _('Join pdf files'),
              _('Join pdf files in one document'), 'join'),
             ('09', _('Split pdf files'),
              _('Split a pdf in several documents'), 'split'),
             ('10', _('Combine pdf pages'),
              _('Combine pdf pages in one page'), 'combine'),
             ('11', _('Reduce pdf size'), _('Reduce pdf size'), 'reduce'),
             ('12', _('Resize pdf pages'), _('Resize pdf pages'), 'resize'),
             ('13', _('Convert pdf to png'),
              _('Convert pdf file to png image'), 'convert2png'),
         ]
         for item in items:
             sub_menuitem = FileManager.MenuItem(
                 name='PdfToolsMenuProvider::Gtk-pdf-tools-' + item[0],
                 label=item[1],
                 tip=item[2])
             sub_menuitem.connect('activate', self.doit, item[3], sel_items)
             submenu.append_item(sub_menuitem)
         #
         sub_menuitem_98 = FileManager.MenuItem(
             name='PdfToolsMenuProvider::Gtk-None', label=SEPARATOR)
         submenu.append_item(sub_menuitem_98)
         #
         sub_menuitem_99 = FileManager.MenuItem(
             name='PdfToolsMenuProvider::Gtk-pdf-tools-99',
             label=_('About'),
             tip=_('About'),
             icon='Gtk-find-and-replace')
         sub_menuitem_99.connect('activate', self.about)
         submenu.append_item(sub_menuitem_99)
         #
         return top_menuitem,
     elif tools.all_files_are_images(sel_items):
         top_menuitem = FileManager.MenuItem(
             name='PdfToolsMenuProvider::Gtk-pdf-tools',
             label=_('Pdf Tools'),
             tip=_('Tools to manipulate pdf files'),
             icon='Gtk-find-and-replace')
         submenu = FileManager.Menu()
         top_menuitem.set_submenu(submenu)
         sub_menus = []
         items = [('51', _('Convert to pdf'), _('Convert images to pdf'),
                   'convert2pdf')]
         for item in items:
             sub_menuitem = FileManager.MenuItem(
                 name='PdfToolsMenuProvider::Gtk-pdf-tools-' + item[0],
                 label=item[1],
                 tip=item[2])
             sub_menuitem.connect('activate', self.doit, item[3], sel_items)
             submenu.append_item(sub_menuitem)
         #
         sub_menuitem_98 = FileManager.MenuItem(
             name='PdfToolsMenuProvider::Gtk-None', label=SEPARATOR)
         submenu.append_item(sub_menuitem_98)
         #
         sub_menuitem_99 = FileManager.MenuItem(
             name='PdfToolsMenuProvider::Gtk-pdf-tools-99',
             label=_('About'),
             tip=_('About'),
             icon='Gtk-find-and-replace')
         sub_menuitem_99.connect('activate', self.about)
         submenu.append_item(sub_menuitem_99)
         #
         return top_menuitem,
     return