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

« back to all changes in this revision

Viewing changes to src/addins/ChangeLogAddIn/CommitDialogExtensionWidget.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:
48
48
                bool notConfigured;
49
49
                Dictionary<string,ChangeLogEntry> entries;
50
50
                int unknownFileCount;
 
51
                int uncommentedCount;
 
52
                bool requireComment;
 
53
                bool enabled;
51
54
                
52
55
                public CommitDialogExtensionWidget()
53
 
                {
54
 
                        if (!IntegrationEnabled)
55
 
                                return;
56
 
                                
 
56
                {       
57
57
                        Add (box);
58
58
                        box.PackStart (vbox, true, true, 0);
59
59
                        
72
72
                        haux.PackStart (optionsButton, false, false, 0);
73
73
                }
74
74
                
75
 
                public static bool IntegrationEnabled {
76
 
                        get { return PropertyService.Get ("ChangeLogAddIn.VersionControlIntegration", true); }
77
 
                }
78
 
                
79
75
                public override void Initialize (ChangeSet cset)
80
 
                {
81
 
                        if (!IntegrationEnabled)
82
 
                                return;
83
 
                                
 
76
                {       
84
77
                        this.cset = cset;
85
78
                        msgLabel = new Label ();
86
79
                        pathLabel = new Label ();
88
81
                        pathLabel.Xalign = 0;
89
82
                        vbox.PackStart (msgLabel, false, false, 0);
90
83
                        vbox.PackStart (pathLabel, false, false, 3);
91
 
                        ShowAll ();
 
84
                        
92
85
                        GenerateLogEntries ();
93
 
                        UpdateStatus ();
 
86
                        if (enabled) {
 
87
                                ShowAll ();
 
88
                                UpdateStatus ();
 
89
                        }
94
90
                }
95
91
                
96
92
                void UpdateStatus ()
97
93
                {
98
 
                        if (!IntegrationEnabled)
 
94
                        if (!enabled)
99
95
                                Remove (box);
100
 
 
101
 
                        string name = PropertyService.Get ("ChangeLogAddIn.Name", "");
102
 
                        string email = PropertyService.Get ("ChangeLogAddIn.Email", "");
103
 
                        
104
 
                        if (name.Length == 0 || email.Length == 0) {
 
96
                        
 
97
                        AllowCommit = !requireComment;
 
98
                        
 
99
                        if (!AuthorInformation.Default.IsValid) {
105
100
                                msgLabel.Markup = "<b><span foreground='red'>" + GettextCatalog.GetString ("ChangeLog entries can't be generated.") + "</span></b>";
106
101
                                pathLabel.Text = GettextCatalog.GetString ("The name or e-mail of the user has not been configured.");
107
102
                                logButton.Label = GettextCatalog.GetString ("Configure user data");
112
107
                        
113
108
                        optionsButton.Visible = true;
114
109
                        logButton.Label = GettextCatalog.GetString ("Details...");
 
110
                        string warning = "";
 
111
                        if (uncommentedCount > 0) {
 
112
                                string fc = GettextCatalog.GetString ("There are {0} files without a comment.\nThe ChangeLog entry for those files will not be generated.", uncommentedCount);
 
113
                                if (requireComment)
 
114
                                        fc += "\n" + GettextCatalog.GetString ("Some of the projects require that files have comments when they are committed.");
 
115
                                warning = "<b><span foreground='red'>" + fc + "</span></b>\n";
 
116
                        }
115
117
                        if (unknownFileCount > 0) {
116
118
                                string fc = GettextCatalog.GetPluralString ("{0} ChangeLog file not found. Some changes will not be logged.","{0} ChangeLog files not found. Some changes will not be logged.", unknownFileCount, unknownFileCount);
117
 
                                msgLabel.Markup = "<b><span foreground='red'>" + fc + "</span></b>";
 
119
                                msgLabel.Markup = warning + "<b><span foreground='red'>" + fc + "</span></b>";
118
120
                                pathLabel.Text = GettextCatalog.GetString ("Click on the 'Details' button for more info.");
119
121
                        } else if (entries.Count == 1) {
120
 
                                msgLabel.Markup = "<b>" + GettextCatalog.GetString ("The following ChangeLog file will be updated:") + "</b>";
 
122
                                msgLabel.Markup = warning + "<b>" + GettextCatalog.GetString ("The following ChangeLog file will be updated:") + "</b>";
121
123
                                foreach (ChangeLogEntry e in entries.Values)
122
124
                                        pathLabel.Text = e.File;
123
125
                        } else {
124
 
                                msgLabel.Markup = "<b>" + GettextCatalog.GetString ("{0} ChangeLog files will be updated.", entries.Count) + "</b>";
 
126
                                msgLabel.Markup = warning + "<b>" + GettextCatalog.GetString ("{0} ChangeLog files will be updated.", entries.Count) + "</b>";
125
127
                                pathLabel.Text = GettextCatalog.GetString ("Click on the 'Details' button for more info.");
126
128
                        }
127
129
                        notConfigured = false;
129
131
                
130
132
                public override bool OnBeginCommit (ChangeSet changeSet)
131
133
                {
132
 
                        if (!IntegrationEnabled)
 
134
                        if (!enabled)
133
135
                                return true;
134
136
 
135
137
                        try {
204
206
                
205
207
                public override void OnEndCommit (ChangeSet changeSet, bool success)
206
208
                {
207
 
                        if (!IntegrationEnabled)
 
209
                        if (!enabled)
208
210
                                return;
209
211
                                
210
212
                        if (!success)
217
219
                {
218
220
                        entries = new Dictionary<string,ChangeLogEntry> ();
219
221
                        unknownFileCount = 0;
 
222
                        enabled = false;
 
223
                        requireComment = false;
220
224
                        
221
225
                        foreach (ChangeSetItem item in cset.Items) {
222
 
                                string logf = ChangeLogService.GetChangeLogForFile (cset.BaseLocalPath, item.LocalPath);
 
226
                                MonoDevelop.Projects.SolutionItem parentItem;
 
227
                                ChangeLogPolicy policy;
 
228
                                string logf = ChangeLogService.GetChangeLogForFile (cset.BaseLocalPath, item.LocalPath,
 
229
                                                                                    out parentItem, out policy);
 
230
                                
223
231
                                if (logf == string.Empty)
224
232
                                        continue;
225
233
                                
 
234
                                enabled = true;
226
235
                                bool cantGenerate = false;
227
236
                                
228
237
                                if (logf == null) {
231
240
                                        logf = System.IO.Path.Combine (logf, "ChangeLog");
232
241
                                }
233
242
                                
 
243
                                if (string.IsNullOrEmpty (item.Comment) && !item.IsDirectory) {
 
244
                                        uncommentedCount++;
 
245
                                        if (policy != null && policy.VcsIntegration == VcsIntegration.RequireEntry)
 
246
                                                requireComment = true;
 
247
                                }
 
248
                                
234
249
                                ChangeLogEntry entry;
235
250
                                if (!entries.TryGetValue (logf, out entry)) {
236
251
                                        entry = new ChangeLogEntry ();
 
252
                                        entry.AuthorInformation = MonoDevelop.Ide.Gui.IdeApp.Workspace.GetAuthorInformation (parentItem);
 
253
                                        entry.MessageStyle = ChangeLogService.GetMessageStyle (parentItem);
237
254
                                        entry.CantGenerate = cantGenerate;
238
255
                                        entry.File = logf;
239
256
                                        if (cantGenerate)
247
264
                                entry.Items.Add (item);
248
265
                        }
249
266
                        
 
267
                        CommitMessageFormat format = new CommitMessageFormat ();
 
268
                        format.TabsAsSpaces = false;
 
269
                        format.TabWidth = 8;
 
270
                        format.MaxColumns = 70;
 
271
                        format.AppendNewlines = 2;
250
272
                        foreach (ChangeLogEntry entry in entries.Values) {
251
 
                                string path = System.IO.Path.GetDirectoryName (entry.File);
252
 
                                string msg = cset.GeneratePathComment (path, entry.Items, 75);
253
 
 
254
 
                                string name = PropertyService.Get ("ChangeLogAddIn.Name", "");
255
 
                                string email = PropertyService.Get ("ChangeLogAddIn.Email", "");
256
 
                                string date = DateTime.Now.ToString("yyyy-MM-dd");
257
 
                                string text = date + "  " + name + " <" + email + "> " + Environment.NewLine + Environment.NewLine;
258
 
                                
259
 
                                msg = msg.Trim ('\n');
260
 
                                entry.Message = text + "\t" + msg.Replace ("\n", "\n\t") + "\n\n";
 
273
                                format.Style = entry.MessageStyle;
 
274
                                entry.Message = cset.GeneratePathComment (entry.File, entry.Items, 
 
275
                                        format, entry.AuthorInformation);
261
276
                        }
262
277
                }
263
278
                
264
279
                void OnClickButton (object s, EventArgs args)
265
280
                {
266
281
                        if (notConfigured) {
267
 
                                IdeApp.Workbench.ShowGlobalPreferencesDialog (Toplevel as Gtk.Window, "ChangeLogAddInOptions");
 
282
                                IdeApp.Workbench.ShowGlobalPreferencesDialog (Toplevel as Gtk.Window, "GeneralAuthorInfo");
268
283
                                UpdateStatus ();
269
284
                                GenerateLogEntries ();
270
285
                                return;
278
293
                
279
294
                void OnClickOptions (object s, EventArgs args)
280
295
                {
281
 
                        IdeApp.Workbench.ShowGlobalPreferencesDialog (Toplevel as Gtk.Window, "ChangeLogAddInOptions");
 
296
                        IdeApp.Workbench.ShowGlobalPreferencesDialog (Toplevel as Gtk.Window, "GeneralAuthorInfo");
282
297
                        UpdateStatus ();
283
298
                        GenerateLogEntries ();
284
299
                }
292
307
                public bool CantGenerate;
293
308
                public bool IsNew;
294
309
                public List<ChangeSetItem> Items = new List<ChangeSetItem> ();
 
310
                public AuthorInformation AuthorInformation;
 
311
                public CommitMessageStyle MessageStyle;
295
312
        }
296
313
}