diff --git a/src/Lanceur.Core/Models/AliasQueryResult.cs b/src/Lanceur.Core/Models/AliasQueryResult.cs
index 8557ba4a..5a0fd8dd 100644
--- a/src/Lanceur.Core/Models/AliasQueryResult.cs
+++ b/src/Lanceur.Core/Models/AliasQueryResult.cs
@@ -81,21 +81,21 @@ public string Synonyms
set
{
Set(ref _synonyms, value);
- OnPropertyChanged(nameof(SynonymsNextState));
+ OnPropertyChanged(nameof(SynonymsToAdd));
}
}
///
/// New synonyms added when updated
///
- public string SynonymsNextState => (from n in Synonyms.SplitCsv()
- where !SynonymsPreviousState.SplitCsv().Contains(n)
+ public string SynonymsToAdd => (from n in Synonyms.SplitCsv()
+ where !SynonymsWhenLoaded.SplitCsv().Contains(n)
select n).ToArray().JoinCsv();
///
/// Synonyms present when the entity was loaded
///
- public string SynonymsPreviousState { get; set; }
+ public string SynonymsWhenLoaded { get; set; }
public string WorkingDirectory { get; set; }
@@ -105,7 +105,5 @@ public string Synonyms
public static AliasQueryResult FromName(string aliasName) => new() { Name = aliasName, Synonyms = aliasName };
- public override int GetHashCode() => (base.GetHashCode(), (Parameters?.GetHashCode() ?? 0)).GetHashCode();
-
#endregion Methods
}
\ No newline at end of file
diff --git a/src/Lanceur.Core/Models/AliasQueryResultMixin.cs b/src/Lanceur.Core/Models/AliasQueryResultMixin.cs
index d37f6471..f5770e4d 100644
--- a/src/Lanceur.Core/Models/AliasQueryResultMixin.cs
+++ b/src/Lanceur.Core/Models/AliasQueryResultMixin.cs
@@ -1,3 +1,5 @@
+using Lanceur.SharedKernel.Mixins;
+
namespace Lanceur.Core.Models;
public static class AliasQueryResultMixin
@@ -16,5 +18,16 @@ public static void UpdateIcon(this AliasQueryResult alias)
}
}
+ ///
+ /// Set first names defined in the synonyms as the name of the alias
+ ///
+ /// The alias
+ public static void SetName(this AliasQueryResult alias)
+ {
+ alias.Name = alias.Synonyms
+ .SplitCsv()
+ .FirstOrDefault();
+ }
+
#endregion Methods
}
\ No newline at end of file
diff --git a/src/Lanceur.Core/Models/ExistingNameResponse.cs b/src/Lanceur.Core/Models/ExistingNameResponse.cs
index f0ba4c72..7e5f207b 100644
--- a/src/Lanceur.Core/Models/ExistingNameResponse.cs
+++ b/src/Lanceur.Core/Models/ExistingNameResponse.cs
@@ -7,9 +7,7 @@ public record ExistingNameResponse
{
public ExistingNameResponse(string[] existingNames)
{
- ExistingNames = existingNames is null
- ? Array.Empty()
- : existingNames;
+ ExistingNames = existingNames ?? Array.Empty();
}
///
diff --git a/src/Lanceur.Core/Models/QueryResult.cs b/src/Lanceur.Core/Models/QueryResult.cs
index 4b66ca74..75aa2655 100644
--- a/src/Lanceur.Core/Models/QueryResult.cs
+++ b/src/Lanceur.Core/Models/QueryResult.cs
@@ -25,7 +25,7 @@ public abstract class QueryResult : ObservableModel
protected static Task> NoResultAsync => Task.FromResult(NoResult);
public static IEnumerable NoResult => new List();
- public int Count { get; set; } = 0;
+ public int Count { get; set; }
public virtual string Description { get; set; }
///
@@ -46,7 +46,7 @@ public abstract class QueryResult : ObservableModel
///
public virtual bool IsResult => true;
- public virtual string Name { get; set; } = string.Empty;
+ public string Name { get; set; } = string.Empty;
public Cmdline Query { get; set; } = Cmdline.Empty;
///
@@ -66,11 +66,6 @@ public object Thumbnail
#region Methods
- ///
- /// This hashcode is calculated on not readonly properties and can be outdated if properties are updated!
- ///
- public override int GetHashCode() => (Count, Description, Icon, Id, IsResult, Name, Query, Thumbnail).GetHashCode();
-
public virtual string ToQuery() => $"{Name}";
#endregion Methods
diff --git a/src/Lanceur.Infra.SQLite/DbActions/AliasDbAction.cs b/src/Lanceur.Infra.SQLite/DbActions/AliasDbAction.cs
index c341a898..3913943e 100644
--- a/src/Lanceur.Infra.SQLite/DbActions/AliasDbAction.cs
+++ b/src/Lanceur.Infra.SQLite/DbActions/AliasDbAction.cs
@@ -382,7 +382,7 @@ update alias
UpdateName(alias, tx);
});
- alias.SynonymsPreviousState = alias.Synonyms;
+ alias.SynonymsWhenLoaded = alias.Synonyms;
return alias.Id;
}
diff --git a/src/Lanceur.Infra.SQLite/DbActions/AliasSearchDbAction.cs b/src/Lanceur.Infra.SQLite/DbActions/AliasSearchDbAction.cs
index 0ec0dfad..7a9e7056 100644
--- a/src/Lanceur.Infra.SQLite/DbActions/AliasSearchDbAction.cs
+++ b/src/Lanceur.Infra.SQLite/DbActions/AliasSearchDbAction.cs
@@ -43,7 +43,7 @@ public IEnumerable Search(string name, long idSession)
a.lua_script as {nameof(AliasQueryResult.LuaScript)},
c.exec_count as {nameof(AliasQueryResult.Count)},
s.synonyms as {nameof(AliasQueryResult.Synonyms)},
- s.Synonyms as {nameof(AliasQueryResult.SynonymsPreviousState)}
+ s.Synonyms as {nameof(AliasQueryResult.SynonymsWhenLoaded)}
from
alias a
left join alias_name an on a.id = an.id_alias
@@ -80,7 +80,7 @@ public IEnumerable SearchAliasWithAdditionalParameters(string
a.lua_script as {nameof(AliasQueryResult.LuaScript)},
c.exec_count as {nameof(AliasQueryResult.Count)},
s.synonyms as {nameof(AliasQueryResult.Synonyms)},
- s.Synonyms as {nameof(AliasQueryResult.SynonymsPreviousState)}
+ s.Synonyms as {nameof(AliasQueryResult.SynonymsWhenLoaded)}
from
alias a
left join alias_name an on a.id = an.id_alias
diff --git a/src/Lanceur.Infra.SQLite/DbActions/GetAllAliasDbAction.cs b/src/Lanceur.Infra.SQLite/DbActions/GetAllAliasDbAction.cs
index c893a26b..aac48767 100644
--- a/src/Lanceur.Infra.SQLite/DbActions/GetAllAliasDbAction.cs
+++ b/src/Lanceur.Infra.SQLite/DbActions/GetAllAliasDbAction.cs
@@ -41,7 +41,7 @@ public IEnumerable GetAll(long? idSession = null)
a.lua_script as {nameof(AliasQueryResult.LuaScript)},
c.exec_count as {nameof(AliasQueryResult.Count)},
s.synonyms as {nameof(AliasQueryResult.Synonyms)},
- s.Synonyms as {nameof(AliasQueryResult.SynonymsPreviousState)}
+ s.Synonyms as {nameof(AliasQueryResult.SynonymsWhenLoaded)}
from
alias a
left join alias_name an on a.id = an.id_alias
@@ -81,7 +81,7 @@ public IEnumerable GetAllAliasWithAdditionalParameters(long id
a.lua_script as {nameof(AliasQueryResult.LuaScript)},
c.exec_count as {nameof(AliasQueryResult.Count)},
s.synonyms as {nameof(AliasQueryResult.Synonyms)},
- s.Synonyms as {nameof(AliasQueryResult.SynonymsPreviousState)}
+ s.Synonyms as {nameof(AliasQueryResult.SynonymsWhenLoaded)}
from
alias a
left join alias_name an on a.id = an.id_alias
diff --git a/src/Lanceur.Infra.SQLite/SQLiteRepository.cs b/src/Lanceur.Infra.SQLite/SQLiteRepository.cs
index c3a3cd7f..2dddf83a 100644
--- a/src/Lanceur.Infra.SQLite/SQLiteRepository.cs
+++ b/src/Lanceur.Infra.SQLite/SQLiteRepository.cs
@@ -309,6 +309,9 @@ public void SaveOrUpdate(ref AliasQueryResult alias, long? idSession = null)
_aliasDbAction.Update(alias);
break;
}
+
+ // Reset state after save
+ alias.SynonymsWhenLoaded = alias.Synonyms;
}
///
diff --git a/src/Lanceur/AssemblyInfo.cs b/src/Lanceur/AssemblyInfo.cs
index 5cb6b839..7fc2e629 100644
--- a/src/Lanceur/AssemblyInfo.cs
+++ b/src/Lanceur/AssemblyInfo.cs
@@ -1,4 +1,5 @@
-using System.Windows;
+using System.Runtime.CompilerServices;
+using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
@@ -7,4 +8,6 @@
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
-)]
\ No newline at end of file
+)]
+
+[assembly:InternalsVisibleTo("Lanceur.Tests")]
\ No newline at end of file
diff --git a/src/Lanceur/Views/KeywordsView.xaml.cs b/src/Lanceur/Views/KeywordsView.xaml.cs
index 048f0b96..65138308 100644
--- a/src/Lanceur/Views/KeywordsView.xaml.cs
+++ b/src/Lanceur/Views/KeywordsView.xaml.cs
@@ -49,11 +49,16 @@ public KeywordsView()
this.OneWayBind(ViewModel, vm => vm.BusyMessage, v => v.BusyMessage.Text).DisposeWith(d);
this.OneWayBind(ViewModel, vm => vm.IsBusy, v => v.BusyControl.Visibility).DisposeWith(d);
this.OneWayBind(ViewModel, vm => vm.IsBusy, v => v.AliasList.Visibility, val => val.ToVisibilityInverted()).DisposeWith(d);
+ this.OneWayBind(
+ ViewModel,
+ vm => vm.SelectedAlias,
+ v => v.BtnDeleteAlias.Content,
+ val => val is null ? "Delete" : val.Id == 0 ? "Discard" : "Delete").DisposeWith(d);
this.Bind(ViewModel, vm => vm.SearchQuery, v => v.QueryBox.Text).DisposeWith(d);
this.Bind(ViewModel, vm => vm.SelectedAlias, v => v.Aliases.SelectedItem).DisposeWith(d);
- this.BindCommand(ViewModel, vm => vm.CreateAlias, v => v.BtnCreateAlias).DisposeWith(d);
+ this.BindCommand(ViewModel, vm => vm.CreatingAlias, v => v.BtnCreateAlias).DisposeWith(d);
this.BindCommand(ViewModel, vm => vm.RemoveAlias, v => v.BtnDeleteAlias, v => v.SelectedAlias).DisposeWith(d);
this.BindCommand(ViewModel, vm => vm.SaveOrUpdateAlias, v => v.BtnSaveOrUpdateAlias, v => v.SelectedAlias).DisposeWith(d);
diff --git a/src/Lanceur/Views/KeywordsViewModel.cs b/src/Lanceur/Views/KeywordsViewModel.cs
index a943453e..986b5608 100644
--- a/src/Lanceur/Views/KeywordsViewModel.cs
+++ b/src/Lanceur/Views/KeywordsViewModel.cs
@@ -34,13 +34,13 @@ public class KeywordsViewModel : RoutableViewModel, IValidatableViewModel, IActi
private readonly SourceList _aliases = new();
private readonly IDbRepository _aliasService;
- private readonly Interaction