diff options
-rw-r--r-- | packages/finder/main.py | 25 | ||||
-rw-r--r-- | packages/finder/plugin/searcher/file/name.py | 4 |
2 files changed, 27 insertions, 2 deletions
diff --git a/packages/finder/main.py b/packages/finder/main.py index 32aca1f..38c6c7f 100644 --- a/packages/finder/main.py +++ b/packages/finder/main.py @@ -55,11 +55,30 @@ class FinderMain(): def change(self, _): self.update_list_buffer(self.searcher.filter(self.input_field.text)) + async def refresh(self): + # Clean the list buffer + self.clear_list_buffer() + + # Sleep just the bare minimum, for UX purposes + await asyncio.sleep(0.01) + + # Update the list of items + self.update_list_buffer(await self.searcher.finder(use_cache=False)) + + # Update the current selection + self.change('') + + # Update the toolbar + self.state['loading'] = False + def open(self): item = self.list_buffer.document.current_line self.opener.open(os.path.join(self.path, item)) + def clear_list_buffer(self): + self.list_buffer.set_document(Document(''), bypass_readonly=True) + def update_list_buffer(self, items): # This only works when the buffer is read-write #self.list_buffer.text = self.format(items) @@ -88,6 +107,12 @@ class FinderMain(): def _(event): event.app.layout.focus_next() + @self.keybindings.add("f5") + async def _(event): + self.state['loading'] = True + + refresh = asyncio.create_task(self.refresh()) + @self.keybindings.add("enter", filter = has_focus(self.list_buffer)) def _(event): self.open() diff --git a/packages/finder/plugin/searcher/file/name.py b/packages/finder/plugin/searcher/file/name.py index 85bacbd..c6a96de 100644 --- a/packages/finder/plugin/searcher/file/name.py +++ b/packages/finder/plugin/searcher/file/name.py @@ -42,9 +42,9 @@ class FinderPluginFileNameSearcher(): self.path = path self.cache = os.path.join(cache_dir, 'plugin', 'searcher', 'file', os.path.abspath(self.path).replace(os.sep, '_') + '.json') - async def finder(self, force = False): + async def finder(self, use_cache = True): # Check existing cache - if not force and os.path.exists(self.cache) and os.path.isfile(self.cache): + if use_cache and os.path.exists(self.cache) and os.path.isfile(self.cache): with open(self.cache, 'r') as f: self.items = json.load(f) |