Fix duplicate program sources when editing

This commit is contained in:
Vic 2022-11-04 14:15:42 +08:00
parent 4725b0df07
commit ff430c71d3
3 changed files with 17 additions and 2 deletions

View file

@ -27,9 +27,10 @@ namespace Flow.Launcher.Plugin.Program
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
}
public AddProgramSource(ProgramSource source, Settings settings)
public AddProgramSource(PluginInitContext context, ProgramSource source, Settings settings)
{
InitializeComponent();
_context = context;
_editing = source;
_settings = settings;
update = true;
@ -70,11 +71,24 @@ namespace Flow.Launcher.Plugin.Program
_settings.ProgramSources.Insert(0, source);
ProgramSetting.ProgramSettingDisplayList.Add(source);
}
else
{
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
return;
}
}
else
{
if (!_editing.Location.Equals(path, System.StringComparison.OrdinalIgnoreCase))
{
if (ProgramSetting.ProgramSettingDisplayList
.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase)))
{
// Check if the new location is used
// No need to check win32 or uwp, just override them
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
return;
}
modified = true;
_editing.Location = path; // Changes UniqueIdentifier internally
}

View file

@ -35,6 +35,7 @@
<system:String x:Key="flowlauncher_plugin_program_pls_select_program_source">Please select a program source</system:String>
<system:String x:Key="flowlauncher_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String>
<system:String x:Key="flowlauncher_plugin_program_duplicate_program_source">Another program source with the same location alreaday exists.</system:String>
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_title">Program Source</system:String>
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_tips">Edit directory and status of this program source.</system:String>

View file

@ -160,7 +160,7 @@ namespace Flow.Launcher.Plugin.Program.Views
}
else
{
var add = new AddProgramSource(selectedProgramSource, _settings);
var add = new AddProgramSource(context, selectedProgramSource, _settings);
if (add.ShowDialog() ?? false)
{
if (selectedProgramSource.Enabled)