Implement editing

This commit is contained in:
Kevin Zhang 2021-09-23 13:32:10 -05:00
parent 672616ef62
commit e5e8c48d51
5 changed files with 54 additions and 17 deletions

View file

@ -2,7 +2,25 @@
{ {
public class CustomBrowser : BaseModel public class CustomBrowser : BaseModel
{ {
public string Name { get; set; } private string _name;
public string DataDirectoryPath { get; set; } private string _dataDirectoryPath;
public string Name
{
get => _name;
set
{
_name = value;
OnPropertyChanged(nameof(Name));
}
}
public string DataDirectoryPath
{
get => _dataDirectoryPath;
set
{
_dataDirectoryPath = value;
OnPropertyChanged(nameof(DataDirectoryPath));
}
}
} }
} }

View file

@ -6,6 +6,7 @@
xmlns:local="clr-namespace:Flow.Launcher.Plugin.BrowserBookmark.Models" xmlns:local="clr-namespace:Flow.Launcher.Plugin.BrowserBookmark.Models"
mc:Ignorable="d" mc:Ignorable="d"
Title="CustomBrowserSetting" Height="450" Width="600" Title="CustomBrowserSetting" Height="450" Width="600"
KeyDown="WindowKeyDown"
> >
<Window.DataContext> <Window.DataContext>
<local:CustomBrowser/> <local:CustomBrowser/>
@ -21,13 +22,13 @@
<ColumnDefinition Width="6*"/> <ColumnDefinition Width="6*"/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Browser Name" FontSize="15" <TextBlock Grid.Row="0" Grid.Column="0" Text="Browser Name" FontSize="15"
HorizontalAlignment="Center" VerticalAlignment="Center"/> HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Browser Data Directory Path" FontSize="15" <TextBlock Grid.Row="1" Grid.Column="0" Text="Browser Data Directory Path" FontSize="15"
HorizontalAlignment="Center" VerticalAlignment="Center"/> HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name}" <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name}"
HorizontalAlignment="Center" VerticalAlignment="Center" Width="100" Height="30"/> HorizontalAlignment="Left" VerticalAlignment="Center" Width="100" Height="30"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding DataDirectoryPath}" <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding DataDirectoryPath}"
HorizontalAlignment="Center" VerticalAlignment="Center" Width="200" Height="30"/> HorizontalAlignment="Left" VerticalAlignment="Center" Width="200" Height="30"/>
<StackPanel HorizontalAlignment="Right" Grid.Row="2" Orientation="Horizontal" Grid.Column="1" Height="60"> <StackPanel HorizontalAlignment="Right" Grid.Row="2" Orientation="Horizontal" Grid.Column="1" Height="60">
<Button Content="Confirm" Margin="15" Click="ConfirmEditCustomBrowser"/> <Button Content="Confirm" Margin="15" Click="ConfirmEditCustomBrowser"/>
<Button Content="Cancel" Margin="15"/> <Button Content="Cancel" Margin="15"/>

View file

@ -27,8 +27,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
currentCustomBrowser = browser; currentCustomBrowser = browser;
DataContext = new CustomBrowser DataContext = new CustomBrowser
{ {
Name = browser.Name, Name = browser.Name, DataDirectoryPath = browser.DataDirectoryPath
DataDirectoryPath = browser.DataDirectoryPath
}; };
} }
@ -41,5 +40,12 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
} }
Close(); Close();
} }
private void WindowKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
ConfirmEditCustomBrowser(sender, e);
}
}
} }
} }

View file

