forked from wl879/SublimeOnSave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (66 loc) · 2.51 KB
/
main.py
File metadata and controls
79 lines (66 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# encoding: UTF-8
import re, fnmatch
import sublime, sublime_plugin
from os import path
from . import st_tools
from .program import on_save
class OnSaveCommand(sublime_plugin.EventListener):
def on_load(self, view):
pass
# file = view.file_name()
# cmds = on_save.watch( file )
# if cmds:
# for cmd in cmds:
# if cmd.get('usebuild'):
# view.settings().set('usebuild', True)
# return
def on_post_save(self, view):
file = view.file_name()
if path.basename(file) == on_save.CONFIG_NAME:
on_save.clear()
else:
cmds = on_save.watch( file )
if cmds:
on_save.run( cmds )
# 检查 关闭输出窗口
def on_pre_close(self, view):
name = view.name()
if name and name.find('OnSave Console [') == 0:
info = st_tools.view.info( view )
if info:
win = info['window']
views = win.views_in_group( info['group'] )
if not views or len(views) == 1:
sublime.set_timeout(lambda: st_tools.group.delete(info['group'], win), 100)
# 创建 OnSave 配置文件
class NewOnSaveConfigCommand(sublime_plugin.WindowCommand):
def run(self, paths):
setting = sublime.load_settings('Default.sublime-settings')
dir_path = paths[0]
if path.isfile(paths[0]):
dir_path = path.dirname(dir_path)
if path.isfile( path.join(dir_path, on_save.CONFIG_NAME) ):
view = self.window.open_file( path.join(dir_path, on_save.CONFIG_NAME) )
else:
view = st_tools.view.create( on_save.CONFIG_NAME, win = self.window )
st_tools.view.content( view, '\n'.join( setting.get('config_template') or [] ) )
if view:
st_tools.view.setting(view, syntax = "Packages/YAML/YAML.tmLanguage", default_dir=dir_path)
self.window.focus_view(view)
def is_visible(self, paths):
return len(paths) == 1
class OnSaveBuildCommand(sublime_plugin.WindowCommand):
def run(self, paths):
file = ""
if len(paths):
file = paths[0]
else:
file = self.window.active_view().file_name()
print(file)
cmds = on_save.watch( file, True )
if cmds:
on_save.run( cmds )
else:
self.window.run_command("build")
def is_visible(self, paths):
return len(paths) == 1