Skip to content

Commit

Permalink
(#827) Add a confirmation when removing source
Browse files Browse the repository at this point in the history
Since this is a destructive operation for both Chocolatey and Chocolatey
GUI we should verify that this is actually what the user intended to do
before proceeding with the operation.
  • Loading branch information
gep13 committed Apr 8, 2021
1 parent 3e89b47 commit 45703b8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 43 deletions.
46 changes: 30 additions & 16 deletions Source/ChocolateyGui.Common.Windows/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,37 @@ await _progressService.ShowMessageAsync(

public async void Remove()
{
await _progressService.StartLoading(Resources.SettingsViewModel_RemovingSource);
try
{
await _chocolateyService.RemoveSource(_originalId);
Sources.Remove(SelectedSource);
SelectedSource = null;
await _eventAggregator.PublishOnUIThreadAsync(new SourcesUpdatedMessage());
}
catch (UnauthorizedAccessException)
{
await _progressService.ShowMessageAsync(
Resources.General_UnauthorisedException_Title,
Resources.General_UnauthorisedException_Description);
}
finally
var result = await _dialogCoordinator.ShowMessageAsync(
this,
Resources.Dialog_AreYouSureTitle,
string.Format(Resources.Dialog_AreYourSureRemoveSourceMessage, _originalId),
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings
{
AffirmativeButtonText = Resources.Dialog_Yes,
NegativeButtonText = Resources.Dialog_No
});

if (result == MessageDialogResult.Affirmative)
{
await _progressService.StopLoading();
await _progressService.StartLoading(Resources.SettingsViewModel_RemovingSource);
try
{
await _chocolateyService.RemoveSource(_originalId);
Sources.Remove(SelectedSource);
SelectedSource = null;
await _eventAggregator.PublishOnUIThreadAsync(new SourcesUpdatedMessage());
}
catch (UnauthorizedAccessException)
{
await _progressService.ShowMessageAsync(
Resources.General_UnauthorisedException_Title,
Resources.General_UnauthorisedException_Description);
}
finally
{
await _progressService.StopLoading();
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions Source/ChocolateyGui.Common/Properties/Resources.Designer.cs

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

58 changes: 31 additions & 27 deletions Source/ChocolateyGui.Common/Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
Expand All @@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
Expand Down Expand Up @@ -1040,4 +1040,8 @@ Please contact your System Administrator to enable this operation.</value>
<data name="LocalSourceView_ButtonUpdateAllDisabled" xml:space="preserve">
<value>No packages need to be updated</value>
</data>
<data name="Dialog_AreYourSureRemoveSourceMessage" xml:space="preserve">
<value>This action will remove the '{0}' source from both Chocolatey and Chocolatey GUI. Are you sure you want to proceed (this action cannot be undone)?</value>
<comment>{0} = The id of the source which is away to be deleted, i.e. chocolatey, chocolatey.licensed, etc</comment>
</data>
</root>

0 comments on commit 45703b8

Please sign in to comment.