@ -6,7 +6,7 @@
mc:Ignorable="d" mc:Ignorable="d"
Background="White" Background="White"
d:DesignHeight="300" d:DesignWidth="500" d:DesignHeight="300" d:DesignWidth="500"
DataContext="{Binding RelativeSource={RelativeSource Self}, Path=Settings}"> DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="50" /> <RowDefinition Height="50" />
@ -33,30 +33,32 @@
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Grid.Row="1" Height="60" Margin="25,13,0,0"> <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Grid.Row="1" Height="60" Margin="25,13,0,0">
<Label Content="{DynamicResource flowlauncher_plugin_browserbookmark_settings_setBrowserFromPath}" <Label Content="{DynamicResource flowlauncher_plugin_browserbookmark_settings_setBrowserFromPath}"
Height="28" Margin="10"/> Height="28" Margin="10"/>
<TextBox x:Name="browserPathBox" <TextBox x:Name="BrowserPathBox"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Height="30" Height="30"
TextWrapping="NoWrap" TextWrapping="NoWrap"
VerticalAlignment="Center" VerticalAlignment="Center"
Text="{Binding BrowserPath}" Text="{Binding Settings.BrowserPath}"
Width="240" Width="240"
Margin="10"/> Margin="10"/>
<Button x:Name="viewButton" Content="{DynamicResource flowlauncher_plugin_browserbookmark_settings_choose}" <Button x:Name="ViewButton" Content="{DynamicResource flowlauncher_plugin_browserbookmark_settings_choose}"
HorizontalAlignment="Left" Margin="10" Width="100" Height="30" Click="OnChooseClick" FontSize="14" /> HorizontalAlignment="Left" Margin="10" Width="100" Height="30" Click="OnChooseClick" FontSize="14" />
</StackPanel> </StackPanel>
<StackPanel Grid.Row="2" Orientation="Vertical"> <StackPanel Grid.Row="2" Orientation="Vertical">
<TextBlock Text="CustomBrowsers" Margin="10"/> <TextBlock Text="CustomBrowsers" Margin="10"/>
<ListView Grid.Row="2" ItemsSource="{Binding CustomChromiumBrowsers}" <ListView Grid.Row="2" ItemsSource="{Binding Settings.CustomChromiumBrowsers}"
SelectedItem="{Binding SelectedCustomBrowser}"
Margin="10" Margin="10"
BorderBrush="DarkGray" BorderBrush="DarkGray"
BorderThickness="1" BorderThickness="1"
Style="{StaticResource {x:Static GridView.GridViewStyleKey}}" Style="{StaticResource {x:Static GridView.GridViewStyleKey}}"
Height="auto" Height="auto"
Name="CustomBrowsers"> Name="CustomBrowsers"
MouseDoubleClick="MouseDoubleClickOnSelectedCustomBrowser">
<ListView.View> <ListView.View>
<GridView> <GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Browser Name"/> <GridViewColumn DisplayMemberBinding="{Binding Name, Mode=OneWay}" Header="Browser Name"/>
<GridViewColumn DisplayMemberBinding="{Binding DataDirectoryPath}" Header="DataDirectoryPath"/> <GridViewColumn DisplayMemberBinding="{Binding DataDirectoryPath, Mode=OneWay}" Header="DataDirectoryPath"/>
</GridView> </GridView>
</ListView.View> </ListView.View>
</ListView> </ListView>

View file

@ -2,6 +2,7 @@ using Microsoft.Win32;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using Flow.Launcher.Plugin.BrowserBookmark.Models; using Flow.Launcher.Plugin.BrowserBookmark.Models;
using System.Windows.Input;
namespace Flow.Launcher.Plugin.BrowserBookmark.Views namespace Flow.Launcher.Plugin.BrowserBookmark.Views
{ {
@ -11,6 +12,7 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
public partial class SettingsControl public partial class SettingsControl
{ {
public Settings Settings { get; } public Settings Settings { get; }
public CustomBrowser SelectedCustomBrowser { get; set; }
public SettingsControl(Settings settings) public SettingsControl(Settings settings)
{ {
@ -64,5 +66,13 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Views
Settings.CustomChromiumBrowsers.Remove(selectedCustomBrowser); Settings.CustomChromiumBrowsers.Remove(selectedCustomBrowser);
} }
} }
private void MouseDoubleClickOnSelectedCustomBrowser(object sender, MouseButtonEventArgs e)
{
if (SelectedCustomBrowser is null)
return;
var window = new CustomBrowserSettingWindow(SelectedCustomBrowser);
window.ShowDialog();
}
} }
} }