Custom Explorer Binding (Part 1)

This commit is contained in:
Kevin Zhang 2021-11-02 15:07:11 -05:00
parent 7dc5806a2d
commit 4eb36c8ba3
7 changed files with 181 additions and 85 deletions

View file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Flow.Launcher.ViewModel
{
public class CustomExplorerViewModel
{
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;
}
}

View file

@ -1,10 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Drawing; using System.Drawing;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Flow.Launcher.Plugin; using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedModels; using Flow.Launcher.Plugin.SharedModels;
using Flow.Launcher; using Flow.Launcher;
using Flow.Launcher.ViewModel;
namespace Flow.Launcher.Infrastructure.UserSettings namespace Flow.Launcher.Infrastructure.UserSettings
{ {
@ -37,6 +39,29 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public string ResultFontStretch { get; set; } public string ResultFontStretch { get; set; }
public bool UseGlyphIcons { get; set; } = true; public bool UseGlyphIcons { get; set; } = true;
public CustomExplorerViewModel CustomExplorer { get; set; }
public List<CustomExplorerViewModel> CustomExplorerList { get; set; } = new()
{
new()
{
Name = "Explorer",
Path = "explorer",
FileArgument = "/select, \"%f\"",
DirectoryArgument = "\"%d\"",
Editable = false
},
new()
{
Name = "Total Commander",
Path = @"C:\Program Files\TOTALCMD\totalcommander.exe"
},
new()
{
Name = "Dopus",
Path = @"c:\programe files\dopus\dopus.exe"
}
};
/// <summary> /// <summary>
/// when false Alphabet static service will always return empty results /// when false Alphabet static service will always return empty results

View file

@ -101,7 +101,7 @@ namespace Flow.Launcher
API.SaveAppAllSettings(); API.SaveAppAllSettings();
_mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible; _mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Collapsed : Visibility.Visible;
Log.Info("|App.OnStartup|End Flow Launcher startup ---------------------------------------------------- "); Log.Info("|App.OnStartup|End Flow Launcher startup ---------------------------------------------------- ");
}); });
} }

View file

@ -138,7 +138,8 @@
<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> <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>
<system:String x:Key="fileManager_name">File Manager</system:String> <system:String x:Key="fileManager_name">File Manager</system:String>
<system:String x:Key="fileManager_path">Path</system:String> <system:String x:Key="fileManager_path">Path</system:String>
<system:String x:Key="fileManager_arg">Argument</system:String> <system:String x:Key="fileManager_directory_arg">Argument For Directory</system:String>
<system:String x:Key="fileManager_file_arg">Argument For File Parent Directory</system:String>
<!--Priority Setting Dialog--> <!--Priority Setting Dialog-->
<system:String x:Key="changePriorityWindow">Change Priority</system:String> <system:String x:Key="changePriorityWindow">Change Priority</system:String>

View file

