forked from paulirwin/JavaToCSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.axaml.cs
More file actions
69 lines (58 loc) · 2.27 KB
/
Copy pathMainWindow.axaml.cs
File metadata and controls
69 lines (58 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Styling;
using AvaloniaEdit;
using AvaloniaEdit.TextMate;
using JavaToCSharpGui.Infrastructure;
using JavaToCSharpGui.ViewModels;
using TextMateSharp.Grammars;
namespace JavaToCSharpGui.Views;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
protected override void OnOpened(EventArgs e)
{
base.OnOpened(e);
IHostStorageProvider storageProvider = new HostStorageProvider(StorageProvider);
IUIDispatcher dispatcher = new UIDispatcher(Avalonia.Threading.Dispatcher.UIThread);
ITextClipboard clipboard = new TextClipboard(Clipboard);
var vm = new MainWindowViewModel(storageProvider, dispatcher, clipboard);
DataContext = vm;
ConfigureEditors();
InstallTextMate();
}
private void ConfigureEditors()
{
ConfigureEditor(JavaTextEditor);
ConfigureEditor(CSharpTextEditor);
}
private static void ConfigureEditor(ITextEditorComponent editor)
{
// TODO.PI: make these options in settings for people with odd preferences
editor.Options.ConvertTabsToSpaces = true;
editor.Options.IndentationSize = 4;
}
private void InstallTextMate()
{
var appTheme = Application.Current?.ActualThemeVariant ?? ThemeVariant.Dark;
var registryOptions = new RegistryOptions(appTheme == ThemeVariant.Dark ? ThemeName.DarkPlus : ThemeName.LightPlus);
var javaTextMate = JavaTextEditor.InstallTextMate(registryOptions);
javaTextMate.SetGrammar(registryOptions.GetScopeByLanguageId(registryOptions.GetLanguageByExtension(".java").Id));
var csharpTextMate = CSharpTextEditor.InstallTextMate(registryOptions);
csharpTextMate.SetGrammar(registryOptions.GetScopeByLanguageId(registryOptions.GetLanguageByExtension(".cs").Id));
}
private void ToggleButton_OnIsCheckedChanged(object sender, RoutedEventArgs e)
{
var app = Application.Current;
if (app is not null)
{
var theme = app.ActualThemeVariant;
app.RequestedThemeVariant = theme == ThemeVariant.Dark ? ThemeVariant.Light : ThemeVariant.Dark;
InstallTextMate();
}
}
}