Merge pull request #361 from prculley/addon_reload

Fix Addon manager to recognize newly installed addons immediately
This commit is contained in:
Sam Manzi 2017-03-03 15:37:17 +11:00 committed by GitHub
commit 49df7446b2
5 changed files with 28 additions and 9 deletions

View File

@ -331,12 +331,14 @@ class CLIManager:
recent_files(filename, name) recent_files(filename, name)
self.file_loaded = True self.file_loaded = True
def do_reg_plugins(self, dbstate, uistate): def do_reg_plugins(self, dbstate, uistate, rescan=False):
""" """
Register the plugins at initialization time. Register the plugins at initialization time.
""" """
self._pmgr.reg_plugins(PLUGINS_DIR, dbstate, uistate) self._pmgr.reg_plugins(PLUGINS_DIR, dbstate, uistate, rescan=rescan)
self._pmgr.reg_plugins(USER_PLUGINS, dbstate, uistate, load_on_reg=True) self._pmgr.reg_plugins(USER_PLUGINS, dbstate, uistate, load_on_reg=True)
if rescan: # supports updated plugin installs
self._pmgr.reload_plugins()
def startcli(errors, argparser): def startcli(errors, argparser):
""" """

View File

@ -104,7 +104,7 @@ class BasePluginManager:
self.__scanned_dirs = [] self.__scanned_dirs = []
def reg_plugins(self, direct, dbstate=None, uistate=None, def reg_plugins(self, direct, dbstate=None, uistate=None,
load_on_reg=False): load_on_reg=False, rescan=False):
""" """
Searches the specified directory, and registers python plugin that Searches the specified directory, and registers python plugin that
are being defined in gpr.py files. are being defined in gpr.py files.
@ -112,6 +112,14 @@ class BasePluginManager:
If a relationship calculator for env var LANG is present, it is If a relationship calculator for env var LANG is present, it is
immediately loaded so it is available for all. immediately loaded so it is available for all.
""" """
if rescan:
self.__import_plugins = []
self.__export_plugins = []
self.__docgen_plugins = []
self.__docgen_names = []
self.__scanned_dirs = []
self.__pgr._PluginRegister__plugindata = []
self.__pgr._PluginRegister__id_to_pdata = {}
# if we've already scanned this directory or if the directory does not # if we've already scanned this directory or if the directory does not
# exist, we are done. Should only happen in tests. # exist, we are done. Should only happen in tests.
@ -300,6 +308,8 @@ class BasePluginManager:
self.__import_plugins = [] self.__import_plugins = []
self.__export_plugins = [] self.__export_plugins = []
self.__docgen_plugins = [] self.__docgen_plugins = []
self.__docgen_names = []
def reload_plugins(self): def reload_plugins(self):
""" Reload previously loaded plugins """ """ Reload previously loaded plugins """

View File

@ -1421,7 +1421,10 @@ class GrampsPreferences(ConfigureDialog):
return return
if len(addon_update_list) > 0: if len(addon_update_list) > 0:
PluginWindows.UpdateAddons(self.uistate, self.track, addon_update_list) rescan = PluginWindows.UpdateAddons(self.uistate, self.track,
addon_update_list).rescan
self.uistate.viewmanager.do_reg_plugins(self.dbstate, self.uistate,
rescan=rescan)
else: else:
check_types = config.get('behavior.check-for-addon-update-types') check_types = config.get('behavior.check-for-addon-update-types')
OkDialog( OkDialog(
@ -1434,7 +1437,6 @@ class GrampsPreferences(ConfigureDialog):
# Dead code for l10n # Dead code for l10n
_('new'), _('update') _('new'), _('update')
self.uistate.viewmanager.do_reg_plugins(self.dbstate, self.uistate)
def database_backend_changed(self, obj): def database_backend_changed(self, obj):
the_list = obj.get_model() the_list = obj.get_model()

View File

@ -1082,6 +1082,7 @@ class UpdateAddons(ManagedWindow):
self.set_window(glade.toplevel, None, None) self.set_window(glade.toplevel, None, None)
self.window.set_title(self.title) self.window.set_title(self.title)
self.setup_configs("interface.updateaddons", 750, 400) self.setup_configs("interface.updateaddons", 750, 400)
self.rescan = False
apply_button = glade.get_object('apply') apply_button = glade.get_object('apply')
cancel_button = glade.get_object('cancel') cancel_button = glade.get_object('cancel')
@ -1137,6 +1138,7 @@ class UpdateAddons(ManagedWindow):
self.list.selection.select_iter(pos) self.list.selection.select_iter(pos)
self.show() self.show()
self.window.run()
def build_menu_names(self, obj): def build_menu_names(self, obj):
return (self.title, " ") return (self.title, " ")
@ -1210,6 +1212,7 @@ class UpdateAddons(ManagedWindow):
", ".join(errors), ", ".join(errors),
parent=self.parent_window) parent=self.parent_window)
if count: if count:
self.rescan = True
OkDialog(_("Done downloading and installing addons"), OkDialog(_("Done downloading and installing addons"),
# translators: leave all/any {...} untranslated # translators: leave all/any {...} untranslated
"%s %s" % (ngettext("{number_of} addon was installed.", "%s %s" % (ngettext("{number_of} addon was installed.",

View File

@ -345,8 +345,9 @@ class ViewManager(CLIManager):
""" """
Called when add-on updates are available. Called when add-on updates are available.
""" """
PluginWindows.UpdateAddons(self.uistate, [], addon_update_list) rescan = PluginWindows.UpdateAddons(self.uistate, [],
self.do_reg_plugins(self.dbstate, self.uistate) addon_update_list).rescan
self.do_reg_plugins(self.dbstate, self.uistate, rescan=rescan)
def _errordialog(self, title, errormessage): def _errordialog(self, title, errormessage):
""" """
@ -728,14 +729,15 @@ class ViewManager(CLIManager):
if not self.dbstate.is_open() and show_manager: if not self.dbstate.is_open() and show_manager:
self.__open_activate(None) self.__open_activate(None)
def do_reg_plugins(self, dbstate, uistate): def do_reg_plugins(self, dbstate, uistate, rescan=False):
""" """
Register the plugins at initialization time. The plugin status window Register the plugins at initialization time. The plugin status window
is opened on an error if the user has requested. is opened on an error if the user has requested.
""" """
# registering plugins # registering plugins
self.uistate.status_text(_('Registering plugins...')) self.uistate.status_text(_('Registering plugins...'))
error = CLIManager.do_reg_plugins(self, dbstate, uistate) error = CLIManager.do_reg_plugins(self, dbstate, uistate,
rescan=rescan)
# get to see if we need to open the plugin status window # get to see if we need to open the plugin status window
if error and config.get('behavior.pop-plugin-status'): if error and config.get('behavior.pop-plugin-status'):