Skip to content

Commit

Permalink
GNOME - AutocompleteBox Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Aug 8, 2023
1 parent ab4be5a commit b38c04f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
2 changes: 2 additions & 0 deletions NickvisionMoney.GNOME/Blueprints/autocomplete_box.blp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Gtk.Box _root {
orientation: vertical;
spacing: 12;
visible: false;
halign: center;
valign: start;

Gtk.Label {
margin-start: 12;
Expand Down
34 changes: 9 additions & 25 deletions NickvisionMoney.GNOME/Views/TransactionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ private TransactionDialog(Gtk.Builder builder, TransactionDialogController contr
};
//Description
_autocompleteBox = new AutocompleteBox<Transaction>();
_autocompleteBox.SetSizeRequest(378, -1);
_autocompleteBox.SetMarginTop(66);
_autocompleteBox.SuggestionAccepted += (sender, e) =>
{
_descriptionRow.SetText(e.Item1);
Expand All @@ -205,18 +207,20 @@ private TransactionDialog(Gtk.Builder builder, TransactionDialogController contr
_colorButton.SetExtRgba(transactionColor!.Value);
}
};
_autocompleteBox.SetSizeRequest(378, -1);
_autocompleteBox.SetMarginTop(66);
_autocompleteBox.SetHalign(Gtk.Align.Center);
_autocompleteBox.SetValign(Gtk.Align.Start);
_overlay.AddOverlay(_autocompleteBox);
_descriptionRow.OnNotify += (sender, e) =>
{
if (e.Pspec.GetName() == "text")
{
if (!_constructing)
{
AutocompleteDescription();
var matchingDescriptions = _controller.GetDescriptionSuggestions(_descriptionRow.GetText());
if(matchingDescriptions.Count > 0)
{
_autocompleteBox.UpdateSuggestions(matchingDescriptions);
}
_descriptionRow.SetActivatesDefault(matchingDescriptions.Count == 0);
_autocompleteBox.SetVisible(matchingDescriptions.Count > 0);
Validate();
}
}
Expand Down Expand Up @@ -514,26 +518,6 @@ private void Validate()
}
}

/// <summary>
/// Sets up autocomplete for description
/// </summary>
private void AutocompleteDescription()
{
if(!string.IsNullOrEmpty(_descriptionRow.GetText()))
{
var matchingDescriptions = _controller.GetDescriptionSuggestions(_descriptionRow.GetText());
if(matchingDescriptions.Count != 0)
{
_descriptionRow.SetActivatesDefault(false);
_autocompleteBox.UpdateSuggestions(matchingDescriptions);
_autocompleteBox.SetVisible(true);
return;
}
}
_descriptionRow.SetActivatesDefault(true);
_autocompleteBox.SetVisible(false);
}

/// <summary>
/// Occurs when either Income or Expense button is toggled
/// </summary>
Expand Down

0 comments on commit b38c04f

Please sign in to comment.