Skip to content

Commit 4eb36c8

Browse files
committed
Custom Explorer Binding (Part 1)
1 parent 7dc5806 commit 4eb36c8

File tree

7 files changed

+181
-85
lines changed

7 files changed

+181
-85
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Flow.Launcher.ViewModel
8+
{
9+
public class CustomExplorerViewModel
10+
{
11+
public string Name { get; set; }
12+
public string Path { get; set; }
13+
public string FileArgument { get; set; } = "\"%d\"";
14+
public string DirectoryArgument { get; set; } = "\"%d\"";
15+
public bool Editable { get; init; } = true;
16+
}
17+
}

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Collections.ObjectModel;
34
using System.Drawing;
45
using System.Text.Json.Serialization;
56
using Flow.Launcher.Plugin;
67
using Flow.Launcher.Plugin.SharedModels;
78
using Flow.Launcher;
9+
using Flow.Launcher.ViewModel;
810

911
namespace Flow.Launcher.Infrastructure.UserSettings
1012
{
@@ -37,6 +39,29 @@ public string Language
3739
public string ResultFontStretch { get; set; }
3840
public bool UseGlyphIcons { get; set; } = true;
3941

42+
public CustomExplorerViewModel CustomExplorer { get; set; }
43+
public List<CustomExplorerViewModel> CustomExplorerList { get; set; } = new()
44+
{
45+
new()
46+
{
47+
Name = "Explorer",
48+
Path = "explorer",
49+
FileArgument = "/select, \"%f\"",
50+
DirectoryArgument = "\"%d\"",
51+
Editable = false
52+
},
53+
new()
54+
{
55+
Name = "Total Commander",
56+
Path = @"C:\Program Files\TOTALCMD\totalcommander.exe"
57+
},
58+
new()
59+
{
60+
Name = "Dopus",
61+
Path = @"c:\programe files\dopus\dopus.exe"
62+
}
63+
};
64+
4065

4166
/// <summary>
4267
/// when false Alphabet static service will always return empty results

Flow.Launcher/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
101101

102102
API.SaveAppAllSettings();
103103

104-
_mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
104+
_mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Collapsed : Visibility.Visible;
105105
Log.Info("|App.OnStartup|End Flow Launcher startup ---------------------------------------------------- ");
106106
});
107107
}

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@
138138
<system:String x:Key="fileManager_tips">Please specify the file location of the file manager you using and add arguments (optional) if necessary.</system:String>
139139
<system:String x:Key="fileManager_name">File Manager</system:String>
140140
<system:String x:Key="fileManager_path">Path</system:String>
141-
<system:String x:Key="fileManager_arg">Argument</system:String>
141+
<system:String x:Key="fileManager_directory_arg">Argument For Directory</system:String>
142+
<system:String x:Key="fileManager_file_arg">Argument For File Parent Directory</system:String>
142143

143144
<!--Priority Setting Dialog-->
144145
<system:String x:Key="changePriorityWindow">Change Priority</system:String>

Flow.Launcher/SelectFileManagerWindow.xaml

