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
29
using System.ComponentModel;
30
using MonoDevelop.Core;
32
namespace MonoDevelop.MacDev
35
[Category ("MonoDevelop.MacDev")]
36
public class SigningIdentityCombo : ComboBox
40
public SigningIdentityCombo () : base (new ListStore (typeof (string), typeof (string), typeof (object)))
42
store = (ListStore) this.Model;
44
var txtRenderer = new CellRendererText ();
45
txtRenderer.Ellipsize = Pango.EllipsizeMode.End;
46
PackStart (txtRenderer, true);
47
AddAttribute (txtRenderer, "markup", 0);
49
RowSeparatorFunc = delegate (TreeModel model, TreeIter iter) {
50
return (string)model.GetValue (iter, 0) == "-";
54
public TreeIter AddItem (string label, string name, object item)
56
return store.AppendValues (GLib.Markup.EscapeText (label), name, item);
59
public TreeIter AddItemWithMarkup (string labelMarkup, string name, object item)
61
return store.AppendValues (labelMarkup, name, item);
64
public void AddSeparator ()
66
store.AppendValues ("-", "-", null);
69
public object SelectedItem {
71
return this.GetActiveValue<object> (2);
75
public string SelectedName {
77
return this.GetActiveValue<string> (1);
80
if (string.IsNullOrEmpty (value) && store.IterNChildren () > 0) {
82
} else if (!this.SelectMatchingItem (1, value)) {
83
var name = GettextCatalog.GetString ("Unknown ({0})", value);
84
var iter = AddItem (GLib.Markup.EscapeText (name), value, new object ());
85
this.SetActiveIter (iter);
87
Sensitive = store.IterNChildren () > 1;
92
public void ClearList ()
98
static class GtkExtensions
100
public static bool SelectMatchingItem (this ComboBox combo, int column, object value)
105
if (m.GetIterFirst (out iter)) {
107
if (value.Equals (m.GetValue (iter, column))) {
112
} while (m.IterNext (ref iter));
117
public static T GetActiveValue<T> (this ComboBox combo, int column) where T : class
120
if (combo.GetActiveIter (out iter))
121
return (T) combo.Model.GetValue (iter, column);