~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/addins/MacPlatform/MacSelectFileDialogHandler.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// MacSelectFileDialogHandler.cs
 
3
//  
 
4
// Author:
 
5
//       Michael Hutchinson <mhutchinson@novell.com>
 
6
// 
 
7
// Copyright (c) 2010 Novell, Inc. (http://www.novell.com)
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using MonoDevelop.Components.Extensions;
 
29
using OSXIntegration.Framework;
 
30
using MonoDevelop.Ide.Extensions;
 
31
using Gtk;
 
32
 
 
33
namespace MonoDevelop.Platform.Mac
 
34
{
 
35
        class MacSelectFileDialogHandler : ISelectFileDialogHandler
 
36
        {
 
37
                public bool Run (SelectFileDialogData data)
 
38
                {
 
39
                        var options = NavDialogCreationOptions.NewFromDefaults ();
 
40
                        NavDialog dialog = null;
 
41
                        
 
42
                        try {
 
43
                                options.Modality = WindowModality.AppModal;
 
44
                                
 
45
                                if (!string.IsNullOrEmpty (data.Title))
 
46
                                        options.WindowTitle = data.Title;
 
47
                                
 
48
                                options.OptionFlags |= NavDialogOptionFlags.DontAddTranslateItems
 
49
                                        & NavDialogOptionFlags.DontAutoTranslate & NavDialogOptionFlags.DontConfirmReplacement;
 
50
                                
 
51
                                if (data.SelectMultiple)
 
52
                                        options.OptionFlags |= NavDialogOptionFlags.AllowMultipleFiles;
 
53
                                else
 
54
                                        options.OptionFlags ^= NavDialogOptionFlags.AllowMultipleFiles;
 
55
                                
 
56
                                //data.SelectedFiles
 
57
                                
 
58
                                switch (data.Action) {
 
59
                                case FileChooserAction.CreateFolder:
 
60
                                        dialog = NavDialog.CreateNewFolderDialog (options);
 
61
                                        break;
 
62
                                case FileChooserAction.Save:
 
63
                                        options.SaveFileName = data.InitialFileName;
 
64
                                        dialog = NavDialog.CreatePutFileDialog (options);
 
65
                                        break;
 
66
                                case FileChooserAction.Open:
 
67
                                        dialog = NavDialog.CreateChooseFileDialog (options);
 
68
                                        break;
 
69
                                case FileChooserAction.SelectFolder:
 
70
                                        dialog = NavDialog.CreateChooseFolderDialog (options);
 
71
                                        break;
 
72
                                default:
 
73
                                        throw new InvalidOperationException ("Unknown action " + data.Action.ToString ());
 
74
                                }
 
75
                                
 
76
                                if (!string.IsNullOrEmpty (data.CurrentFolder))
 
77
                                        dialog.SetLocation (data.CurrentFolder);
 
78
                                
 
79
                                var action = dialog.Run ();
 
80
                                if (action == NavUserAction.Cancel || action == NavUserAction.None)
 
81
                                        return false;
 
82
                                using (var reply = dialog.GetReply ()) {
 
83
                                }
 
84
                        } finally {
 
85
                                if (dialog != null)
 
86
                                        dialog.Dispose ();
 
87
                                if (options != null)
 
88
                                        options.Dispose ();
 
89
                        }
 
90
                        return true;
 
91
                }
 
92
        }
 
93
        
 
94
        class MacAddFileDialogHandler : IAddFileDialogHandler
 
95
        {
 
96
                public bool Run (AddFileDialogData data)
 
97
                {
 
98
                        throw new NotImplementedException ();
 
99
                }
 
100
        }
 
101
        
 
102
        class MacOpenFileDialogHandler : IOpenFileDialogHandler
 
103
        {
 
104
                public bool Run (OpenFileDialogData data)
 
105
                {
 
106
                        throw new NotImplementedException ();
 
107
                }
 
108
        }
 
109
}
 
110