~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.MacDev/SigningIdentityCombo.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// SigningCombo.cs
3
 
//  
4
 
// Author:
5
 
//       Michael Hutchinson <mhutchinson@novell.com>
6
 
// 
7
 
// Copyright (c) 2010 Novell, Inc.
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 Gtk;
29
 
using System.ComponentModel;
30
 
using MonoDevelop.Core;
31
 
 
32
 
namespace MonoDevelop.MacDev
33
 
{
34
 
        [ToolboxItem (true)]
35
 
        [Category ("MonoDevelop.MacDev")]
36
 
        public class SigningIdentityCombo : ComboBox
37
 
        {
38
 
                ListStore store;
39
 
                
40
 
                public SigningIdentityCombo () : base (new ListStore (typeof (string), typeof (string), typeof (object)))
41
 
                {
42
 
                        store = (ListStore) this.Model;
43
 
                        
44
 
                        var txtRenderer = new CellRendererText ();
45
 
                        txtRenderer.Ellipsize = Pango.EllipsizeMode.End;
46
 
                        PackStart (txtRenderer, true);
47
 
                        AddAttribute (txtRenderer, "markup", 0);
48
 
                        
49
 
                        RowSeparatorFunc = delegate (TreeModel model, TreeIter iter) {
50
 
                                return (string)model.GetValue (iter, 0) == "-";
51
 
                        };
52
 
                }
53
 
                
54
 
                public TreeIter AddItem (string label, string name, object item)
55
 
                {
56
 
                        return store.AppendValues (GLib.Markup.EscapeText (label), name, item);
57
 
                }
58
 
                
59
 
                public TreeIter AddItemWithMarkup (string labelMarkup, string name, object item)
60
 
                {
61
 
                        return store.AppendValues (labelMarkup, name, item);
62
 
                }
63
 
                
64
 
                public void AddSeparator ()
65
 
                {
66
 
                        store.AppendValues ("-", "-", null);
67
 
                }
68
 
                
69
 
                public object SelectedItem {
70
 
                        get {
71
 
                                return this.GetActiveValue<object> (2);
72
 
                        }
73
 
                }
74
 
                
75
 
                public string SelectedName {
76
 
                        get {
77
 
                                return this.GetActiveValue<string> (1);
78
 
                        }
79
 
                        set {
80
 
                                if (string.IsNullOrEmpty (value) && store.IterNChildren () > 0) {
81
 
                                        Active = 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);
86
 
                                }
87
 
                                Sensitive = store.IterNChildren () > 1;
88
 
                                OnChanged ();
89
 
                        }
90
 
                }
91
 
                
92
 
                public void ClearList ()
93
 
                {
94
 
                        store.Clear ();
95
 
                }
96
 
        }
97
 
        
98
 
        static class GtkExtensions
99
 
        {
100
 
                public static bool SelectMatchingItem (this ComboBox combo, int column, object value)
101
 
                {
102
 
                        var m = combo.Model;
103
 
                        TreeIter iter;
104
 
                        int i = 0;
105
 
                        if (m.GetIterFirst (out iter)) {
106
 
                                do {
107
 
                                        if (value.Equals (m.GetValue (iter, column))) {
108
 
                                                combo.Active = i;
109
 
                                                return true;
110
 
                                        }
111
 
                                        i++;
112
 
                                } while (m.IterNext (ref iter));
113
 
                        }
114
 
                        return false;
115
 
                }
116
 
                
117
 
                public static T GetActiveValue<T> (this ComboBox combo, int column) where T : class
118
 
                {
119
 
                        TreeIter iter;
120
 
                        if (combo.GetActiveIter (out iter))
121
 
                                        return (T) combo.Model.GetValue (iter, column);
122
 
                        return null;
123
 
                }
124
 
        }
125
 
}
126