4
4
using Flow . Launcher . ViewModel ;
5
5
using Flow . Launcher . Core ;
6
6
using System . Linq ;
7
- using Flow . Launcher . Core . Plugin ;
8
7
using System . Collections . Generic ;
9
8
10
9
namespace Flow . Launcher
@@ -43,11 +42,14 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
43
42
44
43
newActionKeywords = newActionKeywords . Count > 0 ? newActionKeywords : new ( ) { Query . GlobalPluginWildcardSign } ;
45
44
46
- if ( ! newActionKeywords . Except ( oldActionKeywords ) . Any ( PluginManager . ActionKeywordRegistered ) )
45
+ var addedActionKeywords = newActionKeywords . Except ( oldActionKeywords ) . ToList ( ) ;
46
+ var removedActionKeywords = oldActionKeywords . Except ( newActionKeywords ) . ToList ( ) ;
47
+ if ( ! addedActionKeywords . Any ( App . API . ActionKeywordAssigned ) )
47
48
{
48
49
if ( oldActionKeywords . Count != newActionKeywords . Count )
49
50
{
50
- ReplaceActionKeyword ( plugin . Metadata . ID , oldActionKeywords , newActionKeywords ) ;
51
+ ReplaceActionKeyword ( plugin . Metadata . ID , removedActionKeywords , addedActionKeywords ) ;
52
+ return ;
51
53
}
52
54
53
55
var sortedOldActionKeywords = oldActionKeywords . OrderBy ( s => s ) . ToList ( ) ;
@@ -61,7 +63,7 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
61
63
}
62
64
else
63
65
{
64
- ReplaceActionKeyword ( plugin . Metadata . ID , oldActionKeywords , newActionKeywords ) ;
66
+ ReplaceActionKeyword ( plugin . Metadata . ID , removedActionKeywords , addedActionKeywords ) ;
65
67
}
66
68
}
67
69
else
@@ -71,21 +73,18 @@ private void btnDone_OnClick(object sender, RoutedEventArgs _)
71
73
}
72
74
}
73
75
74
- private void ReplaceActionKeyword ( string id , IReadOnlyList < string > oldActionKeywords , IReadOnlyList < string > newActionKeywords )
76
+ private void ReplaceActionKeyword ( string id , IReadOnlyList < string > removedActionKeywords , IReadOnlyList < string > addedActionKeywords )
75
77
{
76
- // Because add & remove action keyword will change action keyword metadata,
77
- // so we need to clone it to fix collection modified while iterating exception
78
- var oldActionKeywordsClone = oldActionKeywords . ToList ( ) ;
79
- foreach ( var actionKeyword in oldActionKeywordsClone )
78
+ foreach ( var actionKeyword in removedActionKeywords )
80
79
{
81
- PluginManager . RemoveActionKeyword ( id , actionKeyword ) ;
80
+ App . API . RemoveActionKeyword ( id , actionKeyword ) ;
82
81
}
83
- foreach ( var actionKeyword in newActionKeywords )
82
+ foreach ( var actionKeyword in addedActionKeywords )
84
83
{
85
- PluginManager . AddActionKeyword ( id , actionKeyword ) ;
84
+ App . API . AddActionKeyword ( id , actionKeyword ) ;
86
85
}
87
86
88
- // Update action keywords text and close
87
+ // Update action keywords text and close window
89
88
pluginViewModel . OnActionKeywordsChanged ( ) ;
90
89
Close ( ) ;
91
90
}
0 commit comments