~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to Pastebin/src/Config/PastebinConfig.cs

  • Committer: Chris Szikszoy
  • Date: 2008-11-21 05:09:06 UTC
  • Revision ID: chris@chris-laptop-ibex-20081121050906-y3rh3ni89a503kw2
changes to Pastebin UI

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
//  this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
using System;
 
21
using System.Collections.Generic;
21
22
using Do.Addins;
22
23
 
23
24
namespace Pastebin
29
30
                public PastebinConfig ()
30
31
                {
31
32
                        this.Build();
32
 
                        
33
 
                        switch (SelectedProviderType) {
34
 
                        case "Pastebin.Paste2":
35
 
                                Paste2RadioButton.Active = true;
36
 
                                break;
37
 
                        case "Pastebin.PastebinCA":
38
 
                                PastebinCARadioButton.Active = true;
39
 
                                break;
40
 
                        case "Pastebin.LodgeIt":
41
 
                                LodgeItRadioButton.Active = true;
42
 
                                break;
43
 
                        default:
44
 
                                Paste2RadioButton.Active = true;
45
 
                                break;
46
 
                        }
 
33
                        SetupColumns();
 
34
                        FillProviders();
47
35
                }       
48
36
                
 
37
                private void SetupColumns()
 
38
                {               
 
39
                        //setup columns
 
40
                        /*
 
41
                        Gtk.TreeViewColumn IconCol = new Gtk.TreeViewColumn();
 
42
                        Gtk.CellRendererPixbuf pixbuf = new Gtk.CellRendererPixbuf ();  
 
43
                        IconCol.PackStart(pixbuf, false);
 
44
                        treeCodes.AppendColumn(IconCol);
 
45
                        IconCol.AddAttribute(pixbuf, "pixbuf", 0);
 
46
                        */
 
47
                        
 
48
                        Gtk.TreeViewColumn CodeCol = new Gtk.TreeViewColumn();
 
49
                        Gtk.CellRendererText text = new Gtk.CellRendererText();
 
50
                        CodeCol.PackStart(text, true);
 
51
                        treeCodes.AppendColumn(CodeCol);
 
52
                        CodeCol.AddAttribute(text, "text", 0);
 
53
                }               
 
54
                
49
55
                public static string SelectedProviderType {
50
56
                        get { return prefs.Get<string> ("SelectedProviderType", typeof(Paste2).ToString()); }
51
57
                        set { prefs.Set<string> ("SelectedProviderType", value); }
55
61
                {
56
62
                        prefs = Do.Addins.Util.GetPreferences ("Pastebin");
57
63
                }
58
 
 
59
 
                protected virtual void OnPaste2Toggled (object sender, System.EventArgs e)
60
 
                {
61
 
                        SelectedProviderType = typeof(Paste2).ToString();
62
 
                }
63
 
 
64
 
                protected virtual void OnPastebinCAToggled (object sender, System.EventArgs e)
65
 
                {
66
 
                        SelectedProviderType = typeof(PastebinCA).ToString();
67
 
                }
68
 
 
69
 
                protected virtual void OnLodgeItToggled (object sender, System.EventArgs e)
70
 
                {
71
 
                        SelectedProviderType = typeof(LodgeIt).ToString();
 
64
                
 
65
                private void FillProviders ()
 
66
                { 
 
67
                        cmbProvider.Clear ();
 
68
                        
 
69
                Gtk.CellRendererText cell = new Gtk.CellRendererText ();
 
70
                        cmbProvider.PackStart (cell, true);
 
71
                        cmbProvider.AddAttribute (cell, "text" , 0);
 
72
                        
 
73
                        Gtk.ListStore ProvidersList = new Gtk.ListStore (typeof (string), typeof (string));
 
74
                                
 
75
                        foreach (IPastebinProvider provider in AvailableProviders.Providers)
 
76
                                ProvidersList.AppendValues(provider.Name, provider.GetType().ToString());
 
77
                        
 
78
                        cmbProvider.Model = ProvidersList;
 
79
                        //set selection to what's in GConf, if we can
 
80
                        Gtk.TreeIter ti;
 
81
                        if (SearchCombobox(out ti, cmbProvider, SelectedProviderType, 1))
 
82
                                cmbProvider.SetActiveIter(ti);
 
83
                }
 
84
                
 
85
                public bool SearchCombobox (out Gtk.TreeIter ti, Gtk.ComboBox box, string val, int col)
 
86
                {               
 
87
                        box.Model.GetIterFirst (out ti);
 
88
                        do 
 
89
                        {
 
90
                                if ((string)box.Model.GetValue (ti,col) == val)
 
91
                                        return true;
 
92
                        } while (box.Model.IterNext (ref ti));
 
93
                        //haven't found it
 
94
                        return false;
 
95
                }
 
96
                
 
97
                private void FillSyntaxBox (IPastebinProvider paster)
 
98
                {
 
99
                        //Gtk.ListStore CodeList = new Gtk.ListStore(typeof (Gdk.Pixbuf), typeof (string));
 
100
                        Gtk.ListStore CodeList = new Gtk.ListStore(typeof (string));
 
101
                        int count = 1;
 
102
                        //const int scale_height = 25;
 
103
                        //Gdk.Pixbuf syntax_icon = null;
 
104
                        //Gdk.Pixbuf temp = null;
 
105
                        //string[] Icon = null;
 
106
 
 
107
                        foreach (TextSyntaxItem syntax in paster.SupportedLanguages)
 
108
                        {
 
109
                                /*
 
110
                                //first determine if this icon is built in - or - comes from resource
 
111
                                Icon = syntax.Icon.Split (new char[] {'@'});
 
112
                                if (Icon.Length > 1)
 
113
                                {
 
114
                                        temp = Gdk.Pixbuf.LoadFromResource (Icon[0]);
 
115
                                        syntax_icon = temp.ScaleSimple ((scale_height * temp.Width) / temp.Height, scale_height, Gdk.InterpType.Bilinear);
 
116
                                }
 
117
                                else
 
118
                                {
 
119
                                        //this section is commented because setting
 
120
                                        //syntax_icon = null throws a GLIB exception
 
121
                                        syntax_icon = null;
 
122
                                }
 
123
                                //CodeList.AppendValues (syntax_icon, syntax.Name);
 
124
                                */
 
125
                                CodeList.AppendValues (syntax.Name);
 
126
                                count++;
 
127
                        }
 
128
                        //get rid of our temporary pixbuf
 
129
                        //temp.Dispose();
 
130
 
 
131
                        treeCodes.HeadersVisible = false;
 
132
                        treeCodes.Model = CodeList;
 
133
                        
 
134
                        lblCodes.Text = string.Format ("{0} syntax highlighting modes supported.", count);
 
135
                }               
 
136
 
 
137
                protected virtual void cmbProviderChanged (object sender, System.EventArgs e)
 
138
                {
 
139
                        Gtk.ComboBox ProviderBox = (Gtk.ComboBox)sender;
 
140
                        Gtk.TreeIter ti;
 
141
                        ProviderBox.GetActiveIter (out ti);
 
142
                        SelectedProviderType = (string)ProviderBox.Model.GetValue (ti,1);
 
143
                        IPastebinProvider Pastebin = PastebinProviderFactory.GetProviderFromPreferences();
 
144
                        
 
145
                        //fill treeview with supported codes
 
146
                        FillSyntaxBox (Pastebin);                       
 
147
                        
72
148
                }
73
149
        }
74
150
}