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.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", diff --git a/plugin/main.py b/plugin/main.py index cdd3a8f..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/" @@ -23,14 +23,20 @@ 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 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.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'])) + self.add_item( title=icon['name'], subtitle='Press ENTER to copy to clipboard (SHIFT+ENTER for more options)', @@ -41,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, @@ -59,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]] ) @@ -68,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):