From a5b4e8e24d96f107e7a289af3fe04393d24cfa9e Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Mon, 26 Jul 2021 02:51:49 -0400 Subject: [PATCH 1/4] folder creation only needs to be checked once --- plugin/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index cdd3a8f..4cd18b8 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -23,11 +23,12 @@ def __init__(self): self.results = [] with open("./plugin/icons.json", "r") as f: self.icons = json.load(f) + if not os.path.exists(ICON_FOLDER): + os.mkdir(ICON_FOLDER) super().__init__() def filter(self, icon): - if not os.path.exists(ICON_FOLDER): - os.mkdir(ICON_FOLDER) + if not os.path.isfile(f"{ICON_FOLDER}{icon['name']}.svg"): with open(f"{ICON_FOLDER}{icon['name']}.svg", 'w') as f: f.write(SVG_FILE.format(icon['data'])) From b60e6bc8246e9068ca50481d0ba31ba04542ca6e Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Mon, 26 Jul 2021 03:13:22 -0400 Subject: [PATCH 2/4] icon creation has its own method --- plugin/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin/main.py b/plugin/main.py index 4cd18b8..404ac76 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -27,11 +27,16 @@ def __init__(self): os.mkdir(ICON_FOLDER) super().__init__() + def create_icon(self, icon_name): + if not os.path.isfile(f"{ICON_FOLDER}{icon_name}.svg"): + for icon in self.icons['icons']: + if icon['name'] == icon_name: + with open(f"{ICON_FOLDER}{icon['name']}.svg", 'w') as f: + f.write(SVG_FILE.format(icon['data'])) + return f"{ICON_FOLDER}{icon_name}.svg" + def filter(self, icon): - if not os.path.isfile(f"{ICON_FOLDER}{icon['name']}.svg"): - with open(f"{ICON_FOLDER}{icon['name']}.svg", 'w') as f: - f.write(SVG_FILE.format(icon['data'])) self.add_item( title=icon['name'], subtitle='Press ENTER to copy to clipboard (SHIFT+ENTER for more options)', @@ -42,7 +47,7 @@ def filter(self, icon): ) def add_item(self, title, subtitle='', icon=None, method=None, parameters=None, context=None, hide=False): - icon = f"{ICON_FOLDER}{icon}.svg" + icon = self.create_icon(icon) item = { "Title": title, @@ -60,6 +65,7 @@ def context_menu(self, data): self.add_item( title='View icon on website', subtitle=f"{MDI_URL}{data[0]}", + icon='web', method="open_web", parameters=[data[0]] ) From 0a51dc13e40840bf06f319d88a4d42e9c1e96540 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Mon, 26 Jul 2021 03:15:21 -0400 Subject: [PATCH 3/4] remove limitations on results --- plugin/app.png => app.png | Bin plugin/main.py | 30 ++++++++++++------------------ 2 files changed, 12 insertions(+), 18 deletions(-) rename plugin/app.png => app.png (100%) diff --git a/plugin/app.png b/app.png similarity index 100% rename from plugin/app.png rename to app.png diff --git a/plugin/main.py b/plugin/main.py index 404ac76..86c4c3f 100644 --- a/plugin/main.py +++ b/plugin/main.py @@ -12,7 +12,7 @@ from flowlauncher import FlowLauncher ICON_FOLDER = './icons/' -MAX_RESULTS = 20 +MAX_RESULTS = 100 SVG_FILE = '' MDI_URL = "https://materialdesignicons.com/icon/" @@ -75,23 +75,17 @@ def query(self, query): # names = [icon['name'] for icon in icons['icons']] q = query.lower() - if len(q) > 0: - for icon in self.icons['icons']: - # If only one char search by first letter only - if len(q) < 2 and icon['name'].startswith(q): - self.filter(icon) - elif len(q) > 1 and q in icon['name'] or q in icon['aliases']: - self.filter(icon) - if len(self.results) >= MAX_RESULTS: - break - else: - self.results.append( - { - "Title": 'Please enter your search term', - "SubTitle": '...' - } - ) - return self.results[:10] + + for icon in self.icons['icons']: + # If only one char search by first letter only + if len(q) < 2 and icon['name'].startswith(q): + self.filter(icon) + elif len(q) > 1 and q in icon['name'] or q in icon['aliases']: + self.filter(icon) + if len(self.results) >= MAX_RESULTS: + break + + return self.results def copy_to_clipboard(self, icon_name): From 233bc74ba0e12a9db503b4ac358b440a307d2f70 Mon Sep 17 00:00:00 2001 From: Garulf <535299+Garulf@users.noreply.github.com> Date: Mon, 26 Jul 2021 03:30:08 -0400 Subject: [PATCH 4/4] Update plugin.json --- plugin.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.json b/plugin.json index af49596..b77f6e4 100644 --- a/plugin.json +++ b/plugin.json @@ -4,7 +4,7 @@ "Name": "Search-MDI", "Description": "Search materialdesignicons.com", "Author": "Garulf", - "Version": "2.0", + "Version": "2.0.1", "Language": "python", "Website": "https://github.com/Garulf/Search-MDI", "IcoPath": "app.png",