Browse Source

Use WPF for file conflict dialog.

MessageService.ShowCustomDialog() does not set focus
to the accept button.
Extract common code from the NuGet addin dialogs.
pull/44/head
Matt Ward 12 years ago
parent
commit
64f2ec885e
  1. 7
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  2. 36
      src/AddIns/Misc/PackageManagement/Project/Src/FileConflictResolver.cs
  3. 63
      src/AddIns/Misc/PackageManagement/Project/Src/FileConflictView.xaml
  4. 32
      src/AddIns/Misc/PackageManagement/Project/Src/FileConflictView.xaml.cs
  5. 48
      src/AddIns/Misc/PackageManagement/Project/Src/FileConflictViewModel.cs
  6. 14
      src/AddIns/Misc/PackageManagement/Project/Src/LicenseAcceptanceService.cs
  7. 14
      src/AddIns/Misc/PackageManagement/Project/Src/SelectProjectsService.cs
  8. 24
      src/AddIns/Misc/PackageManagement/Project/Src/ServiceWithWorkbenchOwner.cs

7
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -148,6 +148,11 @@ @@ -148,6 +148,11 @@
<Compile Include="Src\EnvDTE\TextPoint.cs" />
<Compile Include="Src\EnvDTE\Window.cs" />
<Compile Include="Src\FileConflictResolver.cs" />
<Compile Include="Src\FileConflictView.xaml.cs">
<DependentUpon>FileConflictView.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\FileConflictViewModel.cs" />
<Compile Include="Src\IClassKindUpdater.cs" />
<Compile Include="Src\IDocumentNamespaceCreator.cs" />
<Compile Include="Src\IPackageExtensions.cs" />
@ -226,6 +231,7 @@ @@ -226,6 +231,7 @@
<Compile Include="Src\PackageManagementServiceProvider.cs" />
<Compile Include="Src\ProjectBuilder.cs" />
<Compile Include="Src\ResolveFileConflictEventArgs.cs" />
<Compile Include="Src\ServiceWithWorkbenchOwner.cs" />
<Compile Include="Src\VirtualMethodUpdater.cs" />
<Compile Include="Src\NewProjectsCreated.cs" />
<Compile Include="Src\OpenMSBuildProjects.cs" />
@ -480,6 +486,7 @@ @@ -480,6 +486,7 @@
<Compile Include="Src\VisualStudio\VsSolution.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="Src\FileConflictView.xaml" />
<Page Include="Src\ManagePackagesView.xaml" />
<Page Include="Src\LicenseAcceptanceView.xaml" />
<Page Include="Src\PackageManagementOptionsView.xaml" />

36
src/AddIns/Misc/PackageManagement/Project/Src/FileConflictResolver.cs

@ -7,38 +7,22 @@ using NuGet; @@ -7,38 +7,22 @@ using NuGet;
namespace ICSharpCode.PackageManagement
{
public class FileConflictResolver : IFileConflictResolver
public class FileConflictResolver : ServiceWithWorkbenchOwner, IFileConflictResolver
{
string[] buttons = new string[] { "Yes", "Yes to All", "No", "No to All" };
const int YesButtonIndex = 0;
const int YesToAllButtonIndex = 1;
const int NoButtonIndex = 2;
const int NoToAllButtonIndex = 3;
public FileConflictResolution ResolveFileConflict(string message)
{
int result = MessageService.ShowCustomDialog(
"File Conflict",
message,
NoButtonIndex, // "No" is default accept button.
-1,
buttons);
return MapResultToFileConflictResolution(result);
var viewModel = new FileConflictViewModel(message);
FileConflictView view = CreateFileConflictView(viewModel);
view.ShowDialog();
return viewModel.GetResolution();
}
FileConflictResolution MapResultToFileConflictResolution(int result)
FileConflictView CreateFileConflictView(FileConflictViewModel viewModel)
{
switch (result) {
case YesButtonIndex:
return FileConflictResolution.Overwrite;
case YesToAllButtonIndex:
return FileConflictResolution.OverwriteAll;
case NoToAllButtonIndex:
return FileConflictResolution.IgnoreAll;
default:
return FileConflictResolution.Ignore;
}
var view = new FileConflictView();
view.ViewModel = viewModel;
view.Owner = Owner;
return view;
}
}
}

63
src/AddIns/Misc/PackageManagement/Project/Src/FileConflictView.xaml

