コード例 #1
0
ファイル: main.py プロジェクト: therj/ulauncher-devdocs
    def open_in_devdocs(self, doc, entry=None):
        """
        Opens a documentation page in DevDocs.
        :param str doc: The documentation slug
        :param str entry: The entry slug.
        Depending of the extension configurations it might open in:
            - DevDocs website
            - Devdocs desktop (devdocs protocol)
            - HawkHeye
        """

        open_result_in = self.preferences['open_doc_in']

        doc_path = doc

        if entry:
            doc_path = doc_path + "/" + entry

        doc_url = "https://devdocs.io/%s" % doc_path

        if open_result_in == "Hawkeye":
            return RunScriptAction('hawkeye --uri="%s"' % doc_url, [])
        elif open_result_in == "DevDocs Protocol":
            return OpenAction("devdocs://%s" % doc_path)

        return OpenUrlAction(doc_url)
コード例 #2
0
    def get_projects(self, query: str):
        projects = self.vscode.get_projects(self.preferences)

        if query:
            projects = [
                item for item in projects
                if query.strip().lower() in item['name'].lower()
            ]

        if not projects:
            return self.show_no_results_message(query)

        items = []
        for project in projects[:MAX_PROJECTS_IN_LIST]:
            icon = 'images/icon.png'

            if project['type'] == 'workspace':
                icon = 'images/code-dark-icon.png'

            items.append(
                ExtensionResultItem(icon=icon,
                                    name=project['name'],
                                    description=project['path'],
                                    on_enter=ExtensionCustomAction(
                                        {'path': project['path']}),
                                    on_alt_enter=OpenAction(project['path'])))

        return RenderResultListAction(items)
コード例 #3
0
ファイル: main.py プロジェクト: therj/ulauncher-devdocs
    def show_options_menu(self, query):
        """ Shoe some general configuration options for the extension """
        items = [
            ExtensionResultItem(
                icon='images/icon.png',
                name='Open DevDocs.io',
                description='Opens DevDocs on your default browser',
                highlightable=False,
                on_enter=OpenUrlAction("https://devdocs.io/")),
            ExtensionResultItem(
                icon='images/icon.png',
                name='Open cache folder',
                description=
                "Opens the folder where the documentation cache is stored",
                highlightable=False,
                on_enter=OpenAction(self.devdocs_svc.cache_dir)),
            ExtensionResultItem(
                icon='images/icon.png',
                name='Index Documentation',
                description=
                "This process might take a while. You will receive a notification when finished.",
                highlightable=False,
                on_enter=ExtensionCustomAction([]))
        ]

        return RenderResultListAction(items)
コード例 #4
0
    def on_event(self, event, extension):
        arg = event.get_argument()
        items = []

        if arg is None:
            items = self.__help()
        else:
            try:
                results = locator.run(arg)
                alt_action = ExtensionCustomAction(results, True)
                for file in results:
                    items.append(
                        ExtensionSmallResultItem(icon='images/ok.png',
                                                 name=str(file, 'utf-8'),
                                                 on_enter=OpenAction(file),
                                                 on_alt_enter=alt_action))
            except Exception as e:
                error_info = str(e)
                items = [
                    ExtensionSmallResultItem(
                        icon='images/error.png',
                        name=error_info,
                        on_enter=CopyToClipboardAction(error_info))
                ]

        return RenderResultListAction(items)
コード例 #5
0
    def on_enter(self, query):
        self._file_queries.save_query(self.path.get_abs_path())
        if self.path.is_dir():
            return SetUserQueryAction(
                os.path.join(self.path.get_user_path(), ''))

        return OpenAction(self.path.get_abs_path())
