Browse Source

- Finished support for external AddIns installed from .addin files. They are shown with a different icon in AddIn list.

- Improved error handling and visualization.
- Some more refactoring.
pull/32/head
Andreas Weizel 13 years ago
parent
commit
f6c202745f
  1. 3
      src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj
  2. 5
      src/AddIns/Misc/AddInManager2/Project/Resources/StringResources.resx
  3. BIN
      src/AddIns/Misc/AddInManager2/Project/Resources/external_addin_small.png
  4. 24
      src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInExceptionEventArgs.cs
  5. 12
      src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInManagerEvents.cs
  6. 49
      src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInOperationErrorEventArgs.cs
  7. 58
      src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInSetup.cs
  8. 5
      src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerEvents.cs
  9. 1
      src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/ISDAddInManagement.cs
  10. 5
      src/AddIns/Misc/AddInManager2/Project/Src/Model/SDAddInManagement.cs
  11. 22
      src/AddIns/Misc/AddInManager2/Project/Src/View/AddInManagerView.xaml
  12. 18
      src/AddIns/Misc/AddInManager2/Project/Src/View/AddInsView.xaml
  13. 9
      src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/AddInManagerViewModel.cs
  14. 8
      src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/AddInPackageViewModelBase.cs
  15. 2
      src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/InstalledAddInsViewModel.cs
  16. 12
      src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/NuGetPackageViewModel.cs
  17. 42
      src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/OfflineAddInViewModel.cs

3
src/AddIns/Misc/AddInManager2/Project/AddInManager2.csproj

@ -77,6 +77,7 @@
<Resource Include="Resources\sd_packageicon.png" /> <Resource Include="Resources\sd_packageicon.png" />
<Resource Include="Resources\accept.png" /> <Resource Include="Resources\accept.png" />
<Resource Include="Resources\exclamation.png" /> <Resource Include="Resources\exclamation.png" />
<Resource Include="Resources\external_addin_small.png" />
<None Include="Resources\license.txt" /> <None Include="Resources\license.txt" />
<Resource Include="Resources\magnifier.png" /> <Resource Include="Resources\magnifier.png" />
<Resource Include="Resources\packageicon.png" /> <Resource Include="Resources\packageicon.png" />
@ -110,7 +111,7 @@
<Compile Include="Src\Model\NuGetPackageManager.cs" /> <Compile Include="Src\Model\NuGetPackageManager.cs" />
<Compile Include="Src\Model\AddInSetup.cs" /> <Compile Include="Src\Model\AddInSetup.cs" />
<Compile Include="Src\Model\AddInManagerEvents.cs" /> <Compile Include="Src\Model\AddInManagerEvents.cs" />
<Compile Include="Src\Model\AddInExceptionEventArgs.cs" /> <Compile Include="Src\Model\AddInOperationErrorEventArgs.cs" />
<Compile Include="Src\Model\NuGetPackageOperationEventArgs.cs" /> <Compile Include="Src\Model\NuGetPackageOperationEventArgs.cs" />
<Compile Include="Src\Model\PackageMessageLoggedEventArgs.cs" /> <Compile Include="Src\Model\PackageMessageLoggedEventArgs.cs" />
<Compile Include="Src\Model\PackageRepositories.cs" /> <Compile Include="Src\Model\PackageRepositories.cs" />

5
src/AddIns/Misc/AddInManager2/Project/Resources/StringResources.resx

@ -236,7 +236,7 @@ If you do not agree to the license terms click "I Decline".</value>
<value>License Agreements</value> <value>License Agreements</value>
</data> </data>
<data name="AddInManager2.SDAddInFileFilter" xml:space="preserve"> <data name="AddInManager2.SDAddInFileFilter" xml:space="preserve">
<value>SharpDevelop AddIns|*.sdaddin|All files|*.*</value> <value>SharpDevelop AddIns|*.sdaddin;*.addin|All files|*.*</value>
</data> </data>
<data name="AddInManager2.InstallDependentMessage" xml:space="preserve"> <data name="AddInManager2.InstallDependentMessage" xml:space="preserve">
<value>Package "{0}" needs at least one additional package: <value>Package "{0}" needs at least one additional package:
@ -254,4 +254,7 @@ The application will try to download and install them, as well. Do you want to c
<data name="AddInManager2.Details.FileName" xml:space="preserve"> <data name="AddInManager2.Details.FileName" xml:space="preserve">
<value>File name:</value> <value>File name:</value>
</data> </data>
<data name="AddInManager2.InvalidPackage" xml:space="preserve">
<value>Selected package doesn't contain a valid SharpDevelop AddIn.</value>
</data>
</root> </root>

