generated from itdominator/Python-With-Gtk-Template
Added open file multi select; focus active file's dir on open file dialog
This commit is contained in:
parent
d886ef37d4
commit
ad40f33988
@ -129,11 +129,12 @@ class EditorNotebook(EditorControllerMixin, Gtk.Notebook):
|
|||||||
|
|
||||||
self.create_view(None, None, gfile, line)
|
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
|
if not self.is_editor_focused: # TODO: Find way to converge this
|
||||||
return
|
return
|
||||||
|
|
||||||
self.open_file(gfile)
|
for gfile in gfiles:
|
||||||
|
self.open_file(gfile)
|
||||||
|
|
||||||
def _keyboard_scale_up_text(self):
|
def _keyboard_scale_up_text(self):
|
||||||
self.action_controller("scale_up_text")
|
self.action_controller("scale_up_text")
|
||||||
|
@ -51,7 +51,10 @@ class KeyInputController:
|
|||||||
self._create_view()
|
self._create_view()
|
||||||
if keyname == "o":
|
if keyname == "o":
|
||||||
page_num, container, source_view = self.get_active_view()
|
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
|
return True
|
||||||
|
|
||||||
|
@ -41,24 +41,45 @@ class OpenFileButton(Gtk.Button):
|
|||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
def _open_files(self, widget = None, eve = None):
|
def _open_files(self, widget = None, eve = None, gfile = None):
|
||||||
chooser = Gtk.FileChooserDialog("Open File...", 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.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:
|
try:
|
||||||
folder = widget.get_current_file().get_parent()
|
folder = widget.get_current_file().get_parent() if not start_dir else start_dir
|
||||||
chooser.set_current_folder( folder.get_uri() )
|
chooser.set_current_folder( folder.get_path() )
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
...
|
...
|
||||||
|
|
||||||
response = chooser.run()
|
response = chooser.run()
|
||||||
if response == Gtk.ResponseType.OK:
|
if not response == Gtk.ResponseType.OK:
|
||||||
filename = chooser.get_filename()
|
chooser.destroy()
|
||||||
if filename:
|
return _gfiles
|
||||||
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,))
|
|
||||||
|
|
||||||
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
|
Loading…
Reference in New Issue
Block a user