|
27 | 27 | using System.Windows.Shapes; |
28 | 28 | using System.Windows.Threading; |
29 | 29 | using System.Xml; |
| 30 | + |
| 31 | +using PilotAIAssistantControl; |
30 | 32 | using RegExpressLibrary; |
31 | 33 | using RegExpressWPFNET.Code; |
32 | 34 | using Path = System.IO.Path; |
@@ -130,7 +132,7 @@ private async void Window_Loaded( object sender, RoutedEventArgs e ) |
130 | 132 | catch( Exception exc ) |
131 | 133 | { |
132 | 134 | _ = exc; |
133 | | - if (RegExpressLibrary.InternalConfig.HandleException( exc )) |
| 135 | + if( RegExpressLibrary.InternalConfig.HandleException( exc ) ) |
134 | 136 | throw; |
135 | 137 | } |
136 | 138 |
|
@@ -177,6 +179,13 @@ private async void Window_Loaded( object sender, RoutedEventArgs e ) |
177 | 179 | { |
178 | 180 | taskBarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None; |
179 | 181 | } |
| 182 | + |
| 183 | + // Import AI settings |
| 184 | + //all_tab_data.AIConfig = new(); |
| 185 | + ucAi.ImportData( all_tab_data.AIConfig ); |
| 186 | + if( all_tab_data.AITabOpen ) |
| 187 | + ucAi.IsExpanded = true; |
| 188 | + |
180 | 189 | } |
181 | 190 |
|
182 | 191 | // --- Delay effect |
@@ -210,7 +219,14 @@ private void tabControlMain_SelectionChanged( object sender, SelectionChangedEve |
210 | 219 | var old_metrics = old_uc_main.GetMetrics( ); |
211 | 220 | new_uc_main.ApplyMetrics( old_metrics, full: false ); |
212 | 221 | } |
| 222 | + if( new_uc_main != null ) |
| 223 | + { |
| 224 | + AiOptions.CurrentTab = new_uc_main; |
| 225 | + ucAi.Configure( AiOptions ); |
| 226 | + } |
| 227 | + |
213 | 228 | } |
| 229 | + OurIAIUIOptions AiOptions = new( ); |
214 | 230 |
|
215 | 231 |
|
216 | 232 | private void Window_Closing( object sender, System.ComponentModel.CancelEventArgs e ) |
@@ -429,6 +445,10 @@ void SaveAllTabData( ) |
429 | 445 | all_data.Tabs.Add( tab_data ); |
430 | 446 | } |
431 | 447 |
|
| 448 | + |
| 449 | + all_data.AIConfig = ucAi.ExportData( ); |
| 450 | + all_data.AITabOpen = ucAi.IsExpanded; |
| 451 | + |
432 | 452 | string json = JsonSerializer.Serialize( all_data, PluginLoader.JsonOptions ); |
433 | 453 | string my_file = GetMyDataFile( ); |
434 | 454 |
|
@@ -466,7 +486,7 @@ void SaveAllTabData( ) |
466 | 486 | catch( Exception exc ) |
467 | 487 | { |
468 | 488 | _ = exc; |
469 | | - if (InternalConfig.HandleException( exc )) |
| 489 | + if( InternalConfig.HandleException( exc ) ) |
470 | 490 | throw; |
471 | 491 |
|
472 | 492 | // ignore |
@@ -776,10 +796,54 @@ void GoToOptions( ) |
776 | 796 | } |
777 | 797 |
|
778 | 798 |
|
| 799 | + private void AiExpander_Expanded( object sender, RoutedEventArgs e ) |
| 800 | + { |
| 801 | + // Connect the AI panel to the current tab when expanded |
| 802 | + var uc_main = GetActiveUCMain( ); |
| 803 | + if( uc_main != null ) |
| 804 | + { |
| 805 | + AiOptions.CurrentTab = uc_main; |
| 806 | + ucAi.Configure( AiOptions ); |
| 807 | + } |
| 808 | + } |
| 809 | + |
| 810 | + |
779 | 811 | [GeneratedRegex( @"^Regex\s*(\d+)$" )] |
780 | 812 | private static partial Regex HeaderParserRegex( ); |
781 | 813 |
|
782 | 814 | #endregion |
783 | 815 |
|
| 816 | + |
| 817 | + |
| 818 | + public class OurIAIUIOptions : AIOptions |
| 819 | + { |
| 820 | + public override string HintForUserInput => "Ask about a regex or matching..."; |
| 821 | + public override string ReferenceTextDisplayName => "Target Text"; |
| 822 | + public override string FormatUserQuestion( string userQuestion ) => $"Current pattern:\n```{CurrentTab.CurrentRegexEngine?.AIPatternCodeblockType}\n{CurrentTab.ucPattern.GetTextData( "\n" ).Text}\n```\n\nMy question: {userQuestion}"; |
| 823 | + public UCMain? CurrentTab; |
| 824 | + |
| 825 | + public override string GetCurrentReferenceText( ) => CurrentTab?.ucText.GetTextData( "\n" ).Text; |
| 826 | + public override IEnumerable<ICodeblockAction> CodeblockActions => [ GenericCodeblockAction.ClipboardAction, |
| 827 | + new GenericCodeblockAction("📝 Use as Pattern", async ( block ) => |
| 828 | + { |
| 829 | + |
| 830 | + if( CurrentTab == null ) return false; |
| 831 | + CurrentTab.ucPattern.SetText( block.Code ); |
| 832 | + return true; |
| 833 | + } ) |
| 834 | + { |
| 835 | + Tooltip="Use this code block as the regex pattern", |
| 836 | + FeedbackOnAction="✓ Applied!" |
| 837 | + } |
| 838 | + ]; |
| 839 | + |
| 840 | + public override void HandleDebugMessage( string msg ) |
| 841 | + { |
| 842 | + if( InternalConfig.DEBUG_LOG_AI_MESSAGES ) |
| 843 | + System.Diagnostics.Debug.WriteLine( msg ); |
| 844 | + } |
| 845 | + |
| 846 | + public override string GetSystemPrompt( ) => CurrentTab?.CurrentRegexEngine?.GetSystemPrompt( ) ?? null; |
| 847 | + } |
784 | 848 | } |
785 | 849 | } |
0 commit comments