From c54f183b0a70efa29f3fa9e4c915a1f92a3dad36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Hamal=20Dvo=C5=99=C3=A1k?= <mordae@anilinux.org>
Date: Sun, 9 Mar 2025 12:02:00 +0100
Subject: [PATCH] Simplify directory navigation

---
 lazy_player/__init__.py   | 22 ++++++++++------------
 lazy_player/file_model.py | 12 ------------
 2 files changed, 10 insertions(+), 24 deletions(-)

diff --git a/lazy_player/__init__.py b/lazy_player/__init__.py
index 5b1b04e..433fe3b 100644
--- a/lazy_player/__init__.py
+++ b/lazy_player/__init__.py
@@ -266,13 +266,10 @@ class MainWindow(Gtk.ApplicationWindow):
     def _navigate_to(self, path: Path):
         # Check if we have history and if target is where we came from
         if self.directory_history:
-            print(path, "vs", self.directory_history[-1])
             if path == self.directory_history[-1]:
-                print("navigate back")
                 self._navigate_back()
                 return
 
-        print("navigate to", path)
         # Regular directory navigation
         self.directory_history.append(Path(os.getcwd()))
         os.chdir(path)
@@ -535,20 +532,21 @@ class MainWindow(Gtk.ApplicationWindow):
             self.last_position_save = frame_time
 
     def _populate_file_list(self) -> None:
-        # TODO: Implement proper version sort (strverscmp equivalent)
-
         items: list[FileItem] = []
 
         # Add parent directory
         items.append(FileItem("..", FileType.DIRECTORY, Path("..").resolve()))
 
-        with os.scandir(".") as it:
-            for entry in it:
-                if not entry.name.startswith("."):
-                    try:
-                        items.append(FileItem.from_path(entry.name))
-                    except ValueError:
-                        continue  # Skip unsupported file types
+        for entry in os.scandir():
+            if entry.name.startswith("."):
+                continue
+
+            path = Path(entry.name)
+
+            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
         items.sort(key=lambda x: (x.file_type != FileType.DIRECTORY, x.name.lower()))
diff --git a/lazy_player/file_model.py b/lazy_player/file_model.py
index 833b4cd..ed1ba41 100644
--- a/lazy_player/file_model.py
+++ b/lazy_player/file_model.py
@@ -31,18 +31,6 @@ class FileItem(GObject.Object):
         self.file_type = file_type
         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
     def load_attribute(self, name: str, dfl: str) -> str: ...