Bug fix to select examples in any directory level (Issue: https://github.com/gepd/Deviot/issues/82)
@@ -409,65 +409,21 @@ class QuickMenu(PreferencesBridge):
return
library_path = self.quick_list[selected][1]
- examples_path = os.path.join(library_path, 'examples', '*')
- self.quick_list = [[_("select_example").upper()]]
-
- for files in glob(examples_path):
- caption = os.path.basename(files)
- self.quick_list.append([caption, files])
-
- quick_panel(self.quick_list, self.callback_example)
-
- def callback_example(self, selected):
- """Open Example
-
- Search the files .ino and .pde in the path of the example selected
- and open it in a new window
-
- Arguments:
- selected {int} -- user index selection
- """
- if(selected <= 0):
- return
-
- example_path = self.quick_list[selected][1]
-
- has_file = True
- temp_list = []
- check_path = os.path.join(example_path, '*')
-
- for path in glob(check_path):
- caption = os.path.basename(path)
- temp_list.append([caption, path])
+ if('examples' not in library_path):
+ library_path = os.path.join(library_path, 'examples')
- if(not os.path.isfile(path)):
- has_file = False
-
- if(not has_file):
- self.quick_list = temp_list
- self.quick_list.insert(0, [_("select_example").upper()])
- quick_panel(self.quick_list, self.callback_deeper)
+ if(self.open_file(library_path)):
return
- self.open_file(example_path)
-
-
- def callback_deeper(self, selected):
- """Examples
-
- If an example folder has more folder (instead of .ino .pde files)
- this method will be call to show the extra examples
-
- Arguments:
- selected {int} -- user index selection
- """
- if(selected <= 0):
- return
+ library_path = os.path.join(library_path, '*')
+ self.quick_list = [[_("select_example").upper()]]
- example_path = self.quick_list[selected][1]
+ for files in glob(library_path):
+ caption = os.path.basename(files)
+ self.quick_list.append([caption, files])
- self.open_file(example_path)
+ quick_panel(self.quick_list, self.callback_library)
def open_file(self, sketch_path):
"""Open sketch
@@ -477,15 +433,18 @@ class QuickMenu(PreferencesBridge):
Arguments:
sketch_path {str} -- path (file/folder) where to search
+ Returns:
+ [bool] -- true if it open file, false if not
"""
window = sublime.active_window()
if(sketch_path.endswith(('.ino', '.pde'))):
window.open_file(sketch_path)
+ return True
- files = os.path.join(sketch_path, '*')
- files = glob(files)
-
- for file in files:
+ for file in os.listdir(sketch_path):
if(file.endswith(('.ino', '.pde'))):
+ file = os.path.join(sketch_path, file)
window.open_file(file)
+ return True
+ return False
