mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add SelectBrowserWindow Binding
This commit is contained in:
parent
6458c99515
commit
a1af487449
5 changed files with 103 additions and 8 deletions
|
|
@ -0,0 +1,30 @@
|
|||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.Infrastructure.UserSettings
|
||||
{
|
||||
public class CustomBrowserViewModel : BaseModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string PrivateArg { get; set; }
|
||||
public bool EnablePrivate { get; set; }
|
||||
public bool Editable { get; set; } = true;
|
||||
|
||||
public CustomBrowserViewModel Copy()
|
||||
{
|
||||
return new CustomBrowserViewModel
|
||||
{
|
||||
Name = Name,
|
||||
Path = Path,
|
||||
PrivateArg = PrivateArg,
|
||||
EnablePrivate = EnablePrivate,
|
||||
Editable = Editable
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -82,6 +82,25 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
}
|
||||
};
|
||||
|
||||
public int CustomBrowserIndex { get; set; } = 0;
|
||||
|
||||
|
||||
public CustomBrowserViewModel CustomBrowser
|
||||
{
|
||||
get => CustomBrowserList[CustomBrowserIndex];
|
||||
set => CustomBrowserList[CustomBrowserIndex] = value;
|
||||
}
|
||||
|
||||
public List<CustomBrowserViewModel> CustomBrowserList { get; set; } = new()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Name = "Default",
|
||||
Path = "",
|
||||
Editable = false
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// when false Alphabet static service will always return empty results
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@
|
|||
Margin="14,0,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
ItemsSource="{Binding CustomExplorers}"
|
||||
SelectedIndex="{Binding SelectedCustomExplorerIndex}">
|
||||
ItemsSource="{Binding CustomBrowsers}"
|
||||
SelectedIndex="{Binding SelectedCustomBrowserIndex}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" />
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
using System;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -17,29 +21,71 @@ namespace Flow.Launcher
|
|||
/// <summary>
|
||||
/// SelectBrowserWindow.xaml에 대한 상호 작용 논리
|
||||
/// </summary>
|
||||
public partial class SelectBrowserWindow : Window
|
||||
public partial class SelectBrowserWindow : Window, INotifyPropertyChanged
|
||||
{
|
||||
public SelectBrowserWindow()
|
||||
private int selectedCustomExplorerIndex;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public Settings Settings { get; }
|
||||
|
||||
public int SelectedCustomBrowserIndex
|
||||
{
|
||||
get => selectedCustomExplorerIndex; set
|
||||
{
|
||||
selectedCustomExplorerIndex = value;
|
||||
PropertyChanged?.Invoke(this, new(nameof(CustomExplorer)));
|
||||
}
|
||||
}
|
||||
public ObservableCollection<CustomBrowserViewModel> CustomBrowsers { get; set; }
|
||||
|
||||
public CustomBrowserViewModel CustomExplorer => CustomBrowsers[SelectedCustomBrowserIndex];
|
||||
public SelectBrowserWindow(Settings settings)
|
||||
{
|
||||
Settings = settings;
|
||||
CustomBrowsers = new ObservableCollection<CustomBrowserViewModel>(Settings.CustomBrowserList.Select(x => x.Copy()));
|
||||
SelectedCustomBrowserIndex = Settings.CustomExplorerIndex;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnDone_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Settings.CustomBrowserList = CustomBrowsers.ToList();
|
||||
Settings.CustomBrowserIndex = SelectedCustomBrowserIndex;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void btnAdd_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CustomBrowsers.Add(new()
|
||||
{
|
||||
Name = "New Profile"
|
||||
});
|
||||
SelectedCustomBrowserIndex = CustomBrowsers.Count - 1;
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CustomBrowsers.RemoveAt(SelectedCustomBrowserIndex--);
|
||||
}
|
||||
|
||||
private void btnBrowseFile_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
|
||||
Nullable<bool> result = dlg.ShowDialog();
|
||||
|
||||
if (result == true)
|
||||
{
|
||||
TextBox path = (TextBox)(((FrameworkElement)sender).Parent as FrameworkElement).FindName("PathTextBox");
|
||||
path.Text = dlg.FileName;
|
||||
path.Focus();
|
||||
((Button)sender).Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ namespace Flow.Launcher
|
|||
|
||||
private void OnSelectDefaultBrowserClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SelectBrowserWindow test = new SelectBrowserWindow();
|
||||
SelectBrowserWindow test = new SelectBrowserWindow(settings);
|
||||
test.ShowDialog();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue