Add history stack

This commit is contained in:
Jan Hamal Dvořák 2025-03-09 10:58:01 +01:00
parent 2472f80111
commit ba24b8b5b7

View file

@ -33,6 +33,9 @@ class MainWindow(Gtk.ApplicationWindow):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
# Directory history stack
self.directory_history: list[str] = []
# For overlay text timeout
self.overlay_hide_time = 0.0
self.last_position_save = 0.0
@ -148,6 +151,8 @@ class MainWindow(Gtk.ApplicationWindow):
file_item = cast(FileItem, selected_item)
if file_item.file_type == FileType.DIRECTORY:
# Save current directory before changing
self.directory_history.append(os.getcwd())
os.chdir(file_item.full_path)
self._populate_file_list()
return
@ -369,6 +374,13 @@ class MainWindow(Gtk.ApplicationWindow):
self._toggle_watched_status()
return True
elif keyval == Gdk.keyval_from_name("BackSpace"):
if self.directory_history:
prev_dir = self.directory_history.pop()
os.chdir(prev_dir)
self._populate_file_list()
return True
return False
def _on_key_pressed(