def finish_the_job(self):
self.view.set_scratch(True)
self.view.settings().set('save_on_focus_lost', False)
self.cleanup()
sublime.run_command('no_dialogs_create_close_window_prompt')
python类run_command()的实例源码
def finish_the_job(self):
self.view.set_scratch(True)
self.view.settings().set('save_on_focus_lost', False)
self.cleanup()
sublime.run_command('no_dialogs_create_exit_prompt')
def run(self):
self.alias_window_and_view()
view_file_name = self.view.file_name()
if not view_file_name or not os.path.exists(view_file_name):
sublime.run_command('no_dialogs_create_close_prompt')
return
if not settings.get('no_dialogs_delete_without_prompt'):
self.show_prompt()
else:
self.finish_the_job()
def _remove():
try:
shutil.rmtree(path.get_overlay_aliases())
except Exception as error:
log("Error during remove")
dump(error)
finally:
sublime.run_command("refresh_folder_list")
def _rename():
aliases_path = path.get_overlay_aliases()
try:
for alias_base in os.listdir(aliases_path):
alias_path = os.path.join(aliases_path, alias_base)
if os.path.isfile(alias_path):
name, ext = os.path.splitext(alias_path)
os.rename(alias_path, alias_path.replace(".disabled-", "."))
except Exception as error:
log("Error during rename")
dump(error)
finally:
sublime.run_command("refresh_folder_list")
def run(self):
log("Cleaning")
overlay_path = path.get_overlay()
patches = _get_patches(overlay_path, ".sublime-theme")
if os.path.exists(overlay_path):
try:
for p in patches:
os.remove(p)
except Exception as error:
log("Error during cleaning")
dump(error)
else:
log("Cleaned up successfully")
sublime.run_command("afi_patch_themes")
def _on_aliases_change():
log("Aliases settings changed")
sublime.run_command("afi_check_aliases")
def _on_icons_change():
log("Icons settings changed")
sublime.run_command("afi_patch_themes", {"overwrite": True})
def _on_force_mode_change():
log("Force mode settings changed")
sublime.run_command("afi_patch_themes")
def on_post_save(self, view):
if not (os.path.dirname(__file__) in view.file_name() and
view.file_name().endswith('.py')):
return
sublime.run_command('reload_plugin', {
'main': os.path.join(sublime.packages_path(), 'MarkdownLivePreview',
'MarkdownLivePreview.py'),
'scripts': ['image_manager', 'functions', 'MLPApi',
'setting_names'],
'folders': ['lib'],
'quiet': True
})
def run(self):
"""Inspired by the edit_settings command"""
current_view = sublime.active_window().active_view()
file_name = current_view.file_name()
if get_settings().get('keep_open_when_opening_preview') is False:
current_view.close()
if file_name is None:
return sublime.error_message('MarkdownLivePreview: Not supporting '
'unsaved file for now')
sublime.run_command('new_window')
self.window = sublime.active_window()
self.window.settings().set(PREVIEW_WINDOW, True)
self.window.run_command('set_layout', {
'cols': [0.0, 0.5, 1.0],
'rows': [0.0, 1.0],
'cells': [[0, 0, 1, 1], [1, 0, 2, 1]]
})
self.window.focus_group(1)
preview = create_preview(self.window, current_view)
self.window.focus_group(0)
md_view = self.window.open_file(file_name)
mdsettings = md_view.settings()
mdsettings.set(PREVIEW_ENABLED, True)
mdsettings.set(PREVIEW_ID, preview.id())
def on_activated_async(self, view):
vsettings = view.settings()
if (is_markdown_view(view) and get_settings().get(ON_OPEN)
and not vsettings.get(PREVIEW_ENABLED)
and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + \
'.sublime/MarkdownLivePreviewSyntax' + \
'.hidden-tmLanguage'
and not any(filter(lambda window: window.settings().get(PREVIEW_WINDOW) is True,
sublime.windows()))):
sublime.run_command('new_markdown_live_preview')
def run(self, edit):
project = get_or_create_project_and_add_view(self.view)
if project:
sublime.active_window().run_command('save_all')
project.reopen_project()
#project.tsserver.reload(lambda: )
# ################################# SHOW INFOS #################################
def async_react(self, refs, filename, line, col):
if refs is None or len(refs) == 0:
return
view = sublime.active_window().active_view()
project = get_or_create_project_and_add_view(view)
if not project:
return
if self.selection_has_changed(filename, line, col):
return
Debug('refactor', refs)
#{'lineText': ' let total = 0;',
# 'file': '/home/daniel/.config/sublime-text-3/Packages/ArcticTypescript/tests/TDDTesting/main.ts',
# 'min': {'character': 13,
# 'line': 43},
# 'lim': {'character': 18,
# 'line': 43},
# 'ref': {'textSpan': {'start': 760,
# 'length': 5},
# 'fileName': '/home/daniel/.config/sublime-text-3/Packages/ArcticTypescript/tests/TDDTesting/main.ts',
# 'isWriteAccess': True}}
refactor_member = self.get_entire_member_name(refs)
if not refactor_member:
return
Debug('refactor', refactor_member)
sublime.active_window().show_input_panel(
'Refactoring %s (found %i times) to:' % (refactor_member, len(refs)),
refactor_member,
lambda new_name: sublime.run_command("typescript_apply_refactor",
{"project":project, "refs":refs, "old_name":refactor_member, "new_name":new_name}), # require edit token
None, # change
None) # camcel
## TODO: keine Objekte ins run_command -> verweise bze hashes und die refs temporär im project abspeicern
def run(self, edit_token):
project = get_or_create_project_and_add_view(self.view)
if project:
return # typescript tools dropped support for this
Debug('structure', 'open view if not already open')
project.assert_initialisation_finished()
T3SVIEWS.OUTLINE.enable()
T3SVIEWS.OUTLINE.bring_to_top(back_to=self.view)
self.view.run_command('typescript_update_structure', {"force": True})
# ################################# REFRESH OUTLINE ############################
def on_message(self, text):
try:
request = json.loads(text)
self._current_view.run_command('replace_content', request)
self._current_view.window().focus_view(self._current_view)
except ValueError as e:
Utils.show_error(e, 'Invalid JSON')
def __init__(self):
# Again, unsafe
sublime.run_command()
def __init__(self):
# This is safe, though
sublime.run_command()
def on_close(self, view):
"""
Closes the other settings view when one of the two is closed
"""
view_settings = view.settings()
if not view_settings.get('edit_settings_view'):
return
window = sublime.active_window()
sublime.set_timeout(lambda: window.run_command('close_window'), 50)
def on_load(self, view):
default_contents = view.settings().get('default_contents')
if not os.path.isfile(view.file_name()) and default_contents:
view.run_command('insert_snippet', {'contents': default_contents})