def run(self):
old = self.old
new = self.new
key = self.key
window_set_status(key, 'Duplicating…')
item = SideBarItem(old, os.path.isdir(old))
try:
if not item.copy(new):
window_set_status(key, '')
if SideBarItem(new, os.path.isdir(new)).overwrite():
self.run()
else:
SideBarDuplicateCommand(sublime_plugin.WindowCommand).run([old], new)
return
except:
window_set_status(key, '')
sublime.error_message("Unable to copy:\n\n"+old+"\n\nto\n\n"+new)
SideBarDuplicateCommand(sublime_plugin.WindowCommand).run([old], new)
return
item = SideBarItem(new, os.path.isdir(new))
if item.isFile():
item.edit();
SideBarProject().refresh();
window_set_status(key, '')
python类WindowCommand()的实例源码
def run(self):
old = self.old
new = self.new
key = self.key
window_set_status(key, 'Moving…')
item = SideBarItem(old, os.path.isdir(old))
try:
if not item.move(new):
if SideBarItem(new, os.path.isdir(new)).overwrite():
self.run()
else:
window_set_status(key, '')
SideBarMoveCommand(sublime_plugin.WindowCommand).run([old], new)
return
except:
window_set_status(key, '')
sublime.error_message("Unable to move:\n\n"+old+"\n\nto\n\n"+new)
SideBarMoveCommand(sublime_plugin.WindowCommand).run([old], new)
raise
return
SideBarProject().refresh();
window_set_status(key, '')
def _view(self):
"""Return the view that should receive any actions."""
view = None
try:
view = self.view
except AttributeError:
try:
view = self.window.active_view()
except AttributeError:
raise AttributeError(
'ViCommandMixin must be used with a TextCommand or a WindowCommand class')
return view
def _window(self):
"""Return the view that should receive any actions."""
window = None
try:
window = self.window
except AttributeError:
try:
window = self.view.window()
except AttributeError:
raise AttributeError(
'ViCommandMixin must be used with a TextCommand or a WindowCommand class')
return window
def on_load_async(self, view):
if view and view.file_name() and not view.settings().get('open_with_edit'):
item = SideBarItem(os.path.join(sublime.packages_path(), 'User', 'SideBarEnhancements', 'Open With', 'Side Bar.sublime-menu'), False)
if item.exists():
settings = sublime.decode_value(item.contentUTF8())
selection = SideBarSelection([view.file_name()])
for item in settings[0]['children']:
try:
if item['open_automatically'] and selection.hasFilesWithExtension(item['args']['extensions']):
SideBarFilesOpenWithCommand(sublime_plugin.WindowCommand).run([view.file_name()], item['args']['application'], item['args']['extensions'])
view.window().run_command('close')
break
except:
pass
def run(self, paths = [], name = ""):
import functools
Window().run_command('hide_panel');
Window().show_input_panel("File Name:", name, functools.partial(SideBarNewFileCommand(sublime_plugin.WindowCommand).on_done, paths, True), None, None)
def run(self, paths = [], name = ""):
import functools
Window().run_command('hide_panel');
Window().show_input_panel("Folder Name:", name, functools.partial(SideBarNewDirectoryCommand(sublime_plugin.WindowCommand).on_done, paths, True), None, None)
def run(self):
SideBarPasteCommand2(sublime_plugin.WindowCommand).run(self.paths, self.in_parent, self.test, self.replace, self.key)
def run(self):
SideBarDeleteCommand(sublime_plugin.WindowCommand)._delete_threaded(self.paths)
def _view(self):
'''
Returns the view that should receive any actions.
'''
view = None
try:
view = self.view
except AttributeError:
try:
view = self.window.active_view()
except AttributeError:
raise AttributeError(
'ViCommandMixin must be used with a TextCommand or a WindowCommand class')
return view
def _window(self):
'''
Returns the view that should receive any actions.
'''
window = None
try:
window = self.window
except AttributeError:
try:
window = self.view.window()
except AttributeError:
raise AttributeError(
'ViCommandMixin must be used with a TextCommand or a WindowCommand class')
return window
def __init__(self, window):
sublime_plugin.WindowCommand.__init__(self, window)