Skip to content

Commit ff430c7

Browse files
Fix duplicate program sources when editing
1 parent 4725b0d commit ff430c7

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ public AddProgramSource(PluginInitContext context, Settings settings)
2727
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
2828
}
2929

30-
public AddProgramSource(ProgramSource source, Settings settings)
30+
public AddProgramSource(PluginInitContext context, ProgramSource source, Settings settings)
3131
{
3232
InitializeComponent();
33+
_context = context;
3334
_editing = source;
3435
_settings = settings;
3536
update = true;
@@ -70,11 +71,24 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
7071
_settings.ProgramSources.Insert(0, source);
7172
ProgramSetting.ProgramSettingDisplayList.Add(source);
7273
}
74+
else
75+
{
76+
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
77+
return;
78+
}
7379
}
7480
else
7581
{
7682
if (!_editing.Location.Equals(path, System.StringComparison.OrdinalIgnoreCase))
7783
{
84+
if (ProgramSetting.ProgramSettingDisplayList
85+
.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase)))
86+
{
87+
// Check if the new location is used
88+
// No need to check win32 or uwp, just override them
89+
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
90+
return;
91+
}
7892
modified = true;
7993
_editing.Location = path; // Changes UniqueIdentifier internally
8094
}

Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
<system:String x:Key="flowlauncher_plugin_program_pls_select_program_source">Please select a program source</system:String>
3737
<system:String x:Key="flowlauncher_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String>
38+
<system:String x:Key="flowlauncher_plugin_program_duplicate_program_source">Another program source with the same location alreaday exists.</system:String>
3839

3940
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_title">Program Source</system:String>
4041
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_tips">Edit directory and status of this program source.</system:String>

Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private void EditProgramSource(ProgramSource selectedProgramSource)
160160
}
161161
else
162162
{
163-
var add = new AddProgramSource(selectedProgramSource, _settings);
163+
var add = new AddProgramSource(context, selectedProgramSource, _settings);
164164
if (add.ShowDialog() ?? false)
165165
{
166166
if (selectedProgramSource.Enabled)

0 commit comments

Comments
 (0)