def set_item_and_action(self, item, act): self.current_item = item self.current_action = act if item and act: ownsrc, use_catalog = actioncompat.iobject_source_for_action(act, item) if ownsrc and not use_catalog: self.source_rebase(ownsrc) else: extra_sources = [ownsrc] if ownsrc else () sc = GetSourceController() self.source_rebase(sc.root_for_types(act.object_types(), extra_sources)) else: self.reset()
def _load(self, sched): """Begin Data Controller work when we get application 'load' signal Load the data model from saved configuration and caches """ setctl = settings.GetSettingsController() setctl.connect("plugin-enabled-changed", self._plugin_enabled) setctl.connect("plugin-toplevel-changed", self._plugin_catalog_changed) self._load_all_plugins() D_s, d_s = self._get_directory_sources() sc = GetSourceController() sc.add(None, D_s, toplevel=True) sc.add(None, d_s, toplevel=False) sc.initialize() learn.load()
def search(self, key="", context=None, text_mode=False): """ filter for action @item """ self.latest_key = key sources = [ self.get_source() ] if not text_mode else [] if key and self.is_at_source_root(): # Only use text sources when we are at root catalog sc = GetSourceController() textsrcs = sc.get_text_sources() sources.extend(textsrcs) decorator = lambda seq: dress_leaves(seq, action=None) match, match_iter = self.searcher.search(sources, key, score=bool(key), decorator=decorator) self.emit_search_result(match, match_iter, context)
def resolve_action_id(puid, for_item=None): if puid is None: return None if isinstance(puid, SerializedObject): return resolve_unique_id(puid) get_action_id = repr sc = GetSourceController() if for_item is not None: for action in actioncompat.actions_for_item(for_item, sc): if get_unique_id(action) == puid: return action for item_type, actions in sc.action_decorators.items(): for action in actions: if get_action_id(action) == puid: return action pretty.print_debug(__name__, "Unable to resolve %s (%s)" % (puid, for_item)) return None
def register_content_decorators(self, plugin_id, contents): """ Register the sequence of classes @contents as potential content decorators. Classes not conforming to the decoration protocol (most importantly, ``.decorates_type()``) will be skipped """ # Keep a mapping: # Decorated Leaf Type -> Set of content decorator types decorate_item_types = {} for c in contents: try: applies = c.decorates_type() except AttributeError: continue decorate_item_types.setdefault(applies, set()).add(c) if not decorate_item_types: return sc = GetSourceController() sc.add_content_decorators(plugin_id, decorate_item_types)
def search(self, key="", context=None, text_mode=False): """ filter for action @item """ self.latest_key = key sources = [] if not text_mode or hasattr(self.get_source(), "get_text_items"): sources.append(self.get_source()) if key and self.is_at_source_root(): # Only use text sources when we are at root catalog sc = GetSourceController() textsrcs = sc.get_text_sources() sources.extend(textsrcs) item_check = actioncompat.iobjects_valid_for_action(self.current_action, self.current_item) decorator = lambda seq: dress_leaves(seq, action=self.current_action) match, match_iter = self.searcher.search(sources, key, score=True, item_check=item_check, decorator=decorator) self.emit_search_result(match, match_iter, context)
def _decorate_object(self, *objects): sc = GetSourceController() for obj in objects: sc.decorate_object(obj)
def _finish(self, sched): "Close down the data model, save user data, and write caches to disk" GetSourceController().finalize() self._save_data(final_invocation=True) self.output_info("Saving cache...") GetSourceController().save_cache()
def _reload_source_root(self): self.output_debug("Reloading source root") sc = GetSourceController() self.source_pane.source_rebase(sc.root)
def _remove_plugin(self, plugin_id): sc = GetSourceController() if sc.remove_objects_for_plugin_id(plugin_id): self._reload_source_root() pluginload.remove_plugin(plugin_id)
def register_action_generators(self, plugin_id, generators): sc = GetSourceController() for generator in generators: sc.add_action_generator(plugin_id, generator)
def register_text_sources(self, plugin_id, srcs): """Pass in text sources as @srcs we register text sources """ sc = GetSourceController() sc.add_text_sources(plugin_id, srcs)
def dress_leaves(seq, action): """yield items of @seq "dressed" by the source controller""" sc = GetSourceController() for itm in seq: sc.decorate_object(itm.object, action=action) yield itm
def _load_source(self, src): """Try to get a source from the SourceController, if it is already loaded we get it from there, else returns @src""" sc = GetSourceController() return sc.get_canonical_source(src)
The caller (if a Source) should pass itself as @excluding, so that recursion into itself is avoided. """ if excluding is not None: with _exclusion(excluding): return resolve_unique_id(puid, None) if puid is None: return None if isinstance(puid, SerializedObject): try: return puid.reconstruct() except Exception, exc: pretty.print_debug(__name__, type(exc).__name__, exc) return None sc = GetSourceController() obj = _find_obj_in_catalog(puid, sc._firstlevel) if obj is not None: return obj other_sources = set(sc.sources) - set(sc._firstlevel) obj = _find_obj_in_catalog(puid, other_sources) return obj def resolve_action_id(puid, for_item=None): if puid is None: return None if isinstance(puid, SerializedObject): return resolve_unique_id(puid) get_action_id = repr sc = GetSourceController()