diff options
| -rw-r--r-- | src/vtt_publish/tui.py | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/vtt_publish/tui.py b/src/vtt_publish/tui.py index 4d6bf4a..1b86a37 100644 --- a/src/vtt_publish/tui.py +++ b/src/vtt_publish/tui.py @@ -64,12 +64,10 @@ else: CONFIG = DEFAULT_CONFIG -# --- MOCK DATA GENERATOR (Creates fake files for testing) --- def create_mock_files(): root = Path("mock_campaign") root.mkdir(exist_ok=True) - # Create a structure matching your mockup dirs = [ "artwork/scenes/4_belcorras_retreat/lasdas_lament", "artwork/scenes/4_belcorras_retreat/affinity", @@ -95,15 +93,12 @@ class CampaignTree(DirectoryTree): # Map Vim keys to standard Tree actions Binding("j", "cursor_down", "Down", show=False), Binding("k", "cursor_up", "Up", show=False), - Binding("h", "cursor_left", "Collapse / Parent", show=True), - Binding("l", "cursor_right", "Expand / Child", show=True), ] class FileTable(DataTable): """A DataTable with custom file selection actions.""" - # Define our constants here for easy access ICON_CHECKED = "✔" ICON_UNCHECKED = "✘" @@ -112,11 +107,12 @@ class FileTable(DataTable): Binding("a", "toggle_all", "Select All"), Binding("j", "cursor_down", "Down", show=False), Binding("k", "cursor_up", "Up", show=False), + Binding("l", "toggle_synced", "Hide/Show Synced"), # Category Shortcuts Binding("s", "set_category('Scenes')", "Set: Scenes"), Binding("t", "set_category('Tokens')", "Set: Tokens"), Binding("m", "set_category('Maps')", "Set: Maps"), - Binding("h", "set_category('Handouts')", "Set: Handouts"), # 'h' is safe here! + Binding("h", "set_category('Handouts')", "Set: Handouts"), ] def action_toggle_select(self): @@ -125,7 +121,6 @@ class FileTable(DataTable): current_val = str(self.get_cell(row_key, "Select")) new_val = self.ICON_CHECKED if current_val == self.ICON_UNCHECKED else self.ICON_UNCHECKED self.update_cell(row_key, "Select", new_val) - # We can bubble a log message event up if we want, or just print for now except Exception: pass @@ -140,6 +135,19 @@ class FileTable(DataTable): for row_key in self.rows: self.update_cell(row_key, "Select", target_val) + def action_toggle_synced(self): + """ + Toggle visibiity of [OK] files. + """ + app = self.app + app.show_synced_files = not app.show_synced_files + + state = "Showing" if app.show_synced_files else "Hiding" + app.log_message(f"{state} synced files.") + + if hasattr(app, "current_scan_path") and app.current_scan_path: + app.populate_table(app.current_scan_path) + def action_set_category(self, category_name: str): try: row_key, _ = self.coordinate_to_cell_key(self.cursor_coordinate) @@ -235,7 +243,6 @@ class PublisherApp(App): } """ - # KEY BINDINGS BINDINGS = [ ("tab", "toggle_focus", "Switch Pane"), ("p", "publish", "Publish Selected"), @@ -301,12 +308,12 @@ class PublisherApp(App): version_str = self.get_git_version() self.title = f"FVTT PUBLISH {version_str}" + self.show_synced_files = True self.history = self.load_history() table = self.query_one(FileTable) table.cursor_type = "row" - # DEFINING EXPLICIT KEYS HERE IS THE MAGIC SAUCE table.add_column("Select", key="Select") table.add_column("Status", key="Status") table.add_column("Category", key="Category") @@ -327,12 +334,10 @@ class PublisherApp(App): """Guess category based on path keywords.""" path_str = str(path).lower() - # Iterate through keywords in config for keyword, category in CONFIG.get("category_keywords", {}).items(): if keyword in path_str: return category - # Default fallback return "Misc" # --- ACTIONS & LOGIC --- @@ -385,6 +390,9 @@ class PublisherApp(App): else: status = "[OK]" + if status == "[OK]" and not self.show_synced_files: + continue + try: display_location = str(path.parent.relative_to(root)) except ValueError: @@ -416,9 +424,7 @@ class PublisherApp(App): table = self.query_one(FileTable) selected_rows = [] - # 1. Identify what to publish for row_key in table.rows: - # Check the "Select" column (Column 0) if table.get_cell(row_key, "Select") == table.ICON_CHECKED: selected_rows.append(row_key) @@ -428,16 +434,12 @@ class PublisherApp(App): self.log_message(f"Starting publish for {len(selected_rows)} files...") - # 2. Process each file for row_key in selected_rows: - # Recover the full path from the key we saved earlier full_path = Path(row_key.value) filename = full_path.name - # Get the category specific to this file category_display = table.get_cell(row_key, "Category") - # Map "Scenes" -> "scenes", etc. remote_folder = CONFIG["category_map"].get(category_display, "misc") destination = ( @@ -447,11 +449,9 @@ class PublisherApp(App): cmd = ["rsync", "-avz", str(full_path), destination] - # 4. Execute try: self.log_message(f"Run: {' '.join(cmd)}") # Debug print - # Run actual command result = subprocess.run( cmd, capture_output=True, @@ -459,7 +459,6 @@ class PublisherApp(App): check=True ) - # 5. Update UI on success self.log_message(f"SUCCESS: {filename}") table.update_cell(row_key, "Status", "[DONE]") table.update_cell(row_key, "Select", table.ICON_UNCHECKED) |
