diff --git a/src/core/widgets/base/notebook/editor_notebook.py b/src/core/widgets/base/notebook/editor_notebook.py index afc3d95..f7b696e 100644 --- a/src/core/widgets/base/notebook/editor_notebook.py +++ b/src/core/widgets/base/notebook/editor_notebook.py @@ -129,11 +129,12 @@ class EditorNotebook(EditorControllerMixin, Gtk.Notebook): self.create_view(None, None, gfile, line) - def _keyboard_open_file(self, gfile): + def _keyboard_open_file(self, gfiles = []): if not self.is_editor_focused: # TODO: Find way to converge this return - self.open_file(gfile) + for gfile in gfiles: + self.open_file(gfile) def _keyboard_scale_up_text(self): self.action_controller("scale_up_text") diff --git a/src/core/widgets/base/notebook/key_input_controller.py b/src/core/widgets/base/notebook/key_input_controller.py index 21f21be..189e38b 100644 --- a/src/core/widgets/base/notebook/key_input_controller.py +++ b/src/core/widgets/base/notebook/key_input_controller.py @@ -51,7 +51,10 @@ class KeyInputController: self._create_view() if keyname == "o": page_num, container, source_view = self.get_active_view() - event_system.emit("open_files", (source_view,)) + file = source_view.get_current_file() + _gfiles = event_system.emit_and_await("open_files", (source_view, None, file if file else None)) + + event_system.emit("keyboard_open_file", (_gfiles,)) return True diff --git a/src/core/widgets/controls/open_file_button.py b/src/core/widgets/controls/open_file_button.py index 3b98d65..6a1fdad 100644 --- a/src/core/widgets/controls/open_file_button.py +++ b/src/core/widgets/controls/open_file_button.py @@ -41,24 +41,45 @@ class OpenFileButton(Gtk.Button): def _load_widgets(self): ... - def _open_files(self, widget = None, eve = None): - chooser = Gtk.FileChooserDialog("Open File...", None, + def _open_files(self, widget = None, eve = None, gfile = None): + start_dir = None + _gfiles = [] + + if gfile and gfile.query_exists(): + start_dir = gfile.get_parent() + + chooser = Gtk.FileChooserDialog("Open File(s)...", None, Gtk.FileChooserAction.OPEN, - (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, - Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) - + ( + Gtk.STOCK_CANCEL, + Gtk.ResponseType.CANCEL, + Gtk.STOCK_OPEN, + Gtk.ResponseType.OK + ) + ) + + chooser.set_select_multiple(True) + try: - folder = widget.get_current_file().get_parent() - chooser.set_current_folder( folder.get_uri() ) + folder = widget.get_current_file().get_parent() if not start_dir else start_dir + chooser.set_current_folder( folder.get_path() ) except Exception as e: ... response = chooser.run() - if response == Gtk.ResponseType.OK: - filename = chooser.get_filename() - if filename: - path = filename if os.path.isabs(filename) else os.path.abspath(filename) - _gfile = Gio.File.new_for_path(path) - event_system.emit("keyboard_open_file", (_gfile,)) + if not response == Gtk.ResponseType.OK: + chooser.destroy() + return _gfiles - chooser.destroy() \ No newline at end of file + filenames = chooser.get_filenames() + if not filenames: + chooser.destroy() + return _gfiles + + for file in filenames: + path = file if os.path.isabs(file) else os.path.abspath(file) + _gfiles.append( Gio.File.new_for_path(path) ) + + chooser.destroy() + + return _gfiles \ No newline at end of file