Skip to content

Commit

Permalink
Merge pull request #4 from Garulf/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Garulf authored Jul 26, 2021
2 parents 0361a3c + 233bc74 commit efaa371
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
File renamed without changes
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 25 additions & 24 deletions plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from flowlauncher import FlowLauncher

ICON_FOLDER = './icons/'
MAX_RESULTS = 20
MAX_RESULTS = 100
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>'
MDI_URL = "https://materialdesignicons.com/icon/"

Expand All @@ -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)',
Expand All @@ -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,
Expand All @@ -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]]
)
Expand All @@ -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):
Expand Down

0 comments on commit efaa371

Please sign in to comment.