Lines changed: 128 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,154 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:local="clr-namespace:Flow.Launcher"
56
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
67
xmlns:ui="http://schemas.modernwpf.com/2019"
7-
xmlns:local="clr-namespace:Flow.Launcher"
8-
mc:Ignorable="d"
8+
Title="{DynamicResource fileManagerWindow}"
9+
Width="500"
10+
Height="420"
11+
Background="#f3f3f3"
12+
DataContext="{Binding RelativeSource={RelativeSource Self}}"
13+
ResizeMode="NoResize"
914
WindowStartupLocation="CenterScreen"
10-
Title="{DynamicResource fileManagerWindow}" Height="420" Width="500" ResizeMode="NoResize" Background="#f3f3f3">
15+
mc:Ignorable="d">
1116
<Grid>
1217
<Grid.RowDefinitions>
1318
<RowDefinition />
14-
<RowDefinition Height="80"/>
19+
<RowDefinition Height="80" />
1520
</Grid.RowDefinitions>
16-
<Border BorderThickness="0 0 0 1" BorderBrush="#e5e5e5" Background="#ffffff" Padding="26 26 26 0">
21+
<Border Padding="26,26,26,0"
22+
Background="#ffffff"
23+
BorderBrush="#e5e5e5"
24+
BorderThickness="0,0,0,1">
1725
<Grid>
1826
<StackPanel>
19-
<StackPanel Grid.Row="0" Margin="0 0 0 12">
20-
<TextBlock Grid.Column="0" Text="{DynamicResource fileManagerWindow}" FontSize="20" FontWeight="SemiBold" FontFamily="Segoe UI" TextAlignment="Left"
21-
Margin="0 0 0 0" />
27+
<StackPanel Grid.Row="0" Margin="0,0,0,12">
28+
<TextBlock Grid.Column="0"
29+
Margin="0,0,0,0"
30+
FontFamily="Segoe UI"
31+
FontSize="20"
32+
FontWeight="SemiBold"
33+
Text="{DynamicResource fileManagerWindow}"
34+
TextAlignment="Left" />
2235
</StackPanel>
2336
<StackPanel>
24-
<TextBlock
25-
Text="{DynamicResource fileManager_tips}" Foreground="#1b1b1b" FontSize="14" TextWrapping="WrapWithOverflow" TextAlignment="Left"/>
37+
<TextBlock FontSize="14"
38+
Foreground="#1b1b1b"
39+
Text="{DynamicResource fileManager_tips}"
40+
TextAlignment="Left"
41+
TextWrapping="WrapWithOverflow" />
2642
</StackPanel>
2743

