Skip to content

Commit

Permalink
Merge pull request #735 from UrtsiSantsi/null_or_whitespace
Browse files Browse the repository at this point in the history
Use IsNullOrWhitespace instead of IsNullOrEmpty
  • Loading branch information
nlogozzo authored Nov 17, 2023
2 parents 91255a9 + 6ddc3af commit 7dc0896
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 49 deletions.
4 changes: 2 additions & 2 deletions NickvisionMoney.GNOME/Controls/CurrencyConverterDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private CurrencyConverterDialog(Gtk.Builder builder, Gtk.Window parent, string i
};
_copyResultButton.OnClicked += (sender, e) =>
{
if (!string.IsNullOrEmpty(_resultAmountRow.GetText()))
if (!string.IsNullOrWhiteSpace(_resultAmountRow.GetText()))
{
_resultAmountRow.GetClipboard().SetText(_resultAmountRow.GetText());
_toastOverlay.AddToast(Adw.Toast.New(_("Result was copied to clipboard.")));
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task PresentAsync()
private async Task OnAmountRowChangedAsync()
{
_sourceAmountRow.RemoveCssClass("error");
if (string.IsNullOrEmpty(_sourceAmountRow.GetText()))
if (string.IsNullOrWhiteSpace(_sourceAmountRow.GetText()))
{
_resultAmountRow.SetText("");
}
Expand Down
2 changes: 2 additions & 0 deletions NickvisionMoney.GNOME/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public Program(string[] args)
@"* Fixed an issue where exported PDF values were incorrect
* Fixed an issue where some system cultures were not read properly
* Fixed an issue where scrolling the sidebar with the mouse over the calendar would scroll the calendar instead
* Disallowed whitespace-only group and account names
* Fixed an issue where leading or trailing spaces in group/account names aren't discarded
* Updated to GNOME 45 runtime with latest libadwaita design
* Updated and added translations (Thanks to everyone on Weblate)!";
_application.OnActivate += OnActivate;
Expand Down
2 changes: 1 addition & 1 deletion NickvisionMoney.GNOME/Views/AccountSettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private void Validate()
};
var customDecimalDigits = _customDecimalDigitsRow.GetSelected() == 5 ? 99 : _customDecimalDigitsRow.GetSelected() + 2;
var oldSymbol = _controller.Metadata.CustomCurrencySymbol;
var checkStatus = _controller.UpdateMetadata(_nameRow.GetText(), (AccountType)_accountTypeRow.GetSelected(), _useCustomCurrencyRow.GetActive(), _customSymbolRow.GetText(), _customCodeRow.GetText(), (int?)_customAmountStyleRow.GetSelected(), customDecimalSeparator, customGroupSeparator, (int?)customDecimalDigits, transactionType, (RemindersThreshold)_transactionRemindersRow.GetSelected(), _newPasswordRow.GetText(), _newPasswordConfirmRow.GetText());
var checkStatus = _controller.UpdateMetadata(_nameRow.GetText().Trim(), (AccountType)_accountTypeRow.GetSelected(), _useCustomCurrencyRow.GetActive(), _customSymbolRow.GetText(), _customCodeRow.GetText(), (int?)_customAmountStyleRow.GetSelected(), customDecimalSeparator, customGroupSeparator, (int?)customDecimalDigits, transactionType, (RemindersThreshold)_transactionRemindersRow.GetSelected(), _newPasswordRow.GetText(), _newPasswordConfirmRow.GetText());
_nameRow.RemoveCssClass("error");
_nameRow.SetTitle(_("Name"));
_customCurrencyRow.RemoveCssClass("error");
Expand Down
2 changes: 1 addition & 1 deletion NickvisionMoney.GNOME/Views/GroupDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public GroupDialog(GroupDialogController controller, Gtk.Window parent) : this(B
private void Validate()
{
var color = _colorButton.GetExtRgba();
var checkStatus = _controller.UpdateGroup(_nameRow.GetText(), _descriptionRow.GetText(), color.ToString());
var checkStatus = _controller.UpdateGroup(_nameRow.GetText().Trim(), _descriptionRow.GetText().Trim(), color.ToString());
_nameRow.RemoveCssClass("error");
_nameRow.SetTitle(_("Name"));
if (checkStatus == GroupCheckStatus.Valid)
Expand Down
4 changes: 2 additions & 2 deletions NickvisionMoney.GNOME/Views/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void SendShellNotification(ShellNotificationSentEventArgs e)
NotificationSeverity.Error => Gio.NotificationPriority.Urgent,
_ => Gio.NotificationPriority.Normal
});
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SNAP")))
if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("SNAP")))
{
notification.SetIcon(Gio.ThemedIcon.New($"{_controller.AppInfo.ID}-symbolic"));
}
Expand Down Expand Up @@ -429,7 +429,7 @@ private void About(Gio.SimpleAction sender, EventArgs e)
{
debugInfo.AppendLine("Flatpak");
}
else if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SNAP")))
else if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("SNAP")))
{
debugInfo.AppendLine("Snap");
}
Expand Down
4 changes: 2 additions & 2 deletions NickvisionMoney.GNOME/Views/NewAccountDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ private void ValidateName()
{
_accountNameRow.RemoveCssClass("error");
_accountNameRow.SetTitle(_("Account Name"));
var checkStatus = _controller.UpdateName(_accountNameRow.GetText());
var checkStatus = _controller.UpdateName(_accountNameRow.GetText().Trim());
if (checkStatus == NameCheckStatus.Valid)
{
_nextButton1.SetSensitive(!string.IsNullOrEmpty(_accountNameRow.GetText()));
_nextButton1.SetSensitive(!string.IsNullOrWhiteSpace(_accountNameRow.GetText()));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion NickvisionMoney.GNOME/Views/TransactionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ private TransactionDialog(Gtk.Builder builder, TransactionDialogController contr
_addTagButton.OnClicked += (sender, e) =>
{
var tag = _addTagEntry.GetBuffer().GetText().Trim();
if (!string.IsNullOrEmpty(tag) && !_controller.AccountTags.Contains(tag))
if (!string.IsNullOrWhiteSpace(tag) && !_controller.AccountTags.Contains(tag))
{
_controller.AccountTags.Add(tag);
UpdateTagsList();
Expand Down
2 changes: 1 addition & 1 deletion NickvisionMoney.GNOME/Views/TransferDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private async Task SetupConversionRateGroupAsync()
if (_conversionRateGroup.Visible)
{
var res = await _controller.GetConversionRateOnlineAsync();
if (string.IsNullOrEmpty(res.Source) || string.IsNullOrEmpty(res.Destination))
if (string.IsNullOrWhiteSpace(res.Source) || string.IsNullOrWhiteSpace(res.Destination))
{
_sourceCurrencyRow.SetText("");
_destinationCurrencyRow.SetText("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ internal AccountSettingsDialogController(AccountMetadata metadata, bool isEncryp
public AccountMetadataCheckStatus UpdateMetadata(string name, AccountType type, bool useCustom, string? customSymbol, string? customCode, int? customAmountStyle, string? customDecimalSeparator, string? customGroupSeparator, int? customDecimalDigits, TransactionType defaultTransactionType, RemindersThreshold transactionReminder, string newPassword, string confirmPassword)
{
AccountMetadataCheckStatus result = 0;
if (string.IsNullOrEmpty(name))
if (string.IsNullOrWhiteSpace(name))
{
result |= AccountMetadataCheckStatus.EmptyName;
}
if (useCustom && string.IsNullOrEmpty(customSymbol))
if (useCustom && string.IsNullOrWhiteSpace(customSymbol))
{
result |= AccountMetadataCheckStatus.EmptyCurrencySymbol;
}
if (useCustom && !string.IsNullOrEmpty(customSymbol) && Decimal.TryParse(customSymbol, out _))
if (useCustom && !string.IsNullOrWhiteSpace(customSymbol) && Decimal.TryParse(customSymbol, out _))
{
result |= AccountMetadataCheckStatus.InvalidCurrencySymbol;
}
if (useCustom && string.IsNullOrEmpty(customCode))
if (useCustom && string.IsNullOrWhiteSpace(customCode))
{
result |= AccountMetadataCheckStatus.EmptyCurrencyCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ private void FilterUIUpdate()
var groupBalances = new Dictionary<uint, (decimal Income, decimal Expense)>();
foreach (var pair in _account.Transactions)
{
if (!string.IsNullOrEmpty(SearchDescription))
if (!string.IsNullOrWhiteSpace(SearchDescription))
{
if (!pair.Value.Description.ToLower().Contains(SearchDescription.ToLower()))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ internal DashboardViewController(List<AccountViewController> openAccounts, strin
name = nameBuilder.ToString();
if (!Groups.ContainsKey(name))
{
Groups[name] = (new DashboardAmount(), string.IsNullOrEmpty(group.RGBA) ? defaultColor : group.RGBA);
Groups[name] = (new DashboardAmount(), string.IsNullOrWhiteSpace(group.RGBA) ? defaultColor : group.RGBA);
}
if (!Groups[name].DashboardAmount.Currencies.Contains(currency))
{
Expand Down
4 changes: 2 additions & 2 deletions NickvisionMoney.Shared/Controllers/GroupDialogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal GroupDialogController(Group group, List<string> existingNames, string g
_existingNames = existingNames;
Group = (Group)group.Clone();
IsEditing = true;
if (string.IsNullOrEmpty(Group.RGBA))
if (string.IsNullOrWhiteSpace(Group.RGBA))
{
Group.RGBA = groupDefaultColor;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ internal GroupDialogController(uint id, List<string> existingNames, string group
/// <returns>GroupCheckStatus</returns>
public GroupCheckStatus UpdateGroup(string name, string description, string rgba)
{
if (string.IsNullOrEmpty(name))
if (string.IsNullOrWhiteSpace(name))
{
return GroupCheckStatus.EmptyName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ public NameCheckStatus UpdateName(string name)
public CurrencyCheckStatus UpdateCurrency(bool useCustom, string? customSymbol, string? customCode, int? customAmountStyle, string? customDecimalSeparator, string? customGroupSeparator, int? customDecimalDigits)
{
CurrencyCheckStatus result = 0;
if (useCustom && string.IsNullOrEmpty(customSymbol))
if (useCustom && string.IsNullOrWhiteSpace(customSymbol))
{
result |= CurrencyCheckStatus.EmptyCurrencySymbol;
}
if (useCustom && !string.IsNullOrEmpty(customSymbol) && Decimal.TryParse(customSymbol, out _))
if (useCustom && !string.IsNullOrWhiteSpace(customSymbol) && Decimal.TryParse(customSymbol, out _))
{
result |= CurrencyCheckStatus.InvalidCurrencySymbol;
}
if (useCustom && string.IsNullOrEmpty(customCode))
if (useCustom && string.IsNullOrWhiteSpace(customCode))
{
result |= CurrencyCheckStatus.EmptyCurrencyCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ internal TransactionDialogController(Transaction transaction, Dictionary<uint, T
CopyRequested = false;
OriginalRepeatInterval = Transaction.RepeatInterval;
CultureForNumberString = cultureNumber;
if (string.IsNullOrEmpty(Transaction.RGBA))
if (string.IsNullOrWhiteSpace(Transaction.RGBA))
{
Transaction.RGBA = DefaultTransactionColor;
}
Expand Down Expand Up @@ -300,7 +300,7 @@ public TransactionCheckStatus UpdateTransaction(DateOnly date, string descriptio
{
TransactionCheckStatus result = 0;
var amount = 0m;
if (string.IsNullOrEmpty(description))
if (string.IsNullOrWhiteSpace(description))
{
result |= TransactionCheckStatus.EmptyDescription;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public string GetColorForAccountType(AccountType accountType)
/// <returns>(string Source, string Destination)</returns>
public async Task<(string Source, string Destination)> GetConversionRateOnlineAsync()
{
if (string.IsNullOrEmpty(DestinationCurrencyCode))
if (string.IsNullOrWhiteSpace(DestinationCurrencyCode))
{
return ("", "");
}
Expand All @@ -142,7 +142,7 @@ public TransferCheckStatus UpdateTransfer(string destPath, string? destPassword,
TransferCheckStatus result = 0;
var amount = 0m;
var conversionRate = 0m;
if (string.IsNullOrEmpty(destPath) || !Path.Exists(destPath) || Path.GetExtension(destPath).ToLower() != ".nmoney" || Transfer.SourceAccountPath == destPath)
if (string.IsNullOrWhiteSpace(destPath) || !Path.Exists(destPath) || Path.GetExtension(destPath).ToLower() != ".nmoney" || Transfer.SourceAccountPath == destPath)
{
result |= TransferCheckStatus.InvalidDestPath;
}
Expand Down Expand Up @@ -172,8 +172,8 @@ public TransferCheckStatus UpdateTransfer(string destPath, string? destPassword,
{
lcMonetary = lcMonetary.Replace('@', '-');
}
CultureForDestNumberString = new CultureInfo(!string.IsNullOrEmpty(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name, true);
var destRegion = new RegionInfo(!string.IsNullOrEmpty(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name);
CultureForDestNumberString = new CultureInfo(!string.IsNullOrWhiteSpace(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name, true);
var destRegion = new RegionInfo(!string.IsNullOrWhiteSpace(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name);
if (_previousDestMetadata == null)
{
_previousDestMetadata = AccountMetadata.LoadFromAccountFile(destPath, destPassword)!;
Expand Down
14 changes: 7 additions & 7 deletions NickvisionMoney.Shared/Helpers/CultureHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static CultureHelpers()
{
lcTime = lcTime.Replace('_', '-');
}
DateCulture = new CultureInfo(!string.IsNullOrEmpty(lcTime) ? lcTime : CultureInfo.CurrentCulture.Name, true);
DateCulture = new CultureInfo(!string.IsNullOrWhiteSpace(lcTime) ? lcTime : CultureInfo.CurrentCulture.Name, true);
//Reported Currency String
var lcMonetary = Environment.GetEnvironmentVariable("LC_MONETARY");
if (lcMonetary != null && lcMonetary.Contains(".UTF-8"))
Expand All @@ -56,8 +56,8 @@ static CultureHelpers()
{
lcMonetary = lcMonetary.Replace('@', '-');
}
var culture = new CultureInfo(!string.IsNullOrEmpty(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name, true);
var region = new RegionInfo(!string.IsNullOrEmpty(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name);
var culture = new CultureInfo(!string.IsNullOrWhiteSpace(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name, true);
var region = new RegionInfo(!string.IsNullOrWhiteSpace(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name);
ReportedCurrencyString = $"{culture.NumberFormat.CurrencySymbol} ({region.ISOCurrencySymbol})";
}

Expand Down Expand Up @@ -85,12 +85,12 @@ public static CultureInfo GetNumberCulture(AccountMetadata metadata)
{
lcMonetary = lcMonetary.Replace('@', '-');
}
var culture = new CultureInfo(!string.IsNullOrEmpty(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name, true);
var region = new RegionInfo(!string.IsNullOrEmpty(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name);
var culture = new CultureInfo(!string.IsNullOrWhiteSpace(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name, true);
var region = new RegionInfo(!string.IsNullOrWhiteSpace(lcMonetary) ? lcMonetary : CultureInfo.CurrentCulture.Name);
if (metadata.UseCustomCurrency)
{
culture.NumberFormat.CurrencySymbol = string.IsNullOrEmpty(metadata.CustomCurrencySymbol) ? culture.NumberFormat.CurrencySymbol : metadata.CustomCurrencySymbol;
culture.NumberFormat.NaNSymbol = string.IsNullOrEmpty(metadata.CustomCurrencyCode) ? region.ISOCurrencySymbol : metadata.CustomCurrencyCode;
culture.NumberFormat.CurrencySymbol = string.IsNullOrWhiteSpace(metadata.CustomCurrencySymbol) ? culture.NumberFormat.CurrencySymbol : metadata.CustomCurrencySymbol;
culture.NumberFormat.NaNSymbol = string.IsNullOrWhiteSpace(metadata.CustomCurrencyCode) ? region.ISOCurrencySymbol : metadata.CustomCurrencyCode;
culture.NumberFormat.CurrencyPositivePattern = metadata.CustomCurrencyAmountStyle ?? culture.NumberFormat.CurrencyPositivePattern;
culture.NumberFormat.CurrencyDecimalSeparator = string.IsNullOrEmpty(metadata.CustomCurrencyDecimalSeparator) ? culture.NumberFormat.CurrencyDecimalSeparator : metadata.CustomCurrencyDecimalSeparator;
culture.NumberFormat.NumberDecimalSeparator = string.IsNullOrEmpty(metadata.CustomCurrencyDecimalSeparator) ? culture.NumberFormat.NumberDecimalSeparator : metadata.CustomCurrencyDecimalSeparator;
Expand Down
2 changes: 1 addition & 1 deletion NickvisionMoney.Shared/Helpers/DocumentationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class DocumentationHelpers
/// <returns>URL to either yelp or web page</returns>
public static string GetHelpURL(string pageName)
{
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SNAP")) && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
if (string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("SNAP")) && RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return $"help:tagger/{pageName}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<p>- Fixed an issue where exported PDF values were incorrect</p>
<p>- Fixed an issue where some system cultures were not read properly</p>
<p>- Fixed an issue where scrolling the sidebar with the mouse over the calendar would scroll the calendar instead</p>
<p>- Disallowed whitespace-only group and account names</p>
<p>- Fixed an issue where leading or trailing spaces in group/account names aren't discarded</p>
<p>- Updated to GNOME 45 runtime with latest libadwaita design</p>
<p>- Updated translations (Thanks to everyone on Weblate)!</p>
</description>
Expand Down
Loading

0 comments on commit 7dc0896

Please sign in to comment.