11import Environment
22import Preferences
3+ import SuggestionModel
34import SwiftUI
45
56@MainActor
@@ -26,8 +27,10 @@ struct WidgetView: View {
2627 . onTapGesture {
2728 withAnimation ( . easeInOut( duration: 0.2 ) ) {
2829 let isDisplayed = {
29- if panelViewModel. isPanelDisplayed && panelViewModel. content != nil { return true }
30- if chatWindowViewModel. isPanelDisplayed && chatWindowViewModel. chat != nil { return true }
30+ if panelViewModel. isPanelDisplayed,
31+ panelViewModel. content != nil { return true }
32+ if chatWindowViewModel. isPanelDisplayed,
33+ chatWindowViewModel. chat != nil { return true }
3134 return false
3235 } ( )
3336 panelViewModel. isPanelDisplayed = !isDisplayed
@@ -115,10 +118,12 @@ struct WidgetContextMenu: View {
115118 @AppStorage ( \. hideCommonPrecedingSpacesInSuggestion) var hideCommonPrecedingSpacesInSuggestion
116119 @AppStorage ( \. disableSuggestionFeatureGlobally) var disableSuggestionFeatureGlobally
117120 @AppStorage ( \. suggestionFeatureEnabledProjectList) var suggestionFeatureEnabledProjectList
121+ @AppStorage ( \. suggestionFeatureDisabledLanguageList) var suggestionFeatureDisabledLanguageList
118122 @AppStorage ( \. customCommands) var customCommands
119123 @ObservedObject var chatWindowViewModel : ChatWindowViewModel
120124 @ObservedObject var widgetViewModel : WidgetViewModel
121125 @State var projectPath : String ?
126+ @State var fileURL : URL ?
122127 var isChatOpen : Bool
123128 var onOpenChatClicked : ( ) -> Void = { }
124129 var onCustomCommandClicked : ( CustomCommand ) -> Void = { _ in }
@@ -139,6 +144,14 @@ struct WidgetContextMenu: View {
139144
140145 Divider ( )
141146
147+ Group {
148+ enableSuggestionForProject
149+
150+ disableSuggestionForLanguage
151+ }
152+
153+ Divider ( )
154+
142155 Group { // Settings
143156 Button ( action: {
144157 chatWindowViewModel. chatPanelInASeparateWindow. toggle ( )
@@ -184,26 +197,6 @@ struct WidgetContextMenu: View {
184197 Image ( systemName: " checkmark " )
185198 }
186199 } )
187-
188- if let projectPath, disableSuggestionFeatureGlobally {
189- let matchedPath = suggestionFeatureEnabledProjectList. first { path in
190- projectPath. hasPrefix ( path)
191- }
192- Button ( action: {
193- if matchedPath != nil {
194- suggestionFeatureEnabledProjectList
195- . removeAll { path in path == matchedPath }
196- } else {
197- suggestionFeatureEnabledProjectList. append ( projectPath)
198- }
199- } ) {
200- if matchedPath == nil {
201- Text ( " Add to Suggestion-Enabled Project List " )
202- } else {
203- Text ( " Remove from Suggestion-Enabled Project List " )
204- }
205- }
206- }
207200 }
208201
209202 Divider ( )
@@ -227,6 +220,7 @@ struct WidgetContextMenu: View {
227220 let projectURL = try ? await Environment . fetchCurrentProjectRootURL ( fileURL)
228221 if let projectURL {
229222 Task { @MainActor in
223+ self . fileURL = fileURL
230224 self . projectPath = projectURL. path
231225 }
232226 }
@@ -246,6 +240,54 @@ struct WidgetContextMenu: View {
246240 }
247241}
248242
243+ extension WidgetContextMenu {
244+ @ViewBuilder
245+ var enableSuggestionForProject : some View {
246+ if let projectPath, disableSuggestionFeatureGlobally {
247+ let matchedPath = suggestionFeatureEnabledProjectList. first { path in
248+ projectPath. hasPrefix ( path)
249+ }
250+ Button ( action: {
251+ if matchedPath != nil {
252+ suggestionFeatureEnabledProjectList
253+ . removeAll { path in path == matchedPath }
254+ } else {
255+ suggestionFeatureEnabledProjectList. append ( projectPath)
256+ }
257+ } ) {
258+ if matchedPath == nil {
259+ Text ( " Add to Suggestion-Enabled Project List " )
260+ } else {
261+ Text ( " Remove from Suggestion-Enabled Project List " )
262+ }
263+ }
264+ }
265+ }
266+
267+ @ViewBuilder
268+ var disableSuggestionForLanguage : some View {
269+ if let fileURL {
270+ let fileLanguage = languageIdentifierFromFileURL ( fileURL)
271+ let matched = suggestionFeatureDisabledLanguageList. first { rawValue in
272+ fileLanguage. rawValue == rawValue
273+ }
274+ Button ( action: {
275+ if let matched {
276+ suggestionFeatureDisabledLanguageList. removeAll { $0 == matched }
277+ } else {
278+ suggestionFeatureDisabledLanguageList. append ( fileLanguage. rawValue)
279+ }
280+ } ) {
281+ if matched == nil {
282+ Text ( " Disable Suggestion for \" \( fileLanguage. rawValue. capitalized) \" " )
283+ } else {
284+ Text ( " Enable Suggestion for \" \( fileLanguage. rawValue. capitalized) \" " )
285+ }
286+ }
287+ }
288+ }
289+ }
290+
249291struct WidgetView_Preview : PreviewProvider {
250292 static var previews : some View {
251293 VStack {
@@ -288,3 +330,4 @@ struct WidgetView_Preview: PreviewProvider {
288330 . background ( Color . black)
289331 }
290332}
333+
0 commit comments