@@ -17,6 +17,7 @@ struct WidgetView: View {
1717 @State var isHovering : Bool = false
1818 @State var processingProgress : Double = 0
1919 var onOpenChatClicked : ( ) -> Void = { }
20+ var onCustomCommandClicked : ( String ) -> Void = { _ in }
2021
2122 var body : some View {
2223 Circle ( ) . fill ( isHovering ? . white. opacity ( 0.8 ) : . white. opacity ( 0.3 ) )
@@ -77,7 +78,8 @@ struct WidgetView: View {
7778 WidgetContextMenu (
7879 widgetViewModel: viewModel,
7980 isChatOpen: panelViewModel. isPanelDisplayed && panelViewModel. chat != nil ,
80- onOpenChatClicked: onOpenChatClicked
81+ onOpenChatClicked: onOpenChatClicked,
82+ onCustomCommandClicked: onCustomCommandClicked
8183 )
8284 }
8385 }
@@ -103,84 +105,92 @@ struct WidgetContextMenu: View {
103105 @AppStorage ( \. forceOrderWidgetToFront) var forceOrderWidgetToFront
104106 @AppStorage ( \. disableSuggestionFeatureGlobally) var disableSuggestionFeatureGlobally
105107 @AppStorage ( \. suggestionFeatureEnabledProjectList) var suggestionFeatureEnabledProjectList
108+ @AppStorage ( \. customCommands) var customCommands
106109 @ObservedObject var widgetViewModel : WidgetViewModel
107110 @State var projectPath : String ?
108111 var isChatOpen : Bool
109112 var onOpenChatClicked : ( ) -> Void = { }
113+ var onCustomCommandClicked : ( String ) -> Void = { _ in }
110114
111115 var body : some View {
112116 Group {
113- if !isChatOpen {
114- Button ( action: {
115- onOpenChatClicked ( )
116- } ) {
117- Text ( " Open Chat " )
117+ Group { // Commands
118+ if !isChatOpen {
119+ Button ( action: {
120+ onOpenChatClicked ( )
121+ } ) {
122+ Text ( " Open Chat " )
123+ }
118124 }
125+
126+ customCommandMenu ( )
119127 }
120128
121129 Divider ( )
122130
123- Button ( action: {
124- useGlobalChat. toggle ( )
125- } ) {
126- Text ( " Use Global Chat " )
127- if useGlobalChat {
128- Image ( systemName: " checkmark " )
129- }
130- }
131-
132- Button ( action: {
133- realtimeSuggestionToggle. toggle ( )
134- } ) {
135- Text ( " Realtime Suggestion " )
136- if realtimeSuggestionToggle {
137- Image ( systemName: " checkmark " )
138- }
139- }
140-
141- Button ( action: {
142- acceptSuggestionWithAccessibilityAPI. toggle ( )
143- } , label: {
144- Text ( " Accept Suggestion with Accessibility API " )
145- if acceptSuggestionWithAccessibilityAPI {
146- Image ( systemName: " checkmark " )
147- }
148- } )
149-
150- Button ( action: {
151- hideCommonPrecedingSpacesInSuggestion. toggle ( )
152- } , label: {
153- Text ( " Hide Common Preceding Spaces in Suggestion " )
154- if hideCommonPrecedingSpacesInSuggestion {
155- Image ( systemName: " checkmark " )
156- }
157- } )
158-
159- Button ( action: {
160- forceOrderWidgetToFront. toggle ( )
161- } , label: {
162- Text ( " Force Order Widget to Front " )
163- if forceOrderWidgetToFront {
164- Image ( systemName: " checkmark " )
131+ Group { // Settings
132+ Button ( action: {
133+ useGlobalChat. toggle ( )
134+ } ) {
135+ Text ( " Use Global Chat " )
136+ if useGlobalChat {
137+ Image ( systemName: " checkmark " )
138+ }
165139 }
166- } )
167-
168- if let projectPath, disableSuggestionFeatureGlobally {
169- let matchedPath = suggestionFeatureEnabledProjectList. first { path in
170- projectPath. hasPrefix ( path)
140+
141+ Button ( action: {
142+ realtimeSuggestionToggle. toggle ( )
143+ } ) {
144+ Text ( " Realtime Suggestion " )
145+ if realtimeSuggestionToggle {
146+ Image ( systemName: " checkmark " )
147+ }
171148 }
149+
172150 Button ( action: {
173- if matchedPath != nil {
174- suggestionFeatureEnabledProjectList
175- . removeAll { path in path == matchedPath }
176- } else {
177- suggestionFeatureEnabledProjectList . append ( projectPath )
151+ acceptSuggestionWithAccessibilityAPI . toggle ( )
152+ } , label : {
153+ Text ( " Accept Suggestion with Accessibility API " )
154+ if acceptSuggestionWithAccessibilityAPI {
155+ Image ( systemName : " checkmark " )
178156 }
179- } ) {
180- if matchedPath == nil {
181- Text ( " Add to Suggestion-Enabled Project List " )
182- } else {
183- Text ( " Remove from Suggestion-Enabled Project List " )
157+ } )
158+
159+ Button ( action: {
160+ hideCommonPrecedingSpacesInSuggestion. toggle ( )
161+ } , label: {
162+ Text ( " Hide Common Preceding Spaces in Suggestion " )
163+ if hideCommonPrecedingSpacesInSuggestion {
164+ Image ( systemName: " checkmark " )
165+ }
166+ } )
167+
168+ Button ( action: {
169+ forceOrderWidgetToFront. toggle ( )
170+ } , label: {
171+ Text ( " Force Order Widget to Front " )
172+ if forceOrderWidgetToFront {
173+ Image ( systemName: " checkmark " )
174+ }
175+ } )
176+
177+ if let projectPath, disableSuggestionFeatureGlobally {
178+ let matchedPath = suggestionFeatureEnabledProjectList. first { path in
179+ projectPath. hasPrefix ( path)
180+ }
181+ Button ( action: {
182+ if matchedPath != nil {
183+ suggestionFeatureEnabledProjectList
184+ . removeAll { path in path == matchedPath }
185+ } else {
186+ suggestionFeatureEnabledProjectList. append ( projectPath)
187+ }
188+ } ) {
189+ if matchedPath == nil {
190+ Text ( " Add to Suggestion-Enabled Project List " )
191+ } else {
192+ Text ( " Remove from Suggestion-Enabled Project List " )
193+ }
184194 }
185195 }
186196 }
@@ -211,6 +221,18 @@ struct WidgetContextMenu: View {
211221 }
212222 }
213223 }
224+
225+ func customCommandMenu( ) -> some View {
226+ Menu ( " Custom Commands " ) {
227+ ForEach ( customCommands, id: \. name) { command in
228+ Button ( action: {
229+ onCustomCommandClicked ( command. name)
230+ } ) {
231+ Text ( command. name)
232+ }
233+ }
234+ }
235+ }
214236}
215237
216238struct WidgetView_Preview : PreviewProvider {
0 commit comments