BIN
src/AddIns/Misc/AddInManager2/Project/Resources/external_addin_small.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

24
src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInExceptionEventArgs.cs

@ -1,24 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.AddInManager2.Model
{
/// <summary>
/// Data for events indicating an exception during package-related operations.
/// </summary>
public class AddInExceptionEventArgs : EventArgs
{
public AddInExceptionEventArgs(Exception exception)
{
Exception = exception;
}
public Exception Exception
{
get;
private set;
}
}
}

12
src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInManagerEvents.cs

@ -13,6 +13,14 @@ namespace ICSharpCode.AddInManager2.Model
{ {
public event EventHandler OperationStarted; public event EventHandler OperationStarted;
public void OnOperationStarted()
{
if (OperationStarted != null)
{
OperationStarted(this, new EventArgs());
}
}
public void OnOperationStarted(EventArgs e) public void OnOperationStarted(EventArgs e)
{ {
if (OperationStarted != null) if (OperationStarted != null)
@ -41,9 +49,9 @@ namespace ICSharpCode.AddInManager2.Model
} }
} }
public event EventHandler<AddInExceptionEventArgs> AddInOperationError; public event EventHandler<AddInOperationErrorEventArgs> AddInOperationError;
public void OnAddInOperationError(AddInExceptionEventArgs e) public void OnAddInOperationError(AddInOperationErrorEventArgs e)
{ {
if (AddInOperationError != null) if (AddInOperationError != null)
{ {

49
src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInOperationErrorEventArgs.cs

@ -0,0 +1,49 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.AddInManager2.Model
{
/// <summary>
/// Data for events indicating an exception or other errors during package-related operations.
/// </summary>
public class AddInOperationErrorEventArgs : EventArgs
{
private string _message = null;
public AddInOperationErrorEventArgs(Exception exception)
{
Exception = exception;
}
public AddInOperationErrorEventArgs(string message)
{
Exception = null;
_message = message;
}
public Exception Exception
{
get;
private set;
}
public string Message
{
get
{
if (_message != null)
{
return _message;
}
if (Exception != null)
{
return Exception.Message;
}
return null;
}
}
}
}

58
src/AddIns/Misc/AddInManager2/Project/Src/Model/AddInSetup.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.AddInManager2.Model
} }
catch (Exception ex) catch (Exception ex)
{ {
_events.OnAddInOperationError(new AddInExceptionEventArgs(ex)); _events.OnAddInOperationError(new AddInOperationErrorEventArgs(ex));
} }
} }
@ -71,8 +71,9 @@ namespace ICSharpCode.AddInManager2.Model
if (addInEntry != null) if (addInEntry != null)
{ {
_events.OnAddInOperationError( _events.OnAddInOperationError(
new AddInExceptionEventArgs( new AddInOperationErrorEventArgs(
new AddInLoadException("The package may only contain one .addin file."))); SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
return null;
} }
addInEntry = entry; addInEntry = entry;
} }
@ -80,8 +81,9 @@ namespace ICSharpCode.AddInManager2.Model
if (addInEntry == null) if (addInEntry == null)
{ {
_events.OnAddInOperationError( _events.OnAddInOperationError(
new AddInExceptionEventArgs( new AddInOperationErrorEventArgs(
new AddInLoadException("The package must contain one .addin file."))); SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
return null;
} }
using (Stream s = file.GetInputStream(addInEntry)) using (Stream s = file.GetInputStream(addInEntry))
{ {
@ -100,22 +102,28 @@ namespace ICSharpCode.AddInManager2.Model
{ {
AddIn addIn = null; AddIn addIn = null;
bool installAsExternal = false;
switch (Path.GetExtension(fileName).ToLowerInvariant()) switch (Path.GetExtension(fileName).ToLowerInvariant())
{ {
case ".addin": case ".addin":
if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, fileName)) if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, fileName))
{ {
// TODO Send around the error message // Don't allow to install AddIns from application root path
// MessageService.ShowMessage("${res:AddInManager.CannotInstallIntoApplicationDirectory}"); _events.OnAddInOperationError(
new AddInOperationErrorEventArgs(
SD.ResourceService.GetString("AddInManager.CannotInstallIntoApplicationDirectory")));
return null; return null;
} }
// Load directly from location // Load directly from location
addIn = _sdAddInManagement.Load(fileName); addIn = _sdAddInManagement.Load(fileName);
installAsExternal = true;
break; break;
case ".sdaddin": case ".sdaddin":
case ".zip":
// Try to load the *.sdaddin file as ZIP archive // Try to load the *.sdaddin file as ZIP archive
ZipFile zipFile = null; ZipFile zipFile = null;
try try
@ -123,10 +131,12 @@ namespace ICSharpCode.AddInManager2.Model
zipFile = new ZipFile(fileName); zipFile = new ZipFile(fileName);
addIn = LoadAddInFromZip(zipFile); addIn = LoadAddInFromZip(zipFile);
} }
catch (Exception ex) catch (Exception)
{ {
// Report the exception // ZIP file seems not to be valid
_events.OnAddInOperationError(new AddInExceptionEventArgs(ex)); _events.OnAddInOperationError(
new AddInOperationErrorEventArgs(
SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
return null; return null;
} }
finally finally
@ -139,8 +149,10 @@ namespace ICSharpCode.AddInManager2.Model
break; break;
default: default:
// TODO Send around the error message // Unknown format of file
// MessageService.ShowMessage("${res:AddInManager.UnknownFileFormat} " + Path.GetExtension(file)); _events.OnAddInOperationError(
new AddInOperationErrorEventArgs(
SD.ResourceService.GetString("AddInManager.UnknownFileFormat") + " " + Path.GetExtension(fileName)));
return null; return null;
} }
@ -149,7 +161,7 @@ namespace ICSharpCode.AddInManager2.Model
if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null)) if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null))
{ {
_events.OnAddInOperationError( _events.OnAddInOperationError(
new AddInExceptionEventArgs( new AddInOperationErrorEventArgs(
new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity"))));
return null; return null;
} }
@ -172,6 +184,8 @@ namespace ICSharpCode.AddInManager2.Model
_sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity); _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity);
} }
if (!installAsExternal)
{
// Create target directory for AddIn in user profile & copy package contents there // Create target directory for AddIn in user profile & copy package contents there
CopyAddInFromZip(addIn, fileName); CopyAddInFromZip(addIn, fileName);
@ -185,6 +199,12 @@ namespace ICSharpCode.AddInManager2.Model
addIn.Action = AddInAction.Install; addIn.Action = AddInAction.Install;
_sdAddInManagement.AddToTree(addIn); _sdAddInManagement.AddToTree(addIn);
} }
}
else
{
// Only add a reference to an external manifest
_sdAddInManagement.AddExternalAddIns(new AddIn[] { addIn });
}
// Mark this AddIn // Mark this AddIn
ManagedAddIn markedAddIn = new ManagedAddIn(addIn) ManagedAddIn markedAddIn = new ManagedAddIn(addIn)
@ -202,13 +222,9 @@ namespace ICSharpCode.AddInManager2.Model
return addIn; return addIn;
} }
else
{
// This is not a valid SharpDevelop AddIn package!
// TODO Show a message to user!
}
} }
// In successful cases we should have exited somewhere else, in error cases the error event was already fired.
return null; return null;
} }
@ -222,7 +238,7 @@ namespace ICSharpCode.AddInManager2.Model
if (addIn.Manifest.PrimaryIdentity == null) if (addIn.Manifest.PrimaryIdentity == null)
{ {
_events.OnAddInOperationError( _events.OnAddInOperationError(
new AddInExceptionEventArgs( new AddInOperationErrorEventArgs(
new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity"))));
return null; return null;
} }
@ -278,7 +294,9 @@ namespace ICSharpCode.AddInManager2.Model
else else
{ {
// This is not a valid SharpDevelop AddIn package! // This is not a valid SharpDevelop AddIn package!
// TODO Throw something. _events.OnAddInOperationError(
new AddInOperationErrorEventArgs(
SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
} }
return null; return null;

5
src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/IAddInManagerEvents.cs

@ -13,6 +13,7 @@ namespace ICSharpCode.AddInManager2.Model
{ {
event EventHandler OperationStarted; event EventHandler OperationStarted;
void OnOperationStarted(EventArgs e); void OnOperationStarted(EventArgs e);
void OnOperationStarted();
event EventHandler<AddInInstallationEventArgs> AddInInstalled; event EventHandler<AddInInstallationEventArgs> AddInInstalled;
void OnAddInInstalled(AddInInstallationEventArgs e); void OnAddInInstalled(AddInInstallationEventArgs e);
@ -20,8 +21,8 @@ namespace ICSharpCode.AddInManager2.Model
event EventHandler<AddInInstallationEventArgs> AddInUninstalled; event EventHandler<AddInInstallationEventArgs> AddInUninstalled;
void OnAddInUninstalled(AddInInstallationEventArgs e); void OnAddInUninstalled(AddInInstallationEventArgs e);
event EventHandler<AddInExceptionEventArgs> AddInOperationError; event EventHandler<AddInOperationErrorEventArgs> AddInOperationError;
void OnAddInOperationError(AddInExceptionEventArgs e); void OnAddInOperationError(AddInOperationErrorEventArgs e);
event EventHandler<PackageOperationEventArgs> AddInPackageDownloaded; event EventHandler<PackageOperationEventArgs> AddInPackageDownloaded;
void OnAddInPackageDownloaded(PackageOperationEventArgs e); void OnAddInPackageDownloaded(PackageOperationEventArgs e);

1
src/AddIns/Misc/AddInManager2/Project/Src/Model/Interfaces/ISDAddInManagement.cs

@ -35,5 +35,6 @@ namespace ICSharpCode.AddInManager2.Model
void RemoveUserAddInOnNextStart(string identity); void RemoveUserAddInOnNextStart(string identity);
AddIn Load(TextReader textReader); AddIn Load(TextReader textReader);
AddIn Load(string fileName); AddIn Load(string fileName);
void AddExternalAddIns(IList<AddIn> addIns);
} }
} }

5
src/AddIns/Misc/AddInManager2/Project/Src/Model/SDAddInManagement.cs

@ -84,5 +84,10 @@ namespace ICSharpCode.AddInManager2.Model
{ {
return AddIn.Load(SD.AddInTree, fileName); return AddIn.Load(SD.AddInTree, fileName);
} }
public void AddExternalAddIns(IList<AddIn> addIns)
{
ICSharpCode.Core.AddInManager.AddExternalAddIns(addIns);
}
} }
} }

