示例#1
0
    def handle_query(self, query: str) -> BaseAction:
        if query == '~':
            return SetUserQueryAction('~/')

        path = Path(query)  # type: Path
        result_items = []  # type: Union[List, SortedList]

        try:
            existing_dir = path.get_existing_dir()

            if existing_dir == path.get_abs_path():
                file_names = self.list_files(path.get_abs_path(), sort_by_usage=True)
                for name in self.filter_dot_files(file_names)[:self.RESULT_LIMIT]:
                    file = os.path.join(existing_dir, name)
                    result_items.append(self.create_result_item(file))

            else:
                file_names = self.list_files(existing_dir)
                search_for = path.get_search_part()

                if not search_for.startswith('.'):
                    file_names = self.filter_dot_files(file_names)

                files = [os.path.join(existing_dir, name) for name in file_names]
                result_items = SortedList(search_for, min_score=40, limit=self.RESULT_LIMIT)
                result_items.extend([self.create_result_item(name) for name in reversed(files)])

        except (InvalidPathError, OSError):
            result_items = []

        return RenderResultListAction(result_items)
示例#2
0
 def on_event(self, event, extension):
     items = []
     arg = event.get_argument()
     if arg:
         result_list = SortedList(arg, min_score=40, limit=10)
         result_list.extend(extension.character_list)
         for char in result_list:
             image_path = get_character_icon(char)
             items.append(
                 ExtensionResultItem(
                     icon=image_path,
                     name=char.name + " - " + char.character,
                     description=char.block + " - " + char.code,
                     on_enter=CopyToClipboardAction(char.character),
                 ))
     return RenderResultListAction(items)