Skip to content

Commit efaa371

Browse files
authored
Merge pull request #4 from Garulf/dev
Dev
2 parents 0361a3c + 233bc74 commit efaa371

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed
File renamed without changes.

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "Search-MDI",
55
"Description": "Search materialdesignicons.com",
66
"Author": "Garulf",
7-
"Version": "2.0",
7+
"Version": "2.0.1",
88
"Language": "python",
99
"Website": "https://github.com/Garulf/Search-MDI",
1010
"IcoPath": "app.png",

plugin/main.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from flowlauncher import FlowLauncher
1313

1414
ICON_FOLDER = './icons/'
15-
MAX_RESULTS = 20
15+
MAX_RESULTS = 100
1616
SVG_FILE = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="{}" /></svg>'
1717
MDI_URL = "https://materialdesignicons.com/icon/"
1818

@@ -23,14 +23,20 @@ def __init__(self):
2323
self.results = []
2424
with open("./plugin/icons.json", "r") as f:
2525
self.icons = json.load(f)
26+
if not os.path.exists(ICON_FOLDER):
27+
os.mkdir(ICON_FOLDER)
2628
super().__init__()
2729

30+
def create_icon(self, icon_name):
31+
if not os.path.isfile(f"{ICON_FOLDER}{icon_name}.svg"):
32+
for icon in self.icons['icons']:
33+
if icon['name'] == icon_name:
34+
with open(f"{ICON_FOLDER}{icon['name']}.svg", 'w') as f:
35+
f.write(SVG_FILE.format(icon['data']))
36+
return f"{ICON_FOLDER}{icon_name}.svg"
37+
2838
def filter(self, icon):
29-
if not os.path.exists(ICON_FOLDER):
30-
os.mkdir(ICON_FOLDER)
31-
if not os.path.isfile(f"{ICON_FOLDER}{icon['name']}.svg"):
32-
with open(f"{ICON_FOLDER}{icon['name']}.svg", 'w') as f:
33-
f.write(SVG_FILE.format(icon['data']))
39+
3440
self.add_item(
3541
title=icon['name'],
3642
subtitle='Press ENTER to copy to clipboard (SHIFT+ENTER for more options)',
@@ -41,7 +47,7 @@ def filter(self, icon):
4147
)
4248

4349
def add_item(self, title, subtitle='', icon=None, method=None, parameters=None, context=None, hide=False):
44-
icon = f"{ICON_FOLDER}{icon}.svg"
50+
icon = self.create_icon(icon)
4551

4652
item = {
4753
"Title": title,
@@ -59,6 +65,7 @@ def context_menu(self, data):
5965
self.add_item(
6066
title='View icon on website',
6167
subtitle=f"{MDI_URL}{data[0]}",
68+
icon='web',
6269
method="open_web",
6370
parameters=[data[0]]
6471
)
@@ -68,23 +75,17 @@ def query(self, query):
6875
# names = [icon['name'] for icon in icons['icons']]
6976
q = query.lower()
7077

71-
if len(q) > 0:
72-
for icon in self.icons['icons']:
73-
# If only one char search by first letter only
74-
if len(q) < 2 and icon['name'].startswith(q):
75-
self.filter(icon)
76-
elif len(q) > 1 and q in icon['name'] or q in icon['aliases']:
77-
self.filter(icon)
78-
if len(self.results) >= MAX_RESULTS:
79-
break
80-
else:
81-
self.results.append(
82-
{
83-
"Title": 'Please enter your search term',
84-
"SubTitle": '...'
85-
}
86-
)
87-
return self.results[:10]
78+
79+
for icon in self.icons['icons']:
80+
# If only one char search by first letter only
81+
if len(q) < 2 and icon['name'].startswith(q):
82+
self.filter(icon)
83+
elif len(q) > 1 and q in icon['name'] or q in icon['aliases']:
84+
self.filter(icon)
85+
if len(self.results) >= MAX_RESULTS:
86+
break
87+
88+
return self.results
8889

8990

9091
def copy_to_clipboard(self, icon_name):

0 commit comments

Comments
 (0)