2
// MacOpenFileDialogHandler.cs
5
// Michael Hutchinson <mhutchinson@novell.com>
7
// Copyright (c) 2010 Novell, Inc.
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
30
using System.Collections.Generic;
31
using MonoMac.Foundation;
34
using MonoDevelop.Core;
35
using MonoDevelop.Ide;
36
using MonoDevelop.Ide.Extensions;
37
using MonoDevelop.Components.Extensions;
38
using MonoDevelop.MacInterop;
39
using MonoDevelop.Projects.Text;
41
namespace MonoDevelop.Platform.Mac
43
class SelectEncodingPopUpButton : NSPopUpButton
45
MonoMac.ObjCRuntime.Selector itemActivationSel = new MonoMac.ObjCRuntime.Selector ("itemActivated:");
46
MonoMac.ObjCRuntime.Selector addRemoveActivationSel = new MonoMac.ObjCRuntime.Selector ("addRemoveActivated:");
48
NSMenuItem autoDetectedItem, addRemoveItem;
49
TextEncoding[] encodings;
51
public SelectEncodingPopUpButton (bool showAutoDetected)
53
Cell.UsesItemFromMenu = false;
55
if (showAutoDetected) {
56
autoDetectedItem = new NSMenuItem () {
57
Title = GettextCatalog.GetString ("Auto Detected"),
60
Action = itemActivationSel,
64
addRemoveItem = new NSMenuItem () {
65
Title = GettextCatalog.GetString ("Add or Remove..."),
68
Action = addRemoveActivationSel,
72
SelectedEncodingId = null;
75
public string SelectedEncodingId {
77
var idx = Cell.MenuItem.Tag;
80
return encodings[idx - 1].Id;
83
NSMenuItem item = null;
84
if (!string.IsNullOrEmpty (value)) {
86
foreach (var e in encodings) {
88
item = Menu.ItemWithTag (i);
94
Cell.SelectItem (Cell.MenuItem = item ?? Cell.Menu.ItemAt (0));
98
void Populate (bool clear)
101
Menu.RemoveAllItems ();
103
encodings = TextEncoding.ConversionEncodings;
104
if (encodings == null || encodings.Length == 0)
105
encodings = new TextEncoding [] { TextEncoding.GetEncoding (TextEncoding.DefaultEncoding) };
107
if (autoDetectedItem != null) {
108
Menu.AddItem (autoDetectedItem);
109
Cell.MenuItem = autoDetectedItem;
110
Menu.AddItem (NSMenuItem.SeparatorItem);
114
foreach (var e in MonoDevelop.Projects.Text.TextEncoding.ConversionEncodings) {
115
Menu.AddItem (new NSMenuItem () {
116
Title = string.Format ("{0} ({1})", e.Name, e.Id),
119
Action = itemActivationSel,
123
Menu.AddItem (NSMenuItem.SeparatorItem);
124
Menu.AddItem (addRemoveItem);
127
[Export ("addRemoveActivated:")]
128
void HandleAddRemoveItemActivated (NSObject sender)
130
Cell.SelectItem (Cell.MenuItem);
132
var selection = SelectedEncodingId;
133
var dlg = new SelectEncodingPanel ();
134
if (dlg.RunModalSheet (this.Window) != 0) {
136
SelectedEncodingId = selection;
140
[Export ("itemActivated:")]
141
void HandleItemActivated (NSObject sender)
143
Cell.MenuItem = (NSMenuItem)sender;