Implement chdir
This commit is contained in:
parent
981beffcce
commit
789f86de25
1 changed files with 14 additions and 7 deletions
|
@ -16,6 +16,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
file_info_label: Gtk.Label
|
file_info_label: Gtk.Label
|
||||||
stack: Gtk.Stack
|
stack: Gtk.Stack
|
||||||
list_view: Gtk.ListView
|
list_view: Gtk.ListView
|
||||||
|
list_store: Gtk.StringList
|
||||||
|
|
||||||
def __init__(self, *args: Any, **kwargs: Any):
|
def __init__(self, *args: Any, **kwargs: Any):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -69,9 +70,9 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
main_box.append(grid)
|
main_box.append(grid)
|
||||||
|
|
||||||
# Create list store and view
|
# Create list store and view
|
||||||
list_store = Gtk.StringList()
|
self.list_store = Gtk.StringList()
|
||||||
self.list_view = Gtk.ListView()
|
self.list_view = Gtk.ListView()
|
||||||
selection_model = Gtk.SingleSelection.new(list_store)
|
selection_model = Gtk.SingleSelection.new(self.list_store)
|
||||||
selection_model.connect("selection-changed", self._on_selection_changed)
|
selection_model.connect("selection-changed", self._on_selection_changed)
|
||||||
self.list_view.set_model(selection_model)
|
self.list_view.set_model(selection_model)
|
||||||
self.list_view.set_vexpand(True)
|
self.list_view.set_vexpand(True)
|
||||||
|
@ -81,6 +82,12 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
if selected_item:
|
if selected_item:
|
||||||
string_obj = cast(Gtk.StringObject, selected_item)
|
string_obj = cast(Gtk.StringObject, selected_item)
|
||||||
string = string_obj.get_string()
|
string = string_obj.get_string()
|
||||||
|
|
||||||
|
if string.endswith("/"):
|
||||||
|
os.chdir(string)
|
||||||
|
self._populate_file_list()
|
||||||
|
return
|
||||||
|
|
||||||
print("activated", string)
|
print("activated", string)
|
||||||
|
|
||||||
self.stack.set_visible_child_name("overlay")
|
self.stack.set_visible_child_name("overlay")
|
||||||
|
@ -94,7 +101,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
self.list_view.set_factory(factory)
|
self.list_view.set_factory(factory)
|
||||||
|
|
||||||
# Populate the list store
|
# Populate the list store
|
||||||
self._populate_file_list(list_store)
|
self._populate_file_list()
|
||||||
|
|
||||||
# Add list view to a scrolled window
|
# Add list view to a scrolled window
|
||||||
scrolled = Gtk.ScrolledWindow()
|
scrolled = Gtk.ScrolledWindow()
|
||||||
|
@ -141,7 +148,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _populate_file_list(self, list_store: Gtk.StringList) -> None:
|
def _populate_file_list(self) -> None:
|
||||||
# TODO: Implement proper version sort (strverscmp equivalent)
|
# TODO: Implement proper version sort (strverscmp equivalent)
|
||||||
|
|
||||||
directories: list[str] = ["../"]
|
directories: list[str] = ["../"]
|
||||||
|
@ -158,11 +165,11 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
directories.sort(key=lambda x: x.lower())
|
directories.sort(key=lambda x: x.lower())
|
||||||
files.sort(key=lambda x: x.lower())
|
files.sort(key=lambda x: x.lower())
|
||||||
|
|
||||||
while list_store.get_n_items():
|
while self.list_store.get_n_items():
|
||||||
list_store.remove(0)
|
self.list_store.remove(0)
|
||||||
|
|
||||||
for name in directories + files:
|
for name in directories + files:
|
||||||
list_store.append(name)
|
self.list_store.append(name)
|
||||||
|
|
||||||
all = directories + files
|
all = directories + files
|
||||||
self.file_info_label.set_text(all[0] if all else "")
|
self.file_info_label.set_text(all[0] if all else "")
|
||||||
|
|
Loading…
Reference in a new issue