コード例 #6
0
    def show_cheats_list(self, cheats):
        """ Shows the cheats list """

        hawkeye_bin = self.preferences['hawkeye_bin']
        use_hawkeye_default = self.preferences['use_hawkeye_as_default_action']

        items = []
        for cheat in cheats[:8]:

            open_file_action = OpenAction(cheat['path'])
            open_in_hawkeye_action = RunScriptAction(
                '%s --uri="file://%s"' % (hawkeye_bin, cheat['path']), [])

            if use_hawkeye_default:
                primary_action = open_in_hawkeye_action
                secondary_action = open_file_action
            else:
                primary_action = open_file_action
                secondary_action = open_in_hawkeye_action

            items.append(
                ExtensionResultItem(icon='images/icon.png',
                                    name=cheat['normalized_name'],
                                    on_enter=primary_action,
                                    on_alt_enter=secondary_action))

        return RenderResultListAction(items)
コード例 #7
0
def show_notes(vault, notes: List[Note], limit=10):
    return [
        ExtensionResultItem(
            icon=ICON_FILE,
            name=note.name,
            description=note.description,
            on_enter=OpenAction(generate_url(vault, note.path)),
        ) for note in notes[:limit]
    ]
コード例 #8
0
    def on_event(self, event, extension):
        """ Handles the event """
        fd_cmd = extension.preferences["fd_cmd"]
        if shutil.which(fd_cmd) is None:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name=
                    f"Command {fd_cmd} is not found, please install it first",
                    on_enter=HideWindowAction())
            ])

        query = event.get_argument()

        if not query or len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name="Keep typing your search criteria ...",
                    on_enter=DoNothingAction())
            ])

        keyword = event.get_keyword()
        keyword_id = None
        # Find the keyword id using the keyword (since the keyword can be changed by users)
        for kw_id, kw in list(extension.preferences.items()):
            if kw == keyword:
                keyword_id = kw_id

        file_type = FILE_SEARCH_ALL
        if keyword_id == "ff_kw":
            file_type = FILE_SEARCH_FILE
        elif keyword_id == "fd_kw":
            file_type = FILE_SEARCH_DIRECTORY

        results = extension.search(query.strip(), file_type, fd_cmd)

        if not results:
            return RenderResultListAction([
                ExtensionResultItem(icon="images/icon.png",
                                    name=f"No Results found matching {query}",
                                    on_enter=HideWindowAction())
            ])

        items = []
        for result in results[:15]:
            items.append(
                ExtensionSmallResultItem(
                    icon=result["icon"],
                    name=result["path"].decode("utf-8"),
                    on_enter=OpenAction(result["path"].decode("utf-8")),
                    on_alt_enter=extension.get_open_in_terminal_script(
                        result["path"].decode("utf-8"))))

        return RenderResultListAction(items)
コード例 #9
0
ファイル: result_items.py プロジェクト: brpaz/zealdoc
    def docset_searchforin_result(item, query):
        """Creates a docset 'search for in' result
    Zeal doc action example dash-plugin://keys=python,django&query=string
    """

        ResultItems.assert_valid_docset(item)
        return ExtensionResultItem(
            icon=item["icon2"],
            name=_("Search for %s in %s") % (query, item["name"]),
            on_enter=OpenAction(path="dash-plugin://keys=%s&query=%s" %
                                (item["id"], query)),
        )
コード例 #10
0
ファイル: main.py プロジェクト: null011/ulauncher-file-search
    def on_event(self, event, extension):
        """ Handles the event """
        items = []

        query = event.get_argument()

        if not query or len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='Keep typing your search criteria ...',
                    on_enter=DoNothingAction())
            ])

        keyword = event.get_keyword()
        # Find the keyword id using the keyword (since the keyword can be changed by users)
        for kw_id, kw in list(extension.preferences.items()):
            if kw == keyword:
                keyword_id = kw_id

        file_type = FILE_SEARCH_ALL
        if keyword_id == "ff_kw":
            file_type = FILE_SEARCH_FILE
        elif keyword_id == "fd_kw":
            file_type = FILE_SEARCH_DIRECTORY

        results = extension.search(query.strip(), file_type)

        if not results:
            return RenderResultListAction([
                ExtensionResultItem(icon='images/icon.png',
                                    name='No Results found matching %s' %
                                    query,
                                    on_enter=HideWindowAction())
            ])

        items = []
        for result in results[:15]:
            items.append(
                ExtensionResultItem(
                    icon=result['icon'],
                    name=result['name'],
                    description=result['dir'],
                    on_enter=OpenAction(result['path'].decode("utf-8")),
                    on_alt_enter=extension.get_open_in_terminal_script(
                        result['path'].decode("utf-8"))))

        return RenderResultListAction(items)
