Skip to content

Commit

Permalink
Merge pull request #355 from jibedoubleve/issue/313
Browse files Browse the repository at this point in the history
Issue/313
  • Loading branch information
jibedoubleve authored Nov 1, 2023
2 parents c466cc4 + dca3c8b commit 503e960
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 92 deletions.
10 changes: 4 additions & 6 deletions src/Lanceur.Core/Models/AliasQueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ public string Synonyms
set
{
Set(ref _synonyms, value);
OnPropertyChanged(nameof(SynonymsNextState));
OnPropertyChanged(nameof(SynonymsToAdd));
}
}

/// <summary>
/// New synonyms added when updated
/// </summary>
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();

/// <summary>
/// Synonyms present when the entity was loaded
/// </summary>
public string SynonymsPreviousState { get; set; }
public string SynonymsWhenLoaded { get; set; }

public string WorkingDirectory { get; set; }

Expand All @@ -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
}
13 changes: 13 additions & 0 deletions src/Lanceur.Core/Models/AliasQueryResultMixin.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Lanceur.SharedKernel.Mixins;

namespace Lanceur.Core.Models;

public static class AliasQueryResultMixin
Expand All @@ -16,5 +18,16 @@ public static void UpdateIcon(this AliasQueryResult alias)
}
}

/// <summary>
/// Set first names defined in the synonyms as the name of the alias
/// </summary>
/// <param name="alias">The alias</param>
public static void SetName(this AliasQueryResult alias)
{
alias.Name = alias.Synonyms
.SplitCsv()
.FirstOrDefault();
}

#endregion Methods
}
4 changes: 1 addition & 3 deletions src/Lanceur.Core/Models/ExistingNameResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ public record ExistingNameResponse
{
public ExistingNameResponse(string[] existingNames)
{
ExistingNames = existingNames is null
? Array.Empty<string>()
: existingNames;
ExistingNames = existingNames ?? Array.Empty<string>();
}

/// <summary>
Expand Down
9 changes: 2 additions & 7 deletions src/Lanceur.Core/Models/QueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class QueryResult : ObservableModel
protected static Task<IEnumerable<QueryResult>> NoResultAsync => Task.FromResult(NoResult);

public static IEnumerable<QueryResult> NoResult => new List<QueryResult>();
public int Count { get; set; } = 0;
public int Count { get; set; }
public virtual string Description { get; set; }

/// <summary>
Expand All @@ -46,7 +46,7 @@ public abstract class QueryResult : ObservableModel
/// </summary>
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;

/// <summary>
Expand All @@ -66,11 +66,6 @@ public object Thumbnail

#region Methods

/// <remarks>
/// This hashcode is calculated on not readonly properties and can be outdated if properties are updated!
/// </remarks>
public override int GetHashCode() => (Count, Description, Icon, Id, IsResult, Name, Query, Thumbnail).GetHashCode();

public virtual string ToQuery() => $"{Name}";

#endregion Methods
Expand Down
2 changes: 1 addition & 1 deletion src/Lanceur.Infra.SQLite/DbActions/AliasDbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ update alias
UpdateName(alias, tx);
});

alias.SynonymsPreviousState = alias.Synonyms;
alias.SynonymsWhenLoaded = alias.Synonyms;
return alias.Id;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Lanceur.Infra.SQLite/DbActions/AliasSearchDbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public IEnumerable<AliasQueryResult> 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
Expand Down Expand Up @@ -80,7 +80,7 @@ public IEnumerable<AliasQueryResult> 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
Expand Down
4 changes: 2 additions & 2 deletions src/Lanceur.Infra.SQLite/DbActions/GetAllAliasDbAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public IEnumerable<AliasQueryResult> 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
Expand Down Expand Up @@ -81,7 +81,7 @@ public IEnumerable<AliasQueryResult> 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
Expand Down
3 changes: 3 additions & 0 deletions src/Lanceur.Infra.SQLite/SQLiteRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

///<inheritdoc/>
Expand Down
7 changes: 5 additions & 2 deletions src/Lanceur/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
)]
)]

[assembly:InternalsVisibleTo("Lanceur.Tests")]
7 changes: 6 additions & 1 deletion src/Lanceur/Views/KeywordsView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading

0 comments on commit 503e960

Please sign in to comment.