@ -2,112 +2,154 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Flow.Launcher"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019" xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:local="clr-namespace:Flow.Launcher" Title="{DynamicResource fileManagerWindow}"
mc:Ignorable="d" Width="500"
Height="420"
Background="#f3f3f3"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Title="{DynamicResource fileManagerWindow}" Height="420" Width="500" ResizeMode="NoResize" Background="#f3f3f3"> mc:Ignorable="d">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition /> <RowDefinition />
<RowDefinition Height="80"/> <RowDefinition Height="80" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Border BorderThickness="0 0 0 1" BorderBrush="#e5e5e5" Background="#ffffff" Padding="26 26 26 0"> <Border Padding="26,26,26,0"
Background="#ffffff"
BorderBrush="#e5e5e5"
BorderThickness="0,0,0,1">
<Grid> <Grid>
<StackPanel> <StackPanel>
<StackPanel Grid.Row="0" Margin="0 0 0 12"> <StackPanel Grid.Row="0" Margin="0,0,0,12">
<TextBlock Grid.Column="0" Text="{DynamicResource fileManagerWindow}" FontSize="20" FontWeight="SemiBold" FontFamily="Segoe UI" TextAlignment="Left" <TextBlock Grid.Column="0"
Margin="0 0 0 0" /> Margin="0,0,0,0"
FontFamily="Segoe UI"
FontSize="20"
FontWeight="SemiBold"
Text="{DynamicResource fileManagerWindow}"
TextAlignment="Left" />
</StackPanel> </StackPanel>
<StackPanel> <StackPanel>
<TextBlock <TextBlock FontSize="14"
Text="{DynamicResource fileManager_tips}" Foreground="#1b1b1b" FontSize="14" TextWrapping="WrapWithOverflow" TextAlignment="Left"/> Foreground="#1b1b1b"
Text="{DynamicResource fileManager_tips}"
TextAlignment="Left"
TextWrapping="WrapWithOverflow" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Horizontal" Margin="14 28 0 0"> <StackPanel Margin="14,28,0,0" Orientation="Horizontal">
<TextBlock FontSize="14" Grid.Column="1" VerticalAlignment="Center" <TextBlock Grid.Column="1"
HorizontalAlignment="Left" Text="{DynamicResource fileManager_name}" /> HorizontalAlignment="Left"
<ComboBox Height="35" SelectedIndex="0" HorizontalAlignment="Left" Margin="14 0 0 0" Name="comboBox" VerticalAlignment="Center" Width="200"> VerticalAlignment="Center"
<ComboBoxItem Content="Explorer (Default)" /> FontSize="14"
<ComboBoxItem Content="Custom" /> Text="{DynamicResource fileManager_name}" />
<ComboBoxItem Content="Files" /> <ComboBox Name="comboBox"
<ComboBoxItem Content="Directory Opus" /> Width="200"
<ComboBoxItem Content="Total Commander" /> Height="35"
Margin="14,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
ItemsSource="{Binding Settings.CustomExplorerList}"
SelectedIndex="0"
SelectedItem="{Binding Settings.CustomExplorer}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>
<Rectangle Margin="0 20 0 12" Height="1" Fill="#cecece"></Rectangle> <Rectangle Height="1" Margin="0,20,0,12" Fill="#cecece" />
<StackPanel Orientation="Horizontal" Margin="0 0 0 0" HorizontalAlignment="Stretch"> <StackPanel Margin="0,0,0,0"
HorizontalAlignment="Stretch"
DataContext="{Binding Settings.CustomExplorer}"
Orientation="Horizontal">
<Grid Width="430"> <Grid Width="430">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/> <ColumnDefinition Width="100" />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="50"/> <RowDefinition Height="50" />
<RowDefinition /> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock FontSize="14" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0" <TextBlock Grid.Row="0"
HorizontalAlignment="Left" Text="{DynamicResource fileManager_path}" Margin="14 0 0 0"/> Grid.Column="0"
<TextBox Margin="10 0 15 0" Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="0"> Margin="14,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource fileManager_path}" />
<TextBox Grid.Row="0"
Grid.Column="1"
Width="Auto"
Margin="10,0,15,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
IsEnabled="{Binding Editable}"
Text="{Binding Path}">
<TextBox.Style> <TextBox.Style>
<Style TargetType="TextBox"> <Style TargetType="TextBox">
<Setter Property="Background" Value="#ffffff"/> <Setter Property="Background" Value="#ffffff" />
<Setter Property="Height" Value="34"/> <Setter Property="Height" Value="34" />
<Setter Property="FontSize" Value="14"/> <Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="6 6 0 0"/> <Setter Property="Padding" Value="6,6,0,0" />
<Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#000000" />
<Setter Property="BorderBrush" Value="#000000"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="0">
<Setter Property="IsEnabled" Value="False"/>
<Setter Property="Text" Value=""/>
<Setter Property="Background" Value="#cecece"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="2">
<Setter Property="Text" Value="Files"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="3">
<Setter Property="Text" Value="c:\programe files\dopus\dopus.exe"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="4">
<Setter Property="Text" Value="C:\Program Files\TOTALCMD\totalcommander.exe"/>
</DataTrigger>
</Style.Triggers>
</Style> </Style>
</TextBox.Style> </TextBox.Style>
</TextBox> </TextBox>
<TextBlock Grid.Row="1"
Grid.Column="0"
Margin="14,0,0,0"
<TextBlock FontSize="14" VerticalAlignment="Center" Margin="14 0 0 0" HorizontalAlignment="Left"
HorizontalAlignment="Left" Text="{DynamicResource fileManager_arg}" Grid.Column="0" Grid.Row="1"/> VerticalAlignment="Center"
<TextBox Margin="10 0 15 0" Width="Auto" VerticalAlignment="Center" HorizontalAlignment="Stretch" Grid.Column="1" Grid.Row="1" > FontSize="14"
Text="{DynamicResource fileManager_directory_arg}" />
<TextBox Grid.Row="1"
Grid.Column="1"
Width="Auto"
Margin="10,0,15,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Text="{Binding DirectoryArgument}">
<TextBox.Style> <TextBox.Style>
<Style TargetType="TextBox"> <Style TargetType="TextBox">
<Setter Property="Background" Value="#ffffff"/> <Setter Property="Background" Value="#ffffff" />
<Setter Property="Height" Value="34"/> <Setter Property="Height" Value="34" />
<Setter Property="FontSize" Value="14"/> <Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="6 6 0 0"/> <Setter Property="Padding" Value="6,6,0,0" />
<Setter Property="VerticalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#000000" />
<Setter Property="BorderBrush" Value="#000000"/> </Style>
<Style.Triggers> </TextBox.Style>
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="0"> </TextBox>
<Setter Property="IsEnabled" Value="False"/> <TextBlock Grid.Row="1"
<Setter Property="Text" Value=""/> Grid.Column="0"
<Setter Property="Background" Value="#cecece"/> Margin="14,0,0,0"
</DataTrigger> HorizontalAlignment="Left"
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="2"> VerticalAlignment="Center"
<Setter Property="Text" Value=""/> FontSize="14"
</DataTrigger> Text="{DynamicResource fileManager_directory_arg}" />
<DataTrigger Binding="{Binding Path=SelectedIndex, ElementName=comboBox}" Value="3"> <TextBox Grid.Row="1"
<Setter Property="Text" Value=""/> Grid.Column="1"
</DataTrigger> Width="Auto"
</Style.Triggers> Margin="10,0,15,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Text="{Binding FileArgument}">
<TextBox.Style>
<Style TargetType="TextBox">
<Setter Property="Background" Value="#ffffff" />
<Setter Property="Height" Value="34" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="6,6,0,0" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="#000000" />
</Style> </Style>
</TextBox.Style> </TextBox.Style>
</TextBox> </TextBox>
@ -116,10 +158,16 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="1"> <StackPanel Grid.Row="1" HorizontalAlignment="Center" Orientation="Horizontal">
<Button x:Name="btnCancel" Margin="0 0 5 0" Width="100" Height="30" <Button x:Name="btnCancel"
Width="100"
Height="30"
Margin="0,0,5,0"
Content="{DynamicResource cancel}" /> Content="{DynamicResource cancel}" />
<Button x:Name="btnDone" Margin="5 0 0 0" Width="100" Height="30"> <Button x:Name="btnDone"
Width="100"
Height="30"
Margin="5,0,0,0">
<TextBlock x:Name="lblAdd" Text="{DynamicResource done}" /> <TextBlock x:Name="lblAdd" Text="{DynamicResource done}" />
</Button> </Button>
</StackPanel> </StackPanel>

View file

@ -1,4 +1,6 @@
using System; using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.ViewModel;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -19,8 +21,11 @@ namespace Flow.Launcher
/// </summary> /// </summary>
public partial class SelectFileManagerWindow : Window public partial class SelectFileManagerWindow : Window
{ {
public SelectFileManagerWindow() public Settings Settings { get; }
public SelectFileManagerWindow(Settings settings)
{ {
Settings = settings;
InitializeComponent(); InitializeComponent();
} }
} }

View file

@ -117,7 +117,7 @@ namespace Flow.Launcher
private void OnSelectFileManagerClick(object sender, RoutedEventArgs e) private void OnSelectFileManagerClick(object sender, RoutedEventArgs e)
{ {
SelectFileManagerWindow fileManagerChangeWindow = new SelectFileManagerWindow(); SelectFileManagerWindow fileManagerChangeWindow = new SelectFileManagerWindow(settings);
fileManagerChangeWindow.ShowDialog(); fileManagerChangeWindow.ShowDialog();
} }