22
src/AddIns/Misc/AddInManager2/Project/Src/View/AddInManagerView.xaml

@ -20,6 +20,25 @@
<BitmapImage x:Key="ErrorIcon" <BitmapImage x:Key="ErrorIcon"
UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/exclamation.png"/> UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/exclamation.png"/>
<Style x:Key="errorImageStyle" TargetType="{x:Type Image}">
<Setter Property="Visibility" Value="{Binding Path=HasError, Converter={StaticResource BoolToVisibility}}" />
<Setter Property="Source" Value="{StaticResource ErrorIcon}" />
<Style.Triggers>
<DataTrigger Binding="{Binding Path=HasError}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard Name="BlinkingIconStoryboard">
<Storyboard>
<DoubleAnimation
RepeatBehavior="Forever" AutoReverse="True"
From="1" To="0" Duration="0:0:0.75"
Storyboard.TargetProperty="Opacity" />
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="tabHeaderTextStyle" TargetType="{x:Type TextBlock}"> <Style x:Key="tabHeaderTextStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding DataContext.HasHighlightCount}" Value="True"> <DataTrigger Binding="{Binding DataContext.HasHighlightCount}" Value="True">
@ -60,8 +79,7 @@
<StackPanel> <StackPanel>
<Image <Image
Margin="4, 4" Margin="4, 4"
Visibility="{Binding Path=HasError, Converter={StaticResource BoolToVisibility}}" Style="{StaticResource errorImageStyle}" />
Source="{StaticResource ErrorIcon}"/>
</StackPanel> </StackPanel>
<TextBlock <TextBlock
Grid.Column="1" Grid.Column="1"