@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
<Window
x:Class="ICSharpCode.PackageManagement.FileConflictView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="File Conflict"
FocusManager.FocusedElement="{Binding ElementName=NoButton}"
WindowStartupLocation="CenterOwner"
Style="{x:Static core:GlobalStyles.DialogWindowStyle}"
MinHeight="150"
Height="150"
MinWidth="400"
Width="200">
<Window.Resources>
<Style TargetType="Button" BasedOn="{x:Static core:GlobalStyles.ButtonStyle}"/>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock
Margin="5"
Text="{Binding Message}"
Grid.ColumnSpan="5"
TextWrapping="Wrap"/>
<Button
Margin="4"
Grid.Row="1"
Grid.Column="1"
Command="{Binding YesCommand}"
Content="Yes"/>
<Button
Margin="4"
Grid.Row="1"
Grid.Column="2"
Command="{Binding YesToAllCommand}"
Content="Yes to All"/>
<Button
x:Name="NoButton"
Margin="4"
Grid.Row="1"
Grid.Column="3"
IsDefault="True"
Command="{Binding NoCommand}"
Content="No"/>
<Button
Margin="4"
Grid.Row="1"
Grid.Column="4"
Command="{Binding NoToAllCommand}"
Content="No to All"/>
</Grid>
</Window>

32
src/AddIns/Misc/PackageManagement/Project/Src/FileConflictView.xaml.cs

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
// 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;
using System.Windows;
namespace ICSharpCode.PackageManagement
{
public partial class FileConflictView : Window
{
FileConflictViewModel viewModel;
public FileConflictView()
{
InitializeComponent();
}
public FileConflictViewModel ViewModel {
get { return viewModel; }
set {
viewModel = value;
viewModel.Close += CloseView;
DataContext = viewModel;
}
}
void CloseView(object sender, EventArgs e)
{
DialogResult = true;
}
}
}

48
src/AddIns/Misc/PackageManagement/Project/Src/FileConflictViewModel.cs

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
// 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;
using System.Windows.Input;
using NuGet;
namespace ICSharpCode.PackageManagement
{
public class FileConflictViewModel
{
FileConflictResolution resolution = FileConflictResolution.Ignore;
public FileConflictViewModel(string message)
{
this.Message = message;
CreateCommands();
}
void CreateCommands()
{
YesCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.Overwrite));
YesToAllCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.OverwriteAll));
NoCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.Ignore));
NoToAllCommand = new DelegateCommand(param => UpdateResolution(FileConflictResolution.IgnoreAll));
}
void UpdateResolution(FileConflictResolution resolution)
{
this.resolution = resolution;
Close(this, new EventArgs());
}
public event EventHandler Close;
public ICommand YesCommand { get; private set; }
public ICommand YesToAllCommand { get; private set; }
public ICommand NoCommand { get; private set; }
public ICommand NoToAllCommand { get; private set; }
public string Message { get; private set; }
public FileConflictResolution GetResolution()
{
return resolution;
}
}
}

14
src/AddIns/Misc/PackageManagement/Project/Src/LicenseAcceptanceService.cs

@ -10,20 +10,8 @@ using NuGet; @@ -10,20 +10,8 @@ using NuGet;
namespace ICSharpCode.PackageManagement
{
public class LicenseAcceptanceService : ILicenseAcceptanceService
public class LicenseAcceptanceService : ServiceWithWorkbenchOwner, ILicenseAcceptanceService
{
Window owner;
public Window Owner {
get {
if (owner == null) {
owner = WorkbenchSingleton.MainWindow;
}
return owner;
}
set { owner = value; }
}
public bool AcceptLicenses(IEnumerable<IPackage> packages)
{
LicenseAcceptanceView view = CreateLicenseAcceptanceView(packages);

14
src/AddIns/Misc/PackageManagement/Project/Src/SelectProjectsService.cs

@ -8,20 +8,8 @@ using ICSharpCode.SharpDevelop.Gui; @@ -8,20 +8,8 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PackageManagement
{
public class SelectProjectsService : ISelectProjectsService
public class SelectProjectsService : ServiceWithWorkbenchOwner, ISelectProjectsService
{
Window owner;
public Window Owner {
get {
if (owner == null) {
owner = WorkbenchSingleton.MainWindow;
}
return owner;
}
set { owner = value; }
}
public bool SelectProjects(IEnumerable<IPackageManagementSelectedProject> projects)
{
SelectProjectsView view = CreateSelectProjectsView(projects);

24
src/AddIns/Misc/PackageManagement/Project/Src/ServiceWithWorkbenchOwner.cs

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
// 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;
using System.Windows;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.PackageManagement
{
public class ServiceWithWorkbenchOwner
{
Window owner;
public Window Owner {
get {
if (owner == null) {
owner = WorkbenchSingleton.MainWindow;
}
return owner;
}
set { owner = value; }
}
}
}
Loading…
Cancel
Save