8
8
from dataclasses import dataclass
9
9
from albert import *
10
10
11
- md_iid = "2.2 "
12
- md_version = "1.2 "
11
+ md_iid = "2.3 "
12
+ md_version = "1.3 "
13
13
md_name = "VSCode projects"
14
14
md_description = "Open VSCode projects"
15
15
md_url = "https://github.com/albertlauncher/python/tree/master/vscode_projects"
16
16
md_license = "MIT"
17
17
md_bin_dependencies = ["code" ]
18
18
md_authors = ["@Sharsie" ]
19
19
20
-
21
20
@dataclass
22
21
class Project :
23
22
displayName : str
@@ -104,10 +103,11 @@ def projectManagerEnabled(self, value):
104
103
if found == False :
105
104
warning (
106
105
"Project Manager search was enabled, but configuration file was not found" )
107
- self . notification = Notification (
108
- title = f"{ md_name } " ,
109
- body = f"Configuration file was not found for the Project Manager extension. Please make sure the extension is installed."
106
+ notif = Notification (
107
+ title = f"{ self . name } " ,
108
+ text = f"Configuration file was not found for the Project Manager extension. Please make sure the extension is installed."
110
109
)
110
+ notif .send ()
111
111
112
112
# Priority settings for project manager results using name search
113
113
@property
@@ -160,19 +160,19 @@ def terminalCommand(self, value):
160
160
self .writeConfig ("terminalCommand" , value )
161
161
162
162
def __init__ (self ):
163
+ self .iconUrls = [f"file:{ Path (__file__ ).parent } /icon.svg" ]
164
+
165
+ PluginInstance .__init__ (self )
166
+
163
167
TriggerQueryHandler .__init__ (
164
168
self ,
165
- id = md_id ,
166
- name = md_name ,
167
- description = md_description ,
169
+ id = self . id ,
170
+ name = self . name ,
171
+ description = self . description ,
168
172
defaultTrigger = "code " ,
169
173
synopsis = "project name or path"
170
174
)
171
175
172
- PluginInstance .__init__ (self , extensions = [self ])
173
- self .iconUrls = [f"file:{ Path (__file__ ).parent } /icon.svg" ]
174
- self .notification = None
175
-
176
176
configFound = False
177
177
178
178
for p in self ._configStoragePaths :
@@ -312,19 +312,18 @@ def handleTriggerQuery(self, query):
312
312
if not query .isValid :
313
313
return
314
314
315
- # Normalize user query
316
- normalizedQuery = self ._normalizeString (query .string .strip ())
317
-
318
- if normalizedQuery == "" :
315
+ if query .string == "" :
319
316
return
320
317
318
+ matcher = Matcher (query .string )
319
+
321
320
results : dict [str , SearchResult ] = {}
322
321
323
322
if self .recentEnabled :
324
- results = self ._searchInRecentFiles (normalizedQuery , results )
323
+ results = self ._searchInRecentFiles (matcher , results )
325
324
326
325
if self .projectManagerEnabled :
327
- results = self ._searchInProjectManager (normalizedQuery , results )
326
+ results = self ._searchInProjectManager (matcher , results )
328
327
329
328
sortedItems = sorted (results .values (), key = lambda item : "%s_%s_%s" % (
330
329
'{:03d}' .format (item .priority ), '{:03d}' .format (item .sortIndex ), item .project .name ), reverse = False )
@@ -333,7 +332,7 @@ def handleTriggerQuery(self, query):
333
332
query .add (self ._createItem (i .project , query ))
334
333
335
334
# Creates an item for the query based on the project and plugin settings
336
- def _createItem (self , project : Project , query : TriggerQuery ) -> StandardItem :
335
+ def _createItem (self , project : Project , query : Query ) -> StandardItem :
337
336
actions : list [Action ] = []
338
337
339
338
if self .terminalCommand != "" :
@@ -362,18 +361,18 @@ def _createItem(self, project: Project, query: TriggerQuery) -> StandardItem:
362
361
id = project .path ,
363
362
text = project .displayName ,
364
363
subtext = project .path ,
365
- iconUrls = [f"file:{ Path (__file__ ).parent } /icon.svg" ],
364
+ iconUrls = [f"file:// { Path (__file__ ).parent } /icon.svg" ],
366
365
inputActionText = f"{ query .trigger } { project .displayName } " ,
367
366
actions = actions ,
368
367
)
369
368
370
- def _searchInRecentFiles (self , search : str , results : dict [str , SearchResult ]) -> dict [str , SearchResult ]:
369
+ def _searchInRecentFiles (self , matcher : Matcher , results : dict [str , SearchResult ]) -> dict [str , SearchResult ]:
371
370
sortIndex = 1
372
371
373
372
for path in self ._configStoragePaths :
374
373
c = self ._getStorageConfig (path )
375
374
for proj in c .projects :
376
- if proj .name . find ( search ) != - 1 or proj .path . find ( search ) != - 1 :
375
+ if matcher . match ( proj .name ) or matcher . match ( proj .path ) :
377
376
results [proj .path ] = self ._getHigherPriorityResult (
378
377
SearchResult (
379
378
project = proj ,
@@ -388,21 +387,21 @@ def _searchInRecentFiles(self, search: str, results: dict[str, SearchResult]) ->
388
387
389
388
return results
390
389
391
- def _searchInProjectManager (self , search : str , results : dict [str , SearchResult ]) -> dict [str , SearchResult ]:
390
+ def _searchInProjectManager (self , matcher : Matcher , results : dict [str , SearchResult ]) -> dict [str , SearchResult ]:
392
391
for path in self ._configProjectManagerPaths :
393
392
c = self ._getProjectManagerConfig (path )
394
393
for proj in c .projects :
395
- if proj .name . find ( search ) != - 1 :
394
+ if matcher . match ( proj .name ) :
396
395
results [proj .path ] = self ._getHigherPriorityResult (
397
396
SearchResult (
398
397
project = proj ,
399
398
priority = self .priorityPMName ,
400
- sortIndex = 0 if proj .name == search else 1
399
+ sortIndex = 0 if matcher . match ( proj .name ). isExactMatch () else 1
401
400
),
402
401
results .get (proj .path ),
403
402
)
404
403
405
- if proj .path . find ( search ) != - 1 :
404
+ if matcher . match ( proj .path ) :
406
405
results [proj .path ] = self ._getHigherPriorityResult (
407
406
SearchResult (
408
407
project = proj ,
@@ -413,7 +412,7 @@ def _searchInProjectManager(self, search: str, results: dict[str, SearchResult])
413
412
)
414
413
415
414
for tag in proj .tags :
416
- if tag . find ( search ) != - 1 :
415
+ if matcher . match ( tag ) :
417
416
results [proj .path ] = self ._getHigherPriorityResult (
418
417
SearchResult (
419
418
project = proj ,
0 commit comments