28-
<StackPanel Orientation="Horizontal" Margin="14 28 0 0">
29-
<TextBlock FontSize="14" Grid.Column="1" VerticalAlignment="Center"
30-
HorizontalAlignment="Left" Text="{DynamicResource fileManager_name}" />
31-
<ComboBox Height="35" SelectedIndex="0" HorizontalAlignment="Left" Margin="14 0 0 0" Name="comboBox" VerticalAlignment="Center" Width="200">
32-
<ComboBoxItem Content="Explorer (Default)" />
33-
<ComboBoxItem Content="Custom" />
34-
<ComboBoxItem Content="Files" />
35-
<ComboBoxItem Content="Directory Opus" />
36-
<ComboBoxItem Content="Total Commander" />
44+
<StackPanel Margin="14,28,0,0" Orientation="Horizontal">
45+
<TextBlock Grid.Column="1"
46+
HorizontalAlignment="Left"
47+
VerticalAlignment="Center"
48+
FontSize="14"
49+
Text="{DynamicResource fileManager_name}" />
50+
<ComboBox Name="comboBox"
51+
Width="200"
52+
Height="35"
53+
Margin="14,0,0,0"
54+
HorizontalAlignment="Left"
55+
VerticalAlignment="Center"
56+
ItemsSource="{Binding Settings.CustomExplorerList}"
57+
SelectedIndex="0"
58+
SelectedItem="{Binding Settings.CustomExplorer}">
59+
<ComboBox.ItemTemplate>
60+
<DataTemplate>
61+
<TextBlock Text="{Binding Name}" />
62+
</DataTemplate>
63+
</ComboBox.ItemTemplate>
3764
</ComboBox>
3865
</StackPanel>
39-
<Rectangle Margin="0 20 0 12" Height="1" Fill="#cecece"></Rectangle>
40-
<StackPanel Orientation="Horizontal" Margin="0 0 0 0" HorizontalAlignment="Stretch">
66+
<Rectangle Height="1" Margin="0,20,0,12" Fill="#cecece" />
67+
<StackPanel Margin="0,0,0,0"
68+
HorizontalAlignment="Stretch"
69+
DataContext="{Binding Settings.CustomExplorer}"
70+
Orientation="Horizontal">
4171
<Grid Width="430">
4272
<Grid.ColumnDefinitions>
43-
<ColumnDefinition Width="100"/>
73+
<ColumnDefinition Width="100" />
4474
<ColumnDefinition />
4575
</Grid.ColumnDefinitions>
4676
<Grid.RowDefinitions>
47-
<RowDefinition Height="50"/>
77+
<RowDefinition Height="50" />
4878
<RowDefinition />
4979
</Grid.RowDefinitions>
50-
<TextBlock FontSize="14" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0"
51-
HorizontalAlignment="Left" Text="{DynamicResource fileManager_path}" Margin="14 0 0 0"/>
52-
<TextBox Margin="10 0 15 0" Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0">
80+
<TextBlock Grid.Row="0"
81+
Grid.Column="0"
82+
Margin="14,0,0,0"
83+
HorizontalAlignment="Left"
84+
VerticalAlignment="Center"
85+
FontSize="14"
86+
Text="{DynamicResource fileManager_path}" />
87+
<TextBox Grid.Row="0"
88+
Grid.Column="1"
89+
Width="Auto"
90+
Margin="10,0,15,0"
91+
HorizontalAlignment="Stretch"
92+
VerticalAlignment="Center"
93+
IsEnabled="{Binding Editable}"
94+
Text="{Binding Path}">
5395
<TextBox.Style>
5496
<Style TargetType="TextBox">
55-
<Setter Property="Background" Value="#ffffff"/>
56-
<Setter Property="Height" Value="34"/>
57-
<Setter Property="FontSize" Value="14"/>
58-
<Setter Property="Padding" Value="6 6 0 0"/>
59-
<Setter Property="VerticalAlignment" Value="Center"/>
60-
61-
<Setter Property="BorderBrush" Value="#000000"/>
62-
<Style.Triggers>
63-
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="0">
64-
<Setter Property="IsEnabled" Value="False"/>
65-
<Setter Property="Text" Value=""/>
66-
<Setter Property="Background" Value="#cecece"/>
67-
</DataTrigger>
68-
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="2">
69-
<Setter Property="Text" Value="Files"/>
70-
71-
</DataTrigger>
72-
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="3">
73-
<Setter Property="Text" Value="c:\programe files\dopus\dopus.exe"/>
74-
</DataTrigger>
75-
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="4">
76-
<Setter Property="Text" Value="C:\Program Files\TOTALCMD\totalcommander.exe"/>
77-
</DataTrigger>
78-
</Style.Triggers>
97+
<Setter Property="Background" Value="#ffffff" />
98+
<Setter Property="Height" Value="34" />
99+
<Setter Property="FontSize" Value="14" />
100+
<Setter Property="Padding" Value="6,6,0,0" />
101+
<Setter Property="VerticalAlignment" Value="Center" />
102+
<Setter Property="BorderBrush" Value="#000000" />
79103
</Style>
80104
</TextBox.Style>
81-
82105
</TextBox>
83-
84-
85-
86-
<TextBlock FontSize="14" VerticalAlignment="Center" Margin="14 0 0 0"
87-
HorizontalAlignment="Left" Text="{DynamicResource fileManager_arg}" Grid.Column="0" Grid.Row="1"/>
88-
<TextBox Margin="10 0 15 0" Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="1" >
106+
<TextBlock Grid.Row="1"
107+
Grid.Column="0"
108+
Margin="14,0,0,0"
109+
HorizontalAlignment="Left"
110+
VerticalAlignment="Center"
111+
FontSize="14"
112+
Text="{DynamicResource fileManager_directory_arg}" />
113+
<TextBox Grid.Row="1"
114+
Grid.Column="1"
115+
Width="Auto"
116+
Margin="10,0,15,0"
117+
HorizontalAlignment="Stretch"
118+
VerticalAlignment="Center"
119+
Text="{Binding DirectoryArgument}">
89120
<TextBox.Style>
90121
<Style TargetType="TextBox">
91-
<Setter Property="Background" Value="#ffffff"/>
92-
<Setter Property="Height" Value="34"/>
93-
<Setter Property="FontSize" Value="14"/>
94-
<Setter Property="Padding" Value="6 6 0 0"/>
95-
<Setter Property="VerticalAlignment" Value="Center"/>
96-
97-
<Setter Property="BorderBrush" Value="#000000"/>
98-
<Style.Triggers>
99-
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="0">
100-
<Setter Property="IsEnabled" Value="False"/>
101-
<Setter Property="Text" Value=""/>
102-
<Setter Property="Background" Value="#cecece"/>
103-
</DataTrigger>
104-
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="2">
105-
<Setter Property="Text" Value=""/>
106-
</DataTrigger>
107-
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="3">
108-
<Setter Property="Text" Value=""/>
109-
</DataTrigger>
110-
</Style.Triggers>
122+
<Setter Property="Background" Value="#ffffff" />
123+
<Setter Property="Height" Value="34" />
124+
<Setter Property="FontSize" Value="14" />
125+
<Setter Property="Padding" Value="6,6,0,0" />
126+
<Setter Property="VerticalAlignment" Value="Center" />
127+
<Setter Property="BorderBrush" Value="#000000" />
128+
</Style>
129+
</TextBox.Style>
130+
</TextBox>
131+
<TextBlock Grid.Row="1"
132+
Grid.Column="0"
133+
Margin="14,0,0,0"
134+
HorizontalAlignment="Left"
135+
VerticalAlignment="Center"
136+
FontSize="14"
137+
Text="{DynamicResource fileManager_directory_arg}" />
138+
<TextBox Grid.Row="1"
139+
Grid.Column="1"
140+
Width="Auto"
141+
Margin="10,0,15,0"
142+
HorizontalAlignment="Stretch"
143+
VerticalAlignment="Center"
144+
Text="{Binding FileArgument}">
145+
<TextBox.Style>
146+
<Style TargetType="TextBox">
147+
<Setter Property="Background" Value="#ffffff" />
148+
<Setter Property="Height" Value="34" />
149+
<Setter Property="FontSize" Value="14" />
150+
<Setter Property="Padding" Value="6,6,0,0" />
151+
<Setter Property="VerticalAlignment" Value="Center" />
152+
<Setter Property="BorderBrush" Value="#000000" />
111153
</Style>
112154
</TextBox.Style>
113155
</TextBox>
@@ -116,10 +158,16 @@
116158
</StackPanel>
117159
</Grid>
118160
</Border>
119-
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="1">
120-
<Button x:Name="btnCancel" Margin="0 0 5 0" Width="100" Height="30"
161+
<StackPanel Grid.Row="1" HorizontalAlignment="Center" Orientation="Horizontal">
162+
<Button x:Name="btnCancel"
163+
Width="100"
164+
Height="30"
165+
Margin="0,0,5,0"
121166
Content="{DynamicResource cancel}" />
122-
<Button x:Name="btnDone" Margin="5 0 0 0" Width="100" Height="30">
167+
<Button x:Name="btnDone"
168+
Width="100"
169+
Height="30"
170+
Margin="5,0,0,0">
123171
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
124172
</Button>
125173
</StackPanel>

Flow.Launcher/SelectFileManagerWindow.xaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
using Flow.Launcher.Infrastructure.UserSettings;
2+
using Flow.Launcher.ViewModel;
3+
using System;
24
using System.Collections.Generic;
35
using System.Linq;
46
using System.Text;
@@ -19,8 +21,11 @@ namespace Flow.Launcher
1921
/// </summary>
2022
public partial class SelectFileManagerWindow : Window
2123
{
22-
public SelectFileManagerWindow()
24+
public Settings Settings { get; }
25+
26+
public SelectFileManagerWindow(Settings settings)
2327
{
28+
Settings = settings;
2429
InitializeComponent();
2530
}
2631
}

0 commit comments

Comments
 (0)