Beispiel #1
0
    def yank(self, url: QUrl, context: HintContext) -> None:
        """Yank an element to the clipboard or primary selection."""
        sel = (context.target == Target.yank_primary
               and utils.supports_selection())

        flags = QUrl.FullyEncoded | QUrl.RemovePassword
        if url.scheme() == 'mailto':
            flags |= QUrl.RemoveScheme
        urlstr = url.toString(flags)  # type: ignore[arg-type]

        new_content = urlstr

        # only second and consecutive yanks are to append to the clipboard
        if context.rapid and not context.first_run:
            try:
                old_content = utils.get_clipboard(selection=sel)
            except utils.ClipboardEmptyError:
                pass
            else:
                new_content = os.linesep.join([old_content, new_content])
        utils.set_clipboard(new_content, selection=sel)

        msg = "Yanked URL to {}: {}".format(
            "primary selection" if sel else "clipboard", urlstr)
        message.info(msg)
Beispiel #2
0
    def yank(self, url, context):
        """Yank an element to the clipboard or primary selection.

        Args:
            url: The URL to open as a QUrl.
            context: The HintContext to use.
        """
        sel = (context.target == Target.yank_primary and
               utils.supports_selection())

        flags = QUrl.FullyEncoded | QUrl.RemovePassword
        if url.scheme() == 'mailto':
            flags |= QUrl.RemoveScheme
        urlstr = url.toString(flags)

        new_content = urlstr

        # only second and consecutive yanks are to append to the clipboard
        if context.rapid and not context.first_run:
            try:
                old_content = utils.get_clipboard(selection=sel)
            except utils.ClipboardEmptyError:
                pass
            else:
                new_content = os.linesep.join([old_content, new_content])
        utils.set_clipboard(new_content, selection=sel)

        msg = "Yanked URL to {}: {}".format(
            "primary selection" if sel else "clipboard",
            urlstr)
        message.info(msg)
Beispiel #3
0
    def completion_item_yank(self, sel=False):
        """Yank the current completion item into the clipboard.

        Args:
            sel: Use the primary selection instead of the clipboard.
        """
        index = self.currentIndex()
        if not index.isValid():
            raise cmdexc.CommandError("No item selected!")
        data = self.model().data(index)
        utils.set_clipboard(data, selection=sel)
    def completion_item_yank(self, sel=False):
        """Yank the current completion item into the clipboard.

        Args:
            sel: Use the primary selection instead of the clipboard.
        """
        index = self.currentIndex()
        if not index.isValid():
            raise cmdexc.CommandError("No item selected!")
        data = self.model().data(index)
        utils.set_clipboard(data, selection=sel)
Beispiel #5
0
    def yank(self, url, context):
        """Yank an element to the clipboard or primary selection.

        Args:
            url: The URL to open as a QUrl.
            context: The HintContext to use.
        """
        sel = context.target == Target.yank_primary and utils.supports_selection()

        urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)
        utils.set_clipboard(urlstr, selection=sel)

        msg = "Yanked URL to {}: {}".format("primary selection" if sel else "clipboard", urlstr)
        message.info(msg)
Beispiel #6
0
    def _yank(self, url, context):
        """Yank an element to the clipboard or primary selection.

        Args:
            url: The URL to open as a QUrl.
            context: The HintContext to use.
        """
        sel = context.target == Target.yank_primary
        urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)
        utils.set_clipboard(urlstr, selection=sel)

        msg = "Yanked URL to {}: {}".format(
            "primary selection" if sel else "clipboard", urlstr)
        message.info(self._win_id, msg)
    def completion_item_yank(self, sel=False):
        """Yank the current completion item into the clipboard.

        Args:
            sel: Use the primary selection instead of the clipboard.
        """
        status = objreg.get('status-command', scope='window',
                            window=self._win_id)
        text = status.selectedText()
        if not text:
            index = self.currentIndex()
            if not index.isValid():
                raise cmdutils.CommandError("No item selected!")
            text = self.model().data(index)
        utils.set_clipboard(text, selection=sel)
    def completion_item_yank(self, sel=False):
        """Yank the current completion item into the clipboard.

        Args:
            sel: Use the primary selection instead of the clipboard.
        """
        status = objreg.get('status-command', scope='window',
                            window=self._win_id)
        text = status.selectedText()
        if not text:
            index = self.currentIndex()
            if not index.isValid():
                raise cmdexc.CommandError("No item selected!")
            text = self.model().data(index)
        utils.set_clipboard(text, selection=sel)
    def completion_item_yank(self, sel=False):
        """Yank the current completion item into the clipboard.

        Args:
            sel: Use the primary selection instead of the clipboard.
        """
        text = self._cmd.selectedText()
        if not text:
            index = self.currentIndex()
            if not index.isValid():
                raise cmdutils.CommandError("No item selected!")
            text = self.model().data(index)

        if not utils.supports_selection():
            sel = False

        utils.set_clipboard(text, selection=sel)
Beispiel #10
0
    def prompt_yank(self, sel=False):
        """Yank URL to clipboard or primary selection.

        Args:
            sel: Use the primary selection instead of the clipboard.
        """
        question = self._prompt.question
        if question.url is None:
            message.error('No URL found.')
            return
        if sel and utils.supports_selection():
            target = 'primary selection'
        else:
            sel = False
            target = 'clipboard'
        utils.set_clipboard(question.url, sel)
        message.info("Yanked to {}: {}".format(target, question.url))
Beispiel #11
0
    def yank_text(self, text, context):
        """Yank an element to the clipboard or primary selection.

        Args:
            text: The text to open as a QUrl.
            context: The HintContext to use.
        """
        sel = (context.target == Target.yank_text_primary
               and utils.supports_selection())

        inner = text.inner_xml()

        utils.set_clipboard(inner, selection=sel)

        msg = "Yanked text to {}: {}".format(
            "primary selection" if sel else "clipboard", inner)
        message.info(msg)
Beispiel #12
0
    def prompt_yank(self, sel=False):
        """Yank URL to clipboard or primary selection.

        Args:
            sel: Use the primary selection instead of the clipboard.
        """
        question = self._prompt.question
        if question.url is None:
            message.error('No URL found.')
            return
        if sel and utils.supports_selection():
            target = 'primary selection'
        else:
            sel = False
            target = 'clipboard'
        utils.set_clipboard(question.url, sel)
        message.info("Yanked to {}: {}".format(target, question.url))
Beispiel #13
0
    def yank(self, url, context):
        """Yank an element to the clipboard or primary selection.

        Args:
            url: The URL to open as a QUrl.
            context: The HintContext to use.
        """
        sel = (context.target == Target.yank_primary
               and utils.supports_selection())

        flags = QUrl.FullyEncoded | QUrl.RemovePassword
        if url.scheme() == 'mailto':
            flags |= QUrl.RemoveScheme
        urlstr = url.toString(flags)
        utils.set_clipboard(urlstr, selection=sel)

        msg = "Yanked URL to {}: {}".format(
            "primary selection" if sel else "clipboard", urlstr)
        message.info(msg)
Beispiel #14
0
 def _yank_url(url: str) -> None:
     utils.set_clipboard(url)
     message.info("Version url {} yanked to clipboard.".format(url))
Beispiel #15
0
 def _yank_url(url):
     utils.set_clipboard(url)
     message.info("Version url {} yanked to clipboard.".format(url))