コード例 #11
0
 def open_note(self, path: str) -> BaseAction:
     """
     Open note file using command specified in preferences
     or OpenAction() if no command specified
     """
     cmd = self.preferences["open-note-command"]
     if not cmd:
         return OpenAction(path)
     args = argbuild(cmd, {"fn": path}, append_missing_field="fn")
     try:
         subprocess.Popen(args)
     except OSError as exc:
         return RenderResultListAction([
             error_item("Could not execute note open command", exc.strerror)
         ])
     return DoNothingAction()
コード例 #12
0
    def on_event(self, event, extension):

        keyword = event.get_keyword()
        for kw_id, kw in list(extension.preferences.items()):
            if kw == keyword:
                keyword_id = kw_id

        file_type = FILE_SEARCH_ALL
        if keyword_id == "ff_kw":
            file_type = FILE_SEARCH_FILE
        elif keyword_id == "fd_kw":
            file_type = FILE_SEARCH_DIRECTORY

        query = event.get_argument()

        if not query or len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='Keep typing your search criteria ...',
                    on_enter=DoNothingAction())
            ])

        #searching
        results = extension.search(query, '/', file_type)
        print(results)

        if not results:
            return RenderResultListAction([
                ExtensionResultItem(icon='images/icon.png',
                                    name='No Results found matching %s' %
                                    query,
                                    on_enter=HideWindowAction())
            ])

        items = []
        sub_results = results[0:7]
        for result in sub_results:
            items.append(
                ExtensionResultItem(
                    icon=result['icon'],
                    name=result['name'],
                    description=result['path'],
                    on_enter=OpenAction(result['path']),
                ))

        return RenderResultListAction(items)
コード例 #13
0
ファイル: ShortcutResult.py プロジェクト: Ulauncher/Ulauncher
    def on_enter(self, query):
        if query.keyword == self.keyword and query.argument:
            argument = query.argument
        elif self.is_default_search:
            argument = query
        else:
            argument = None

        command = self.cmd.strip()
        if argument and not self.run_without_argument:
            command = command.replace('%s', argument)

        if argument or self.run_without_argument:
            return OpenAction(command) if self._is_url() else RunScriptAction(
                command, argument)

        return SetUserQueryAction(f'{self.keyword} ')
コード例 #14
0
    def on_event(self, event, extension):
        """ Handles the event """
        items = []

        query = event.get_argument()

        if not query or len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='Keep typing your search criteria ...',
                    on_enter=DoNothingAction())
            ])

        keyword = event.get_keyword()

        file_type = FILE_SEARCH_ALL
        if keyword == "ff":
            file_type = FILE_SEARCH_FILE
        elif keyword == "fdir":
            file_type = FILE_SEARCH_DIRECTORY

        results = extension.search(query.strip(), file_type)

        if not results:
            return RenderResultListAction([
                ExtensionResultItem(icon='images/icon.png',
                                    name='No Results found matching %s' %
                                    query,
                                    on_enter=HideWindowAction())
            ])

        items = []
        for result in results[:15]:
            items.append(
                ExtensionSmallResultItem(
                    icon=result['icon'],
                    name=result['path'],
                    on_enter=OpenAction(result['path']),
                    on_alt_enter=extension.get_open_in_terminal_script(
                        result['path'])))

        return RenderResultListAction(items)
