Skip to content

Commit

Permalink
🐛 quick panels are async
Browse files Browse the repository at this point in the history
  • Loading branch information
runxel committed Jun 6, 2019
1 parent 2dc5856 commit ebf52e6
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions GDL.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class HsfBuildCommand(sublime_plugin.WindowCommand):

def run(self, *args, **kwargs):
self.os = check_system()
view = self.window.active_view()
if view.settings().get("auto_save", True):
self.view = self.window.active_view()
if self.view.settings().get("auto_save", True):
save_all_files()

settings = sublime.load_settings(PACKAGE_SETTINGS)
Expand All @@ -70,12 +70,18 @@ def run(self, *args, **kwargs):
if len(folders) == 1:
self.multipleFolders = False
self.project_folder = folders[0]
self.on_done_proj() # go on here
else:
self.multipleFolders = True
self.pick_project_folder(folders)


def on_done_proj(self):
# this needs to be in its own function, because
# the sublime text quick panel works asynchronous
self.find_gsm()
self.cmdargs = get_project_data(view, 'to-hsf')

def on_done_file(self):
self.cmdargs = get_project_data(self.view, 'to-hsf')
self.run_hsf()

def pick_project_folder(self, folders):
Expand All @@ -95,6 +101,7 @@ def select_project(self, select):
if select < 0: # will be -1 if panel was cancelled
return
self.project_folder = folders[select]
self.on_done_proj() # go on here

def find_gsm(self):
self.files = []
Expand All @@ -108,14 +115,16 @@ def find_gsm(self):
sublime.error_message("GDL build error: No GSM found.")

if len(self.files) > 1:
self.show_quick_panel(self.files, self.select_project)
self.show_quick_panel(self.files, self.select_gsm)
else:
self.file_to_convert = self.files[0]
self.on_done_file() # go on here

def select_gsm(self, select):
if select < 0:
return
self.file_to_convert = self.files[select]
self.on_done_file() # go on here

# Sublime Text 3 requires a short timeout between quick panels
def show_quick_panel(self, options, done):
Expand All @@ -133,8 +142,8 @@ class LibpartBuildCommand(sublime_plugin.WindowCommand):

def run(self, *args, **kwargs):
self.os = check_system()
view = self.window.active_view()
if view.settings().get("auto_save", True):
self.view = self.window.active_view()
if self.view.settings().get("auto_save", True):
save_all_files()

settings = sublime.load_settings(PACKAGE_SETTINGS)
Expand All @@ -147,13 +156,18 @@ def run(self, *args, **kwargs):
if len(folders) == 1:
self.multipleFolders = False
self.project_folder = folders[0]
self.on_done_proj() # go on here
else:
self.multipleFolders = True
self.pick_project_folder(folders)

def on_done_proj(self):
# own function because quick panel is async
self.find_hsf()

def on_done_file(self):
self.gsm_name = self.folder_to_convert + ".gsm"
self.cmdargs = get_project_data(view, 'to-gsm')
self.cmdargs = get_project_data(self.view, 'to-gsm')
self.run_libpart()

def pick_project_folder(self, folders):
Expand All @@ -173,6 +187,7 @@ def select_project(self, select):
if select < 0: # will be -1 if panel was cancelled
return
self.project_folder = folders[select]
self.on_done_proj() # go on here

def find_hsf(self):
# self.folders = []
Expand All @@ -189,12 +204,14 @@ def find_hsf(self):
self.show_quick_panel(self.folders, self.select_hsf)
else:
self.folder_to_convert = self.project_folder + "\\" + self.folders[0]
self.on_done_file() # go on here

def select_hsf(self, select):
folders = self.folders
if select < 0: # will be -1 if panel was cancelled
return
self.folder_to_convert = self.project_folder + "\\" + folders[select]
self.on_done_file() # go on here

# Sublime Text 3 requires a short timeout between quick panels
def show_quick_panel(self, options, done):
Expand Down

0 comments on commit ebf52e6

Please sign in to comment.