1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
|
// ErrorListPad.cs
//
// Author:
// Todd Berman <tberman@sevenl.net>
// David Makovský <yakeen@sannyas-on.net>
// Lluis Sanchez Gual <lluis@novell.com>
//
// Copyright (c) 2004 Todd Berman
// Copyright (c) 2006 David Makovský
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Drawing;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Ide.Gui;
using MonoDevelop.Ide.Tasks;
using MonoDevelop.Ide.Gui.Content;
using Gtk;
using System.Text;
using MonoDevelop.Components.Docking;
using MonoDevelop.Ide.Gui.Components;
using MonoDevelop.Components.Commands;
using MonoDevelop.Ide.Commands;
using MonoDevelop.Components;
using System.Linq;
namespace MonoDevelop.Ide.Gui.Pads
{
class ErrorListPad : IPadContent
{
HPaned control;
ScrolledWindow sw;
PadTreeView view;
LogView outputView;
TreeStore store;
TreeModelFilter filter;
TreeModelSort sort;
ToggleButton errorBtn, warnBtn, msgBtn, logBtn;
SearchEntry searchEntry;
string currentSearchPattern = null;
Hashtable tasks = new Hashtable ();
int errorCount;
int warningCount;
int infoCount;
bool initialLogShow = true;
IPadWindow window;
Menu menu;
Dictionary<ToggleAction, int> columnsActions = new Dictionary<ToggleAction, int> ();
Clipboard clipboard;
Xwt.Drawing.Image iconWarning;
Xwt.Drawing.Image iconError;
Xwt.Drawing.Image iconInfo;
Xwt.Drawing.Image iconEmpty;
const string showErrorsPropertyName = "SharpDevelop.TaskList.ShowErrors";
const string showWarningsPropertyName = "SharpDevelop.TaskList.ShowWarnings";
const string showMessagesPropertyName = "SharpDevelop.TaskList.ShowMessages";
const string logSeparatorPositionPropertyName = "SharpDevelop.TaskList.LogSeparatorPosition";
const string outputViewVisiblePropertyName = "SharpDevelop.TaskList.OutputViewVisible";
static class DataColumns
{
internal const int Type = 0;
internal const int Read = 1;
internal const int Task = 2;
internal const int Description = 3;
}
static class VisibleColumns
{
internal const int Type = 0;
internal const int Marked = 1;
internal const int Line = 2;
internal const int Description = 3;
internal const int File = 4;
internal const int Project = 5;
internal const int Path = 6;
internal const int Category = 7;
}
public Gtk.Widget Control {
get {
if (control == null)
CreateControl ();
return control;
}
}
public string Id {
get { return "MonoDevelop.Ide.Gui.Pads.ErrorListPad"; }
}
void IPadContent.Initialize (IPadWindow window)
{
this.window = window;
window.Title = GettextCatalog.GetString ("Errors");
DockItemToolbar toolbar = window.GetToolbar (PositionType.Top);
errorBtn = new ToggleButton { Name = "toggleErrors" };
errorBtn.Active = (bool)PropertyService.Get (showErrorsPropertyName, true);
errorBtn.Image = new Gtk.Image (Stock.Error, Gtk.IconSize.Menu);
errorBtn.Image.Show ();
errorBtn.Toggled += new EventHandler (FilterChanged);
errorBtn.TooltipText = GettextCatalog.GetString ("Show Errors");
UpdateErrorsNum();
toolbar.Add (errorBtn);
warnBtn = new ToggleButton { Name = "toggleWarnings" };
warnBtn.Active = (bool)PropertyService.Get (showWarningsPropertyName, true);
warnBtn.Image = new Gtk.Image (Stock.Warning, Gtk.IconSize.Menu);
warnBtn.Image.Show ();
warnBtn.Toggled += new EventHandler (FilterChanged);
warnBtn.TooltipText = GettextCatalog.GetString ("Show Warnings");
UpdateWarningsNum();
toolbar.Add (warnBtn);
msgBtn = new ToggleButton { Name = "toggleMessages" };
msgBtn.Active = (bool)PropertyService.Get (showMessagesPropertyName, true);
msgBtn.Image = new Gtk.Image (Stock.Information, Gtk.IconSize.Menu);
msgBtn.Image.Show ();
msgBtn.Toggled += new EventHandler (FilterChanged);
msgBtn.TooltipText = GettextCatalog.GetString ("Show Messages");
UpdateMessagesNum();
toolbar.Add (msgBtn);
toolbar.Add (new SeparatorToolItem ());
logBtn = new ToggleButton { Name = "toggleBuildOutput" };
logBtn.Label = GettextCatalog.GetString ("Build Output");
logBtn.Image = ImageService.GetImage ("md-message-log", Gtk.IconSize.Menu);
logBtn.Image.Show ();
logBtn.TooltipText = GettextCatalog.GetString ("Show build output");
logBtn.Toggled += HandleLogBtnToggled;
toolbar.Add (logBtn);
//Dummy widget to take all space between "Build Output" button and SearchEntry
toolbar.Add (new HBox (), true);
searchEntry = new SearchEntry ();
searchEntry.Entry.Changed += searchPatternChanged;
searchEntry.WidthRequest = 200;
searchEntry.Visible = true;
toolbar.Add (searchEntry);
toolbar.ShowAll ();
UpdatePadIcon ();
}
void searchPatternChanged (object sender, EventArgs e)
{
currentSearchPattern = searchEntry.Entry.Text;
filter.Refilter ();
}
void CreateControl ()
{
control = new HPaned ();
store = new Gtk.TreeStore (typeof (Xwt.Drawing.Image), // image - type
typeof (bool), // read?
typeof (Task), // read? -- use Pango weight
typeof (string));
TreeModelFilterVisibleFunc filterFunct = new TreeModelFilterVisibleFunc (FilterTasks);
filter = new TreeModelFilter (store, null);
filter.VisibleFunc = filterFunct;
sort = new TreeModelSort (filter);
sort.SetSortFunc (VisibleColumns.Type, SeverityIterSort);
sort.SetSortFunc (VisibleColumns.Project, ProjectIterSort);
sort.SetSortFunc (VisibleColumns.File, FileIterSort);
view = new PadTreeView (sort);
view.ShowExpanders = true;
view.RulesHint = true;
view.DoPopupMenu = (evnt) => IdeApp.CommandService.ShowContextMenu (view, evnt, CreateMenu ());
AddColumns ();
LoadColumnsVisibility ();
view.Columns[VisibleColumns.Type].SortColumnId = VisibleColumns.Type;
view.Columns[VisibleColumns.Project].SortColumnId = VisibleColumns.Project;
view.Columns[VisibleColumns.File].SortColumnId = VisibleColumns.File;
sw = new MonoDevelop.Components.CompactScrolledWindow ();
sw.ShadowType = ShadowType.None;
sw.Add (view);
TaskService.Errors.TasksRemoved += DispatchService.GuiDispatch<TaskEventHandler> (ShowResults);
TaskService.Errors.TasksAdded += DispatchService.GuiDispatch<TaskEventHandler> (TaskAdded);
TaskService.Errors.TasksChanged += DispatchService.GuiDispatch<TaskEventHandler> (TaskChanged);
TaskService.Errors.CurrentLocationTaskChanged += HandleTaskServiceErrorsCurrentLocationTaskChanged;
IdeApp.Workspace.FirstWorkspaceItemOpened += OnCombineOpen;
IdeApp.Workspace.LastWorkspaceItemClosed += OnCombineClosed;
view.RowActivated += new RowActivatedHandler (OnRowActivated);
iconWarning = ImageService.GetIcon (Ide.Gui.Stock.Warning, Gtk.IconSize.Menu);
iconError = ImageService.GetIcon (Ide.Gui.Stock.Error, Gtk.IconSize.Menu);
iconInfo = ImageService.GetIcon (Ide.Gui.Stock.Information, Gtk.IconSize.Menu);
iconEmpty = ImageService.GetIcon (Ide.Gui.Stock.Empty, Gtk.IconSize.Menu);
control.Add1 (sw);
outputView = new LogView { Name = "buildOutput" };
control.Add2 (outputView);
Control.ShowAll ();
control.SizeAllocated += HandleControlSizeAllocated;
bool outputVisible = PropertyService.Get<bool> (outputViewVisiblePropertyName, false);
if (outputVisible) {
outputView.Visible = true;
logBtn.Active = true;
} else {
outputView.Hide ();
}
sw.SizeAllocated += HandleSwSizeAllocated;
// Load existing tasks
foreach (Task t in TaskService.Errors) {
AddTask (t);
}
control.FocusChain = new Gtk.Widget [] { sw };
}
void HandleSwSizeAllocated (object o, SizeAllocatedArgs args)
{
if (!initialLogShow && outputView.Visible) {
var val = (double) ((double) control.Position / (double) control.Allocation.Width);
PropertyService.Set (logSeparatorPositionPropertyName, val);
}
}
[GLib.ConnectBefore]
void HandleControlSizeAllocated (object o, SizeAllocatedArgs args)
{
if (initialLogShow && outputView.Visible) {
SetInitialOutputViewSize (args.Allocation.Width);
initialLogShow = false;
}
}
public IProgressMonitor GetBuildProgressMonitor ()
{
if (control == null)
CreateControl ();
return outputView.GetProgressMonitor ();
}
void HandleTaskServiceErrorsCurrentLocationTaskChanged (object sender, EventArgs e)
{
if (TaskService.Errors.CurrentLocationTask == null) {
view.Selection.UnselectAll ();
return;
}
TreeIter it;
if (!view.Model.GetIterFirst (out it))
return;
do {
Task t = (Task) view.Model.GetValue (it, DataColumns.Task);
if (t == TaskService.Errors.CurrentLocationTask) {
view.Selection.SelectIter (it);
view.ScrollToCell (view.Model.GetPath (it), view.Columns[0], false, 0, 0);
it = filter.ConvertIterToChildIter (sort.ConvertIterToChildIter (it));
store.SetValue (it, DataColumns.Read, true);
return;
}
} while (view.Model.IterNext (ref it));
}
void LoadColumnsVisibility ()
{
var columns = PropertyService.Get ("Monodevelop.ErrorListColumns", string.Join (";", Enumerable.Repeat ("TRUE", view.Columns.Length)));
var tokens = columns.Split (new [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
if (view.Columns.Length == tokens.Length) {
for (int i = 0; i < tokens.Length; i++) {
bool visible;
if (bool.TryParse (tokens [i], out visible))
view.Columns [i].Visible = visible;
}
}
}
void StoreColumnsVisibility ()
{
PropertyService.Set ("Monodevelop.ErrorListColumns", string.Join (";", view.Columns.Select (c => c.Visible ? "TRUE" : "FALSE")));
}
public void RedrawContent()
{
}
Gtk.Menu CreateMenu ()
{
if (menu != null)
return menu;
var group = new ActionGroup ("Popup");
var help = new Gtk.Action ("help", GettextCatalog.GetString ("Show Error Reference"),
GettextCatalog.GetString ("Show Error Reference"), Gtk.Stock.Help);
help.Activated += OnShowReference;
group.Add (help, "F1");
var copy = new Gtk.Action ("copy", GettextCatalog.GetString ("_Copy"),
GettextCatalog.GetString ("Copy task"), Gtk.Stock.Copy);
copy.Activated += OnTaskCopied;
group.Add (copy, "<Control><Mod2>c");
var jump = new Gtk.Action ("jump", GettextCatalog.GetString ("_Go to"),
GettextCatalog.GetString ("Go to task"), Gtk.Stock.JumpTo);
jump.Activated += OnTaskJumpto;
group.Add (jump);
var columns = new Gtk.Action ("columns", GettextCatalog.GetString ("Columns"));
group.Add (columns, null);
var columnType = new ToggleAction ("columnType", GettextCatalog.GetString ("Type"),
GettextCatalog.GetString ("Toggle visibility of Type column"), null);
columnType.Toggled += OnColumnVisibilityChanged;
columnsActions[columnType] = VisibleColumns.Type;
group.Add (columnType);
var columnValidity = new ToggleAction ("columnValidity", GettextCatalog.GetString ("Validity"),
GettextCatalog.GetString ("Toggle visibility of Validity column"), null);
columnValidity.Toggled += OnColumnVisibilityChanged;
columnsActions[columnValidity] = VisibleColumns.Marked;
group.Add (columnValidity);
var columnLine = new ToggleAction ("columnLine", GettextCatalog.GetString ("Line"),
GettextCatalog.GetString ("Toggle visibility of Line column"), null);
columnLine.Toggled += OnColumnVisibilityChanged;
columnsActions[columnLine] = VisibleColumns.Line;
group.Add (columnLine);
var columnDescription = new ToggleAction ("columnDescription", GettextCatalog.GetString ("Description"),
GettextCatalog.GetString ("Toggle visibility of Description column"), null);
columnDescription.Toggled += OnColumnVisibilityChanged;
columnsActions[columnDescription] = VisibleColumns.Description;
group.Add (columnDescription);
var columnFile = new ToggleAction ("columnFile", GettextCatalog.GetString ("File"),
GettextCatalog.GetString ("Toggle visibility of File column"), null);
columnFile.Toggled += OnColumnVisibilityChanged;
columnsActions[columnFile] = VisibleColumns.File;
group.Add (columnFile);
var columnProject = new ToggleAction ("columnProject", GettextCatalog.GetString ("Project"),
GettextCatalog.GetString ("Toggle visibility of Project column"), null);
columnProject.Toggled += OnColumnVisibilityChanged;
columnsActions[columnProject] = VisibleColumns.Project;
group.Add (columnProject);
var columnPath = new ToggleAction ("columnPath", GettextCatalog.GetString ("Path"),
GettextCatalog.GetString ("Toggle visibility of Path column"), null);
columnPath.Toggled += OnColumnVisibilityChanged;
columnsActions[columnPath] = VisibleColumns.Path;
group.Add (columnPath);
var columnCategory = new ToggleAction ("columnCategory", GettextCatalog.GetString ("Category"),
GettextCatalog.GetString ("Toggle visibility of Category column"), null);
columnCategory.Toggled += OnColumnVisibilityChanged;
columnsActions[columnCategory] = VisibleColumns.Category;
group.Add (columnCategory);
var uiManager = new UIManager ();
uiManager.InsertActionGroup (group, 0);
string uiStr = "<ui><popup name='popup'>"
+ "<menuitem action='help'/>"
+ "<menuitem action='copy'/>"
+ "<menuitem action='jump'/>"
+ "<separator/>"
+ "<menu action='columns'>"
+ "<menuitem action='columnType' />"
+ "<menuitem action='columnValidity' />"
+ "<menuitem action='columnLine' />"
+ "<menuitem action='columnDescription' />"
+ "<menuitem action='columnFile' />"
+ "<menuitem action='columnProject' />"
+ "<menuitem action='columnPath' />"
+ "<menuitem action='columnCategory' />"
+ "</menu>"
+ "</popup></ui>";
uiManager.AddUiFromString (uiStr);
menu = (Menu)uiManager.GetWidget ("/popup");
menu.ShowAll ();
menu.Shown += delegate {
columnType.Active = view.Columns[VisibleColumns.Type].Visible;
columnValidity.Active = view.Columns[VisibleColumns.Marked].Visible;
columnLine.Active = view.Columns[VisibleColumns.Line].Visible;
columnDescription.Active = view.Columns[VisibleColumns.Description].Visible;
columnFile.Active = view.Columns[VisibleColumns.File].Visible;
columnProject.Active = view.Columns[VisibleColumns.Project].Visible;
columnPath.Active = view.Columns[VisibleColumns.Path].Visible;
columnCategory.Active = view.Columns[VisibleColumns.Category].Visible;
help.Sensitive = copy.Sensitive = jump.Sensitive =
view.Selection != null &&
view.Selection.CountSelectedRows () > 0 &&
(columnType.Active ||
columnValidity.Active ||
columnLine.Active ||
columnDescription.Active ||
columnFile.Active ||
columnPath.Active);
string dummyString;
help.Sensitive &= GetSelectedErrorReference (out dummyString);
};
return menu;
}
Task SelectedTask
{
get {
TreeModel model;
TreeIter iter;
if (view.Selection.GetSelected (out model, out iter))
return model.GetValue (iter, DataColumns.Task) as Task;
return null; // no one selected
}
}
[CommandHandler (EditCommands.Copy)]
protected void OnCopy ()
{
OnTaskCopied (null, null);
}
void OnTaskCopied (object o, EventArgs args)
{
Task task = SelectedTask;
if (task != null) {
StringBuilder text = new StringBuilder ();
if (!string.IsNullOrEmpty (task.FileName)) {
text.Append (task.FileName);
if (task.Line >= 1) {
text.Append ("(").Append (task.Column);
if (task.Column >= 0)
text.Append (",").Append (task.Column);
text.Append (")");
}
text.Append (": ");
}
text.Append (task.Severity);
if (!string.IsNullOrEmpty (task.Code)) {
text.Append (" ").Append (task.Code);
}
text.Append (": ");
text.Append (task.Description);
if (task.WorkspaceObject != null)
text.Append (" (").Append (task.WorkspaceObject.Name).Append (")");
if (!string.IsNullOrEmpty (task.Category)) {
text.Append (" ").Append (task.Category);
}
clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
clipboard.Text = text.ToString ();
clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
clipboard.Text = text.ToString ();
}
}
void OnShowReference (object o, EventArgs args)
{
string reference = null;
if (GetSelectedErrorReference (out reference)) {
Process.Start ("http://google.com/search?q=" + System.Web.HttpUtility.UrlEncode (reference));
return;
}
}
bool GetSelectedErrorReference (out string reference)
{
Task task = SelectedTask;
if (task != null && !String.IsNullOrEmpty (task.HelpKeyword)) {
reference = task.HelpKeyword;
return true;
}
if (task != null && !String.IsNullOrEmpty (task.Code)) {
reference = task.Code;
return true;
}
reference = null;
return false;
}
void OnTaskJumpto (object o, EventArgs args)
{
TreeIter iter;
TreeModel model;
if (view.Selection.GetSelected (out model, out iter)) {
iter = filter.ConvertIterToChildIter (sort.ConvertIterToChildIter (iter));
store.SetValue (iter, DataColumns.Read, true);
Task task = store.GetValue (iter, DataColumns.Task) as Task;
if (task != null) {
TaskService.ShowStatus (task);
task.JumpToPosition ();
TaskService.Errors.CurrentLocationTask = task;
IdeApp.Workbench.ActiveLocationList = TaskService.Errors;
}
}
}
void OnColumnVisibilityChanged (object o, EventArgs args)
{
ToggleAction action = o as ToggleAction;
if (action != null)
{
view.Columns[columnsActions[action]].Visible = action.Active;
StoreColumnsVisibility ();
}
}
void AddColumns ()
{
CellRendererImage iconRender = new CellRendererImage ();
Gtk.CellRendererToggle toggleRender = new Gtk.CellRendererToggle ();
toggleRender.Toggled += new ToggledHandler (ItemToggled);
TreeViewColumn col;
col = view.AppendColumn ("!", iconRender, "image", DataColumns.Type);
col = view.AppendColumn ("", toggleRender);
col.SetCellDataFunc (toggleRender, new Gtk.TreeCellDataFunc (ToggleDataFunc));
col = view.AppendColumn (GettextCatalog.GetString ("Line"), view.TextRenderer);
col.SetCellDataFunc (view.TextRenderer, new Gtk.TreeCellDataFunc (LineDataFunc));
var descriptionCellRenderer = new DescriptionCellRendererText ();
view.RegisterRenderForFontChanges (descriptionCellRenderer);
var descriptionCol = view.AppendColumn (GettextCatalog.GetString ("Description"), descriptionCellRenderer);
descriptionCol.SetCellDataFunc (descriptionCellRenderer, new Gtk.TreeCellDataFunc (DescriptionDataFunc));
descriptionCol.Resizable = true;
descriptionCellRenderer.WrapMode = Pango.WrapMode.Word;
descriptionCellRenderer.PreferedMaxWidth = IdeApp.Workbench.RootWindow.Allocation.Width / 3;
descriptionCol.AddNotification("width", delegate
{
descriptionCellRenderer.WrapWidth = descriptionCol.Width;
store.Foreach((model, path, iter) =>
{
model.EmitRowChanged(path, iter);
return false;
});
});
col = view.AppendColumn (GettextCatalog.GetString ("File"), view.TextRenderer);
col.SetCellDataFunc (view.TextRenderer, new Gtk.TreeCellDataFunc (FileDataFunc));
col.Resizable = true;
col = view.AppendColumn (GettextCatalog.GetString ("Project"), view.TextRenderer);
col.SetCellDataFunc (view.TextRenderer, new Gtk.TreeCellDataFunc (ProjectDataFunc));
col.Resizable = true;
col = view.AppendColumn (GettextCatalog.GetString ("Path"), view.TextRenderer);
col.SetCellDataFunc (view.TextRenderer, new Gtk.TreeCellDataFunc (PathDataFunc));
col.Resizable = true;
col = view.AppendColumn (GettextCatalog.GetString ("Category"), view.TextRenderer);
col.SetCellDataFunc (view.TextRenderer, new Gtk.TreeCellDataFunc (CategoryDataFunc));
col.Resizable = true;
}
static void ToggleDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Gtk.CellRendererToggle toggleRenderer = (Gtk.CellRendererToggle)cell;
Task task = model.GetValue (iter, DataColumns.Task) as Task;
if (task == null) {
toggleRenderer.Visible = false;
return;
}
toggleRenderer.Active = task.Completed;
}
static void LineDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Gtk.CellRendererText textRenderer = (Gtk.CellRendererText)cell;
Task task = model.GetValue (iter, DataColumns.Task) as Task;
if (task == null) {
textRenderer.Text = "";
return;
}
SetText (textRenderer, model, iter, task, task.Line != 0 ? task.Line.ToString () : "");
}
static void DescriptionDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
var textRenderer = (CellRendererText)cell;
Task task = model.GetValue (iter, DataColumns.Task) as Task;
var text = model.GetValue (iter, DataColumns.Description) as string;
if (task == null) {
if (model.IterParent (out iter, iter)) {
task = model.GetValue (iter, DataColumns.Task) as Task;
if (task == null) {
textRenderer.Text = "";
return;
}
} else {
textRenderer.Text = "";
return;
}
}
SetText (textRenderer, model, iter, task, text);
}
static void FileDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Gtk.CellRendererText textRenderer = (Gtk.CellRendererText)cell;
Task task = model.GetValue (iter, DataColumns.Task) as Task;
if (task == null) {
textRenderer.Text = "";
return;
}
string tmpPath = "";
string fileName = "";
try {
tmpPath = GetPath (task);
fileName = Path.GetFileName (tmpPath);
} catch (Exception) {
fileName = tmpPath;
}
SetText (textRenderer, model, iter, task, fileName);
}
static string GetPath (Task task)
{
if (task.WorkspaceObject != null)
return FileService.AbsoluteToRelativePath (task.WorkspaceObject.BaseDirectory, task.FileName);
return task.FileName;
}
static void ProjectDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Gtk.CellRendererText textRenderer = (Gtk.CellRendererText)cell;
Task task = model.GetValue (iter, DataColumns.Task) as Task;
if (task == null) {
textRenderer.Text = "";
return;
}
SetText (textRenderer, model, iter, task, GetProject(task));
}
static string GetProject (Task task)
{
return (task != null && task.WorkspaceObject is SolutionItem)? task.WorkspaceObject.Name: string.Empty;
}
static void PathDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Gtk.CellRendererText textRenderer = (Gtk.CellRendererText)cell;
Task task = model.GetValue (iter, DataColumns.Task) as Task;
if (task == null) {
textRenderer.Text = "";
return;
}
SetText (textRenderer, model, iter, task, GetPath (task));
}
static void CategoryDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
Gtk.CellRendererText textRenderer = (Gtk.CellRendererText)cell;
Task task = model.GetValue (iter, DataColumns.Task) as Task;
if (task == null) {
textRenderer.Text = "";
return;
}
SetText (textRenderer, model, iter, task, task.Category ?? "");
}
static void SetText (CellRendererText textRenderer, TreeModel model, TreeIter iter, Task task, string text)
{
textRenderer.Text = text;
textRenderer.Weight = (int)((bool)model.GetValue (iter, DataColumns.Read) ? Pango.Weight.Normal : Pango.Weight.Bold);
textRenderer.Strikethrough = task.Completed;
}
void OnCombineOpen(object sender, EventArgs e)
{
Clear();
}
void OnCombineClosed(object sender, EventArgs e)
{
Clear();
}
public void Dispose ()
{
}
void OnRowActivated (object o, RowActivatedArgs args)
{
OnTaskJumpto (null, null);
}
public CompilerResults CompilerResults = null;
void FilterChanged (object sender, EventArgs e)
{
PropertyService.Set (showErrorsPropertyName, errorBtn.Active);
PropertyService.Set (showWarningsPropertyName, warnBtn.Active);
PropertyService.Set (showMessagesPropertyName, msgBtn.Active);
filter.Refilter ();
}
bool FilterTasks (TreeModel model, TreeIter iter)
{
bool canShow = false;
try {
Task task = store.GetValue (iter, DataColumns.Task) as Task;
if (task == null)
return true;
if (task.Severity == TaskSeverity.Error && errorBtn.Active) canShow = true;
else if (task.Severity == TaskSeverity.Warning && warnBtn.Active) canShow = true;
else if (task.Severity == TaskSeverity.Information && msgBtn.Active) canShow = true;
if (canShow && !string.IsNullOrWhiteSpace (currentSearchPattern)) {
canShow = (task.Description != null && task.Description.IndexOf (currentSearchPattern, StringComparison.OrdinalIgnoreCase) != -1) ||
(task.Code != null && task.Code.IndexOf (currentSearchPattern, StringComparison.OrdinalIgnoreCase) != -1) ||
(task.FileName != null && task.FileName.FileName.IndexOf (currentSearchPattern, StringComparison.OrdinalIgnoreCase) != -1) ||
(task.WorkspaceObject != null && task.WorkspaceObject.Name != null && task.WorkspaceObject.Name.IndexOf (currentSearchPattern, StringComparison.OrdinalIgnoreCase) != -1) ||
(task.Category != null && task.Category.IndexOf (currentSearchPattern, StringComparison.OrdinalIgnoreCase) != -1);
}
} catch {
//Not yet fully added
return false;
}
return canShow;
}
public void ShowResults (object sender, EventArgs e)
{
Clear();
AddTasks (TaskService.Errors);
}
private void Clear()
{
errorCount = warningCount = infoCount = 0;
if (view.IsRealized)
view.ScrollToPoint (0, 0);
store.Clear ();
tasks.Clear ();
UpdateErrorsNum ();
UpdateWarningsNum ();
UpdateMessagesNum ();
UpdatePadIcon ();
}
void TaskChanged (object sender, TaskEventArgs e)
{
this.view.QueueDraw ();
}
void TaskAdded (object sender, TaskEventArgs e)
{
AddTasks (e.Tasks);
}
public void AddTasks (IEnumerable<Task> tasks)
{
int n = 1;
foreach (Task t in tasks) {
AddTaskInternal (t);
if ((n++ % 100) == 0) {
// Adding many tasks is a bit slow, so refresh the
// ui at every block of 100.
DispatchService.RunPendingEvents ();
}
}
filter.Refilter ();
}
public void AddTask (Task t)
{
AddTaskInternal (t);
filter.Refilter ();
}
void AddTaskInternal (Task t)
{
if (tasks.Contains (t)) return;
Xwt.Drawing.Image stock;
switch (t.Severity) {
case TaskSeverity.Error:
stock = iconError;
errorCount++;
UpdateErrorsNum ();
break;
case TaskSeverity.Warning:
stock = iconWarning;
warningCount++;
UpdateWarningsNum ();
break;
default:
stock = iconInfo;
infoCount++;
UpdateMessagesNum ();
break;
}
tasks [t] = t;
var indexOfNewLine = t.Description.IndexOfAny (new [] { '\n', '\r' });
if (indexOfNewLine != -1) {
var iter = store.AppendValues (stock, false, t, t.Description.Remove (indexOfNewLine));
store.AppendValues (iter, iconEmpty, false, null, t.Description);
} else {
store.AppendValues (stock, false, t, t.Description);
}
UpdatePadIcon ();
}
void UpdateErrorsNum ()
{
errorBtn.Label = " " + string.Format(GettextCatalog.GetPluralString("{0} Error", "{0} Errors", errorCount), errorCount);
errorBtn.Image.Show ();
}
void UpdateWarningsNum ()
{
warnBtn.Label = " " + string.Format(GettextCatalog.GetPluralString("{0} Warning", "{0} Warnings", warningCount), warningCount);
warnBtn.Image.Show ();
}
void UpdateMessagesNum ()
{
msgBtn.Label = " " + string.Format(GettextCatalog.GetPluralString("{0} Message", "{0} Messages", infoCount), infoCount);
msgBtn.Image.Show ();
}
void UpdatePadIcon ()
{
if (errorCount > 0)
window.Icon = "md-errors-list-has-errors";
else if (warningCount > 0)
window.Icon = "md-errors-list-has-warnings";
else
window.Icon = "md-errors-list";
}
private void ItemToggled (object o, ToggledArgs args)
{
Gtk.TreeIter iter;
if (store.GetIterFromString (out iter, args.Path)) {
Task task = (Task)store.GetValue (iter, DataColumns.Task);
task.Completed = !task.Completed;
TaskService.FireTaskToggleEvent (this, new TaskEventArgs (task));
}
}
static int SeverityIterSort(TreeModel model, TreeIter a, TreeIter z)
{
Task aTask = model.GetValue(a, DataColumns.Task) as Task,
zTask = model.GetValue(z, DataColumns.Task) as Task;
return (aTask != null && zTask != null) ?
aTask.Severity.CompareTo(zTask.Severity) :
0;
}
static int ProjectIterSort (TreeModel model, TreeIter a, TreeIter z)
{
Task aTask = model.GetValue (a, DataColumns.Task) as Task,
zTask = model.GetValue (z, DataColumns.Task) as Task;
return (aTask != null && zTask != null) ?
GetProject (aTask).CompareTo (GetProject (zTask)) :
0;
}
static int FileIterSort (TreeModel model, TreeIter a, TreeIter z)
{
Task aTask = model.GetValue (a, DataColumns.Task) as Task,
zTask = model.GetValue (z, DataColumns.Task) as Task;
return (aTask != null && zTask != null) ?
aTask.FileName.CompareTo (zTask.FileName) :
0;
}
void HandleLogBtnToggled (object sender, EventArgs e)
{
var visible = logBtn.Active;
PropertyService.Set (outputViewVisiblePropertyName, visible);
outputView.Visible = visible;
if (initialLogShow && visible && control.IsRealized) {
initialLogShow = false;
SetInitialOutputViewSize (control.Allocation.Width);
}
}
void SetInitialOutputViewSize (int controlWidth)
{
double relPos = PropertyService.Get<double> (logSeparatorPositionPropertyName, 0.5d);
int pos = (int) (controlWidth * relPos);
pos = Math.Max (30, Math.Min (pos, controlWidth - 30));
control.Position = pos;
}
class DescriptionCellRendererText : CellRendererText
{
public int PreferedMaxWidth { get; set; }
public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
{
int originalWrapWidth = WrapWidth;
WrapWidth = -1;
// First calculate Width with WrapWidth=-1 which will give us
// Width of text in one line(without wrapping)
base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height);
int oneLineWidth = width;
WrapWidth = originalWrapWidth;
// originalWrapWidth(aka WrapWidth) equals to actual width of Column if oneLineWidth is bigger
// then column width/height we must recalculate, because Height is atm for one line
// and not multipline that WrapWidth creates...
if (oneLineWidth > originalWrapWidth) {
base.GetSize (widget, ref cell_area, out x_offset, out y_offset, out width, out height);
}
width = Math.Min (oneLineWidth, PreferedMaxWidth);
}
}
}
}
|