From fe2548a486c7bd40d09f5e9588970dde830da168 Mon Sep 17 00:00:00 2001 From: Jake Herrmann <19476938+jtherrmann@users.noreply.github.com> Date: Sat, 18 Nov 2017 01:20:47 -0900 Subject: [PATCH 1/5] Add config option for automatic page opening Add config option to enable or disable automatically opening a page when it is the only page found for the search query. Disabling this behavior prevents accidentally modifying the page due to it opening automatically while the user is still typing the query. --- instantsearch.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/instantsearch.py b/instantsearch.py index 20a07ca..ae27428 100644 --- a/instantsearch.py +++ b/instantsearch.py @@ -56,6 +56,7 @@ class InstantsearchPlugin(PluginClass): ('ignore_subpages', 'bool', _("Ignore subpages (if ignored, search 'linux' would return page:linux but not page:linux:subpage (if in the subpage, there is no occurece of string 'linux')"), True), ('isWildcarded', 'bool', _("Append wildcards to the search string: *string*"), True), ('isCached', 'bool', _("Cache results of a search to be used in another search. (Till the end of zim process.)"), True), + ('open_when_unique', 'bool', _('When only one page is found, open it automatically.'), True), ('position', 'choice', _('Popup position'), POSITION_RIGHT, (POSITION_RIGHT, POSITION_CENTER)) # T: plugin preference ) @@ -102,6 +103,7 @@ def instantsearch(self): self.title_match_char = self.plugin.preferences['title_match_char'] self.start_search_length = self.plugin.preferences['start_search_length'] self.keystroke_delay = self.plugin.preferences['keystroke_delay'] + self.open_when_unique = self.plugin.preferences['open_when_unique'] # building quick title cache def build(start = ""): @@ -240,9 +242,10 @@ def startZimSearch(self): def checkLast(self): """ opens the page if there is only one option in the menu """ - if len(self.state.menu) == 1: - self._open_page(Path(self.state.menu.keys()[0]), excludeFromHistory=False) - self.close() + if self.open_when_unique is True: + if len(self.state.menu) == 1: + self._open_page(Path(self.state.menu.keys()[0]), excludeFromHistory=False) + self.close() def _search_callback(self, query): def _search_callback(results, path): From a201ae844ef20061920a13cae60f7deb228ce359 Mon Sep 17 00:00:00 2001 From: Jake Herrmann <19476938+jtherrmann@users.noreply.github.com> Date: Sat, 18 Nov 2017 01:41:14 -0900 Subject: [PATCH 2/5] Add config option for older versions of Zim Add config option to allow Instant Search to work with versions of Zim earlier than 0.66-. See issues #24 and #25. --- instantsearch.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/instantsearch.py b/instantsearch.py index ae27428..6ee9222 100644 --- a/instantsearch.py +++ b/instantsearch.py @@ -57,6 +57,7 @@ class InstantsearchPlugin(PluginClass): ('isWildcarded', 'bool', _("Append wildcards to the search string: *string*"), True), ('isCached', 'bool', _("Cache results of a search to be used in another search. (Till the end of zim process.)"), True), ('open_when_unique', 'bool', _('When only one page is found, open it automatically.'), True), + ('old_zim', 'bool', _('Check this option if using Zim version earlier than 0.66-.'), False), ('position', 'choice', _('Popup position'), POSITION_RIGHT, (POSITION_RIGHT, POSITION_CENTER)) # T: plugin preference ) @@ -104,13 +105,31 @@ def instantsearch(self): self.start_search_length = self.plugin.preferences['start_search_length'] self.keystroke_delay = self.plugin.preferences['keystroke_delay'] self.open_when_unique = self.plugin.preferences['open_when_unique'] + self.old_zim = self.plugin.preferences['old_zim'] # building quick title cache def build(start = ""): - for s in self.window.ui.notebook.pages.list_pages(Path(start or ":")): - start2 = (start + ":" if start else "") + s.basename - self.cached_titles.append((start2, start2.lower())) - build(start2) + if self.old_zim is False: + for s in self.window.ui.notebook.pages.list_pages(Path(start or ":")): + start2 = (start + ":" if start else "") + s.basename + self.cached_titles.append((start2, start2.lower())) + build(start2) + else: + for s in self.window.ui.notebook.index.list_pages(Path(':')): + st = s.basename + self.cached_titles.append((st, st.lower())) + for s2 in self.window.ui.notebook.get_pagelist(Path(st)): + st = s.basename + ":" + s2.basename + self.cached_titles.append((st, st.lower())) + for s3 in self.window.ui.notebook.get_pagelist(Path(st)): + st = s.basename + ":" + s2.basename + ":" + s3.basename + self.cached_titles.append((st, st.lower())) + for s4 in self.window.ui.notebook.get_pagelist(Path(st)): + st = s.basename + ":" + s2.basename + ":" + s3.basename + ":" + s4.basename + self.cached_titles.append((st, st.lower())) + for s5 in self.window.ui.notebook.get_pagelist(Path(st)): + st = s.basename + ":" + s2.basename + ":" + s3.basename + ":" + s4.basename + ":" + s5.basename + self.cached_titles.append((st, st.lower())) build() # Gtk From def2aede8804e9c374a8e8ed418199da0cf7316d Mon Sep 17 00:00:00 2001 From: Jake Herrmann <19476938+jtherrmann@users.noreply.github.com> Date: Sat, 18 Nov 2017 01:55:37 -0900 Subject: [PATCH 3/5] Update README Update README to recommend using the config option for older versions of Zim. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 254607e..d25cf6d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Much quicker than current Zim search. ### Working with & Feedback Known to work on Ubuntu 17.04 Zim 0.67+, Ubuntu 15.10 Zim 0.65+, Win 7 Zim 0.63+. -(For **earlier version than Zim 0.66-** use an old commit from Mar 17, not the current version.) +(For **earlier version than Zim 0.66-**, open the plugin configuration window for Instant Search and enable the option for using Zim version earlier than 0.66-, or use an old Instant Search commit from Mar 17 instead of the current version.) I'd be glad to hear from you if it's working either here in the issues or in the original bug https://bugs.launchpad.net/zim/+bug/1409626 . ### Installation From 9334ad282aa0e3278699745357e11c1f7b97948c Mon Sep 17 00:00:00 2001 From: Jake Herrmann <19476938+jtherrmann@users.noreply.github.com> Date: Sun, 19 Nov 2017 00:45:33 -0900 Subject: [PATCH 4/5] Add Tab and Shift+Tab for moving caret Allow Tab to move caret down and Shift+Tab to move caret up --- instantsearch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/instantsearch.py b/instantsearch.py index 6ee9222..0817977 100644 --- a/instantsearch.py +++ b/instantsearch.py @@ -353,11 +353,11 @@ def soutMenu(self, displayImmediately=False): def move(self, widget, event): """ Move caret up and down. Enter to confirm, Esc closes search.""" keyname = gtk.gdk.keyval_name(event.keyval) - if keyname == "Up": + if keyname == "Up" or keyname == "ISO_Left_Tab": self.caret['pos'] -= 1 self.soutMenu(displayImmediately=False) - if keyname == "Down": + if keyname == "Down" or keyname == "Tab": self.caret['pos'] += 1 self.soutMenu(displayImmediately=False) From 768a71e58befcd33e1b34bb1fed697845cae6662 Mon Sep 17 00:00:00 2001 From: Jake Herrmann <19476938+jtherrmann@users.noreply.github.com> Date: Wed, 22 Nov 2017 15:14:39 -0900 Subject: [PATCH 5/5] Automatically work with Zim 0.66- No longer require manual configuration depending on Zim version. Update README to reflect my testing the plugin on Debian 8.9. --- README.md | 9 +++++++-- instantsearch.py | 38 +++++++++++--------------------------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d25cf6d..2b465fd 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,13 @@ Much quicker than current Zim search. ### Working with & Feedback -Known to work on Ubuntu 17.04 Zim 0.67+, Ubuntu 15.10 Zim 0.65+, Win 7 Zim 0.63+. -(For **earlier version than Zim 0.66-**, open the plugin configuration window for Instant Search and enable the option for using Zim version earlier than 0.66-, or use an old Instant Search commit from Mar 17 instead of the current version.) +Known to work on: + +* Ubuntu 17.04 Zim 0.67+ +* Ubuntu 15.10 Zim 0.65+ +* Win 7 Zim 0.63+ +* Debian 8.9 Zim 0.62-3, 0.65-4, 0.67-1 + I'd be glad to hear from you if it's working either here in the issues or in the original bug https://bugs.launchpad.net/zim/+bug/1409626 . ### Installation diff --git a/instantsearch.py b/instantsearch.py index 0817977..566270e 100644 --- a/instantsearch.py +++ b/instantsearch.py @@ -57,7 +57,6 @@ class InstantsearchPlugin(PluginClass): ('isWildcarded', 'bool', _("Append wildcards to the search string: *string*"), True), ('isCached', 'bool', _("Cache results of a search to be used in another search. (Till the end of zim process.)"), True), ('open_when_unique', 'bool', _('When only one page is found, open it automatically.'), True), - ('old_zim', 'bool', _('Check this option if using Zim version earlier than 0.66-.'), False), ('position', 'choice', _('Popup position'), POSITION_RIGHT, (POSITION_RIGHT, POSITION_CENTER)) # T: plugin preference ) @@ -105,31 +104,17 @@ def instantsearch(self): self.start_search_length = self.plugin.preferences['start_search_length'] self.keystroke_delay = self.plugin.preferences['keystroke_delay'] self.open_when_unique = self.plugin.preferences['open_when_unique'] - self.old_zim = self.plugin.preferences['old_zim'] # building quick title cache def build(start = ""): - if self.old_zim is False: - for s in self.window.ui.notebook.pages.list_pages(Path(start or ":")): - start2 = (start + ":" if start else "") + s.basename - self.cached_titles.append((start2, start2.lower())) - build(start2) - else: - for s in self.window.ui.notebook.index.list_pages(Path(':')): - st = s.basename - self.cached_titles.append((st, st.lower())) - for s2 in self.window.ui.notebook.get_pagelist(Path(st)): - st = s.basename + ":" + s2.basename - self.cached_titles.append((st, st.lower())) - for s3 in self.window.ui.notebook.get_pagelist(Path(st)): - st = s.basename + ":" + s2.basename + ":" + s3.basename - self.cached_titles.append((st, st.lower())) - for s4 in self.window.ui.notebook.get_pagelist(Path(st)): - st = s.basename + ":" + s2.basename + ":" + s3.basename + ":" + s4.basename - self.cached_titles.append((st, st.lower())) - for s5 in self.window.ui.notebook.get_pagelist(Path(st)): - st = s.basename + ":" + s2.basename + ":" + s3.basename + ":" + s4.basename + ":" + s5.basename - self.cached_titles.append((st, st.lower())) + if hasattr(self.window.ui.notebook, 'pages'): + o = self.window.ui.notebook.pages + else: # for Zim 0.66- + o = self.window.ui.notebook.index + for s in o.list_pages(Path(start or ":")): + start2 = (start + ":" if start else "") + s.basename + self.cached_titles.append((start2, start2.lower())) + build(start2) build() # Gtk @@ -261,10 +246,9 @@ def startZimSearch(self): def checkLast(self): """ opens the page if there is only one option in the menu """ - if self.open_when_unique is True: - if len(self.state.menu) == 1: - self._open_page(Path(self.state.menu.keys()[0]), excludeFromHistory=False) - self.close() + if self.open_when_unique and len(self.state.menu) == 1: + self._open_page(Path(self.state.menu.keys()[0]), excludeFromHistory=False) + self.close() def _search_callback(self, query): def _search_callback(results, path):