コード例 #15
0
    def on_event(self, event, extension):
        vault = extension.preferences["obsidian_vault"]

        keyword_search_note_vault = extension.preferences[
            "obsidian_search_note_vault"]
        keyword_search_string_vault = extension.preferences[
            "obsidian_search_string_vault"]
        keyword_open_daily = extension.preferences["obsidian_open_daily"]
        keyword_quick_capture = extension.preferences["obsidian_quick_capture"]
        number_of_notes = int(extension.preferences.get("number_of_notes", 8))

        keyword = event.get_keyword()
        search = event.get_argument()

        if extension.state == "quick-capture-to-note":
            notes = find_note_in_vault(vault, search)
            items = select_note(notes, number_of_notes)
            items += create_note(search)
            items += cancel()
            return RenderResultListAction(items)

        if keyword == keyword_search_note_vault:
            notes = find_note_in_vault(vault, search)
            items = show_notes(vault, notes, number_of_notes)
            items += create_note(search)
            items += cancel()
            return RenderResultListAction(items)

        elif keyword == keyword_search_string_vault:
            notes = find_string_in_vault(vault, search)
            items = show_notes(vault, notes, number_of_notes)
            items += create_note(search)
            items += cancel()
            return RenderResultListAction(items)

        elif keyword == keyword_open_daily:
            return OpenAction(generate_daily_url(vault))

        elif keyword == keyword_quick_capture:
            items = quick_capture_note(search)
            return RenderResultListAction(items)

        return DoNothingAction()
コード例 #16
0
    def on_event(self, event, extension):
        vault = extension.preferences["obsidian_vault"]
        data = event.get_data()
        type = data.get("type")

        if type == "cancel":
            extension.reset()
            return SetUserQueryAction("")

        elif type == "create-note" and extension.state == "quick-capture-to-note":
            path = create_note_in_vault(vault, data.get("name"))
            append_to_note_in_vault(vault, path, extension.content)
            extension.reset()
            return HideWindowAction()

        elif type == "create-note":
            path = create_note_in_vault(vault, data.get("name"))
            url = generate_url(vault, path)
            return OpenAction(url)

        elif type == "quick-capture":
            quick_capute_note = extension.preferences[
                "obsidian_quick_capture_note"]
            append_to_note_in_vault(vault, quick_capute_note,
                                    data.get("content"))
            return HideWindowAction()

        elif type == "quick-capture-to-note":
            keyword_quick_capture = extension.preferences[
                "obsidian_quick_capture"]
            extension.state = "quick-capture-to-note"
            extension.content = data.get("content")
            return SetUserQueryAction(keyword_quick_capture + " ")

        elif extension.state == "quick-capture-to-note" and type == "select-note":
            quick_capute_note = data.get("note").path
            append_to_note_in_vault(vault, quick_capute_note,
                                    extension.content)
            extension.reset()
            return HideWindowAction()

        return DoNothingAction()
コード例 #17
0
    def on_event(self, event, extension):
        """ Handles the event """
        items = []

        if not os.path.exists(
                os.path.expanduser(
                    extension.preferences['projects_file_path'])):
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='Projects file not found',
                    description=
                    'Please make sure you have the Project Manager VSCode extension properly installed',  # pylint: disable=line-too-long
                    on_enter=HideWindowAction())
            ])

        with open(
                os.path.expanduser(extension.preferences['projects_file_path'])
        ) as projects_file:
            projects = json.load(projects_file)

        query = event.get_argument()
        if query:
            projects = [
                x for x in projects
                if query.strip().lower() in x['name'].lower()
            ]

        for project in projects[:8]:
            items.append(
                ExtensionResultItem(icon='images/icon.png',
                                    name=project['name'],
                                    description=project.get('fullPath')
                                    or project.get('rootPath'),
                                    on_enter=ExtensionCustomAction(project),
                                    on_alt_enter=OpenAction(
                                        project.get('fullPath')
                                        or project.get('rootPath'))))

        return RenderResultListAction(items)
