1
1
using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
2
4
using System . Threading . Tasks ;
3
5
using System . Windows ;
4
6
using Drachenhorn . Core . Lang ;
7
+ using Drachenhorn . Core . UI ;
5
8
using Drachenhorn . Desktop . UI . Dialogs ;
6
- using GalaSoft . MvvmLight . Views ;
7
9
8
10
namespace Drachenhorn . Desktop . UI . MVVM
9
11
{
10
12
public class DialogService : IDialogService
11
13
{
12
- public Task ShowError ( string message , string title , string buttonText , Action afterHideCallback )
14
+ /// <inheritdoc />
15
+ public Task < int > ShowMessage ( string message , string title = null ,
16
+ IEnumerable < string > buttons = null , Action < int > afterHideCallback = null )
13
17
{
14
- return ShowMessage ( message , title , buttonText , afterHideCallback ) ;
18
+ //TODO: MetroMessageDialog
19
+ return ShowMessageExternal ( message , title , buttons , afterHideCallback ) ;
15
20
}
16
21
17
- public async Task ShowError ( Exception error , string title , string buttonText , Action afterHideCallback )
22
+ /// <inheritdoc />
23
+ public Task < int > ShowMessageExternal ( string message , string title = null ,
24
+ IEnumerable < string > buttons = null , Action < int > afterHideCallback = null )
18
25
{
19
- await Task . Run ( ( ) => { new ExceptionMessageBox ( error , title ) . ShowDialog ( ) ; } ) ;
20
- }
21
-
22
- public async Task ShowMessage ( string message , string title )
23
- {
24
- await Task . Run ( ( ) =>
25
- {
26
- MessageBox . Show (
27
- LanguageManager . TextTranslate ( message ) ,
28
- LanguageManager . TextTranslate ( title ) ,
29
- MessageBoxButton . OK ) ;
30
- } ) ;
31
- }
32
-
33
- public Task ShowMessage ( string message , string title , string buttonText , Action afterHideCallback )
34
- {
35
- var result = new CommonMessageBox ( message , title , buttonText ) . ShowDialog ( ) == true ;
26
+ if ( buttons == null || ! buttons . Any ( ) )
27
+ buttons = new List < string > { LanguageManager . Translate ( "UI.OK" ) } ;
36
28
37
- afterHideCallback ? . Invoke ( ) ;
38
-
39
- return Task . Run ( ( ) => result ) ;
40
- }
41
-
42
- public Task < bool > ShowMessage ( string message , string title , string buttonConfirmText , string buttonCancelText ,
43
- Action < bool > afterHideCallback )
44
- {
45
- var result = new CommonMessageBox ( message , title , buttonConfirmText , buttonCancelText ) . ShowDialog ( ) == true ;
29
+ var result = new CommonMessageBox ( message , title , buttons . ToArray ( ) ) . ShowDialog ( ) ;
46
30
47
31
afterHideCallback ? . Invoke ( result ) ;
48
32
49
33
return Task . Run ( ( ) => result ) ;
50
34
}
51
35
52
- public async Task ShowMessageBox ( string message , string title )
36
+ /// <inheritdoc />
37
+ public Task ShowException ( Exception e , string title , Action afterHideCallback )
53
38
{
54
- await Task . Run ( ( ) =>
55
- {
56
- MessageBox . Show (
57
- LanguageManager . TextTranslate ( message ) ,
58
- LanguageManager . TextTranslate ( title ) ,
59
- MessageBoxButton . OK ) ;
60
- } ) ;
39
+ return Task . Run ( ( ) => { new ExceptionMessageBox ( e , title ) . ShowDialog ( ) ; } ) ;
61
40
}
62
41
}
63
42
}
0 commit comments