Added open file multi select; focus active file's dir on open file dialog

This commit is contained in:
itdominator 2024-03-01 19:56:24 -06:00
parent d886ef37d4
commit ad40f33988
3 changed files with 42 additions and 17 deletions

View File

@ -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")

View File

@ -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

View File

@ -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()
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