コード例 #18
0
    def show_cheats_list(self, cheats):
        """ Shows the cheats list """

        hawkeye_bin = self.preferences['hawkeye_bin']
        use_hawkeye_default = self.preferences['use_hawkeye_as_default_action']

        items = []
        for cheat in cheats[:8]:
            if 'error' in cheat:
                items.append(
                    ExtensionResultItem(icon='images/error.png',
                                        name=cheat['error'],
                                        on_enter=HideWindowAction()))
            else:
                if 'url' in cheat:
                    uri = cheat['path']
                    icon = 'images/url.png'
                else:
                    uri = 'file://%s' % cheat['path']
                    icon = 'images/icon.png'

                open_file_action = OpenAction(cheat['path'])
                open_in_hawkeye_action = RunScriptAction(
                    '%s --uri="%s"' % (hawkeye_bin, uri), [])

                if use_hawkeye_default == 'true':
                    primary_action = open_in_hawkeye_action
                    secondary_action = open_file_action
                else:
                    primary_action = open_file_action
                    secondary_action = open_in_hawkeye_action

                items.append(
                    ExtensionResultItem(icon=icon,
                                        name=cheat['normalized_name'],
                                        on_enter=primary_action,
                                        on_alt_enter=secondary_action))

        return RenderResultListAction(items)
コード例 #19
0
    def on_event(self, event, extension):
        """ Handles the event """
        items = []
        query = event.get_argument() or ""
        projects = extension.get_projects()

        if query:
            projects = [
                item for item in projects
                if query.strip().lower() in item['name'].lower()
            ]

        if not projects:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='No projects found matching your criteria',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        for project in projects[:8]:

            icon = 'images/icon.png'

            if project['type'] == 'workspace':
                icon = 'images/code-dark-icon.png'

            items.append(
                ExtensionResultItem(icon=icon,
                                    name=project['name'],
                                    description=project['path'],
                                    on_enter=ExtensionCustomAction(
                                        {'path': project['path']}),
                                    on_alt_enter=OpenAction(project['path'])))

        return RenderResultListAction(items)
コード例 #20
0
ファイル: main.py プロジェクト: schuach/ulauncher-z-search
    def on_event(self, event, extension):
        """Run search if query was entered and act on results."""
        query = event.get_argument()
        if not query:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name="Type a part of a directory name",
                    on_enter=DoNothingAction(),
                )
            ])

        results = extension.search(query)

        if not results:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name="No results matching %s" % query,
                    on_enter=HideWindowAction(),
                )
            ])

        entries = []
        for result in results:
            actions = [OpenAction(result["path"])]
            if extension.update_z_file:
                actions.append(
                    ExtensionCustomAction(result, keep_app_open=False))
            entries.append(
                ExtensionSmallResultItem(
                    icon=self.folder_icon,
                    name=self.get_display_path(result["path"]),
                    on_enter=ActionList(actions),
                ))

        return RenderResultListAction(entries)
コード例 #21
0
ファイル: OpenFolderItem.py プロジェクト: mat1010/Ulauncher
 def on_enter(self, query):
     return OpenAction(self.path)
コード例 #22
0
    def on_event(self, event, extension):
        items = []

        # call Baloo
        query = event.get_argument()

        if query is None:
            return RenderResultListAction(items)

        # prepare query
        if extension.preferences['tags'] == "Yes":
            query = query.replace("#f", "type:Folder")
            query = query.replace("#img", "type:Image")
            query = query.replace("#doc", "type:Document")
            query = query.replace("#txt", "type:Text")
            query = query.replace("#audio", "type:Audio")
            query = query.replace("#z", "type:Archive")
            query = query.replace("#video", "type:Video")
            query = query.replace("#pres", "type:Presentation")
            query = query.replace("#ss", "type:Spreadsheet")

        # search
        out, err = Popen([
            "baloosearch", "-l", extension.preferences['limit_results'], query
        ],
                         stdout=PIPE).communicate()
        results = out.splitlines()

        # remove duplicates
        lines = list(dict.fromkeys(results))

        for line in lines:

            # extract path
            path = line.decode("UTF-8")

            # properties
            name = os.path.basename(path)
            mime = Mime.get_type2(path)

            # icon
            icon_path = "%s/%s.svg" % (extension.preferences['icons_path'],
                                       str(mime).replace("/", "-"))
            icon = icon_path if os.path.exists(
                icon_path) else "images/default.svg"

            # items
            item_name = name.replace("&", "&amp;")
            item_description = path.replace("&", "&amp;")

            items.append(
                ExtensionResultItem(
                    icon=icon,
                    name=item_name,
                    description=item_description,
                    on_enter=OpenAction(path),
                    on_alt_enter=RunScriptAction(
                        "dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 --type=method_call /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:'"
                        + path + "' string:''")))

        return RenderResultListAction(items)
