Skip to content

Commit 6f82949

Browse files
committed
add builds, fix bugs, add key shortcuts and status
1 parent 1096a78 commit 6f82949

9 files changed

+284
-14
lines changed

Context.sublime-menu

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[
2-
{ "id": "flow-set-project-window-space", "caption": "-" },
3-
{ "id": "flow-set-project-window", "command": "flow_set_project_file_window", "caption": "Set flow project ( this window )" },
4-
// { "id": "flow-set-project-global", "command": "flow_set_project_file_global", "caption": "Set flow project ( all windows )" },
2+
{ "id": "flow-set-project-space", "caption": "-" },
3+
{ "id": "flow-show-status", "command": "flow_show_status", "caption": "flow status" },
4+
{ "id": "flow-set-project-file", "command": "flow_set_project_file", "caption": "Set as current flow project" },
5+
{ "id": "flow-set-target-build", "command": "flow_set_target_build", "caption": "Set build target" }
56
]

Default.sublime-keymap

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[
2+
{
3+
"keys": ["ctrl+shift+0"],
4+
"command": "flow_show_status",
5+
"context":
6+
[
7+
{
8+
"key": "selector",
9+
"operator": "equal",
10+
"operand": "source.haxe,source.flow"
11+
}
12+
]
13+
},
14+
{
15+
"keys": ["ctrl+shift+9"],
16+
"command": "flow_set_project_file",
17+
"context":
18+
[
19+
{
20+
"key": "selector",
21+
"operator": "equal",
22+
"operand": "source.flow"
23+
}
24+
]
25+
},
26+
{
27+
"keys": ["ctrl+shift+8"],
28+
"command": "flow_set_target_build",
29+
"context":
30+
[
31+
{
32+
"key": "selector",
33+
"operator": "equal",
34+
"operand": "source.flow,source.haxe"
35+
}
36+
]
37+
}
38+
39+
]

commands/__init__.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
__version__ = "1.0.0"
22
__version_info__ = (1, 0, 0)
33

4-
from .flow_project_set import FlowSetProjectFileWindow
4+
from .flow_set_project_file import FlowSetProjectFile
5+
from .flow_set_target_build import FlowSetTargetBuild
6+
from .flow_show_status import FlowShowStatus
7+
from .flow_run_build import FlowRunBuild, FlowDoBuild
58

69
print("Flow : load commands")
710

811
__all__ = [
9-
'FlowSetProjectFileWindow'
12+
'FlowSetProjectFile',
13+
'FlowSetTargetBuild',
14+
'FlowRunBuild',
15+
'FlowDoBuild',
16+
'FlowShowStatus'
1017
]

commands/flow_run_build.py

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import sublime, sublime_plugin
2+
import sys, os, subprocess
3+
4+
from ..flow import FlowProject, panel
5+
6+
import Default
7+
stexec = getattr( Default , "exec" )
8+
ExecCommand = stexec.ExecCommand
9+
AsyncProcess = stexec.AsyncProcess
10+
11+
12+
print('flow / load run build')
13+
14+
class FlowRunBuild( sublime_plugin.WindowCommand ):
15+
def run(self):
16+
view = self.window.active_view()
17+
18+
if not FlowProject.flow.flow_file:
19+
self.window.run_command('flow_show_status')
20+
print("[flow] build : no flow file")
21+
return
22+
23+
_cmd = "run"
24+
25+
flow_cmd = [
26+
"haxelib", "run", "flow",
27+
_cmd, FlowProject.flow.target,
28+
"--project", FlowProject.flow.flow_file
29+
]
30+
31+
32+
if FlowProject.flow.build_debug:
33+
flow_cmd.append('--debug')
34+
35+
if FlowProject.flow.build_verbose:
36+
flow_cmd.append('--log')
37+
flow_cmd.append('3')
38+
39+
print("[flow] build " + " ".join(flow_cmd))
40+
41+
self.window.run_command("flow_do_build", {
42+
"cmd": flow_cmd
43+
})
44+
45+
class FlowDoBuild( ExecCommand ):
46+
47+
def run( self, cmd = [], shell_cmd = None, file_regex = "", line_regex = "", working_dir = "",
48+
encoding = None, env = {}, quiet = False, kill = False, **kwargs):
49+
50+
if kill:
51+
if self.proc:
52+
self.proc.kill()
53+
self.proc = None
54+
self.append_data(None, "[Cancelled]")
55+
return
56+
57+
if encoding is None:
58+
encoding = sys.getfilesystemencoding()
59+
60+
self.output_view = self.window.get_output_panel("exec")
61+
self.debug_text = " ".join(cmd)
62+
self.encoding = encoding
63+
self.quiet = quiet
64+
self.proc = None
65+
66+
if working_dir != "":
67+
os.chdir(working_dir)
68+
69+
if not quiet:
70+
print( "Running " + " ".join(cmd) )
71+
72+
sublime.status_message("Running build...")
73+
self.show_output_panel()
74+
75+
try:
76+
self.proc = AsyncProcess( cmd, None, os.environ.copy(), self, **kwargs)
77+
except OSError as e:
78+
print(e)
79+
80+
def show_output_panel(self):
81+
show_panel_on_build = sublime.load_settings("Preferences.sublime-settings").get("show_panel_on_build", True)
82+
if show_panel_on_build:
83+
self.window.run_command("show_panel", {"panel": "output.exec"})
84+
85+
def finish(self, *args, **kwargs):
86+
87+
super(FlowDoBuild, self).finish(*args, **kwargs)
88+
output = self.output_view.substr(sublime.Region(0, self.output_view.size()))
89+
print(output)

