bovender framework
C# framework that implements MVVM and more
FileFolderActionBase.cs
1 /* FileFolderActionBase.cs
2  * part of Daniel's XL Toolbox NG
3  *
4  * Copyright 2014-2018 Daniel Kraus
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 using Bovender.Mvvm.Messaging;
19 using System;
20 using System.Collections.Generic;
21 using System.Linq;
22 using System.Text;
23 
24 namespace Bovender.Mvvm.Actions
25 {
30  public abstract class FileFolderActionBase : NotificationAction
31  {
32  #region Public properties
33 
34  public string Description { get; set; }
35 
36  #endregion
37 
38  #region Abstract methods
39 
47  protected abstract string GetDialogResult(
48  string defaultString,
49  string filter);
50 
51  #endregion
52 
53  #region Protected properties
54 
55  protected StringMessageContent MessageContent { get; private set; }
56 
57  #endregion
58 
59  #region Overrides
60 
61  protected override void Invoke(object parameter)
62  {
63  if (parameter == null)
64  {
65  throw new ArgumentNullException("FileFolderActionBase parameter must not be null");
66  }
68  if (args == null)
69  {
70  throw new ArgumentException(
71  String.Format(
72  "FileFolderActionBase must be invoked with FileNameMessageContent; got {0}",
73  parameter.GetType().ToString()
74  )
75  );
76  }
77  MessageContent = args.Content;
78  string result = GetDialogResult(args.Content.Value, args.Content.Filter);
79  args.Content.Confirmed = !string.IsNullOrEmpty(result);
80  if (args.Content.Confirmed)
81  {
82  args.Content.Value = result;
83  };
84  args.Respond();
85  }
86 
87  protected override System.Windows.Window CreateView()
88  {
89  throw new InvalidOperationException(
90  "This class does not create WPF views and this method should never be called.");
91  }
92 
93  #endregion
94  }
95 }
Encapsulates a string message that is part of the content that a view model sends to a consumer (view...
Abstract base class for the ChooseFileSaveAction and ChooseFolderAction classes.
override System.Windows.Window CreateView()
Returns a view that can bind to expected message contents.
Simple object that encapsulates a boolean value; to be used in MVVM interaction with MessageArgs...
Opens a generic WPF dialog window that displays a message and has a single OK button.