Skip to content

Commit

Permalink
fix: Palette File Search is not showing all files in entire project #111
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jan 3, 2024
1 parent 9c7de53 commit cd4058e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion biscuit/core/components/floating/autocomplete/kind.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from biscuit.core.components.utils.icon import Icon

from .kinds import kinds
from ...lsp.kinds import kinds

if typing.TYPE_CHECKING:
from .item import CompletionItem
Expand Down
4 changes: 2 additions & 2 deletions biscuit/core/components/floating/palette/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def configure_bindings(self) -> None:
def pick_actionset(self, actionset) -> None:
self.active_set = actionset

def pick_file_search(self) -> None:
self.active_set = self.base.explorer.get_actionset()
def pick_file_search(self, term: str) -> None:
self.active_set = self.base.explorer.get_actionset(term)

def choose(self, *_) -> None:
#TODO pass the term to the function as argument (for input requiring commands)
Expand Down
5 changes: 2 additions & 3 deletions biscuit/core/components/floating/palette/searchbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ def filter(self, *args) -> None:
prompt_found = True
break

self.term = term
if not prompt_found:
self.master.master.pick_file_search()
self.master.master.pick_file_search(term)

self.term = term
exact, starts, includes = [], [], []

temp = term.lower()
for i in self.master.master.active_set:
item = i[0].lower()
Expand Down
File renamed without changes.
23 changes: 21 additions & 2 deletions biscuit/core/components/views/sidebar/explorer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from biscuit.core.components.floating.palette import ActionSet

from ..sidebarview import SidebarView
Expand All @@ -20,6 +22,8 @@ def __init__(self, master, *args, **kwargs) -> None:
self.directory = DirectoryTree(self, observe_changes=True)
self.add_widget(self.directory)

self.filesearch_actionset = ActionSet("Search files", "file:", [])

self.newfile_actionset = ActionSet(
"Add new file to directory", "newfile:", pinned=[["Create new file: {}", lambda filename=None: self.directory.new_file(filename)]]
)
Expand All @@ -35,5 +39,20 @@ def __init__(self, master, *args, **kwargs) -> None:
)
self.base.palette.register_actionset(lambda: self.rename_actionset)

def get_actionset(self) -> ActionSet:
return self.directory.get_actionset()
def get_actionset(self, term: str) -> ActionSet:
self.filesearch_actionset.update(self.filesearch(term))
return self.filesearch_actionset

def filesearch(self, t):
if not self.base.active_directory:
return []

pys = []
for r, d, f in os.walk(self.base.active_directory):
if any(i in r for i in self.directory.ignore_dirs):
d[:] = []
continue
for file in f:
if t in file:
pys.append((file, lambda _, path=os.path.join(r, file): self.base.open_editor(path)))
return pys
18 changes: 7 additions & 11 deletions biscuit/core/components/views/sidebar/explorer/directorytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def __init__(self, master, startpath=None, observe_changes=False, itembar=True,

self.nodes = {}

self.actionset = ActionSet("Search files", "file:", [])
self.ignore_dirs = [".git", "__pycache__", ".pytest_cache", "node_modules", "debug", "dist", "build"]
self.ignore_exts = [".pyc"]

Expand Down Expand Up @@ -60,7 +59,7 @@ def change_path(self, path: str) -> None:
self.placeholder.grid_remove()
self.tree.grid()
self.tree.clear_tree()
self.create_root(self.path)
self.create_root(self.path, subdir=False)
self.watcher.watch()

self.set_title(os.path.basename(self.path))
Expand All @@ -69,21 +68,21 @@ def change_path(self, path: str) -> None:
self.placeholder.grid()
self.set_title('No folder opened')

def create_root(self, path: str, parent='') -> None:
def create_root(self, path: str, parent='', subdir=True) -> None:
if self.loading:
return

self.loading = True
t = threading.Thread(target=self.run_create_root, args=(path, parent))
t = threading.Thread(target=self.run_create_sub_root if subdir else self.run_create_root, args=(path, parent))
t.daemon = True
t.start()

def run_create_root(self, path: str, parent='') -> None:
self.files = []

self.update_treeview(path, parent)

self.actionset = ActionSet("Search files by name", "file:", self.files)
self.loading = False

def run_create_sub_root(self, path: str, parent='') -> None:
self.update_treeview(path, parent)
self.loading = False

def get_actionset(self) -> ActionSet:
Expand Down Expand Up @@ -140,9 +139,6 @@ def update_treeview(self, parent_path, parent="") -> None:
node = self.tree.insert(parent, "end", text=f" {name}", values=[path, 'file'], image='document')
self.nodes[os.path.abspath(path)] = node

# for the actionset
self.files.append((name, lambda _, path=path: self.base.open_editor(path)))

def selected_directory(self) -> str:
return (self.tree.selected_path().strip() if self.tree.selected_type() != 'file' else self.tree.selected_parent_path().strip()) or self.path

Expand Down
3 changes: 2 additions & 1 deletion biscuit/core/components/views/sidebar/sidebarview.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tkinter as tk
import typing

from biscuit.core.components.utils import Frame, IconButton

Expand All @@ -10,7 +11,7 @@ class SidebarView(View):

def __init__(self, master, *args, **kwargs) -> None:
super().__init__(master, *args, **kwargs)
self.__buttons__ = ()
self.__buttons__: list[tuple(str, typing.Callable)] = []
self.__icon__ = 'preview'
self.__name__ = self.__class__.__name__

Expand Down

0 comments on commit cd4058e

Please sign in to comment.