commands/flow_project_set.py commands/flow_set_project_file.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
print('flow / load set project file')
66

7-
class FlowSetProjectFileWindow( sublime_plugin.WindowCommand ):
7+
class FlowSetProjectFile( sublime_plugin.WindowCommand ):
88
def run(self):
99
view = self.window.active_view()
1010
FlowProject.flow.set_flow_file( view.file_name() )
@@ -13,7 +13,7 @@ def is_visible(self):
1313
view = self.window.active_view()
1414
pt = view.sel()[0].b
1515
scope = view.scope_name(pt)
16-
print(scope)
16+
1717
if not "source.flow" in scope:
1818
return False
1919
else:

commands/flow_set_target_build.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sublime, sublime_plugin
2+
3+
from ..flow import FlowProject, panel
4+
5+
print('flow / load set build target')
6+
7+
class FlowSetTargetBuild( sublime_plugin.WindowCommand ):
8+
def run(self):
9+
view = self.window.active_view()
10+
panel(self.window, FlowProject.flow.get_targets(), self.on_target_select, 0, 1)
11+
12+
def on_target_select(self, index):
13+
if index > 0:
14+
FlowProject.flow.set_flow_target_by_index(index)
15+
16+
def is_visible(self):
17+
view = self.window.active_view()
18+
pt = view.sel()[0].b
19+
scope = view.scope_name(pt)
20+
if "source.flow" in scope:
21+
if FlowProject.flow.flow_file:
22+
return True
23+
24+
return False
25+
26+

commands/flow_show_status.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sublime, sublime_plugin
2+
3+
from ..flow import FlowProject, panel
4+
5+
print('flow / load show status')
6+
7+
class FlowShowStatus( sublime_plugin.WindowCommand ):
8+
def run(self):
9+
view = self.window.active_view()
10+
panel(self.window, FlowProject.flow.get_status(), self.on_select)
11+
12+
def on_select(self, index):
13+
14+
#the flow file
15+
if index == 0:
16+
if FlowProject.flow.flow_file:
17+
self.window.open_file(FlowProject.flow.flow_file)
18+
19+
#debug flag
20+
if index == 2:
21+
if FlowProject.flow.build_debug:
22+
FlowProject.flow.build_debug = False
23+
else:
24+
FlowProject.flow.build_debug = True
25+
26+
#verbose flag
27+
if index == 3:
28+
if FlowProject.flow.build_verbose:
29+
FlowProject.flow.build_verbose = False
30+
else:
31+
FlowProject.flow.build_verbose = True
32+
33+
def is_visible(self):
34+
view = self.window.active_view()
35+
pt = view.sel()[0].b
36+
scope = view.scope_name(pt)
37+
38+
if "source.flow" in scope or "source.haxe" in scope:
39+
return True
40+
else:
41+
return False

flow.py

+73-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
import sys, os, subprocess, codecs, shutil, json
3+
import sys, os, subprocess, shutil, json
44

