From a69f4a7ea636fd8acc4f2117886bb574f20586d3 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 5 Nov 2021 14:16:20 -0500 Subject: [PATCH] File Explore Binding (Part 2) --- .../UserSettings/CustomExplorerViewModel.cs | 17 ++++++++-- .../UserSettings/Settings.cs | 8 ++++- Flow.Launcher/SelectFileManagerWindow.xaml | 17 +++++----- Flow.Launcher/SelectFileManagerWindow.xaml.cs | 32 ++++++++++++++++++- Flow.Launcher/SettingWindow.xaml | 2 +- 5 files changed, 63 insertions(+), 13 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs index 4fd5e317a..7806debe1 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomExplorerViewModel.cs @@ -1,4 +1,5 @@ -using System; +using Flow.Launcher.Plugin; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,12 +7,24 @@ using System.Threading.Tasks; namespace Flow.Launcher.ViewModel { - public class CustomExplorerViewModel + public class CustomExplorerViewModel : BaseModel { public string Name { get; set; } public string Path { get; set; } public string FileArgument { get; set; } = "\"%d\""; public string DirectoryArgument { get; set; } = "\"%d\""; public bool Editable { get; init; } = true; + + public CustomExplorerViewModel Copy() + { + return new CustomExplorerViewModel + { + Name = Name, + Path = Path, + FileArgument = FileArgument, + DirectoryArgument = DirectoryArgument, + Editable = Editable + }; + } } } diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 53ced1524..f753a4a1a 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -39,7 +39,13 @@ namespace Flow.Launcher.Infrastructure.UserSettings public string ResultFontStretch { get; set; } public bool UseGlyphIcons { get; set; } = true; - public CustomExplorerViewModel CustomExplorer { get; set; } + public int CustomExplorerIndex { get; set; } = 0; + public CustomExplorerViewModel CustomExplorer + { + get => CustomExplorerList[CustomExplorerIndex]; + set => CustomExplorerList[CustomExplorerIndex] = value; + } + public List CustomExplorerList { get; set; } = new() { new() diff --git a/Flow.Launcher/SelectFileManagerWindow.xaml b/Flow.Launcher/SelectFileManagerWindow.xaml index 55eceae27..ff472f007 100644 --- a/Flow.Launcher/SelectFileManagerWindow.xaml +++ b/Flow.Launcher/SelectFileManagerWindow.xaml @@ -53,9 +53,8 @@ Margin="14,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" - ItemsSource="{Binding Settings.CustomExplorerList}" - SelectedIndex="0" - SelectedItem="{Binding Settings.CustomExplorer}"> + ItemsSource="{Binding CustomExplorers}" + SelectedIndex="{Binding SelectedCustomExplorerIndex}"> @@ -66,7 +65,7 @@ @@ -163,13 +162,15 @@ Width="100" Height="30" Margin="0,0,5,0" - Content="{DynamicResource cancel}" /> + Content="{DynamicResource cancel}" + Click="btnCancel_Click"/> + Margin="5,0,0,0" + Content="{DynamicResource done}" + Click="btnDone_Click" + /> diff --git a/Flow.Launcher/SelectFileManagerWindow.xaml.cs b/Flow.Launcher/SelectFileManagerWindow.xaml.cs index 429ccec49..7ac8dc1cf 100644 --- a/Flow.Launcher/SelectFileManagerWindow.xaml.cs +++ b/Flow.Launcher/SelectFileManagerWindow.xaml.cs @@ -2,6 +2,7 @@ using Flow.Launcher.ViewModel; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -19,14 +20,43 @@ namespace Flow.Launcher /// /// SelectFileManagerWindow.xaml에 대한 상호 작용 논리 /// - public partial class SelectFileManagerWindow : Window + public partial class SelectFileManagerWindow : Window, INotifyPropertyChanged { + private int selectedCustomExplorerIndex; + + public event PropertyChangedEventHandler PropertyChanged; + public Settings Settings { get; } + public int SelectedCustomExplorerIndex + { + get => selectedCustomExplorerIndex; set + { + selectedCustomExplorerIndex = value; + PropertyChanged?.Invoke(this, new(nameof(CustomExplorer))); + } + } + public List CustomExplorers { get; set; } + + public CustomExplorerViewModel CustomExplorer => CustomExplorers[SelectedCustomExplorerIndex]; public SelectFileManagerWindow(Settings settings) { Settings = settings; + CustomExplorers = Settings.CustomExplorerList.Select(x => x.Copy()).ToList(); + SelectedCustomExplorerIndex = Settings.CustomExplorerIndex; InitializeComponent(); } + + private void btnCancel_Click(object sender, RoutedEventArgs e) + { + Close(); + } + + private void btnDone_Click(object sender, RoutedEventArgs e) + { + Settings.CustomExplorerIndex = SelectedCustomExplorerIndex; + Settings.CustomExplorerList = CustomExplorers; + Close(); + } } } diff --git a/Flow.Launcher/SettingWindow.xaml b/Flow.Launcher/SettingWindow.xaml index 8e9bc8042..e8064a421 100644 --- a/Flow.Launcher/SettingWindow.xaml +++ b/Flow.Launcher/SettingWindow.xaml @@ -618,7 +618,7 @@