Skip to content

Commit 99d8575

Browse files
committed
File Explore Binding (Part 2)
1 parent b8d1611 commit 99d8575

File tree

5 files changed

+63
-13
lines changed

5 files changed

+63
-13
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1-
using System;
1+
using Flow.Launcher.Plugin;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
56
using System.Threading.Tasks;
67

78
namespace Flow.Launcher.ViewModel
89
{
9-
public class CustomExplorerViewModel
10+
public class CustomExplorerViewModel : BaseModel
1011
{
1112
public string Name { get; set; }
1213
public string Path { get; set; }
1314
public string FileArgument { get; set; } = "\"%d\"";
1415
public string DirectoryArgument { get; set; } = "\"%d\"";
1516
public bool Editable { get; init; } = true;
17+
18+
public CustomExplorerViewModel Copy()
19+
{
20+
return new CustomExplorerViewModel
21+
{
22+
Name = Name,
23+
Path = Path,
24+
FileArgument = FileArgument,
25+
DirectoryArgument = DirectoryArgument,
26+
Editable = Editable
27+
};
28+
}
1629
}
1730
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ public string Language
3838
public string ResultFontStretch { get; set; }
3939
public bool UseGlyphIcons { get; set; } = true;
4040

41-
public CustomExplorerViewModel CustomExplorer { get; set; }
41+
public int CustomExplorerIndex { get; set; } = 0;
42+
public CustomExplorerViewModel CustomExplorer
43+
{
44+
get => CustomExplorerList[CustomExplorerIndex];
45+
set => CustomExplorerList[CustomExplorerIndex] = value;
46+
}
47+
4248
public List<CustomExplorerViewModel> CustomExplorerList { get; set; } = new()
4349
{
4450
new()

Flow.Launcher/SelectFileManagerWindow.xaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@
5353
Margin="14,0,0,0"
5454
HorizontalAlignment="Left"
5555
VerticalAlignment="Center"
56-
ItemsSource="{Binding Settings.CustomExplorerList}"
57-
SelectedIndex="0"
58-
SelectedItem="{Binding Settings.CustomExplorer}">
56+
ItemsSource="{Binding CustomExplorers}"
57+
SelectedIndex="{Binding SelectedCustomExplorerIndex}">
5958
<ComboBox.ItemTemplate>
6059
<DataTemplate>
6160
<TextBlock Text="{Binding Name}" />
@@ -66,7 +65,7 @@
6665
<Rectangle Height="1" Margin="0,20,0,12" Fill="#cecece" />
6766
<StackPanel Margin="0,0,0,0"
6867
HorizontalAlignment="Stretch"
69-
DataContext="{Binding Settings.CustomExplorer}"
68+
DataContext="{Binding CustomExplorer}"
7069
Orientation="Horizontal">
7170
<Grid Width="430">
7271
<Grid.ColumnDefinitions>
@@ -163,13 +162,15 @@
163162
Width="100"
164163
Height="30"
165164
Margin="0,0,5,0"
166-
Content="{DynamicResource cancel}" />
165+
Content="{DynamicResource cancel}"
166+
Click="btnCancel_Click"/>
167167
<Button x:Name="btnDone"
168168
Width="100"
169169
Height="30"
170-
Margin="5,0,0,0">
171-
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
172-
</Button>
170+
Margin="5,0,0,0"
171+
Content="{DynamicResource done}"
172+
Click="btnDone_Click"
173+
/>
173174
</StackPanel>
174175
</Grid>
175176
</Window>

Flow.Launcher/SelectFileManagerWindow.xaml.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Flow.Launcher.ViewModel;
33
using System;
44
using System.Collections.Generic;
5+
using System.ComponentModel;
56
using System.Linq;
67
using System.Text;
78
using System.Threading.Tasks;
@@ -19,14 +20,43 @@ namespace Flow.Launcher
1920
/// <summary>
2021
/// SelectFileManagerWindow.xaml에 대한 상호 작용 논리
2122
/// </summary>
22-
public partial class SelectFileManagerWindow : Window
23+
public partial class SelectFileManagerWindow : Window, INotifyPropertyChanged
2324
{
25+
private int selectedCustomExplorerIndex;
26+
27+
public event PropertyChangedEventHandler PropertyChanged;
28+
2429
public Settings Settings { get; }
2530

31+
public int SelectedCustomExplorerIndex
32+
{
33+
get => selectedCustomExplorerIndex; set
34+
{
35+
selectedCustomExplorerIndex = value;
36+
PropertyChanged?.Invoke(this, new(nameof(CustomExplorer)));
37+
}
38+
}
39+
public List<CustomExplorerViewModel> CustomExplorers { get; set; }
40+
41+
public CustomExplorerViewModel CustomExplorer => CustomExplorers[SelectedCustomExplorerIndex];
2642
public SelectFileManagerWindow(Settings settings)
2743
{
2844
Settings = settings;
45+
CustomExplorers = Settings.CustomExplorerList.Select(x => x.Copy()).ToList();
46+
SelectedCustomExplorerIndex = Settings.CustomExplorerIndex;
2947
InitializeComponent();
3048
}
49+
50+
private void btnCancel_Click(object sender, RoutedEventArgs e)
51+
{
52+
Close();
53+
}
54+
55+
private void btnDone_Click(object sender, RoutedEventArgs e)
56+
{
57+
Settings.CustomExplorerIndex = SelectedCustomExplorerIndex;
58+
Settings.CustomExplorerList = CustomExplorers;
59+
Close();
60+
}
3161
}
3262
}

Flow.Launcher/SettingWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@
618618
</StackPanel>
619619
<StackPanel Grid.Column="2" Orientation="Horizontal">
620620
<Button Margin="10 0 18 0" MaxWidth="250" Width="160"
621-
Content="Explorer" Click="OnSelectFileManagerClick">
621+
Content="{Binding Settings.CustomExplorer.Name}" Click="OnSelectFileManagerClick">
622622
<Button.Resources>
623623
<Style TargetType="Border">
624624
<Setter Property="CornerRadius" Value="2"/>

0 commit comments

Comments
 (0)