18
src/AddIns/Misc/AddInManager2/Project/Src/View/AddInsView.xaml

@ -19,6 +19,8 @@
UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/packageicon_small.png"/> UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/packageicon_small.png"/>
<BitmapImage x:Key="SDPackageIcon" <BitmapImage x:Key="SDPackageIcon"
UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/sd_packageicon.png"/> UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/sd_packageicon.png"/>
<BitmapImage x:Key="SmallExternalAddInIcon"
UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/external_addin_small.png"/>
<BitmapImage x:Key="PackageAddedIcon" <BitmapImage x:Key="PackageAddedIcon"
UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/accept.png"/> UriSource="pack://application:,,,/ICSharpCode.AddInManager2;component/Resources/accept.png"/>
<BitmapImage x:Key="SearchIcon" <BitmapImage x:Key="SearchIcon"
@ -53,6 +55,16 @@
</Style.Triggers> </Style.Triggers>
</Style> </Style>
<Style x:Key="AddInExternalStateImageStyle" TargetType="{x:Type Image}">
<Setter Property="Source" Value="{StaticResource SmallExternalAddInIcon}" />
<Setter Property="Visibility" Value="{Binding Path=IsExternallyReferenced, Converter={StaticResource BoolToVisibility}}" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsEnabled}" Value="False">
<Setter Property="Opacity" Value="0.5" />
</DataTrigger>
</Style.Triggers>
</Style>
<Style x:Key="addInListButtonStyle" TargetType="{x:Type Button}" BasedOn="{x:Static core:GlobalStyles.ButtonStyle}"> <Style x:Key="addInListButtonStyle" TargetType="{x:Type Button}" BasedOn="{x:Static core:GlobalStyles.ButtonStyle}">
<Setter Property="Visibility" Value="Collapsed" /> <Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers> <Style.Triggers>
@ -97,6 +109,12 @@
Margin="36,0,0,0" Margin="36,0,0,0"
VerticalAlignment="Top" VerticalAlignment="Top"
Style="{StaticResource AddInOnlineStateImageStyle}" /> Style="{StaticResource AddInOnlineStateImageStyle}" />
<Image
Grid.Column="0"
Height="16"
Margin="36,0,0,0"
VerticalAlignment="Top"
Style="{StaticResource AddInExternalStateImageStyle}" />
<StackPanel <StackPanel
Grid.Column="1" Grid.Column="1"
Margin="4, 0"> Margin="4, 0">

