Add add & delete feature

This commit is contained in:
Kevin Zhang 2021-11-06 01:04:37 -05:00
parent 1965ba1a08
commit 6e83e2e78f
3 changed files with 55 additions and 9 deletions

View file

@ -137,6 +137,7 @@
<system:String x:Key="fileManagerWindow">Select File Manager</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_profile_name">Profile Name</system:String>
<system:String x:Key="fileManager_path">Path</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>

View file

@ -61,6 +61,9 @@
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<Button Click="btnAdd_Click" Content="{DynamicResource add}" />
<Button Click="btnDelete_Click" Content="{DynamicResource delete}" IsEnabled="{Binding CustomExplorer.Editable}" />
</StackPanel>
<Rectangle Height="1" Margin="0,20,0,12" Fill="#cecece" />
<StackPanel Margin="0,0,0,0"
@ -73,7 +76,8 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
@ -83,8 +87,34 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource fileManager_path}" />
Text="{DynamicResource fileManager_profile_name}" />
<TextBox Grid.Row="0"
Grid.Column="1"
Width="Auto"
Margin="10,0,15,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
IsEnabled="{Binding Editable}"
Text="{Binding Name}">
<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>
</TextBox.Style>
</TextBox>
<TextBlock Grid.Row="1"
Grid.Column="0"
Margin="14,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource fileManager_path}" />
<TextBox Grid.Row="1"
Grid.Column="1"
Width="Auto"
Margin="10,0,15,0"
@ -103,14 +133,14 @@
</Style>
</TextBox.Style>
</TextBox>
<TextBlock Grid.Row="1"
<TextBlock Grid.Row="2"
Grid.Column="0"
Margin="14,15,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource fileManager_directory_arg}" />
<TextBox Grid.Row="1"
<TextBox Grid.Row="2"
Grid.Column="1"
Width="Auto"
Margin="10,15,15,0"
@ -129,14 +159,14 @@
</Style>
</TextBox.Style>
</TextBox>
<TextBlock Grid.Row="2"
<TextBlock Grid.Row="3"
Grid.Column="0"
Margin="14,15,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
FontSize="14"
Text="{DynamicResource fileManager_file_arg}" />
<TextBox Grid.Row="2"
<TextBox Grid.Row="3"
Grid.Column="1"
Width="Auto"
Margin="10,15,15,0"

View file

@ -2,6 +2,7 @@
using Flow.Launcher.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
@ -36,13 +37,13 @@ namespace Flow.Launcher
PropertyChanged?.Invoke(this, new(nameof(CustomExplorer)));
}
}
public List<CustomExplorerViewModel> CustomExplorers { get; set; }
public ObservableCollection<CustomExplorerViewModel> CustomExplorers { get; set; }
public CustomExplorerViewModel CustomExplorer => CustomExplorers[SelectedCustomExplorerIndex];
public SelectFileManagerWindow(Settings settings)
{
Settings = settings;
CustomExplorers = Settings.CustomExplorerList.Select(x => x.Copy()).ToList();
CustomExplorers = new ObservableCollection<CustomExplorerViewModel>(Settings.CustomExplorerList.Select(x => x.Copy()));
SelectedCustomExplorerIndex = Settings.CustomExplorerIndex;
InitializeComponent();
}
@ -55,8 +56,22 @@ namespace Flow.Launcher
private void btnDone_Click(object sender, RoutedEventArgs e)
{
Settings.CustomExplorerIndex = SelectedCustomExplorerIndex;
Settings.CustomExplorerList = CustomExplorers;
Settings.CustomExplorerList = CustomExplorers.ToList();
Close();
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
CustomExplorers.Add(new()
{
Name = "New Profile"
});
SelectedCustomExplorerIndex = CustomExplorers.Count - 1;
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
CustomExplorers.RemoveAt(SelectedCustomExplorerIndex--);
}
}
}