Python sublime.active_window() Examples
The following are 30
code examples of sublime.active_window().
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: ShellExec.py From sublime-3-shell-exec with MIT License | 9 votes |
def command_variables(args, view, command, format=True): if format and args.get("format"): command = args["format"].replace('${input}', command) for region in view.sel(): (row,col) = view.rowcol(view.sel()[0].begin()) command = command.replace('${row}', str(row+1)) command = command.replace('${region}', view.substr(region)) break # packages, platform, file, file_path, file_name, file_base_name, # file_extension, folder, project, project_path, project_name, # project_base_name, project_extension. command = sublime.expand_variables(command, sublime.active_window().extract_variables()) return command
Example #2
Source File: sthelper.py From SublimeJsPrettier with MIT License | 6 votes |
def _get_project_setting(key): """Get a project setting. JsPrettier project settings are stored in the sublime project file as a dictionary, e.g.: "settings": { "js_prettier": { "key": "value", ... } } :param key: The project setting key. :return: The project setting value. :rtype: str """ project_settings = sublime.active_window().active_view().settings() if not project_settings: return None js_prettier_settings = project_settings.get(PROJECT_SETTINGS_KEY) if js_prettier_settings and key in js_prettier_settings: return js_prettier_settings[key] return None
Example #3
Source File: dired_misc.py From SublimeFileBrowser with MIT License | 6 votes |
def on_new(self, view): if not self.MOVE: return w = sublime.active_window() if w.num_groups() < 2: return if is_any_dired_in_group(w, 0): if w.active_group() == 0: # at this point views are exist, so we cannot avoid the use of # set_view_index, but ST2 return None if group has no views # ST3 return None if group has active image’s view avig1 = w.active_view_in_group(1) if avig1: _group, active_view_index_in_other_group = w.get_view_index(avig1) index = active_view_index_in_other_group + 1 else: index = 0 sublime.set_timeout(lambda: w.set_view_index(view, 1, index), 1)
Example #4
Source File: TodoReview.py From SublimeTodoReview with MIT License | 6 votes |
def get_view(self): self.window = sublime.active_window() for view in self.window.views(): if view.settings().get('todo_results', False): view.erase(self.edit, sublime.Region(0, view.size())) return view view = self.window.new_file() view.set_name('TodoReview') view.set_scratch(True) view.settings().set('todo_results', True) if sys.version_info < (3,0,0): view.set_syntax_file('Packages/TodoReview/TodoReview.hidden-tmLanguage') else: view.assign_syntax('Packages/TodoReview/TodoReview.hidden-tmLanguage') view.settings().set('line_padding_bottom', 2) view.settings().set('line_padding_top', 2) view.settings().set('word_wrap', False) view.settings().set('command_mode', True) return view
Example #5
Source File: TodoReview.py From SublimeTodoReview with MIT License | 6 votes |
def draw_file(self, item): if settings.get('render_include_folder', False): depth = settings.get('render_folder_depth', 1) if depth == 'auto': f = item['file'] for folder in sublime.active_window().folders(): if f.startswith(folder): f = os.path.relpath(f, folder) break f = f.replace('\\', '/') else: f = os.path.dirname(item['file']).replace('\\', '/').split('/') f = '/'.join(f[-depth:] + [os.path.basename(item['file'])]) else: f = os.path.basename(item['file']) return '%f:%l' \ .replace('%f', f) \ .replace('%l', str(item['line']))
Example #6
Source File: dired_misc.py From SublimeFileBrowser with MIT License | 6 votes |
def open_from_preview(self, payload): msg, path = payload.split('\v') def show_errors(_): self.view.update_popup( '<br><a href="back\v">←<br><br>' '</a>Errors:<br> %s<br>' % '<br> '.join(self.errors)) def go_back(_): self.update_preview(loading=False) def open_dir(path): self.view.settings().set('dired_path', path) self.view.run_command('dired_refresh') def open_file(path): (self.view.window() or sublime.active_window()).open_file(path) case = { 'dir': open_dir, 'file': open_file, 'errors': show_errors, 'back': go_back } case[msg](path)
Example #7
Source File: spacelistener.py From sublimious with GNU General Public License v3.0 | 6 votes |
def try_resolve_chain(self): if self.inChain: if self.command_chain[-2:] == ['f', 'd'] \ or self.command_chain[-1] == keys["ESCAPE"] \ or self.command_chain[-1] == 'q': self.end_command_chain() return True tree = self.generate_action_tree() for key in self.command_chain: if key not in tree: return False tree = tree[key] # check if we are on the final node if "action" in tree: sublime.active_window().run_command(tree["action"], tree["args"]) self.end_command_chain() return True return False
Example #8
Source File: dired_misc.py From SublimeFileBrowser with MIT License | 6 votes |
def run(self, edit): view = self.view.window().new_file() view.settings().add_on_change('color_scheme', lambda: set_proper_scheme(view)) view.set_name("Browse: shortcuts") view.set_scratch(True) view.settings().set('rulers', []) view.settings().set('syntax', 'Packages/FileBrowser/dired-help' + SYNTAX_EXTENSION) view.settings().set('margin', 16) view.settings().set('line_numbers', False) view.settings().set('gutter', False) view.settings().set('fold_buttons', False) view.settings().set('draw_indent_guides', False) view.settings().set('word_wrap', False) view.settings().set('spell_check', False) view.settings().set('drag_text', False) view.run_command('dired_show_help') sublime.active_window().focus_view(view)
Example #9
Source File: dired_file_operations.py From SublimeFileBrowser with MIT License | 6 votes |
def run(self, edit): self.which = self.view.settings().get('which', '') if not self.which: return sublime.error_message('oops, does not work!') self.refresh = False value = self.view.substr(Region(0, self.view.size())) fqn = self.on_done(value) if not fqn: return sublime.status_message('oops, does not work!') sublime.active_window().run_command('hide_panel', {'cancel': True}) dired_view = sublime.active_window().active_view() if dired_view.settings().has('dired_path'): self.refresh = True if self.which == 'directory': dired_view.settings().set('dired_path', fqn + os.sep) else: sublime.active_window().open_file(fqn) if self.refresh: emit_event(u'watch_view', dired_view.id(), plugin=u'FileBrowserWFS') dired_view.run_command('dired_refresh', {'goto': fqn})
Example #10
Source File: dired_file_operations.py From SublimeFileBrowser with MIT License | 6 votes |
def run(self, edit): s = self.view.settings() self.index = self.get_all() sources_move = s.get('dired_to_move', []) sources_copy = s.get('dired_to_copy') or self.get_marked(full=True) or self.get_selected(parent=False, full=True) mitems = len(sources_move) citems = len(sources_copy) if not (mitems or citems): return sublime.status_message('Nothing to paste') both = mitems and citems msg = '%s%s to:' % (('Move %d' % mitems) if mitems else '', ('%sopy %d' % (' and c' if both else 'C', citems)) if citems else '') path = self.get_path() window = self.view.window() or sublime.active_window() emit_event(u'ignore_view', self.view.id(), plugin=u'FileBrowserWFS') prompt.start(msg, window, path, self.initfo, sources_move, sources_copy)
Example #11
Source File: prompt.py From SublimeFileBrowser with MIT License | 6 votes |
def run(self, edit): self.edit = edit self.prompt_region = Region(0, self.view.size()) content, path, prefix = self.get_content() if not valid(path or content): return completions, error = self.get_completions(path, prefix) if error: return # content of path is unavailable (access, permission, etc.) if not completions: return sublime.status_message('No matches') new_content = self.get_new_content(path, prefix, completions) if new_content: self.fill_prompt(new_content) else: self.completions = completions self._path = path self.w = self.view.window() or sublime.active_window() return self.w.show_quick_panel(completions, self.on_done)
Example #12
Source File: sthelper.py From SublimeJsPrettier with MIT License | 6 votes |
def get_st_project_path(): """Get the active Sublime Text project path. Original: https://gist.github.com/astronaughts/9678368 :rtype: object :return: The active Sublime Text project path. """ window = sublime.active_window() folders = window.folders() if len(folders) == 1: return folders[0] else: active_view = window.active_view() if active_view: active_file_name = active_view.file_name() else: active_file_name = None if not active_file_name: return folders[0] if len(folders) else os.path.expanduser('~') for folder in folders: if active_file_name.startswith(folder): return folder return os.path.dirname(active_file_name)
Example #13
Source File: standard-format.py From sublime-standard-format with MIT License | 6 votes |
def plugin_loaded(): """ perform some work to set up env correctly. """ global global_path global local_path global settings settings = sublime.load_settings(SETTINGS_FILE) view = sublime.active_window().active_view() if platform != "windows": maybe_path = calculate_user_path() if len(maybe_path) > 0: global_path = maybe_path[0] search_path = generate_search_path(view) local_path = search_path print_status(global_path, search_path)
Example #14
Source File: sublime_plugin.py From TerminalView with MIT License | 6 votes |
def on_api_ready(): global api_ready api_ready = True for m in list(sys.modules.values()): if "plugin_loaded" in m.__dict__: try: m.plugin_loaded() except: traceback.print_exc() # Synthesize an on_activated call w = sublime.active_window() if w: view_id = sublime_api.window_active_view(w.window_id) if view_id != 0: try: on_activated(view_id) except: traceback.print_exc()
Example #15
Source File: tern.py From PhaserSublimePackage with MIT License | 6 votes |
def run(self, edit, **args): data = run_command(self.view, {"type": "definition", "lineCharPositions": True}) if data is None: return file = data.get("file", None) if file is not None: # Found an actual definition row, col = self.view.rowcol(self.view.sel()[0].b) cur_pos = self.view.file_name() + ":" + str(row + 1) + ":" + str(col + 1) jump_stack.append(cur_pos) if len(jump_stack) > 50: jump_stack.pop(0) real_file = (os.path.join(get_pfile(self.view).project.dir, file) + ":" + str(data["start"]["line"] + 1) + ":" + str(data["start"]["ch"] + 1)) sublime.active_window().open_file(real_file, sublime.ENCODED_POSITION) else: url = data.get("url", None) if url is None: sublime.error_message("Could not find a definition") else: webbrowser.open(url)
Example #16
Source File: main_toolbox.py From SalesforceXyTools with Apache License 2.0 | 6 votes |
def run(self, edit, deploy_file_list=None): self.window = sublime.active_window() if deploy_file_list: self.open_files = deploy_file_list self.current_file = None self.sel_type_list = ["Deploy Directory", "Deploy Directory To Server(check only)"] self.sel_type_key_list = ["DeployOpenFiles", "CheckDeployOpenFiles"] else: self.open_files = [] for _view in self.window.views(): file_name = _view.file_name() if file_name: self.open_files.append(file_name) self.current_file = self.view.file_name() self.sel_type_list = ["Config Ant Metadata Tool", "Backup All Metadata", "Deploy Open Files To Server", "Deploy Open Files To Server(check only)"] self.sel_type_key_list = ["Build", "Backup", "DeployOpenFiles", "CheckDeployOpenFiles"] if self.current_file: file_path, file_name = os.path.split(self.current_file) self.sel_type_list.append("Deploy Current File To Server : %s" % file_name) self.sel_type_list.append("Deploy Current File To Server : %s (check only)" % file_name) self.sel_type_key_list.append("DeployOne") self.sel_type_key_list.append("CheckDeployOne") self.window.show_quick_panel(self.sel_type_list, self.panel_done, sublime.MONOSPACE_FONT)
Example #17
Source File: tandem.py From tandem with Apache License 2.0 | 6 votes |
def start(self, view, session_id=None, show_gui=False): global is_active if is_active: msg = "Cannot start. An instance is already running on :{}".format( self._agent_port, ) show_message(msg, show_gui) return self._connect_to = session_id if self._connect_to is not None: view = sublime.active_window().new_file() self._initialize(view) self._start_agent() is_active = True if self._connect_to is None: self.check_buffer(view.buffer_id())
Example #18
Source File: ProjectListener.py From FuzzyFilePath with Do What The F*ck You Want To Public License | 6 votes |
def on_activated(self, view): window = view.window() if not window: return False project_id = get_project_id(window) if self.previous_project != project_id: if self.previous_project is not None: self.on_project_activated(view) self.previous_project = project_id elif self.previous_window is not sublime.active_window().id(): self.previous_window = sublime.active_window().id() self.on_window_activated(view) # project has been refocused
Example #19
Source File: bbcode.py From SublimeKSP with GNU General Public License v3.0 | 6 votes |
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 #20
Source File: ShellExec.py From sublime-3-shell-exec with MIT License | 6 votes |
def new_output_file(args, pure_command): if ShellExec.get_setting('debug', args): print('open new empty file: ' + pure_command) output_file = sublime.active_window().new_file() output_file.set_name(pure_command[0:60]) output_file.set_scratch(True) if ShellExec.get_setting('output_syntax', args): if ShellExec.get_setting('debug', args): print('set output syntax: ' + ShellExec.get_setting('output_syntax', args)) if sublime.find_resources(ShellExec.get_setting('output_syntax', args) + '.tmLanguage'): output_file.set_syntax_file(sublime.find_resources(ShellExec.get_setting('output_syntax', args) + '.tmLanguage')[0]) if ShellExec.get_setting('output_word_wrap', args): output_file.settings().set('word_wrap', True) else: output_file.settings().set('word_wrap', False) return output_file
Example #21
Source File: ksp_plugin.py From SublimeKSP with GNU General Public License v3.0 | 6 votes |
def run(self, *args, **kwargs): # wait until any previous thread is finished if self.thread and self.thread.is_alive(): sublime.status_message('Waiting for earlier compilation to finish...') self.thread.stop() self.thread.join() # find the view containing the code to compile view = None if kwargs.get('recompile', None) and self.last_filename: view = CompileKspThread.find_view_by_filename(self.last_filename) if view is None: view = sublime.active_window().active_view() self.thread = CompileKspThread(view) self.thread.start() self.last_filename = view.file_name()
Example #22
Source File: ShellExec.py From sublime-3-shell-exec with MIT License | 5 votes |
def run_shell_command(args, view, command): command = ShellExec.command_variables(args, view, command) if 'folder' in sublime.active_window().extract_variables(): if sublime.platform() == 'windows': pure_command = command.replace(sublime.active_window().extract_variables()['folder'] + '\\', '') else: pure_command = command.replace(sublime.active_window().extract_variables()['folder'] + '/', '') else: pure_command = command if ShellExec.get_setting('context', args) == 'project_folder': if 'folder' in sublime.active_window().extract_variables(): command = "cd '" + sublime.active_window().extract_variables()['folder'] + "' && " + command if ShellExec.get_setting('context', args) == 'file_folder': if 'file_path' in sublime.active_window().extract_variables(): command = "cd '" + sublime.active_window().extract_variables()['file_path'] + "' && " + command sublime_shell_source = '' sh_file_settings = ShellExec.get_setting('load_sh_file', args, True) sh_file_shortcut = ShellExec.get_setting('load_sh_file', args, False) sublime_shell_source = ShellExec.load_sh_file(sublime_shell_source, sh_file_settings, args) if sh_file_settings != sh_file_shortcut: sublime_shell_source = ShellExec.load_sh_file(sublime_shell_source, sh_file_shortcut, args) if ShellExec.get_setting('debug', args): print('new Thread') t = Thread(target=ShellExec.execute_shell_command, args=(sublime_shell_source, command, pure_command, args)) t.start()
Example #23
Source File: ShellExec.py From sublime-3-shell-exec with MIT License | 5 votes |
def increment_output(self, value, args, pure_command): if ShellExec.get_setting('output', args) == "file": if not self.output_file: self.output_file = ShellExec.new_output_file(args, pure_command) self.output_file.run_command('shell_exec_view_insert', {'pos': self.output_file.size(), 'text': value}) elif ShellExec.get_setting('output', args) == "none": self.panel_output = False else: if not self.panel_output: self.panel_output = True sublime.active_window().run_command('show_panel', {"panel": "console", "toggle": False}) sys.stdout.write(value)
Example #24
Source File: ShellExec.py From sublime-3-shell-exec with MIT License | 5 votes |
def run(self, edit, **args): self.args = args if ShellExec.get_setting('debug', self.args): print("\n\n>>>>>>>>>>>>>>>>>> Start Shell Exec Debug:") command = "" if args.get("command"): command = ShellExec.command_variables(args, self.view, args["command"], False) def runShellExec(user_command): ShellExec.run_shell_command(self.args, self.view, user_command) sublime.active_window().show_input_panel(ShellExec.get_setting('title', self.args), command, runShellExec, None, None)
Example #25
Source File: spacelistener.py From sublimious with GNU General Public License v3.0 | 5 votes |
def hide_help(self): sublime.active_window().run_command("hide_panel", {"panel": "output.sublimious_shortcut_panel", "toggle": False})
Example #26
Source File: plugin.py From sublime-phpunit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_window_setting(key, default=None, window=None): if not window: window = active_window() if window.settings().has(key): return window.settings().get(key) view = window.active_view() if view and view.settings().has(key): return view.settings().get(key) return default
Example #27
Source File: package_reloader.py From AutomaticPackageReloader with MIT License | 5 votes |
def prompt_package(self, callback): package = self.current_package_name if not package: package = "" view = sublime.active_window().show_input_panel( 'Package:', package, callback, None, None) view.run_command("select_all")
Example #28
Source File: hound.py From SublimeHound with MIT License | 5 votes |
def open_settings(self): sublime.active_window().open_file(sublime.packages_path() + "/User/" + self.SETTINGS)
Example #29
Source File: spacelistener.py From sublimious with GNU General Public License v3.0 | 5 votes |
def plugin_loaded(): coll = collector.Collector(os.path.dirname(os.path.realpath(__file__))) SpaceListener.shortcut_panel = sublime.active_window().create_output_panel("sublimious_shortcut_panel") SpaceListener.collector = coll SpaceListener.settings = helpers.mergedicts(SpaceListener.settings, coll.get_collected_config())
Example #30
Source File: commands.py From sublimious with GNU General Public License v3.0 | 5 votes |
def run(self, *args, **kw): print("Opening .sublimious") config_path = os.path.expanduser("~/.sublimious") if os.path.exists(config_path): sublime.active_window().open_file(config_path)