Exemple #1
0
 def backup(self):
     """ Copy current file to backup. """
     from bookmarks.tools import get_config
     config = get_config(
         self.ctx, "/org.openoffice.Office.Common/Save/Document")
     if not config.CreateBackup:
         return
     from bookmarks import CONFIG_NODE_CONTROLLERS, NAME_BACKUP_DIRECTORY
     from bookmarks.tools import get_user_backup, join_url, copy_file
     try:
         backup_dir = None
         config = get_config(self.ctx, CONFIG_NODE_CONTROLLERS)
         if config.hasByName(self.command):
             _config = config.getByName(self.command)
             backup_dir = _config.getPropertyValue(NAME_BACKUP_DIRECTORY)
         
         if not backup_dir:
             backup_dir = join_url(get_user_backup(self.ctx), self.BACKUP_DIR)
         file_name = self.FILE_NAME % (
                 time.strftime(self.DATE_FORMAT) + \
                     "_" + self.command.split(":")[-1])
         copy_file(
             self.ctx, 
             self.file_url, 
             join_url(backup_dir, file_name)
         )
     except Exception as e:
         print(e)
Exemple #2
0
 def _init_config_manager(self):
     self.config_supplier = self.create_service(
         "com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
     self.generic_popups = get_config(self.ctx, 
         "/org.openoffice.Office.UI.GenericCommands/UserInterface/Popups")
     self.generic_commands = get_config(self.ctx, 
         "/org.openoffice.Office.UI.GenericCommands/UserInterface/Commands")
Exemple #3
0
 def position_context_changed(self):
     try:
         self.menu_containers.clear()
         position_context, ref = self.get_position_context()
         try:
             self.category_popups = get_config(self.ctx, 
                 "/org.openoffice.Office.UI.%s/UserInterface/Popups" % ref)
             self.category_commands = get_config(self.ctx, 
                 "/org.openoffice.Office.UI.%s/UserInterface/Commands" % ref)
         except:
             pass
         manager = self.config_supplier.getUIConfigurationManager(
             position_context)
         self.menu_settings = manager.getSettings(
                 "private:resource/menubar/menubar", False)
         items = []
         self.get_submenus(items, self.menu_containers, "", "", self.menu_settings)
         #print(items)
         list_menu = self.get(3, self.ID_LIST_MENU)
         list_menu_model = list_menu.getModel()
         list_menu_model.StringItemList = uno.Any("[]string", 
             tuple([item[1] for item in items]))
         for i, item in enumerate(items):
             list_menu_model.setItemData(i, item[0])
         list_menu.selectItemPos(list_menu.getItemCount()-1, True)
     except Exception as e:
         print(e)
Exemple #4
0
    def backup(self):
        """ Copy current file to backup. """
        from bookmarks.tools import get_config
        config = get_config(self.ctx,
                            "/org.openoffice.Office.Common/Save/Document")
        if not config.CreateBackup:
            return
        from bookmarks import CONFIG_NODE_CONTROLLERS, NAME_BACKUP_DIRECTORY
        from bookmarks.tools import get_user_backup, join_url, copy_file
        try:
            backup_dir = None
            config = get_config(self.ctx, CONFIG_NODE_CONTROLLERS)
            if config.hasByName(self.command):
                _config = config.getByName(self.command)
                backup_dir = _config.getPropertyValue(NAME_BACKUP_DIRECTORY)

            if not backup_dir:
                backup_dir = join_url(get_user_backup(self.ctx),
                                      self.BACKUP_DIR)
            file_name = self.FILE_NAME % (
                    time.strftime(self.DATE_FORMAT) + \
                        "_" + self.command.split(":")[-1])
            copy_file(self.ctx, self.file_url, join_url(backup_dir, file_name))
        except Exception as e:
            print(e)
    def fill_menu(self, type, menu):
        """ Fill menu items. """
        commands = COMMANDS
        _ = self.imple._
        window = self.imple.window

        bookmarks_config = get_config(
            self.imple.ctx,
            "/org.openoffice.Office.UI.BookmarksCommands/UserInterface/Commands"
        )
        generic_config = get_config(
            self.imple.ctx,
            "/org.openoffice.Office.UI.GenericCommands/UserInterface/Commands")

        def get_label(name, default, bookmarks):
            if bookmarks:
                config = bookmarks_config
            else:
                config = generic_config
            if config.hasByName(name):
                return config.getByName(name).Label
            return default

        items = [
            (commands.ID_OPEN, self.CMD_PROTOCOL + commands.CMD_OPEN, "~Open",
             1),
            None,
            (commands.ID_INSERT_BOOKMRAK,
             self.CMD_PROTOCOL + commands.CMD_INSERT_BOOKMRAK, "New ~Bookmark",
             1),
            (commands.ID_INSERT_SEPARATOR,
             self.CMD_PROTOCOL + commands.CMD_INSERT_SEPARATOR,
             "New ~Separator", 1),
            (commands.ID_INSERT_FOLDER,
             self.CMD_PROTOCOL + commands.CMD_INSERT_FOLDER, "New ~Folder", 1),
            None,
            (commands.ID_CUT, self.UNO_PROTOCOL + commands.CMD_CUT, "Cu~t", 0),
            (commands.ID_COPY, self.UNO_PROTOCOL + commands.CMD_COPY, "~Copy",
             0),
            (commands.ID_PASTE, self.UNO_PROTOCOL + commands.CMD_PASTE,
             "~Paste", 0),
            None,
            (commands.ID_DELETE, self.CMD_PROTOCOL + commands.CMD_DELETE,
             "~Delete", 1),
            None,
            (commands.ID_SELECTALL, self.UNO_PROTOCOL + commands.CMD_SELECTALL,
             "Select ~All", 0),
        ]

        # ToDo HelpCommand
        mi = menu.insertItem
        msc = menu.setCommand
        for i, item in enumerate(items):
            if item:
                mi(item[0], get_label(item[1], item[2], item[3]), 0, i)
                msc(item[0], item[1])
            else:
                menu.insertSeparator(i)
Exemple #6
0
 def fill_menu(self, type, menu):
     """ Fill menu items. """
     commands = COMMANDS
     _ = self.imple._
     window = self.imple.window
     
     bookmarks_config = get_config(self.imple.ctx, 
         "/org.openoffice.Office.UI.BookmarksCommands/UserInterface/Commands")
     generic_config = get_config(self.imple.ctx, 
         "/org.openoffice.Office.UI.GenericCommands/UserInterface/Commands")
     
     def get_label(name, default, bookmarks):
         if bookmarks:
             config = bookmarks_config
         else:
             config = generic_config
         if config.hasByName(name):
             return config.getByName(name).Label
         return default
     
     items = [
         (commands.ID_OPEN, 
             self.CMD_PROTOCOL + commands.CMD_OPEN, "~Open", 1), 
         None, 
         (commands.ID_INSERT_BOOKMRAK, 
             self.CMD_PROTOCOL + commands.CMD_INSERT_BOOKMRAK, "New ~Bookmark", 1), 
         (commands.ID_INSERT_SEPARATOR, 
             self.CMD_PROTOCOL + commands.CMD_INSERT_SEPARATOR, "New ~Separator", 1), 
         (commands.ID_INSERT_FOLDER, 
             self.CMD_PROTOCOL + commands.CMD_INSERT_FOLDER, "New ~Folder", 1), 
         None, 
         (commands.ID_CUT, 
             self.UNO_PROTOCOL + commands.CMD_CUT, "Cu~t", 0), 
         (commands.ID_COPY, 
             self.UNO_PROTOCOL + commands.CMD_COPY, "~Copy", 0), 
         (commands.ID_PASTE, 
             self.UNO_PROTOCOL + commands.CMD_PASTE, "~Paste", 0), 
         None, 
         (commands.ID_DELETE, 
             self.CMD_PROTOCOL + commands.CMD_DELETE, "~Delete", 1), 
         None, 
         (commands.ID_SELECTALL, 
             self.UNO_PROTOCOL + commands.CMD_SELECTALL, "Select ~All", 0), 
     ]
 
     # ToDo HelpCommand
     mi = menu.insertItem
     msc = menu.setCommand
     for i, item in enumerate(items):
         if item:
             mi(item[0], get_label(item[1], item[2], item[3]), 0, i)
             msc(item[0], item[1])
         else:
             menu.insertSeparator(i)
Exemple #7
0
 def get_command_by_name(self, name):
     config = get_config(self.ctx, CONFIG_NODE_CONTROLLERS)
     for node_name in config.getElementNames():
         node = config.getByName(node_name)
         if node.Name == name:
             return node_name
     return ""
Exemple #8
0
 def command_to_path(ctx, command, fallback=False):
     """ Command to file path in config. """
     parts = command.split(":", 1)
     if len(parts) == 2:
         if fallback:
             from bookmarks.tools import get_extension_dirurl, join_url
             dir_url = get_extension_dirurl(
                             ctx, command.replace(":", "."))
             if dir_url:
                 return join_url(
                     dir_url, 
                     BookmarksManager.FILE_NAME % parts[1].lower())
         else:
             from bookmarks import CONFIG_NODE_CONTROLLERS, NAME_DATA_URL
             from bookmarks.tools import get_config, get_user_config
             config = get_config(ctx, CONFIG_NODE_CONTROLLERS)
             if config.hasByName(command):
                 _config = config.getByName(command)
                 data_url = _config.getByName(NAME_DATA_URL)
                 if data_url:
                     return data_url
             
             return BookmarksManager.FILE_BASE_URL % (
                     get_user_config(ctx), parts[1].lower())
     return ""
Exemple #9
0
 def get_controller_config(self, modifiable=False):
     """ Get controller specific configuration. """
     from bookmarks.tools import get_config
     from bookmarks import CONFIG_NODE_CONTROLLERS
     config = get_config(self.ctx, CONFIG_NODE_CONTROLLERS, modifiable)
     command = self.imple.command
     if config.hasByName(command):
         return config.getByName(command)
Exemple #10
0
 def confirm_Options(self):
     config = get_config(self.ctx, CONFIG_NODE_SETTINGS, True)
     cs = config.setPropertyValue
     cs(NAME_WEB_BROWSER, self.get_text("edit_webbrowser"))
     cs(NAME_FILE_MANAGER, self.get_text("edit_filemanager"))
     cs(NAME_OPEN_COMMAND, self.get_text("edit_opencommand"))
     cs(NAME_USE_CUSTOM_WEB_BROWSER, bool(self.get_state("check_webbrowser")))
     cs(NAME_USE_CUSTOM_FILE_MANAGER, bool(self.get_state("check_filemanager")))
     cs(NAME_USE_CUSTOM_OPEN_COMMAND, bool(self.get_state("check_opencommand")))
     config.commitChanges()
Exemple #11
0
 def confirm_Options(self):
     config = get_config(self.ctx, CONFIG_NODE_SETTINGS, True)
     cs = config.setPropertyValue
     cs(NAME_WEB_BROWSER, self.get_text("edit_webbrowser"))
     cs(NAME_FILE_MANAGER, self.get_text("edit_filemanager"))
     cs(NAME_OPEN_COMMAND, self.get_text("edit_opencommand"))
     cs(NAME_USE_CUSTOM_WEB_BROWSER,
        bool(self.get_state("check_webbrowser")))
     cs(NAME_USE_CUSTOM_FILE_MANAGER,
        bool(self.get_state("check_filemanager")))
     cs(NAME_USE_CUSTOM_OPEN_COMMAND,
        bool(self.get_state("check_opencommand")))
     config.commitChanges()
Exemple #12
0
 def init_Options(self, first_time=False):
     try:
         config = get_config(self.ctx, CONFIG_NODE_SETTINGS)
         cp = config.getPropertyValue
         self.set_text("edit_webbrowser", cp(NAME_WEB_BROWSER))
         self.set_text("edit_filemanager", cp(NAME_FILE_MANAGER))
         self.set_text("edit_opencommand", cp(NAME_OPEN_COMMAND))
         self.set_state("check_webbrowser", cp(NAME_USE_CUSTOM_WEB_BROWSER))
         self.set_state("check_filemanager", cp(NAME_USE_CUSTOM_FILE_MANAGER))
         self.set_state("check_opencommand", cp(NAME_USE_CUSTOM_OPEN_COMMAND))
         if first_time:
             self.translate_labels()
             listener = self.ButtonListener(self)
             self.get("btn_webbrowser").addActionListener(listener)
             self.get("btn_filemanager").addActionListener(listener)
             self.get("btn_opencommand").addActionListener(listener)
     except Exception as e:
         print(e)
Exemple #13
0
 def init_Options(self, first_time=False):
     try:
         config = get_config(self.ctx, CONFIG_NODE_SETTINGS)
         cp = config.getPropertyValue
         self.set_text("edit_webbrowser", cp(NAME_WEB_BROWSER))
         self.set_text("edit_filemanager", cp(NAME_FILE_MANAGER))
         self.set_text("edit_opencommand", cp(NAME_OPEN_COMMAND))
         self.set_state("check_webbrowser", cp(NAME_USE_CUSTOM_WEB_BROWSER))
         self.set_state("check_filemanager",
                        cp(NAME_USE_CUSTOM_FILE_MANAGER))
         self.set_state("check_opencommand",
                        cp(NAME_USE_CUSTOM_OPEN_COMMAND))
         if first_time:
             self.translate_labels()
             listener = self.ButtonListener(self)
             self.get("btn_webbrowser").addActionListener(listener)
             self.get("btn_filemanager").addActionListener(listener)
             self.get("btn_opencommand").addActionListener(listener)
     except Exception as e:
         print(e)
Exemple #14
0
    def command_to_path(ctx, command, fallback=False):
        """ Command to file path in config. """
        parts = command.split(":", 1)
        if len(parts) == 2:
            if fallback:
                from bookmarks.tools import get_extension_dirurl, join_url
                dir_url = get_extension_dirurl(ctx, command.replace(":", "."))
                if dir_url:
                    return join_url(
                        dir_url, BookmarksManager.FILE_NAME % parts[1].lower())
            else:
                from bookmarks import CONFIG_NODE_CONTROLLERS, NAME_DATA_URL
                from bookmarks.tools import get_config, get_user_config
                config = get_config(ctx, CONFIG_NODE_CONTROLLERS)
                if config.hasByName(command):
                    _config = config.getByName(command)
                    data_url = _config.getByName(NAME_DATA_URL)
                    if data_url:
                        return data_url

                return BookmarksManager.FILE_BASE_URL % (get_user_config(ctx),
                                                         parts[1].lower())
        return ""
Exemple #15
0
 def _init_factory_names(self, list_context, ref=False):
     config = get_config(self.ctx, 
         "/org.openoffice.Setup/Office/Factories")
     modules = []
     for name in config.getElementNames():
         node = config.getByName(name)
         if name == "com.sun.star.text.GlobalDocument":
             label = "Global"
         elif name == "com.sun.star.frame.StartModule":
             label = "StartModule"
         else:
             label = node.ooSetupFactoryUIName
         modules.append((label, name, node.ooSetupFactoryCommandConfigRef))
     modules.sort()
     
     list_context_model = list_context.getModel()
     list_context_model.StringItemList = uno.Any("[]string", tuple([item[0] for item in modules]))
     if ref:
         for i, item in enumerate(modules):
             list_context_model.setItemData(i, "%s;%s" % (item[1], item[2]))
     else:
         for i, item in enumerate(modules):
             list_context_model.setItemData(i, item[1])
Exemple #16
0
def load_controller_name(ctx, command):
    """ Get controller specific settings. """
    config = get_config(ctx, CONFIG_NODE_CONTROLLERS)
    if config.hasByName(command):
        return config.getByName(command).getPropertyValue(NAME_NAME)
    return ""
Exemple #17
0
def load_controller_name(ctx, command):
    """ Get controller specific settings. """
    config = get_config(ctx, CONFIG_NODE_CONTROLLERS)
    if config.hasByName(command):
        return config.getByName(command).getPropertyValue(NAME_NAME)
    return ""
Exemple #18
0
 def get_installed_locales(self):
     # the same with ui locales
     return get_config(self.ctx, self.NODE_INSTALLED_LOCALES).getElementNames()
Exemple #19
0
 def _init_names(self):
     self.names = {}
     config = get_config(self.ctx, CONFIG_NODE_CONTROLLERS)
     for id in config.getElementNames():
         self.names[config.getByName(id).Name] = id
Exemple #20
0
 def get_config_settings(self):
     return get_config(self.ctx, CONFIG_NODE_SETTINGS)
Exemple #21
0
 def get_config_settings(self):
     return get_config(self.ctx, CONFIG_NODE_SETTINGS)