9
src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/AddInManagerViewModel.cs

@ -39,7 +39,7 @@ namespace ICSharpCode.AddInManager2.ViewModel
// Add event handlers // Add event handlers
AddInManager.Events.OperationStarted += AddInManager_Events_OperationStarted; AddInManager.Events.OperationStarted += AddInManager_Events_OperationStarted;
AddInManager.Events.AddInOperationError += AddInManager_Events_NuGetPackageOperationError; AddInManager.Events.AddInOperationError += AddInManager_Events_AddInOperationError;
AddInManager.Events.AcceptLicenses += AddInManager_Events_AcceptLicenses; AddInManager.Events.AcceptLicenses += AddInManager_Events_AcceptLicenses;
AvailableAddInsViewModel = new AvailableAddInsViewModel(); AvailableAddInsViewModel = new AvailableAddInsViewModel();
@ -79,7 +79,8 @@ namespace ICSharpCode.AddInManager2.ViewModel
public void Dispose() public void Dispose()
{ {
AddInManager.Events.AddInOperationError -= AddInManager_Events_NuGetPackageOperationError; AddInManager.Events.OperationStarted -= AddInManager_Events_OperationStarted;
AddInManager.Events.AddInOperationError -= AddInManager_Events_AddInOperationError;
AddInManager.Events.AcceptLicenses -= AddInManager_Events_AcceptLicenses; AddInManager.Events.AcceptLicenses -= AddInManager_Events_AcceptLicenses;
} }
@ -126,9 +127,9 @@ namespace ICSharpCode.AddInManager2.ViewModel
this.HasError = false; this.HasError = false;
} }
private void AddInManager_Events_NuGetPackageOperationError(object sender, AddInExceptionEventArgs e) private void AddInManager_Events_AddInOperationError(object sender, AddInOperationErrorEventArgs e)
{ {
ShowErrorMessage(e.Exception.Message); ShowErrorMessage(e.Message);
} }
private void AddInManager_Events_AcceptLicenses(object sender, AcceptLicensesEventArgs e) private void AddInManager_Events_AcceptLicenses(object sender, AcceptLicensesEventArgs e)

