Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
furesoft committed Oct 11, 2024
1 parent e3391ee commit 546b270
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/MimaSim/MimaSim.Desktop/cache.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"input": "\"var hello = 1 + 2\\r\\n//hello\\r\\n\""
"input": "\"\""
}
54 changes: 54 additions & 0 deletions src/MimaSim/MimaSim/Behaviors/DocumentTextBindingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,58 @@ private void TextPropertyChanged(string text)
//_textEditor.CaretOffset = caretOffset;
}
}
}

public class HighlightingBindingBehavior : Behavior<TextEditor>
{
private TextEditor _textEditor;

public static readonly StyledProperty<string> HighlightingProperty =
AvaloniaProperty.Register<DocumentTextBindingBehavior, string>(nameof(Text));

public string Highlighting
{
get => GetValue(HighlightingProperty);
set => SetValue(HighlightingProperty, value);
}

protected override void OnAttached()
{
base.OnAttached();

if (AssociatedObject is TextEditor textEditor)
{
_textEditor = textEditor;
_textEditor.TextChanged += TextChanged;
this.GetObservable(HighlightingProperty).Subscribe(HighlightingPropertyChanged);
}
}

protected override void OnDetaching()
{
base.OnDetaching();

if (_textEditor != null)
{
_textEditor.TextChanged -= TextChanged;
}
}

private void TextChanged(object sender, EventArgs eventArgs)
{
if (_textEditor != null && _textEditor.Document != null)
{
Text = _textEditor.Document.Text;
}
}

private void HighlightingPropertyChanged(IHighlightingDefinition highlighting)

Check failure on line 105 in src/MimaSim/MimaSim/Behaviors/DocumentTextBindingBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHighlightingDefinition' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 105 in src/MimaSim/MimaSim/Behaviors/DocumentTextBindingBehavior.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHighlightingDefinition' could not be found (are you missing a using directive or an assembly reference?)
{
if (_textEditor != null && _textEditor.Document != null && text != null)
{
var caretOffset = _textEditor.CaretOffset;
_textEditor.Highlighting = highlighting;
//_textEditor.CaretOffset = caretOffset;
}
}
}
4 changes: 0 additions & 4 deletions src/MimaSim/MimaSim/Controls/ExecutionBar.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
<PathIcon Classes="tbchecked" Data="{StaticResource pause}" Width="20" Height="20" />
</Grid>
</ToggleButton>
<Button ToolTip.Tip="Schritt ausführen" IsEnabled="{Binding IsCompiled}"
Command="{Binding StepCommand}">
<PathIcon Data="{StaticResource continue}" Margin="2" Width="20" Height="20" />
</Button>
<Button ToolTip.Tip="Stoppen"
Command="{Binding StopCommand}">
<PathIcon Data="{StaticResource stop}" Margin="2" Width="20" Height="20" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:c="clr-namespace:MimaSim.Controls" x:CompileBindings="False"
xmlns:avaloniaEdit="https://github.com/avaloniaui/avaloniaedit"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:behaviors="clr-namespace:MimaSim.Behaviors"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" MinWidth="450"
x:Class="MimaSim.Controls.MimaComponents.Popups.DisassemblyViewPopupControl">
<c:DialogControl CommandText="OK" Header="Disassembler" Command="{Binding CloseCommand}" MaxWidth="500">
<StackPanel Spacing="2">
<CheckBox x:Name="hexDump">Hex Dump</CheckBox>

<avaloniaEdit:TextEditor x:Name="editor" IsVisible="{Binding !#hexDump.IsChecked}" MinWidth="100" MinHeight="350" MaxHeight="350" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto"
FontFamily="Cascadia Code,Consolas,Menlo,Monospace" Margin="0,5,0,5"
ShowLineNumbers="True">
<i:Interaction.Behaviors>
<behaviors:DocumentTextBindingBehavior Text="{Binding Disassembly, Mode=TwoWay}"/>
</i:Interaction.Behaviors>
</avaloniaEdit:TextEditor>

<TextBox IsVisible="{Binding !#hexDump.IsChecked}" Text="{Binding Disassembly}" TextWrapping="Wrap" IsReadOnly="True" MinWidth="100" MinHeight="350" MaxHeight="350" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" />
<TextBox IsVisible="{Binding #hexDump.IsChecked}" Text="{Binding Raw}" TextWrapping="Wrap" IsReadOnly="True" MinWidth="100" MinHeight="350" MaxHeight="350" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</StackPanel>
</c:DialogControl>
Expand Down
1 change: 1 addition & 0 deletions src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ShowLineNumbers="True">
<i:Interaction.Behaviors>
<behaviors:DocumentTextBindingBehavior Text="{Binding Source, Mode=TwoWay}"/>
<behaviors:HighlightingBindingBehavior Highlighting="{Binding Highlighting, Mode=TwoWay}"/>
</i:Interaction.Behaviors>
</avaloniaEdit:TextEditor>

Expand Down
4 changes: 2 additions & 2 deletions src/MimaSim/MimaSim/Controls/ProgramEditorControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ private void InitializeComponent()

private void InitHighlighting()
{
this.Find<TextEditor>("editor").SyntaxHighlighting = LoadHighlighting("Hochsprache", ".hoch", "Highligting_Hochsprache");
LoadHighlighting("Hochsprache", ".hoch", "Highligting_Hochsprache");
LoadHighlighting("Assembler", ".asm", "Highligting_Assembler");
}

private IHighlightingDefinition LoadHighlighting(string name, string extension, string filename)
Expand All @@ -44,7 +45,6 @@ private IHighlightingDefinition LoadHighlighting(string name, string extension,
}
}


HighlightingManager.Instance.RegisterHighlighting(name, new string[] { extension }, customHighlighting);

return customHighlighting;
Expand Down
2 changes: 0 additions & 2 deletions src/MimaSim/MimaSim/MIMA/Parsing/Parsers/Raw/RawParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace MimaSim.MIMA.Parsing.Parsers;

public class RawParser : Parser
{
private TokenEnumerator _enumerator;

protected override void InitLexer(LexerConfig lexer)
{
lexer.IgnoreWhitespace();
Expand Down
9 changes: 9 additions & 0 deletions src/MimaSim/MimaSim/ViewModels/ExecutionTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Avalonia.Platform.Storage;
using MimaSim.ViewModels.Mima;
using Splat;
using AvaloniaEdit.Highlighting;

namespace MimaSim.ViewModels;

Expand All @@ -25,6 +26,7 @@ public class ExecutionTabViewModel : ReactiveObject, IActivatableViewModel
private string? _source;
private string[] _sampleNames;
private bool _isCompiled;
private IHighlightingDefinition _highlighting;

public ObservableCollection<LanguageName> LanguageNames { get; }
public ViewModelActivator Activator => new();
Expand All @@ -48,6 +50,12 @@ public bool IsCompiled
set => this.RaiseAndSetIfChanged(ref _isCompiled, value);
}

public IHighlightingDefinition Highlighting
{
get => _highlighting;
set => this.RaiseAndSetIfChanged(ref _highlighting, value);
}

public LanguageName SelectedLanguage
{
get => _selectedLanguage;
Expand All @@ -58,6 +66,7 @@ public LanguageName SelectedLanguage
SampleNames = Locator.Current.GetService<SampleLoader>().GetSampleNamesFor(_selectedLanguage).ToArray();

SelectedSample = null;
Highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".hoch");
}
}

Expand Down

0 comments on commit 546b270

Please sign in to comment.