コード例 #23
0
    def on_event(self, event, extension):
        keyword = event.get_keyword()
        argument = event.get_argument()

        if argument and '/' in argument:
            # there's an argument and has a "/", we must interpret it like this:
            # "f /foo/bar/baz else" == "search 'baz else' inside /foo/bar/"
            bits = argument.split('/')
            current_path = Path('/'.join(bits[:-1]))
            current_filter = bits[-1]
        else:
            # there's no argument, or the argument has no "/". Search inside the default path
            current_path = Path(extension.preferences.get('fb_default_path'))
            current_filter = argument

        current_path = current_path.expanduser()
        items = []

        # if we aren't filtering stuff inside the current dir, show an option to open the current
        # dir in the OS's file browser
        if not current_filter:
            item = ExtensionSmallResultItem(
                icon=get_icon_for_file(current_path),
                name="[ Open folder in external file browser ]",
                on_enter=OpenAction(str(current_path)),
            )
            items.append(item)

        # children items, filtered, and folders first
        sorted_children = list(
            sorted(
                current_path.iterdir(),
                key=lambda child_path:
                (not child_path.is_dir(), child_path.name),
            ))

        items_limit = extension.preferences.get('fb_items_limit')
        if items_limit is not None:
            try:
                items_limit = int(items_limit)
            except ValueError:
                pass

        show_hidden = extension.preferences.get('fb_show_hidden') == 'Yes'

        # show each one of them
        items_count = 0
        for child_path in sorted_children:
            if show_hidden or not child_path.name.startswith('.'):
                if matches_filter(child_path.name, current_filter):
                    if child_path.is_dir():
                        item_action = SetUserQueryAction("{} {}/".format(
                            keyword, str(child_path)))
                    else:
                        item_action = OpenAction(str(child_path))

                    item = ExtensionSmallResultItem(
                        icon=get_icon_for_file(child_path),
                        name=child_path.name,
                        on_enter=item_action,
                    )
                    items.append(item)

                    items_count += 1
                    if items_limit is not None and items_count == items_limit:
                        break

        return RenderResultListAction(items)
コード例 #24
0
 def build_actions(self, path):
     yield ('Open', OpenAction(path))
     yield ('Copy Path', CopyToClipboardAction(path))
コード例 #25
0
    def on_enter(self, _):
        if isdir(self.path):
            return SetUserQueryAction(join(fold_user_path(self.path), ''))

        return OpenAction(self.path)
コード例 #26
0
 def prefs_open_url(self, query):
     url = query['url']
     logger.info('Open Web URL %s', url)
     OpenAction(url).run()
コード例 #27
0
 def on_enter(self, query):
     return OpenAction(self.path.get_abs_path())
コード例 #28
0
    def on_enter(self, _):
        self._file_queries.save_query(self.path)
        if isdir(self.path):
            return SetUserQueryAction(join(fold_user_path(self.path), ''))

        return OpenAction(self.path)
コード例 #29
0
 def open_extensions_dir(self, _):
     logger.info('Open extensions directory "%s" in default file manager.',
                 EXTENSIONS_DIR)
     OpenAction(EXTENSIONS_DIR).run()