Skip to content

Commit

Permalink
Add Clear User Settings Functionality (RDMP-7/GH#749) (#1586)
Browse files Browse the repository at this point in the history
* Add Clear User Settings button, command and unit test
* Update SelfCertifyingDataAccessPoint.cs - Fix typo


---------

Co-authored-by: jas88 <[email protected]>
  • Loading branch information
JFriel and jas88 authored Aug 11, 2023
1 parent 360aaf5 commit 10e0fed
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) The University of Dundee 2018-2023
// This file is part of the Research Data Management Platform (RDMP).
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.

using NUnit.Framework;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.CommandLine.Interactive.Picking;
using Rdmp.Core.ReusableLibraryCode.Checks;
using Rdmp.Core.ReusableLibraryCode.Settings;

namespace Rdmp.Core.Tests.CommandExecution;

internal sealed class TestExecuteCommandClearUserSettings : CommandCliTests
{
[Test]
public void Test_ClearUserSettings()
{
var invoker = GetInvoker();
var activator = GetActivator();

UserSettings.Wait5SecondsAfterStartupUI = false;

invoker.ExecuteCommand(typeof(ExecuteCommandSetUserSetting), new CommandLineObjectPicker(new[] { nameof(UserSettings.Wait5SecondsAfterStartupUI), "true" }, activator));

Assert.IsTrue(UserSettings.Wait5SecondsAfterStartupUI);
invoker.ExecuteCommand(typeof(ExecuteCommandSetUserSetting), new CommandLineObjectPicker(new[] { nameof(UserSettings.Wait5SecondsAfterStartupUI), "false" }, activator));
Assert.IsFalse(UserSettings.Wait5SecondsAfterStartupUI);
invoker.ExecuteCommand(typeof(ExecuteCommandClearUserSettings), new CommandLineObjectPicker(System.Array.Empty<string>(), activator));

Assert.IsTrue(UserSettings.Wait5SecondsAfterStartupUI);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) The University of Dundee 2018-2019
// This file is part of the Research Data Management Platform (RDMP).
// RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.

using Rdmp.Core.ReusableLibraryCode.Settings;

namespace Rdmp.Core.CommandExecution.AtomicCommands;

public class ExecuteCommandClearUserSettings : BasicCommandExecution
{
public ExecuteCommandClearUserSettings(IBasicActivateItems activator):base(activator)
{

}
public override void Execute()
{
base.Execute();

UserSettings.ClearUserSettings();
}

}
2 changes: 1 addition & 1 deletion Rdmp.Core/Curation/Data/SelfCertifyingDataAccessPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Rdmp.Core.Curation.Data;

/// <summary>
/// Normally to open a connection to an IDataAccessPoint (location of server/database) you also need an optional IDataAccessCredentials (username and encrypted password). These
/// These are usually two separate objects e.g. TableInfo and DataAccessCredentials (optional - if ommmited connections use integrated/windows security).
/// These are usually two separate objects e.g. TableInfo and DataAccessCredentials (optional - if omitted connections use integrated/windows security).
///
/// <para>Instead of doing that however, you can use this class to store all the bits in one object that implements both interfaces. It can then be used with a
/// DataAccessPortal.</para>
Expand Down
22 changes: 22 additions & 0 deletions Rdmp.Core/GlobalStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Rdmp.Core/GlobalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@
<data name="CreateNewCatalogueByImportingExistingDataTableHelp" xml:space="preserve">
<value>Creates a New Catalogue by associating it with an existing Table in your database</value>
</data>
<data name="ConfirmClearUserSettings" xml:space="preserve">
<value>Are you sure you want to clear your settings?</value>
</data>
<data name="ClearUserSettings" xml:space="preserve">
<value>Clear User Settings</value>
</data>
<data name="ClearSettings" xml:space="preserve">
<value>Clear Settings</value>
</data>
<data name="ClearUserSettingsTooltip" xml:space="preserve">
<value>Reset settings back to the defaults</value>
</data>
<data name="Activate" xml:space="preserve">
<value>Edit</value>
</data>
Expand Down
10 changes: 10 additions & 0 deletions Rdmp.Core/ReusableLibraryCode/Settings/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static ISettings AppSettings
}
}


/// <summary>
/// Show a Yes/No confirmation dialog box when closing RDMP
/// </summary>
Expand Down Expand Up @@ -604,5 +605,14 @@ public static void SetSplitterDistance(Guid controlGuid, int splitterDistance)
}
}

public static void ClearUserSettings(){
AppSettings.Clear();
}

private static ISettings CreateSettings()
{
return new RDMPApplicationSettings();
}

private static ISettings CreateSettings() => new RDMPApplicationSettings();
}
14 changes: 14 additions & 0 deletions Rdmp.UI/SimpleDialogs/UserSettingsUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion Rdmp.UI/SimpleDialogs/UserSettingsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;
using Rdmp.Core.CommandExecution.AtomicCommands;
using Rdmp.Core.ReusableLibraryCode;
using Rdmp.Core.ReusableLibraryCode.Checks;
using Rdmp.Core.ReusableLibraryCode.Settings;
Expand All @@ -16,7 +17,6 @@
using Rdmp.UI.TestsAndSetup.ServicePropogation;
using ScintillaNET;
using static BrightIdeasSoftware.ObjectListView;

namespace Rdmp.UI.SimpleDialogs;

/// <summary>
Expand Down Expand Up @@ -148,6 +148,23 @@ public UserSettingsFileUI(IActivateItems activator)
cmd.Execute();
btnClearFavourites.Enabled = !cmd.IsImpossible;
};

var clearUserSettingsCmd = new ExecuteCommandClearUserSettings(activator);
btnClearUserSettings.Enabled = true;

btnClearUserSettings.Click += (s, e) =>
{
if (activator.YesNo(
Core.GlobalStrings.ConfirmClearUserSettings,
Core.GlobalStrings.ClearUserSettings
))
{
clearUserSettingsCmd.Execute();
Dispose(true);
var settings = new UserSettingsFileUI(activator);
settings.Show();
}
};
}

private Dictionary<CheckBox, PropertyInfo> checkboxDictionary = new();
Expand Down

0 comments on commit 10e0fed

Please sign in to comment.