8
src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/AddInPackageViewModelBase.cs

@ -220,6 +220,14 @@ namespace ICSharpCode.AddInManager2.ViewModel
get; get;
} }
public virtual bool IsExternallyReferenced
{
get
{
return false;
}
}
public abstract bool IsPreinstalled public abstract bool IsPreinstalled
{ {
get; get;

2
src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/InstalledAddInsViewModel.cs

@ -125,7 +125,7 @@ namespace ICSharpCode.AddInManager2.ViewModel
} }
} }
addInPackage = new OfflineAddInsViewModelBase(addIn); addInPackage = new OfflineAddInsViewModel(addIn);
yield return addInPackage; yield return addInPackage;
} }
} }

12
src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/NuGetPackageViewModel.cs

@ -307,7 +307,8 @@ namespace ICSharpCode.AddInManager2.ViewModel
private void ClearReportedMessages() private void ClearReportedMessages()
{ {
// packageManagementEvents.OnPackageOperationsStarting(); // Notify about new operation
AddInManager.Events.OnOperationStarted();
} }
private void GetPackageOperations() private void GetPackageOperations()
@ -417,11 +418,12 @@ namespace ICSharpCode.AddInManager2.ViewModel
private void ReportError(Exception ex) private void ReportError(Exception ex)
{ {
AddInManager.Events.OnAddInOperationError(new AddInExceptionEventArgs(ex)); AddInManager.Events.OnAddInOperationError(new AddInOperationErrorEventArgs(ex));
} }
public override void RemovePackage() public override void RemovePackage()
{ {
ClearReportedMessages();
TryUninstallingPackage(); TryUninstallingPackage();
} }
@ -451,6 +453,8 @@ namespace ICSharpCode.AddInManager2.ViewModel
public override void CancelInstallation() public override void CancelInstallation()
{ {
ClearReportedMessages();
AddIn addIn = AddInManager.Setup.GetAddInForNuGetPackage(_package, true); AddIn addIn = AddInManager.Setup.GetAddInForNuGetPackage(_package, true);
if (addIn != null) if (addIn != null)
{ {
@ -460,6 +464,8 @@ namespace ICSharpCode.AddInManager2.ViewModel
public override void CancelUpdate() public override void CancelUpdate()
{ {
ClearReportedMessages();
AddIn addIn = AddInManager.Setup.GetAddInForNuGetPackage(_package, true); AddIn addIn = AddInManager.Setup.GetAddInForNuGetPackage(_package, true);
if (addIn != null) if (addIn != null)
{ {
@ -469,6 +475,8 @@ namespace ICSharpCode.AddInManager2.ViewModel
public override void CancelUninstallation() public override void CancelUninstallation()
{ {
ClearReportedMessages();
AddIn addIn = AddInManager.Setup.GetAddInForNuGetPackage(_package); AddIn addIn = AddInManager.Setup.GetAddInForNuGetPackage(_package);
if (addIn != null) if (addIn != null)
{ {

42
src/AddIns/Misc/AddInManager2/Project/Src/ViewModel/OfflineAddInViewModel.cs

@ -12,7 +12,7 @@ using NuGet;
namespace ICSharpCode.AddInManager2.ViewModel namespace ICSharpCode.AddInManager2.ViewModel
{ {
public class OfflineAddInsViewModelBase : AddInPackageViewModelBase public class OfflineAddInsViewModel : AddInPackageViewModelBase
{ {
private AddIn _addIn; private AddIn _addIn;
private ManagedAddIn _markedAddIn; private ManagedAddIn _markedAddIn;
@ -33,13 +33,13 @@ namespace ICSharpCode.AddInManager2.ViewModel
private string _description; private string _description;
private DateTime? _lastUpdated; private DateTime? _lastUpdated;
public OfflineAddInsViewModelBase(ManagedAddIn addIn) public OfflineAddInsViewModel(ManagedAddIn addIn)
: base() : base()
{ {
Initialize(addIn); Initialize(addIn);
} }
public OfflineAddInsViewModelBase(IAddInManagerServices services, ManagedAddIn addIn) public OfflineAddInsViewModel(IAddInManagerServices services, ManagedAddIn addIn)
: base(services) : base(services)
{ {
Initialize(addIn); Initialize(addIn);
@ -151,6 +151,24 @@ namespace ICSharpCode.AddInManager2.ViewModel
} }
} }
public override bool IsExternallyReferenced
{
get
{
if (_addIn != null)
{
// The AddIn is externally referenced, if it's .addin file doesn't reside in
// somewhere in application path (preinstalled AddIns) or in config path (usually installed AddIns).
return !FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, _addIn.FileName)
&& !FileUtility.IsBaseDirectory(SD.PropertyService.ConfigDirectory, _addIn.FileName);
}
else
{
return false;
}
}
}
public override bool IsPreinstalled public override bool IsPreinstalled
{ {
get get
@ -452,6 +470,8 @@ namespace ICSharpCode.AddInManager2.ViewModel
public override void RemovePackage() public override void RemovePackage()
{ {
ClearReportedMessages();
if (_addIn.Manifest.PrimaryIdentity == "ICSharpCode.AddInManager2") if (_addIn.Manifest.PrimaryIdentity == "ICSharpCode.AddInManager2")
{ {
MessageService.ShowMessage("${res:AddInManager2.CannotRemoveAddInManager}", "${res:AddInManager.Title}"); MessageService.ShowMessage("${res:AddInManager2.CannotRemoveAddInManager}", "${res:AddInManager.Title}");
@ -481,21 +501,29 @@ namespace ICSharpCode.AddInManager2.ViewModel
public override void CancelInstallation() public override void CancelInstallation()
{ {
ClearReportedMessages();
AddInManager.Setup.CancelInstallation(_addIn); AddInManager.Setup.CancelInstallation(_addIn);
} }
public override void CancelUpdate() public override void CancelUpdate()
{ {
ClearReportedMessages();
AddInManager.Setup.CancelUpdate(_addIn); AddInManager.Setup.CancelUpdate(_addIn);
} }
public override void CancelUninstallation() public override void CancelUninstallation()
{ {
ClearReportedMessages();
AddInManager.Setup.CancelUninstallation(_addIn); AddInManager.Setup.CancelUninstallation(_addIn);
} }
public override void DisablePackage() public override void DisablePackage()
{ {
ClearReportedMessages();
if (_addIn == null) if (_addIn == null)
{ {
return; return;
@ -547,6 +575,8 @@ namespace ICSharpCode.AddInManager2.ViewModel
public override void ShowOptions() public override void ShowOptions()
{ {
ClearReportedMessages();
AddInTreeNode dummyNode = new AddInTreeNode(); AddInTreeNode dummyNode = new AddInTreeNode();
foreach (KeyValuePair<string, ExtensionPath> pair in _addIn.Paths) foreach (KeyValuePair<string, ExtensionPath> pair in _addIn.Paths)
{ {
@ -559,5 +589,11 @@ namespace ICSharpCode.AddInManager2.ViewModel
_addIn.Name + " " + SD.ResourceService.GetString("AddInManager.Options"), _addIn.Name + " " + SD.ResourceService.GetString("AddInManager.Options"),
dummyNode); dummyNode);
} }
private void ClearReportedMessages()
{
// Notify about new operation
AddInManager.Events.OnOperationStarted();
}
} }
} }

Loading…
Cancel
Save