Python sublime.set_clipboard() Examples

The following are 25 code examples of sublime.set_clipboard(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sublime , or try the search function .
Example #1
Source File: _generated_2018_02_11_at_20_21_24.py    From JavaScript-Completions with MIT License 6 votes vote down vote up
def action_result(action):
    global result_js
    global region_selected
  
    view = sublime.active_window().active_view()
    sel = region_selected
    str_selected = view.substr(sel).strip()
  
    if action == "copy_to_clipboard" :
      sublime.set_clipboard(result_js)
  
    elif action == "replace_text" :
      view.run_command("replace_text")
  
    elif action == "view_result_formatted":
      view.run_command("view_result_formatted")
  
    view.hide_popup()
    result_js = "" 
Example #2
Source File: terminal.py    From sublime_debugger with MIT License 6 votes vote down vote up
def click(self, text: str):
		values = [
			ui.InputListItem(lambda: sublime.set_clipboard(text), "Copy"),
		]
		for match in url_matching_regex.findall(text):
			values.insert(0, ui.InputListItem(lambda: webbrowser.open_new_tab(match[0]), "Open"))

		if self.clicked_menu:
			values[0].run()
			self.clicked_menu.cancel()
			return

		values[0].text += "\t Click again to select"

		self.clicked_menu = ui.InputList(values, text).run()
		await self.clicked_menu
		self.clicked_menu = None 
Example #3
Source File: adapter.py    From sublime_debugger with MIT License 6 votes vote down vote up
def _insert_snippet(window: sublime.Window, snippet: dict):
		content = json.dumps(snippet, indent="\t")
		content = content.replace('\\\\', '\\') # remove json encoded \ ...
		project = window.project_file_name()
		if project:
			view = await core.sublime_open_file_async(window, project)
			region = view.find('''"\s*debug.configurations\s*"\s*:\s*\[''', 0)
			view.sel().clear()
			view.sel().add(sublime.Region(region.b, region.b))
			view.run_command('insert', {
				'characters': '\n'
			})
			view.run_command('insert_snippet', {
				'contents': content + ','
			})
		else:
			sublime.set_clipboard(content)
			core.display('Unable to insert configuration into sublime-project file: Copied to clipboard instead') 
Example #4
Source File: bbcode.py    From SublimeKSP with GNU General Public License v3.0 6 votes vote down vote up
def run(self, *args, **kwargs):
        view = sublime.active_window().active_view()

        #settings = sublime.load_settings('KSP.sublime-settings')
        #scheme_file = settings.get('color_scheme', 'Packages/SublimeKSP/KScript Light.tmTheme')
        scheme_file = 'Packages/SublimeKSP/KScript Light.tmTheme'
        plist = readPlistFromBytes(sublime.load_binary_resource(scheme_file))

        result = ['[pre]']
        start, end = view.sel()[0].a, view.sel()[0].b
        if start == end:
            start, end = 0, view.size()
        for a, b, scopes in get_ranges(view.scope_name(i) for i in range(start, end)):
            result.append(self.apply_style(scopes, plist, view.substr(sublime.Region(start+a, start+b))))
        result.append('[/pre]')
        sublime.set_clipboard(''.join(result)) 
Example #5
Source File: sublimefunctions.py    From FileManager with MIT License 5 votes vote down vote up
def copy(el):
    return sublime.set_clipboard(el) 
Example #6
Source File: cfc_dotted_path.py    From sublimetext-cfml with MIT License 5 votes vote down vote up
def copy_path(window, files):
    def on_done(i):
        if i != -1:
            sublime.set_clipboard(dotted_paths[i])
            sublime.status_message("CFML: copied cfc dotted path")

    dotted_paths = get_dotted_paths(window, cfc_files(files)[0])

    if len(dotted_paths) > 1:
        window.show_quick_panel(dotted_paths, on_done)
    else:
        on_done(0) 
Example #7
Source File: clipboard.py    From SendCode with MIT License 5 votes vote down vote up
def reset_clipboard(self):
        def _reset_clipboard():
            if self.cb is not None:
                sublime.set_clipboard(self.cb)
            self.cb = None
            self.thread = None
        self.thread = threading.Timer(0.5, _reset_clipboard)
        self.thread.start() 
Example #8
Source File: clipboard.py    From SendCode with MIT License 5 votes vote down vote up
def set_clipboard(self, cmd):
        if not self.thread:
            self.cb = sublime.get_clipboard()
        else:
            self.thread.cancel()
            self.thread = None

        sublime.set_clipboard(cmd) 
Example #9
Source File: SideBar.py    From SideBarTools with MIT License 5 votes vote down vote up
def copy_to_clipboard_and_inform(self, data):
        sublime.set_clipboard(data)
        lines = len(data.split('\n'))
        self.window.status_message('Copied {} to clipboard'.format(
            '{} lines'.format(lines) if lines > 1 else '"{}"'.format(data)
        )) 
Example #10
Source File: show_plugin_version.py    From JavaScriptEnhancements with MIT License 5 votes vote down vote up
def run(self):
    if sublime.ok_cancel_dialog("JavaScript Enhancements plugin version: "+PLUGIN_VERSION, "Copy"):
      sublime.set_clipboard(PLUGIN_VERSION) 
Example #11
Source File: core.py    From Terminus with MIT License 5 votes vote down vote up
def paste_choice(self, choice_index):
        if choice_index == -1:
            return
        # use normal paste command
        text = g_clipboard_history.get()[choice_index][1]

        # rotate to top
        g_clipboard_history.push_text(text)

        sublime.set_clipboard(text)
        self.view.run_command("terminus_paste") 
Example #12
Source File: core.py    From Terminus with MIT License 5 votes vote down vote up
def run(self, edit):
        view = self.view
        if not view.settings().get("terminus_view"):
            return
        text = ""
        for s in view.sel():
            if text:
                text += "\n"
            text += view.substr(s)

        # remove the continuation marker
        text = text.replace(CONTINUATION + "\n", "")
        text = text.replace(CONTINUATION, "")

        sublime.set_clipboard(text) 
Example #13
Source File: find_results_copy.py    From SublimeScraps with MIT License 5 votes vote down vote up
def run(self):
        sublime.active_window ().run_command ("copy")
        sublime.set_clipboard (re.sub (r"^\s*[0-9]+.", "",
            sublime.get_clipboard (), flags=re.MULTILINE)) 
Example #14
Source File: log_graph.py    From GitSavvy with MIT License 5 votes vote down vote up
def copy_sha(self, commit_hash):
        sublime.set_clipboard(self.git("rev-parse", commit_hash).strip()) 
Example #15
Source File: log.py    From GitSavvy with MIT License 5 votes vote down vote up
def copy_sha(self):
        sublime.set_clipboard(self.git("rev-parse", self._commit_hash).strip()) 
Example #16
Source File: blame.py    From st3-gitblame with MIT License 5 votes vote down vote up
def on_phantom_close(self, href):
        href_parts = href.split("-")

        if len(href_parts) > 1:
            intent = href_parts[0]
            sha = href_parts[1]
            # The SHA output by git-blame may have a leading caret to indicate
            # that it is a "boundary commit". That useful information has
            # already been shown in the phantom, so strip it before going on to
            # use the SHA programmatically.
            sha = sha.strip("^")

            if intent == "copy":
                sublime.set_clipboard(sha)
                sublime.status_message("Git SHA copied to clipboard")
            elif intent == "show":
                try:
                    desc = self.get_commit(sha, self.view.file_name())
                except Exception as e:
                    communicate_error(e)
                    return

                buf = self.view.window().new_file()
                buf.run_command(
                    "blame_insert_commit_description",
                    {"desc": desc, "scratch_view_name": "commit " + sha},
                )
            else:
                self.view.erase_phantoms("git-blame")
        else:
            self.view.erase_phantoms("git-blame")

    # ------------------------------------------------------------ 
Example #17
Source File: create_and_upload.py    From SyncSettings with MIT License 5 votes vote down vote up
def create(data):
        try:
            g = gist.Gist(
                token=settings.get('access_token'),
                http_proxy=settings.get('http_proxy'),
                https_proxy=settings.get('https_proxy')
            ).create(data)
            msg = (
                'Sync Settings:\n\n'
                'Your gist `{}` was created successfully\n\n'
                'Do you want to overwrite the current `gist_id` property with the created gist?'
            )
            answer = sublime.yes_no_cancel_dialog(msg.format(g['id']))
            if answer == sublime.DIALOG_NO:
                sublime.set_clipboard(g['id'])
                sublime.status_message('Sync Settings: the created gist`s id, has been copied to clipboard')
            if answer == sublime.DIALOG_YES:
                commit = g['history'][0]
                settings.update('gist_id', g['id'])
                version.update_config_file({
                    'hash': commit['version'],
                    'created_at': commit['committed_at'],
                })
                sublime.status_message('Sync Settings: gist created')
        except gist.NotFoundError as e:
            msg = (
                'Sync Settings:\n\n'
                'Apparently the token was not created with gist scope enabled.\n\n'
                'Please, check your token or create a new one.\n\n'
                'more info: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/'
            )
            sublime.message_dialog(msg.format(str(e)))
        except Exception as e:
            logger.exception(e)
            sublime.message_dialog('Sync Settings:\n\n{}'.format(str(e))) 
Example #18
Source File: project_syntax.py    From sublime-project-specific-syntax with GNU Lesser General Public License v3.0 5 votes vote down vote up
def run(self, edit):
        suggested_setting = self._build_suggested_setting()

        if not suggested_setting:
            sublime.set_clipboard('Unable to create syntax setting')
        else:
            sublime.set_clipboard(suggested_setting) 
Example #19
Source File: commands.py    From network_tech with Apache License 2.0 5 votes vote down vote up
def result_handler(view, encoded_password, decoded_password, index):
    if index is RESULTS.cancel:
        return
    elif index is RESULTS.display:
        message = 'Encoded: {}\nDecoded: {}'.format(encoded_password, decoded_password)
        sublime.message_dialog(message)
    elif index is RESULTS.clipboard:
        sublime.set_clipboard(decoded_password)
        sublime.set_timeout_async(
            functools.partial(clear_clipboard, view, decoded_password),
            10000
        ) 
Example #20
Source File: commands.py    From network_tech with Apache License 2.0 5 votes vote down vote up
def clear_clipboard(view, password):
    if sublime.get_clipboard() == password:
        sublime.set_clipboard('')
        view.window().status_message('Network Tech: Password cleared from clipboard') 
Example #21
Source File: main.py    From SalesforceXyTools with Apache License 2.0 5 votes vote down vote up
def run(self, edit):
        full_path = self.view.file_name()
        if full_path != None:
            str_list = full_path.split(baseutil.get_slash())
            file_name = str(str_list[-1])
            sublime.set_clipboard(file_name)
            sublime.status_message("Copy File Name : %s " % file_name) 
Example #22
Source File: sublime_terminal_buffer.py    From TerminalView with MIT License 5 votes vote down vote up
def run(self, edit):
        # Get selected region or use line that cursor is on if nothing is
        # selected
        selected_region = self.view.sel()[0]
        if selected_region.empty():
            selected_region = self.view.line(selected_region)

        # Clean the selected text and move it into clipboard
        selected_text = self.view.substr(selected_region)
        selected_lines = selected_text.split("\n")
        clean_contents_to_copy = ""
        for line in selected_lines:
            clean_contents_to_copy = clean_contents_to_copy + line.rstrip() + "\n"

        sublime.set_clipboard(clean_contents_to_copy[:-1]) 
Example #23
Source File: support.py    From ColorHelper with MIT License 4 votes vote down vote up
def run(self):
        """Run command."""

        info = {}

        info["platform"] = sublime.platform()
        info["version"] = sublime.version()
        info["arch"] = sublime.arch()
        info["plugin_version"] = __version__
        info["pc_install"] = is_installed_by_package_control()
        try:
            import mdpopups
            info["mdpopups_version"] = format_version(mdpopups, 'version', call=True)
        except Exception:
            info["mdpopups_version"] = 'Version could not be acquired!'

        try:
            import markdown
            info["markdown_version"] = format_version(markdown, 'version')
        except Exception:
            info["markdown_version"] = 'Version could not be acquired!'

        try:
            import jinja2
            info["jinja_version"] = format_version(jinja2, '__version__')
        except Exception:
            info["jinja_version"] = 'Version could not be acquired!'

        try:
            import pygments
            info["pygments_version"] = format_version(pygments, '__version__')
        except Exception:
            info["pygments_version"] = 'Version could not be acquired!'

        msg = textwrap.dedent(
            """\
            - ST ver.: %(version)s
            - Platform: %(platform)s
            - Arch: %(arch)s
            - Plugin ver.: %(plugin_version)s
            - Install via PC: %(pc_install)s
            - mdpopups ver.: %(mdpopups_version)s
            - markdown ver.: %(markdown_version)s
            - pygments ver.: %(pygments_version)s
            - jinja2 ver.: %(jinja_version)s
            """ % info
        )

        sublime.message_dialog(msg + '\nInfo has been copied to the clipboard.')
        sublime.set_clipboard(msg) 
Example #24
Source File: environment.py    From sublime-boxy-theme with MIT License 4 votes vote down vote up
def run(self):
        info = {}

        info['platform'] = sublime.platform()
        info['version'] = sublime.version()
        info['arch'] = sublime.arch()
        info['boxy_version'] = __version__
        info['pc_install'] = is_installed_by_package_control()

        try:
            import mdpopups
            info['mdpopups_version'] = format_version(mdpopups, 'version',
                                                      call=True)
        except Exception:
            info['mdpopups_version'] = 'Version could not be acquired!'

        try:
            import markdown
            info['markdown_version'] = format_version(markdown, 'version')
        except Exception:
            info['markdown_version'] = 'Version could not be acquired!'

        try:
            import jinja2
            info['jinja_version'] = format_version(jinja2, '__version__')
        except Exception:
            info['jinja_version'] = 'Version could not be acquired!'

        try:
            import pygments
            info['pygments_version'] = format_version(pygments, '__version__')
        except Exception:
            info['pygments_version'] = 'Version could not be acquired!'

        msg = textwrap.dedent(
            '''\
            - Boxy Theme: %(boxy_version)s
            - Sublime Text: %(version)s
            - Platform: %(platform)s
            - Package Control: %(pc_install)s
            - Dependencies:
                * mdpopups: %(mdpopups_version)s
                * markdown: %(markdown_version)s
                * pygments: %(pygments_version)s
                * jinja2: %(jinja_version)s
            ''' % info
        )

        view = sublime.active_window().active_view()
        def copy_and_hide(msg):
            sublime.set_clipboard(msg)
            view.hide_popup()
        view.show_popup(msg.replace('\n', '<br>') +
                        '<br><a href="' + msg + '">Copy</a>',
                        on_navigate=copy_and_hide) 
Example #25
Source File: modules.py    From sublime_debugger with MIT License 4 votes vote down vote up
def render(self) -> ui.div.Children:
		items = []
		for session in self.sessions:
			items.append(ui.div(height=css.row_height)[
				ui.text(session.name)
			])
				
			for module in session.modules.values():
				is_expanded = self.is_expanded(module)
				image_toggle = ui.Images.shared.open if is_expanded else ui.Images.shared.close
				item = ui.div(height=css.row_height)[
					ui.click(lambda module=module: self.toggle_expanded(module))[ #type: ignore
						ui.icon(image_toggle),
					],
					ui.text(module.name)
				]
				items.append(item)
				if is_expanded:
					body = []
					def add_item(label, value):
						if value is None:
							return

						def copy():
							ui.InputList([
								ui.InputListItem(lambda: sublime.set_clipboard(value), "Copy")
							], value).run()

						value_str = str(value)
						body.append(
							ui.div(height=3)[
								ui.click(copy)[
									ui.text(label, css=css.label_secondary_padding),
									ui.text(value_str, css=css.label),
								]
							]
						)

					add_item('path', module.path)
					add_item('symbols', module.symbolStatus)
					add_item('symbol file path', module.symbolFilePath)
					add_item('load address', module.addressRange)

					items.append(ui.div(css=css.table_inset)[
						body
					])

		return [
			ui.div()[
				items
			]
		]