Skip to content
Browse files

implemented OpenDialoge in the workbenchservice as win32 wrapper

  • Loading branch information...
1 parent f90338f commit c1bc9e0b5ef646dafa7c594c084bae48f4250711 @IsNull committed Aug 14, 2011
View
2 Archimedes.Patterns.Services.WPF/Archimedes.Services.WPF.csproj
@@ -72,6 +72,7 @@
<Compile Include="FrameWorkDialogs\FolderBrowse\FolderBrowserDialog.cs" />
<Compile Include="FrameWorkDialogs\FolderBrowse\FolderBrowserDialogViewModel.cs" />
<Compile Include="FrameWorkDialogs\FolderBrowse\IFolderBrowserDialog.cs" />
+ <Compile Include="FrameWorkDialogs\IDialogWrapper.cs" />
<Compile Include="FrameWorkDialogs\IFileDialog.cs" />
<Compile Include="FrameWorkDialogs\OpenFile\IOpenFileDialog.cs" />
<Compile Include="FrameWorkDialogs\OpenFile\OpenFileDialog.cs" />
@@ -92,6 +93,7 @@
<Compile Include="WindowViewModelMapping\IWindowViewModelMappings.cs" />
<Compile Include="WindowViewModelMapping\IWindowViewModelMappingsContract.cs" />
<Compile Include="WindowViewModelMapping\WindowViewModelMappings.cs" />
+ <Compile Include="WorkBenchServices\DialogWPFResult.cs" />
<Compile Include="WorkBenchServices\IWorkBenchService.cs" />
<Compile Include="WorkBenchServices\Loader\Block.xaml.cs">
<DependentUpon>Block.xaml</DependentUpon>
View
4 Archimedes.Patterns.Services.WPF/FrameWorkDialogs/FolderBrowse/FolderBrowserDialog.cs
@@ -3,12 +3,12 @@
using System.Windows.Forms;
using WinFormsFolderBrowserDialog = System.Windows.Forms.FolderBrowserDialog;
-namespace Archimedes.Services.WPF.FrameWorkDialogs.FolderBrowse
+namespace Archimedes.Services.WPF.FrameWorkDialogs
{
/// <summary>
/// Class wrapping System.Windows.Forms.FolderBrowserDialog, making it accept a ViewModel.
/// </summary>
- public class FolderBrowserDialog : IDisposable
+ public class FolderBrowserDialog : IDialogWrapper
{
private readonly IFolderBrowserDialog folderBrowserDialog;
private WinFormsFolderBrowserDialog concreteFolderBrowserDialog;
View
2 ...medes.Patterns.Services.WPF/FrameWorkDialogs/FolderBrowse/FolderBrowserDialogViewModel.cs
@@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
-namespace Archimedes.Services.WPF.FrameWorkDialogs.FolderBrowse
+namespace Archimedes.Services.WPF.FrameWorkDialogs
{
/// <summary>
/// Interface describing the FolderBrowserDialog.
View
2 Archimedes.Patterns.Services.WPF/FrameWorkDialogs/FolderBrowse/IFolderBrowserDialog.cs
@@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
-namespace Archimedes.Services.WPF.FrameWorkDialogs.FolderBrowse
+namespace Archimedes.Services.WPF.FrameWorkDialogs
{
/// <summary>
/// Interface describing the FolderBrowserDialog.
View
13 Archimedes.Patterns.Services.WPF/FrameWorkDialogs/IDialogWrapper.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Archimedes.Services.WPF.FrameWorkDialogs
+{
+ internal interface IDialogWrapper : IDisposable
+ {
+ DialogResult ShowDialog(IWin32Window owner);
+ }
+}
View
2 Archimedes.Patterns.Services.WPF/FrameWorkDialogs/OpenFile/IOpenFileDialog.cs
@@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
-namespace Archimedes.Services.WPF.FrameWorkDialogs.OpenFile
+namespace Archimedes.Services.WPF.FrameWorkDialogs
{
/// <summary>
/// Interface describing the OpenFileDialog.
View
4 Archimedes.Patterns.Services.WPF/FrameWorkDialogs/OpenFile/OpenFileDialog.cs
@@ -3,12 +3,12 @@
using System.Windows.Forms;
using WinFormsOpenFileDialog = System.Windows.Forms.OpenFileDialog;
-namespace Archimedes.Services.WPF.FrameWorkDialogs.OpenFile
+namespace Archimedes.Services.WPF.FrameWorkDialogs
{
/// <summary>
/// Class wrapping System.Windows.Forms.OpenFileDialog, making it accept a IOpenFileDialog.
/// </summary>
- public class OpenFileDialog : IDisposable
+ public class OpenFileDialog : IDialogWrapper
{
private readonly IOpenFileDialog openFileDialog;
private WinFormsOpenFileDialog concreteOpenFileDialog;
View
2 Archimedes.Patterns.Services.WPF/FrameWorkDialogs/OpenFile/OpenFileDialogViewModel.cs
@@ -3,7 +3,7 @@
using System.Linq;
using System.Text;
-namespace Archimedes.Services.WPF.FrameWorkDialogs.OpenFile
+namespace Archimedes.Services.WPF.FrameWorkDialogs
{
/// <summary>
/// ViewModel of the OpenFileDialog.
View
5 Archimedes.Patterns.Services.WPF/FrameWorkDialogs/WindowWrapper.cs
@@ -17,7 +17,10 @@ class WindowWrapper : IWin32Window
/// </summary>
/// <param name="window">The WPF window to wrap.</param>
public WindowWrapper(Window window) {
- Handle = new System.Windows.Interop.WindowInteropHelper(window).Handle;
+ if(window != null)
+ Handle = new System.Windows.Interop.WindowInteropHelper(window).Handle;
+ else
+ Handle = IntPtr.Zero;
}
View
88 Archimedes.Patterns.Services.WPF/WorkBenchServices/DialogWPFResult.cs
@@ -0,0 +1,88 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace Archimedes.Services.WPF.WorkBenchServices
+{
+ /// <summary>
+ /// Independend Dialoge-Result (abstracts underliing Windows.Forms/WPF/Platform)
+ /// Specifies identifiers to indicate the return value of a dialog box.
+ /// </summary>
+ public enum IDDialogResult
+ {
+ /// <summary>
+ /// Nothing is returned from the dialog box. This means that the modal dialog
+ /// continues running.
+ /// </summary>
+ None = 0,
+
+ /// <summary>
+ /// The dialog box return value is OK (usually sent from a button labeled OK).
+ /// </summary>
+ OK = 1,
+
+ /// <summary>
+ /// The dialog box return value is Cancel (usually sent from a button labeled Cancel).
+ /// </summary>
+ Cancel = 2,
+
+ /// <summary>
+ /// The dialog box return value is Abort (usually sent from a button labeled Abort).
+ /// </summary>
+ Abort = 3,
+
+ /// <summary>
+ /// The dialog box return value is Retry (usually sent from a button labeled Retry).
+ /// </summary>
+ Retry = 4,
+
+ /// <summary>
+ /// The dialog box return value is Ignore (usually sent from a button labeled Ignore).
+ /// </summary>
+ Ignore = 5,
+
+ /// <summary>
+ /// The dialog box return value is Yes (usually sent from a button labeled Yes).
+ /// </summary>
+ Yes = 6,
+
+
+ /// <summary>
+ /// The dialog box return value is No (usually sent from a button labeled No).
+ /// </summary>
+ No = 7,
+ }
+
+
+ internal static class IDDialogResultConverter
+ {
+
+ internal static IDDialogResult From(DialogResult dlgResult) {
+ switch(dlgResult) {
+
+ case DialogResult.Abort:
+ return IDDialogResult.Abort;
+ case DialogResult.Cancel:
+ return IDDialogResult.Cancel;
+ case DialogResult.Ignore:
+ return IDDialogResult.Ignore;
+ case DialogResult.No:
+ return IDDialogResult.No;
+ case DialogResult.None:
+ return IDDialogResult.None;
+ case DialogResult.OK:
+ return IDDialogResult.OK;
+ case DialogResult.Retry:
+ return IDDialogResult.Retry;
+ case DialogResult.Yes:
+ return IDDialogResult.Yes;
+
+ default:
+ return IDDialogResult.None;
+ }
+ }
+ }
+
+}
View
16 Archimedes.Patterns.Services.WPF/WorkBenchServices/IWorkBenchService.cs
@@ -7,6 +7,7 @@
using Archimedes.Patterns.WPF.ViewModels;
using System.Windows.Documents;
using Archimedes.Services.WPF.WindowViewModelMapping;
+using Archimedes.Services.WPF.FrameWorkDialogs;
namespace Archimedes.Services.WPF.WorkBenchServices
{
@@ -35,10 +36,14 @@ public interface IWorkBenchService
void LoaderView(bool display);
- void ShowRapport(WorkspaceViewModel viewModel, FlowDocument template);
+ void ShowRapport(WorkspaceViewModel viewModel, DependencyObject template);
#region Show Content Methods
+ IDDialogResult ShowDialog(IFileDialog fileDialog, WorkspaceViewModel ownerVM = null);
+
+ #region Show WorkspaceViewModel
+
/// <summary>
/// Show the ViewModel as modal Dialog window (blocks current thread)
/// </summary>
@@ -78,6 +83,9 @@ public interface IWorkBenchService
/// <param name="windowSize"></param>
void ShowFloating(WorkspaceViewModel viewModel, SizeToContent sizeToContent = SizeToContent.WidthAndHeight, Size? windowSize = null);
+ #endregion
+
+ #region Show MessageBox
/// <summary>
/// Show a common MessageBox Dialoge
@@ -87,7 +95,7 @@ public interface IWorkBenchService
/// <param name="type">Type of the Message, which will result in diffrent images displayed to the user</param>
/// <param name="button"></param>
/// <returns></returns>
- DialogWPFResult MessageBox(string message, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK);
+ IDDialogResult MessageBox(string message, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK);
/// <summary>
/// Show a common MessageBox Dialoge
@@ -98,7 +106,9 @@ public interface IWorkBenchService
/// <param name="type">Type of the Message, which will result in diffrent images displayed to the user</param>
/// <param name="button"></param>
/// <returns></returns>
- DialogWPFResult MessageBox(string message, string detail, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK);
+ IDDialogResult MessageBox(string message, string detail, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK);
+
+ #endregion
#endregion
View
42 Archimedes.Patterns.Services.WPF/WorkBenchServices/MessageBox/MessageBoxType.cs
@@ -63,45 +63,5 @@ public enum MessageBoxWPFButton
}
- // Summary:
- // Specifies identifiers to indicate the return value of a dialog box.
- public enum DialogWPFResult
- {
- // Summary:
- // Nothing is returned from the dialog box. This means that the modal dialog
- // continues running.
- None = 0,
- //
- // Summary:
- // The dialog box return value is OK (usually sent from a button labeled OK).
- OK = 1,
- //
- // Summary:
- // The dialog box return value is Cancel (usually sent from a button labeled
- // Cancel).
- Cancel = 2,
- //
- // Summary:
- // The dialog box return value is Abort (usually sent from a button labeled
- // Abort).
- Abort = 3,
- //
- // Summary:
- // The dialog box return value is Retry (usually sent from a button labeled
- // Retry).
- Retry = 4,
- //
- // Summary:
- // The dialog box return value is Ignore (usually sent from a button labeled
- // Ignore).
- Ignore = 5,
- //
- // Summary:
- // The dialog box return value is Yes (usually sent from a button labeled Yes).
- Yes = 6,
- //
- // Summary:
- // The dialog box return value is No (usually sent from a button labeled No).
- No = 7,
- }
+
}
View
16 Archimedes.Patterns.Services.WPF/WorkBenchServices/MessageBox/MessageBoxViewModel.cs
@@ -20,7 +20,7 @@ public class MessageBoxViewModel : WorkspaceViewModel
string _imageSource;
MessageBoxType _messageBoxImage = MessageBoxType.None;
readonly MessageBoxWPFButton _buttons = MessageBoxWPFButton.OK;
- DialogWPFResult _dialogeResult = DialogWPFResult.Abort;
+ IDDialogResult _dialogeResult = IDDialogResult.Abort;
string _button1;
string _button2;
@@ -83,7 +83,7 @@ public class MessageBoxViewModel : WorkspaceViewModel
}
}
- public DialogWPFResult DialogeResult {
+ public IDDialogResult DialogeResult {
get { return _dialogeResult; }
private set { _dialogeResult = value; }
}
@@ -181,27 +181,27 @@ public class MessageBoxViewModel : WorkspaceViewModel
void ButtonAction(int n){
switch(_buttons){
case MessageBoxWPFButton.OK:
- _dialogeResult = DialogWPFResult.OK;
+ _dialogeResult = IDDialogResult.OK;
break;
case MessageBoxWPFButton.OKCancel:
- _dialogeResult = (n == 1) ? DialogWPFResult.OK : DialogWPFResult.Cancel;
+ _dialogeResult = (n == 1) ? IDDialogResult.OK : IDDialogResult.Cancel;
break;
case MessageBoxWPFButton.YesNo:
- _dialogeResult = (n == 1) ? DialogWPFResult.Yes : DialogWPFResult.No;
+ _dialogeResult = (n == 1) ? IDDialogResult.Yes : IDDialogResult.No;
break;
case MessageBoxWPFButton.YesNoCancel:
switch (n) {
case 1:
- _dialogeResult = DialogWPFResult.Yes;
+ _dialogeResult = IDDialogResult.Yes;
break;
case 2:
- _dialogeResult = DialogWPFResult.No;
+ _dialogeResult = IDDialogResult.No;
break;
case 3:
- _dialogeResult = DialogWPFResult.Cancel;
+ _dialogeResult = IDDialogResult.Cancel;
break;
}
break;
View
57 Archimedes.Patterns.Services.WPF/WorkBenchServices/WorkBenchService.cs
@@ -17,6 +17,7 @@ namespace Archimedes.Services.WPF.WorkBenchServices
using Archimedes.Patterns.WPF.ViewModels;
using Archimedes.Services.WPF.WorkBenchServices.Loader;
using System.Windows.Documents;
+ using Archimedes.Services.WPF.FrameWorkDialogs;
/// <summary>
/// Implements the workbenchservice backing AvalonDock
@@ -72,11 +73,37 @@ public class AvalonWorkBenchService : IWorkBenchService
#region IWorkBenchService
- public void ShowRapport(WorkspaceViewModel viewModel, FlowDocument template) {
+ public IDDialogResult ShowDialog(IFileDialog fileDialog, WorkspaceViewModel ownerVM = null) {
- if (viewModel == null)
+ IDialogWrapper dlgwrapper = null;
+
+ if(fileDialog is IFolderBrowserDialog) {
+ dlgwrapper = new FolderBrowserDialog(fileDialog as IFolderBrowserDialog);
+ } else if(fileDialog is IOpenFileDialog) {
+ dlgwrapper = new OpenFileDialog(fileDialog as IOpenFileDialog);
+ }else
+ throw new NotSupportedException(fileDialog.GetType().Name);
+
+ Window owner = null;
+ if(ownerVM == null) {
+ owner = Window.GetWindow(DockManager);
+
+ } else {
+ var content = FindContentByViewModel(ownerVM);
+ if(content != null)
+ owner = Window.GetWindow(content);
+ }
+
+ return IDDialogResultConverter.From(dlgwrapper.ShowDialog(new WindowWrapper(owner)));
+ }
+
+ #region Show VM Content Methods
+
+ public void ShowRapport(WorkspaceViewModel viewModel, DependencyObject template) {
+
+ if(viewModel == null)
throw new ArgumentNullException("viewModel");
- if (template == null)
+ if(template == null)
throw new ArgumentNullException("template");
var dockableContent = CreateDockableContent(template, viewModel);
@@ -90,8 +117,6 @@ public class AvalonWorkBenchService : IWorkBenchService
dockableContent.ShowAsDialoge(DockManager);
}
- #region Show VM Content Methods
-
/// <summary>
/// Show the VM in a dockable floating window
/// </summary>
@@ -183,7 +208,7 @@ public class AvalonWorkBenchService : IWorkBenchService
/// <param name="type">Type of the Message, which will result in diffrent images displayed to the user</param>
/// <param name="button"></param>
/// <returns></returns>
- public DialogWPFResult MessageBox(string message, string detail, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK) {
+ public IDDialogResult MessageBox(string message, string detail, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK) {
var vm = new MessageBoxViewModel(message, button);
vm.DisplayName = title;
vm.DetailMessage = detail;
@@ -209,7 +234,7 @@ public class AvalonWorkBenchService : IWorkBenchService
/// <param name="type">Type of the Message, which will result in diffrent images displayed to the user</param>
/// <param name="button"></param>
/// <returns></returns>
- public DialogWPFResult MessageBox(string message, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK) {
+ public IDDialogResult MessageBox(string message, string title, MessageBoxType type = MessageBoxType.None, MessageBoxWPFButton button = MessageBoxWPFButton.OK) {
var vm = new MessageBoxViewModel(message, button);
vm.DisplayName = title;
vm.MessageBoxImage = type;
@@ -341,8 +366,6 @@ public class AvalonWorkBenchService : IWorkBenchService
dockableContent.DockableStyle = DockableStyle.Floating;
dockableContent.FloatingWindowSizeToContent = sizeToContent;
dockableContent.HideOnClose = false;
- //dockableContent.Closing += (s, e) => viewModel.OnRequestClose();
-
if (windowSize.HasValue) {
dockableContent.FloatingWindowSize = windowSize.Value;
@@ -363,7 +386,7 @@ public class AvalonWorkBenchService : IWorkBenchService
dockableContent = CreateDockableContent(view, viewModel);
return dockableContent;
}
-
+
DockableContent CreateDockableContent(DependencyObject view, WorkspaceViewModel viewModel) {
var dockableContent = new DockableContent();
dockableContent.HideOnClose = false;
@@ -435,6 +458,11 @@ public class AvalonWorkBenchService : IWorkBenchService
return dockableContent;
}
+ /// <summary>
+ /// Finds the representing Content (View) Representation of the given ViewModel
+ /// </summary>
+ /// <param name="vm"></param>
+ /// <returns></returns>
ManagedContent FindContentByViewModel(WorkspaceViewModel vm) {
ManagedContent content = null;
@@ -468,7 +496,6 @@ public class AvalonWorkBenchService : IWorkBenchService
}
}
}
-
}
return content;
@@ -493,14 +520,6 @@ public class AvalonWorkBenchService : IWorkBenchService
window.Closed -= (a, b) => CleanUp(element, vm, window);
}
- //void UpdateHiddenContent(){
- // if (DockManager != null) {
- // var list = DockManager.DockableContents.Where(dc => dc.State == DockableContentState.Hidden).ToList();
- // HiddenContents.Clear();
- // foreach (var dc in list)
- // HiddenContents.Add(dc);
- // }
- //}
#endregion
#region Event Handlers

0 comments on commit c1bc9e0

Please sign in to comment.
Something went wrong with that request. Please try again.