~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ConfigurationComboBox.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
//
28
28
 
29
29
using System;
 
30
using System.Collections.ObjectModel;
30
31
using MonoDevelop.Core;
31
32
using MonoDevelop.Projects;
32
33
using MonoDevelop.Core.Gui;
36
37
{
37
38
        internal class ConfigurationComboBox: ToolbarComboBox
38
39
        {
39
 
                ConfigurationEventHandler onActiveConfigurationChanged;
40
 
                ConfigurationEventHandler onConfigurationsChanged;
 
40
                bool updating;
41
41
                
42
42
                public ConfigurationComboBox () 
43
43
                {
44
44
                        Combo.Changed += new EventHandler (OnChanged);
45
 
                        
46
 
                        onActiveConfigurationChanged = (ConfigurationEventHandler) DispatchService.GuiDispatch (new ConfigurationEventHandler (OnActiveConfigurationChanged));
47
 
                        onConfigurationsChanged = (ConfigurationEventHandler) DispatchService.GuiDispatch (new ConfigurationEventHandler (OnConfigurationsChanged));
48
 
                        
49
 
                        IdeApp.ProjectOperations.CombineOpened += (CombineEventHandler) DispatchService.GuiDispatch (new CombineEventHandler (OpenCombine));
50
 
                        IdeApp.ProjectOperations.CombineClosed += (CombineEventHandler) DispatchService.GuiDispatch (new CombineEventHandler (CloseCombine));
 
45
                        IdeApp.Workspace.ConfigurationsChanged += OnConfigurationsChanged;
 
46
                        IdeApp.Workspace.ActiveConfigurationChanged += OnActiveConfigurationChanged;
51
47
                        Reset ();
52
48
                }
53
49
                
59
55
                        Combo.Sensitive = false;
60
56
                }
61
57
                
62
 
                void RefreshCombo (Combine combine)
 
58
                void RefreshCombo ()
63
59
                {
64
60
                        ((Gtk.ListStore)Combo.Model).Clear ();
65
 
                        Combo.Sensitive = true;
66
 
                        int active = 0;
67
 
                        for (int n=0; n < combine.Configurations.Count; n++) {
68
 
                                IConfiguration c = combine.Configurations [n];
69
 
                                Combo.AppendText (c.Name);
70
 
                                if (combine.ActiveConfiguration == c)
 
61
                        int active = -1;
 
62
                        int n=0;
 
63
                        ReadOnlyCollection<string> configs = IdeApp.Workspace.GetConfigurations ();
 
64
                        foreach (string conf in configs) {
 
65
                                Combo.AppendText (conf);
 
66
                                if (conf == IdeApp.Workspace.ActiveConfiguration)
71
67
                                        active = n;
 
68
                                n++;
72
69
                        }
73
 
                        Combo.Active = active;
 
70
                        Combo.Sensitive = n > 0;
 
71
                        if (active >= 0)
 
72
                                Combo.Active = active;
 
73
                        else if (configs.Count > 0)
 
74
                                IdeApp.Workspace.ActiveConfiguration = configs [0];
74
75
                        Combo.ShowAll ();
75
76
                }
76
77
 
77
 
                void OpenCombine (object sender, CombineEventArgs e)
 
78
                void OnConfigurationsChanged (object sender, EventArgs e)
78
79
                {
79
 
                        RefreshCombo (e.Combine);
80
 
                        e.Combine.ActiveConfigurationChanged += onActiveConfigurationChanged;
81
 
                        e.Combine.ConfigurationAdded += onConfigurationsChanged;
82
 
                        e.Combine.ConfigurationRemoved += onConfigurationsChanged;
 
80
                        RefreshCombo ();
83
81
                }
 
82
                
 
83
                void OnActiveConfigurationChanged (object sender, EventArgs e)
 
84
                {
 
85
                        if (updating)
 
86
                                return;
84
87
 
85
 
                void CloseCombine (object sender, CombineEventArgs e)
86
 
                {
87
 
                        Reset ();
88
 
                        e.Combine.ActiveConfigurationChanged -= onActiveConfigurationChanged;
89
 
                        e.Combine.ConfigurationAdded -= onConfigurationsChanged;
90
 
                        e.Combine.ConfigurationRemoved -= onConfigurationsChanged;
91
 
                }
92
 
                
93
 
                void OnConfigurationsChanged (object sender, ConfigurationEventArgs e)
94
 
                {
95
 
                        RefreshCombo (IdeApp.ProjectOperations.CurrentOpenCombine);
96
 
                }
97
 
                
98
 
                void OnActiveConfigurationChanged (object sender, ConfigurationEventArgs e)
99
 
                {
100
 
                        Combine combine = (Combine) e.CombineEntry;
101
 
                        for (int n=0; n < combine.Configurations.Count; n++) {
102
 
                                IConfiguration c = combine.Configurations [n];
103
 
                                if (combine.ActiveConfiguration == c) {
104
 
                                        Combo.Active = n;
105
 
                                        break;
 
88
                        string knownConfig = null;
 
89
                        
 
90
                        Gtk.TreeIter it;
 
91
                        if (Combo.Model.GetIterFirst (out it)) {
 
92
                                do {
 
93
                                        string cs = (string) Combo.Model.GetValue (it, 0);
 
94
                                        if (knownConfig == null)
 
95
                                                knownConfig = cs;
 
96
                                        if (IdeApp.Workspace.ActiveConfiguration == cs) {
 
97
                                                updating = true;
 
98
                                                Combo.SetActiveIter (it);
 
99
                                                updating = false;
 
100
                                                return;
 
101
                                        }
106
102
                                }
 
103
                                while (Combo.Model.IterNext (ref it));
107
104
                        }
 
105
 
 
106
                        // Configuration not found. Set one that is known.
 
107
                        IdeApp.Workspace.ActiveConfiguration = knownConfig;
108
108
                }
109
109
                
110
110
                protected void OnChanged (object sender, EventArgs args)
111
111
                {
112
 
                        if (IdeApp.ProjectOperations.CurrentOpenCombine != null) {
 
112
                        if (updating)
 
113
                                return;
 
114
                        if (IdeApp.Workspace.IsOpen) {
113
115
                                Gtk.TreeIter iter;
114
116
                                if (Combo.GetActiveIter (out iter)) {
115
117
                                        string cs = (string) Combo.Model.GetValue (iter, 0);
116
 
                                        IConfiguration conf = IdeApp.ProjectOperations.CurrentOpenCombine.GetConfiguration (cs);
117
 
                                        IdeApp.ProjectOperations.CurrentOpenCombine.ActiveConfiguration = conf;
 
118
                                        updating = true;
 
119
                                        IdeApp.Workspace.ActiveConfiguration = cs;
 
120
                                        updating = false;
118
121
                                }
119
122
                        }
120
123
                }