55
import sublime, sublime_plugin
66
from .haxe_parse_completion_list import *
@@ -17,6 +17,8 @@ def run_process( args ):
1717
#startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
1818
return subprocess.Popen(args, stdout=subprocess.PIPE, startupinfo=startupinfo).communicate()[0]
1919

20+
def panel(_window, options, done, flags=0, sel_index=0, on_highlighted=None):
21+
sublime.set_timeout(lambda: _window.show_quick_panel(options, done, flags, sel_index, on_highlighted), 10)
2022

2123

2224
class FlowCompletionCallbackCommand( sublime_plugin.WindowCommand ):
@@ -34,9 +36,15 @@ def __init__(self):
3436

3537
self.flow_path = "flow"
3638
self.flow_file = ""
39+
self.target = ""
3740
self.info_json = None
3841
self.completion_data = None
3942

43+
self.system = self.get_system()
44+
self.target = self.system
45+
self.build_debug = False
46+
self.build_verbose = False
47+
4048
def __del__(self):
4149
print("[flow] __del__")
4250
FlowProject.flow = None
@@ -46,22 +54,26 @@ def __del__(self):
4654
del FlowProject.flow
4755
del self
4856

57+
4958
def set_flow_file( self, file_name ):
5059
print("[flow] set flow file to " + file_name)
5160
sublime.status_message('set flow file to ' + file_name)
61+
5262
self.flow_file = file_name
5363
self.refresh_info()
5464

65+
def set_flow_target_by_index( self, index ):
66+
_targets = self.get_targets()
67+
_target = _targets[index]
68+
self.target = _target[0].lower()
69+
print("[flow] set build target to " + self.target)
5570

5671
def refresh_info(self):
5772
print("[flow] refresh info/hxml on " + self.flow_file)
5873

5974
self.info_json_src = run_process([
60-
"haxelib",
61-
"run",
62-
"flow",
63-
"info",
64-
"--project", self.flow_file
75+
"haxelib", "run", "flow",
76+
"info", "--project", self.flow_file
6577
]).decode("utf-8");
6678

6779
if self.info_json_src:
@@ -190,7 +202,62 @@ def on_modified_async(self, view):
190202
fname = view.file_name()
191203
self.completion(view, fname)
192204

205+
def get_status(self):
206+
207+
_result = []
208+
209+
if self.flow_file:
210+
_result.append(['flow file', self.flow_file])
211+
else:
212+
_result.append(['no flow file', 'specify a flow file first'])
213+
return _result
214+
215+
if self.target:
216+
_result.append(['flow target', self.target])
217+
else:
218+
_result.append(['flow target', self.system])
219+
220+
_result.append(['Toggle debug build', "currently debug : " + str(self.build_debug).lower() ])
221+
_result.append(['Toggle verbose build', "currently verbose : " + str(self.build_verbose).lower() ])
222+
223+
return _result
224+
225+
def get_system(self):
226+
227+
_result = ""
228+
_system = sys.platform
229+
230+
if _system == "win32" or _system == "cygwin":
231+
_result = "windows"
232+
elif _system == "darwin":
233+
_result = "mac"
234+
else:
235+
_system = "linux"
236+
237+
return _result
238+
239+
240+
def get_targets(self):
241+
242+
_result = []
243+
244+
if not self.flow_file:
245+
return _result
246+
247+
_result.append(['Mac', 'desktop, native mac app'])
248+
_result.append(['Linux', 'desktop, native linux app'])
249+
_result.append(['Windows', 'desktop, native windows app'])
250+
_result.append(['Android', 'mobile, native android app'])
251+
_result.append(['iOS', 'mobile, native ios project'])
252+
_result.append(['Web', 'web, web based app'])
253+
254+
_invalid = self.info_json['targets_invalid']
255+
256+
_result[:] = [_item for _item in _result if not _item[0].lower() in _invalid ]
257+
258+
_result.insert(0, ['unavailable from ' + self.system, ", ".join(_invalid) ])
193259

260+
return _result
194261

195262
print("[flow] hello flow")
196263
from .commands import *

flow.sublime-build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"cmd": ["haxelib","run","flow","run"]
2+
"target": "flow_run_build"
33
}

0 commit comments

Comments
 (0)