Skip to content

Commit d89383d

Browse files
committed
Adding different types of tree view. and recursion depths.
Signed-off-by: Sam.Richards@taurich.org <Sam.Richards@taurich.org>
1 parent 95f6049 commit d89383d

4 files changed

Lines changed: 453 additions & 180 deletions

File tree

src/plugin/python_plugins/filesystem_browser/filesystem_browser.py

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ def __init__(self, connection):
152152
)
153153
self.scanned_attr.expose_in_ui_attrs_group("Filesystem Browser")
154154

155+
# New: Scanned directories list
156+
self.scanned_dirs_attr = self.add_attribute(
157+
"scanned_dirs",
158+
"[]",
159+
{"title": "scanned_dirs"},
160+
register_as_preference=False
161+
)
162+
self.scanned_dirs_attr.expose_in_ui_attrs_group("Filesystem Browser")
163+
164+
# New: Recursion limit attribute
165+
self.depth_limit_attr = self.add_attribute(
166+
"recursion_limit",
167+
6,
168+
{"title": "Recursion Limit"},
169+
register_as_preference=True
170+
)
171+
self.depth_limit_attr.expose_in_ui_attrs_group("Filesystem Browser")
172+
155173
# New: Filter attributes
156174
self.filter_time_attr = self.add_attribute(
157175
"filter_time",
@@ -367,6 +385,8 @@ def attribute_changed(self, attribute, role):
367385
self.filter_time_attr.set_value(attr_value)
368386
elif attr_name == "filter_version":
369387
self.filter_version_attr.set_value(attr_value)
388+
elif attr_name == "recursion_limit":
389+
self.depth_limit_attr.set_value(attr_value)
370390

371391
elif action == "add_pin":
372392
name = data.get("name")
@@ -388,6 +408,11 @@ def attribute_changed(self, attribute, role):
388408
elif attribute.uuid in (self.filter_time_attr.uuid, self.filter_version_attr.uuid):
389409
if role == AttributeRole.Value:
390410
self._on_filter_changed(attribute, role)
411+
elif attribute.uuid == self.depth_limit_attr.uuid:
412+
if role == AttributeRole.Value:
413+
# Recursion limit changed, re-scan
414+
current = self.current_path_attr.value()
415+
self.start_search(current)
391416

392417
def compute_completions(self, partial_path):
393418
"""Minimal logic to find subdirectories matching partial path."""
@@ -642,16 +667,20 @@ def _search_worker(self, start_path):
642667
from .scanner import FileScanner
643668

644669
# Config (could be loaded from prefs)
670+
max_depth = self.depth_limit_attr.value()
645671
config = {
646672
"extensions": list(self.extensions),
647673
"ignore_dirs": list(self.ignore_dirs),
674+
"max_depth": max_depth
648675
# "version_regex": r"_v(\d+)"
649676
}
650677

651678
self.scanner = FileScanner(config)
652679
with self.results_lock:
653680
self.current_scan_results = [] # Cache results for filtering
654681
self.pending_scan_results = []
682+
self.scanned_dirs_cache = []
683+
self.scanned_dirs_attr.set_value("[]")
655684
self.last_update = 0
656685

657686
def progress_callback(results, info):
@@ -660,6 +689,7 @@ def progress_callback(results, info):
660689
scanned = info.get("scanned", 0)
661690
phase = info.get("phase", "")
662691
progress = info.get("progress", 0)
692+
new_dirs = info.get("scanned_dirs", [])
663693

664694
# Update progress attribute
665695
# Because of the scanning algorithm, the progress is not linear, so we need to bias it
@@ -669,6 +699,15 @@ def progress_callback(results, info):
669699
self.scanned_attr.set_value(str(scanned))
670700
#self.scanProgress.set_value(str(progress))
671701

702+
# Accumulate scanned dirs
703+
if new_dirs:
704+
self.scanned_dirs_cache.extend(new_dirs)
705+
# Cap the list size if needed/desired? No requirement yet.
706+
# Update attribute periodically? Or always?
707+
# The callback is already throttled to 0.2s in scanner.
708+
import json
709+
self.scanned_dirs_attr.set_value(json.dumps(self.scanned_dirs_cache))
710+
672711
# Handle partial results
673712
if results and phase == "scanning":
674713
self.pending_scan_results.extend(results)
@@ -717,7 +756,19 @@ def _apply_filters_logic(self, results):
717756
filter_time = self.filter_time_attr.value() if hasattr(self, 'filter_time_attr') else "Any"
718757
filter_version = self.filter_version_attr.value() if hasattr(self, 'filter_version_attr') else "All Versions"
719758

720-
# 1. Apply Time Filter
759+
# Separate directories and files
760+
dirs = []
761+
files = []
762+
for r in results:
763+
if r.get("is_folder") or r.get("type") == "Folder":
764+
dirs.append(r)
765+
else:
766+
files.append(r)
767+
768+
# 1. Apply Time Filter (to files only?)
769+
# User wants to see directories "even if there isnt data in them".
770+
# So we probably shouldn't filter directories by time unless requested.
771+
# Let's Apply Time Filter ONLY to files for now.
721772
if filter_time != "Any":
722773
now = time.time()
723774
cutoff = 0
@@ -731,45 +782,43 @@ def _apply_filters_logic(self, results):
731782
cutoff = now - 30 * 86400
732783

733784
if cutoff > 0:
734-
results = [r for r in results if r.get("date", 0) >= cutoff]
785+
files = [r for r in files if r.get("date", 0) >= cutoff]
735786

736-
# 2. Apply Version Filter with Grouping
737-
# Group items by version_group
787+
# 2. Apply Version Filter with Grouping (Files only)
738788
grouped_results = {}
739-
for r in results:
789+
for r in files:
740790
grp = r.get("version_group")
741791
if grp:
742792
grouped_results.setdefault(grp, []).append(r)
743793
else:
744-
# Use item ID as unique group so it survives
745794
grouped_results.setdefault(id(r), [r])
746795

747-
final_filtered = []
796+
filtered_files = []
748797

749798
for grp, items in grouped_results.items():
750-
# If only 1 item, just take it
751799
if len(items) <= 1:
752-
final_filtered.extend(items)
800+
filtered_files.extend(items)
753801
continue
754802

755-
# Sort by version descending
756803
items.sort(key=lambda x: x.get("version", 0), reverse=True)
757804

758805
if filter_version == "Latest Version":
759-
final_filtered.extend(items[:1])
806+
filtered_files.extend(items[:1])
760807
elif filter_version == "Latest 2 Versions":
761-
final_filtered.extend(items[:2])
808+
filtered_files.extend(items[:2])
762809
else:
763-
# All Versions
764-
final_filtered.extend(items)
810+
filtered_files.extend(items)
765811

766-
results = final_filtered
812+
# Combine
813+
final_results = dirs + filtered_files
767814

768-
# Resort by name for display
769-
results.sort(key=lambda x: x["name"])
815+
# Resort by name for display (or keep dirs first?)
816+
# QML handles sorting, but initial sort helps.
817+
# Let's sort all by name.
818+
final_results.sort(key=lambda x: x["name"])
770819

771820
# Serialize
772-
json_str = json.dumps(results)
821+
json_str = json.dumps(final_results)
773822

774823
self.files_attr.set_value(json_str)
775824

0 commit comments

Comments
 (0)