Skip to content

Commit

Permalink
disable message keys from message service
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Mar 16, 2024
1 parent a88087c commit a3dbb05
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,7 @@ public override async Task<Unit> Handle(ShowMessageParams request, CancellationT
{
_service.TryRunAction(() =>
{
var model = MessageModel.FromShowMessageParams(request.Message, level);
var result = _messages.ShowMessage(model);
if (result != MessageActionResult.Disabled)
{
var generalSettings = _service.Settings.GeneralSettings;
if (result.MessageAction.IsDefaultAction)
{
DisabledMessageKeysSetting.DisableMessageKey(model.Key, _service.SettingsProvider);
}
}
else
{
_service.LogTrace("Key is disabled, message was not shown.", $"Key: '{model.Key}'");
}
_messages.ShowMessage(MessageModel.FromShowMessageParams(request.Message, level));
}, nameof(ShowMessageHandler));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public override async Task<MessageActionItem> Handle(ShowMessageRequestParams re

var model = MessageRequestModel.For(level, request.Message, actions);
var generalSettings = _service.Settings.GeneralSettings;
if (result.MessageAction.IsDefaultAction && !result.IsEnabled)
{
DisabledMessageKeysSetting.DisableMessageKey(model.Key, _service.SettingsProvider);
}
}, nameof(ShowMessageRequestHandler));
}
else
Expand Down
12 changes: 1 addition & 11 deletions Client/Rubberduck.UI/Services/NewProject/TemplatesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,7 @@ private bool ConfirmOverwriteTemplate(string name)
MessageActions = [MessageAction.AcceptConfirmAction, MessageAction.CancelAction]
};

var result = _messages.ShowMessageRequest(model);
if (result.MessageAction.IsDefaultAction)
{
if (!result.IsEnabled)
{
DisabledMessageKeysSetting.DisableMessageKey(model.Key, SettingsProvider);
}
return true;
}

return false;
return _messages.ShowMessageRequest(model)?.MessageAction.IsDefaultAction ?? false;
}

public IEnumerable<ProjectTemplate> GetProjectTemplates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ private ISettingViewModel GetChildItem<TSetting>(TSetting setting) where TSettin
case TypedRubberduckSetting<TimeSpan> timeSpanSetting:
return CreateViewModel(timeSpanSetting);
case TypedRubberduckSetting<string[]> listSetting:
return new ListSettingViewModel(_service, listSetting);
//case CodeFoldingSettings foldingSettings:
// return CreateViewModel(foldingSettings);
return new StringListSettingViewModel(_service, listSetting);
case TypedSettingGroup subGroup:
return CreateViewModel(subGroup);
case TypedRubberduckSetting<BooleanRubberduckSetting[]> telemetrySettingGroup:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SettingsWindowViewModel(UIServiceHelper service, MessageActionCommand[] a
_factory = factory;
_service = service;
ShowSettingsCommand = new DelegateCommand(service, parameter => ResetToDefaults());
Settings = _factory.CreateViewModel(_service.Settings);
service.RunOnMainThread(() => Settings = _factory.CreateViewModel(_service.Settings));

CommandBindings = new CommandBinding[]
{
Expand All @@ -38,7 +38,7 @@ public SettingsWindowViewModel(UIServiceHelper service, MessageActionCommand[] a

public bool ShowPinButton => false;

public ISettingGroupViewModel Settings { get; }
public ISettingGroupViewModel Settings { get; private set; }

private ISettingViewModel _selection;
public ISettingViewModel Selection
Expand Down Expand Up @@ -79,12 +79,7 @@ private bool ConfirmReset()
};

var result = _message.ShowMessageRequest(model, provider => provider.OkCancel());
if (!result.IsEnabled && result.MessageAction.IsDefaultAction)
{
DisabledMessageKeysSetting.DisableMessageKey(model.Key, _service.SettingsProvider);
}

return !result.IsEnabled && result.MessageAction == MessageAction.Undefined
return (!result.IsEnabled && result.MessageAction == MessageAction.Undefined)
|| result.MessageAction == MessageAction.AcceptAction;
}
}
Expand Down
54 changes: 54 additions & 0 deletions Client/Rubberduck.UI/Shared/Settings/StringListSettingViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Rubberduck.InternalApi.Settings.Model;
using Rubberduck.UI.Command.Abstract;
using Rubberduck.UI.Services;
using Rubberduck.UI.Shared.Settings.Abstract;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Threading;

namespace Rubberduck.UI.Shared.Settings
{
public class ListSettingViewModel<T> : SettingViewModel<T[]>
{
public ListSettingViewModel(UIServiceHelper service, TypedRubberduckSetting<T[]> setting) : base(setting)
{
ListItems = setting.TypedValue;
RemoveListSettingItemCommand = new DelegateCommand(service, ExecuteRemoveListSettingItemCommand);
}

private IEnumerable<T> _items = [];
public IEnumerable<T> ListItems
{
get => _items;
private set
{
if (_items != value)
{
_items = value;
OnPropertyChanged();
}
}
}

public ICommand RemoveListSettingItemCommand { get; }

private void ExecuteRemoveListSettingItemCommand(object? parameter)
{
if (parameter is T value)
{
ListItems = _items.Except([value]);
Value = _items.ToArray();
}
}
}

public class StringListSettingViewModel : ListSettingViewModel<string>
{
public StringListSettingViewModel(UIServiceHelper service, TypedRubberduckSetting<string[]> setting)
: base(service, setting) { }
}
}

0 comments on commit a3dbb05

Please sign in to comment.