Simplify directory navigation
This commit is contained in:
parent
b0375c863e
commit
c54f183b0a
2 changed files with 10 additions and 24 deletions
lazy_player
|
@ -266,13 +266,10 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
def _navigate_to(self, path: Path):
|
def _navigate_to(self, path: Path):
|
||||||
# Check if we have history and if target is where we came from
|
# Check if we have history and if target is where we came from
|
||||||
if self.directory_history:
|
if self.directory_history:
|
||||||
print(path, "vs", self.directory_history[-1])
|
|
||||||
if path == self.directory_history[-1]:
|
if path == self.directory_history[-1]:
|
||||||
print("navigate back")
|
|
||||||
self._navigate_back()
|
self._navigate_back()
|
||||||
return
|
return
|
||||||
|
|
||||||
print("navigate to", path)
|
|
||||||
# Regular directory navigation
|
# Regular directory navigation
|
||||||
self.directory_history.append(Path(os.getcwd()))
|
self.directory_history.append(Path(os.getcwd()))
|
||||||
os.chdir(path)
|
os.chdir(path)
|
||||||
|
@ -535,20 +532,21 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||||
self.last_position_save = frame_time
|
self.last_position_save = frame_time
|
||||||
|
|
||||||
def _populate_file_list(self) -> None:
|
def _populate_file_list(self) -> None:
|
||||||
# TODO: Implement proper version sort (strverscmp equivalent)
|
|
||||||
|
|
||||||
items: list[FileItem] = []
|
items: list[FileItem] = []
|
||||||
|
|
||||||
# Add parent directory
|
# Add parent directory
|
||||||
items.append(FileItem("..", FileType.DIRECTORY, Path("..").resolve()))
|
items.append(FileItem("..", FileType.DIRECTORY, Path("..").resolve()))
|
||||||
|
|
||||||
with os.scandir(".") as it:
|
for entry in os.scandir():
|
||||||
for entry in it:
|
if entry.name.startswith("."):
|
||||||
if not entry.name.startswith("."):
|
continue
|
||||||
try:
|
|
||||||
items.append(FileItem.from_path(entry.name))
|
path = Path(entry.name)
|
||||||
except ValueError:
|
|
||||||
continue # Skip unsupported file types
|
if path.is_dir():
|
||||||
|
items.append(FileItem(path.name, FileType.DIRECTORY, path.resolve()))
|
||||||
|
elif path.suffix in (".mkv", ".mp4", ".avi"):
|
||||||
|
items.append(FileItem(path.name, FileType.VIDEO, path.resolve()))
|
||||||
|
|
||||||
# Sort directories first, then files, both alphabetically
|
# Sort directories first, then files, both alphabetically
|
||||||
items.sort(key=lambda x: (x.file_type != FileType.DIRECTORY, x.name.lower()))
|
items.sort(key=lambda x: (x.file_type != FileType.DIRECTORY, x.name.lower()))
|
||||||
|
|
|
@ -31,18 +31,6 @@ class FileItem(GObject.Object):
|
||||||
self.file_type = file_type
|
self.file_type = file_type
|
||||||
self.full_path = full_path
|
self.full_path = full_path
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def from_path(path: str | Path) -> FileItem:
|
|
||||||
full_path = Path(path).resolve()
|
|
||||||
|
|
||||||
if full_path.is_dir():
|
|
||||||
return FileItem(full_path.name, FileType.DIRECTORY, full_path)
|
|
||||||
|
|
||||||
if full_path.suffix in (".mkv", ".mp4", ".avi"):
|
|
||||||
return FileItem(full_path.name, FileType.VIDEO, full_path)
|
|
||||||
|
|
||||||
raise ValueError(f"Unsupported file type: {full_path}")
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def load_attribute(self, name: str, dfl: str) -> str: ...
|
def load_attribute(self, name: str, dfl: str) -> str: ...
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue