Skip to content

Commit 0c5ad4d

Browse files
committed
Feature: Shrinker.Avalonia - Processed output can now be copied to the input pane.
1 parent 3696f69 commit 0c5ad4d

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

ShaderShrinker/Shrinker.Avalonia/ViewModels/MainWindowViewModel.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class MainWindowViewModel : ReactiveObject, IDisposable
2525
private ICommand m_importGlslClipboardCommand;
2626
private ICommand m_importGlslFileCommand;
2727
private CommandBase m_importGlslShadertoyCommand;
28+
private CommandBase m_copyLeftCommand;
2829
private string m_shadertoyId;
2930
private CommandBase m_shrinkCommand;
3031
private CommandBase m_exportGlslClipboardCommand;
@@ -96,6 +97,8 @@ public ICommand ExportGlslFileCommand
9697
}
9798
}
9899

100+
public ICommand CopyLeftCommand => m_copyLeftCommand ??= new RelayCommand(_ => ImportGlslFromRhs(), () => Diffs.HasRightContent());
101+
99102
public string ShadertoyId
100103
{
101104
get => m_shadertoyId ??= UserSettings.Instance.ShadertoyId;
@@ -130,9 +133,10 @@ public MainWindowViewModel()
130133

131134
Diffs.CollectionChanged += (_, _) =>
132135
{
133-
m_shrinkCommand.RaiseCanExecuteChanged();
134-
m_exportGlslClipboardCommand.RaiseCanExecuteChanged();
135-
m_exportGlslFileCommand.RaiseCanExecuteChanged();
136+
m_shrinkCommand?.RaiseCanExecuteChanged();
137+
m_exportGlslClipboardCommand?.RaiseCanExecuteChanged();
138+
m_exportGlslFileCommand?.RaiseCanExecuteChanged();
139+
m_copyLeftCommand?.RaiseCanExecuteChanged();
136140
};
137141
Hints.CollectionChanged += (_, _) =>
138142
{
@@ -155,6 +159,12 @@ private void ImportGlslFromFile(FileInfo file)
155159
ImportGlslFromString(File.ReadAllText(file.FullName));
156160
}
157161

162+
private void ImportGlslFromRhs()
163+
{
164+
var glsl = Diffs.GetAllRightText().WithAppMessage();
165+
ImportGlslFromString(glsl);
166+
}
167+
158168
private async void ImportGlslFromShadertoy(object o)
159169
{
160170
try

ShaderShrinker/Shrinker.Avalonia/Views/MainWindow.axaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@
152152

153153
<TextBlock Grid.Column="0" Grid.Row="0" Classes="Title" Text="Original" Margin="0,0,1,4"/>
154154
<TextBlock Grid.Column="1" Grid.Row="0" Classes="Title" Text="Output" Margin="1,0,0,4" />
155+
<Button Grid.Column="1" Grid.Row="0"
156+
HorizontalAlignment="Left" VerticalAlignment="Center"
157+
Padding="0" Margin="4,0,4,2"
158+
ToolTip.Tip="Copy to Left Pane"
159+
Command="{Binding CopyLeftCommand}">
160+
<Avalonia:MaterialIcon Kind="ChevronDoubleLeft" Width="16" Height="16"/>
161+
</Button>
155162

156163
<ScrollViewer Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1"
157164
VerticalScrollBarVisibility="Visible">
@@ -163,7 +170,7 @@
163170
<TextBlock Classes="LineNumber"
164171
Text="{Binding LeftLineNumber}"/>
165172
<Views:CodeLineControl Grid.Column="1"
166-
Diff="{Binding LeftDiff}" />
173+
Diff="{Binding LeftDiff}"/>
167174
</Grid>
168175
<Border Grid.Column="1" Background="#30000000"></Border>
169176
<Grid Grid.Column="2" ColumnDefinitions="30,*">
@@ -239,7 +246,7 @@
239246
Margin="8,0"
240247
VerticalAlignment="Center"
241248
Command="{Binding ShrinkCommand}"
242-
Content="Run"/>
249+
Content="Apply"/>
243250
</StackPanel>
244251

245252
<TextBlock Grid.Column="2"

0 commit comments

Comments
 (0)