-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Settings window + ScriptConfigs add/remove
- Loading branch information
1 parent
5b23d7b
commit 23e4002
Showing
10 changed files
with
200 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/ScriptRunner/ScriptRunner.GUI/ViewModels/SettingsWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using ReactiveUI; | ||
using ScriptRunner.GUI.Settings; | ||
using ScriptRunner.GUI.Views; | ||
|
||
namespace ScriptRunner.GUI.ViewModels; | ||
|
||
public class SettingsWindowViewModel : ViewModelBase | ||
{ | ||
/// <summary> | ||
/// Contains records of configuration scripts loaded from settings file | ||
/// </summary> | ||
private ObservableCollection<ConfigScriptFileRow> _configScriptFiles; | ||
|
||
public ObservableCollection<ConfigScriptFileRow> ConfigScriptFiles | ||
{ | ||
get => _configScriptFiles; | ||
private set => this.RaiseAndSetIfChanged(ref _configScriptFiles, value); | ||
} | ||
|
||
public SettingsWindowViewModel() | ||
{ | ||
var configScripts = AppSettingsService.Load().ConfigScripts; | ||
ConfigScriptFiles = | ||
new ObservableCollection<ConfigScriptFileRow>(configScripts.Select(path => new ConfigScriptFileRow(path, SaveConfigScripts))); | ||
} | ||
|
||
public void AddNewConfigScriptRow() | ||
{ | ||
ConfigScriptFiles.Add(new ConfigScriptFileRow(string.Empty, SaveConfigScripts)); | ||
} | ||
|
||
public void RemoveConfigScript(ConfigScriptFileRow configScriptFileRow) | ||
{ | ||
AppSettingsService.RemoveScriptConfig(configScriptFileRow.Path); | ||
ConfigScriptFiles.Remove(configScriptFileRow); | ||
} | ||
|
||
private void SaveConfigScripts() | ||
{ | ||
AppSettingsService.UpdateScriptConfigs(ConfigScriptFiles.Select(q => q.Path)); | ||
} | ||
} | ||
|
||
public class ConfigScriptFileRow | ||
{ | ||
public string Path { get; set; } | ||
|
||
// TODO: Check if file path is correct and mark this flag | ||
public bool Exists { get; set; } | ||
|
||
public Action UpdateConfigScriptEntry; | ||
|
||
public ConfigScriptFileRow(string path, Action updateConfigScriptEntry) | ||
{ | ||
Path = path; | ||
UpdateConfigScriptEntry = updateConfigScriptEntry; | ||
} | ||
|
||
private void OnFilePicked(FilePickedArgs args) | ||
{ | ||
Path = args.Path; | ||
UpdateConfigScriptEntry.Invoke(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/ScriptRunner/ScriptRunner.GUI/Views/SettingsWindow.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:vm="clr-namespace:ScriptRunner.GUI.ViewModels" | ||
xmlns:views="clr-namespace:ScriptRunner.GUI.Views" | ||
xmlns:avalonia="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia" | ||
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450" | ||
Width="600" Height="450" | ||
x:Class="ScriptRunner.GUI.Views.SettingsWindow" | ||
Title="Settings" | ||
Icon="/Assets/avalonia-logo.ico" | ||
FontFamily="Segoe UI Variable"> | ||
<Design.DataContext> | ||
<vm:SettingsWindowViewModel /> | ||
</Design.DataContext> | ||
|
||
<StackPanel Orientation="Vertical" Margin="5"> | ||
<TextBlock Classes="h2" Text="Config sources:" Margin="0, 5"/> | ||
<ItemsControl Items="{Binding ConfigScriptFiles}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*" /> | ||
<ColumnDefinition Width="100" /> | ||
</Grid.ColumnDefinitions> | ||
<views:FilePicker Grid.Column="0" Name="FilePicker" FilePath="{Binding Path}"> | ||
<Interaction.Behaviors> | ||
<EventTriggerBehavior EventName="OnFilePicked" SourceObject="{Binding #FilePicker}"> | ||
<InvokeCommandAction Command="{Binding OnFilePicked}" PassEventArgsToCommand="True"/> | ||
</EventTriggerBehavior> | ||
</Interaction.Behaviors> | ||
</views:FilePicker> | ||
<Button Grid.Column="1" avalonia:Attached.Icon="fa fa-trash" FontSize="18" Margin="10,0" | ||
Command="{Binding DataContext.RemoveConfigScript, RelativeSource={RelativeSource AncestorType={x:Type views:SettingsWindow}}}" | ||
CommandParameter="{Binding}"/> | ||
</Grid> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
<Button Command="{Binding AddNewConfigScriptRow}"> | ||
<StackPanel Orientation="Horizontal"> | ||
<avalonia:Icon Value="fa fa-plus" Margin="4,0"/> | ||
<TextBlock>Add new config script</TextBlock> | ||
</StackPanel> | ||
</Button> | ||
</StackPanel> | ||
|
||
</Window> |
24 changes: 24 additions & 0 deletions
24
src/ScriptRunner/ScriptRunner.GUI/Views/SettingsWindow.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using ScriptRunner.GUI.ViewModels; | ||
|
||
namespace ScriptRunner.GUI.Views | ||
{ | ||
public partial class SettingsWindow : Window | ||
{ | ||
public SettingsWindow() | ||
{ | ||
InitializeComponent(); | ||
DataContext = new SettingsWindowViewModel(); | ||
#if DEBUG | ||
this.AttachDevTools(); | ||
#endif | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} | ||
} |