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

« back to all changes in this revision

Viewing changes to src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Dialogs/CommitDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
using MonoDevelop.Ide.Gui;
8
8
using Mono.Addins;
9
9
using MonoDevelop.Ide;
 
10
using MonoDevelop.Projects;
10
11
 
11
12
namespace MonoDevelop.VersionControl.Dialogs
12
13
{
48
49
                        colCommit.Visible = false;
49
50
                        
50
51
                        object[] exts = AddinManager.GetExtensionObjects ("/MonoDevelop/VersionControl/CommitDialogExtensions", false);
 
52
                        bool separatorRequired = false;
 
53
                        
51
54
                        foreach (object ob in exts) {
52
55
                                CommitDialogExtension ext = ob as CommitDialogExtension;
53
56
                                if (ext == null) {
54
57
                                        MessageService.ShowError ("Commit extension type " + ob.GetType() + " must be a subclass of CommitDialogExtension");
55
58
                                        continue;
56
59
                                }
57
 
                                vboxExtensions.PackEnd (ext, false, false, 0);
58
 
                                ext.Initialize (changeSet);
59
 
                                extensions.Add (ext);
60
 
                                ext.AllowCommitChanged += HandleAllowCommitChanged;
 
60
                                if (ext.Initialize (changeSet)) {
 
61
                                        if (separatorRequired) {
 
62
                                                HSeparator sep = new HSeparator ();
 
63
                                                sep.Show ();
 
64
                                                vboxExtensions.PackEnd (sep, false, false, 0);
 
65
                                        }
 
66
                                        vboxExtensions.PackEnd (ext, false, false, 0);
 
67
                                        extensions.Add (ext);
 
68
                                        ext.AllowCommitChanged += HandleAllowCommitChanged;
 
69
                                        separatorRequired = true;
 
70
                                } else
 
71
                                        ext.Destroy ();
61
72
                        }
62
73
                        HandleAllowCommitChanged (null, null);
63
74
 
75
86
                                selected.Add (info.LocalPath);
76
87
                        }
77
88
                        
78
 
                        if (changeSet.GlobalComment.Length == 0) {
 
89
                        if (string.IsNullOrEmpty (changeSet.GlobalComment)) {
79
90
                                AuthorInformation aInfo;
80
91
                                CommitMessageFormat fmt = VersionControlService.GetCommitMessageFormat (changeSet, out aInfo);
81
92
                                Message = changeSet.GenerateGlobalComment (fmt, aInfo);
84
95
                                Message = changeSet.GlobalComment;
85
96
                                
86
97
                        textview.Buffer.Changed += OnTextChanged;
 
98
                        
 
99
                        // Focus the text view and move the insert point to the begining. Makes it easier to insert
 
100
                        // a comment header.
 
101
                        textview.Buffer.MoveMark (textview.Buffer.InsertMark, textview.Buffer.StartIter);
 
102
                        textview.Buffer.MoveMark (textview.Buffer.SelectionBound, textview.Buffer.StartIter);
 
103
                        textview.GrabFocus ();
87
104
                }
88
105
 
89
106
                void HandleAllowCommitChanged (object sender, EventArgs e)
96
113
                
97
114
                protected override void OnResponse (Gtk.ResponseType type)
98
115
                {
99
 
                        if (type == Gtk.ResponseType.Ok) {
100
 
                        
101
 
                                // Update the change set
102
 
                                ArrayList todel = new ArrayList ();
103
 
                                foreach (ChangeSetItem it in changeSet.Items) {
104
 
                                        if (!selected.Contains (it.LocalPath))
105
 
                                                todel.Add (it.LocalPath);
106
 
                                }
107
 
                                foreach (string file in todel)
108
 
                                        changeSet.RemoveFile (file);
109
 
                                changeSet.GlobalComment = Message;
110
 
                                
111
 
                                // Perform the commit
112
 
                                
113
 
                                int n;
114
 
                                for (n=0; n<extensions.Count; n++) {
115
 
                                        CommitDialogExtension ext = (CommitDialogExtension) extensions [n];
116
 
                                        bool res;
117
 
                                        try {
118
 
                                                res = ext.OnBeginCommit (changeSet);
119
 
                                        } catch (Exception ex) {
120
 
                                                MessageService.ShowException (ex);
121
 
                                                res = false;
122
 
                                        }
123
 
                                        
124
 
                                        if (!res) {
125
 
                                                // Commit failed. Rollback the previous extensions
126
 
                                                for (int m=0; m<n; m++) {
127
 
                                                        ext = (CommitDialogExtension) extensions [m];
128
 
                                                        try {
129
 
                                                                ext.OnEndCommit (changeSet, false);
130
 
                                                        } catch {}
131
 
                                                }
132
 
                                                return;
133
 
                                        }
134
 
                                        Hide ();
135
 
                                }
136
 
                        } else {
 
116
                        if (type != Gtk.ResponseType.Ok) {
137
117
                                changeSet.GlobalComment = oldMessage;
138
118
                        }
139
119
                        base.OnResponse (type);
140
120
                }
 
121
 
 
122
                protected void OnButtonCommitClicked (object sender, System.EventArgs e)
 
123
                {
 
124
                        // Update the change set
 
125
                        ArrayList todel = new ArrayList ();
 
126
                        foreach (ChangeSetItem it in changeSet.Items) {
 
127
                                if (!selected.Contains (it.LocalPath))
 
128
                                        todel.Add (it.LocalPath);
 
129
                        }
 
130
                        foreach (string file in todel)
 
131
                                changeSet.RemoveFile (file);
 
132
                        changeSet.GlobalComment = Message;
 
133
                        
 
134
                        // Perform the commit
 
135
                        
 
136
                        int n;
 
137
                        for (n=0; n<extensions.Count; n++) {
 
138
                                CommitDialogExtension ext = (CommitDialogExtension) extensions [n];
 
139
                                bool res;
 
140
                                try {
 
141
                                        res = ext.OnBeginCommit (changeSet);
 
142
                                } catch (Exception ex) {
 
143
                                        MessageService.ShowException (ex);
 
144
                                        res = false;
 
145
                                }
 
146
                                System.Console.WriteLine ("RES: " + res);
 
147
                                if (!res) {
 
148
                                        // Commit failed. Rollback the previous extensions
 
149
                                        for (int m=0; m<n; m++) {
 
150
                                                ext = (CommitDialogExtension) extensions [m];
 
151
                                                try {
 
152
                                                        ext.OnEndCommit (changeSet, false);
 
153
                                                } catch {}
 
154
                                        }
 
155
                                        return;
 
156
                                }
 
157
                                Hide ();
 
158
                        }
 
159
                        Respond (Gtk.ResponseType.Ok);
 
160
                }
141
161
                
142
162
                void OnTextChanged (object s, EventArgs args)
143
163
                {