84
90
treeviewSearchResults.ButtonPressEvent += HandleButtonPressEvent;
85
91
treeviewSearchResults.RulesHint = true;
87
TreeViewColumn fileNameColumn = new TreeViewColumn ();
88
fileNameColumn.Resizable = true;
89
fileNameColumn.SortColumnId = 0;
90
fileNameColumn.Title = GettextCatalog.GetString ("File");
93
var fileNameColumn = new TreeViewColumn {
96
Title = GettextCatalog.GetString("File")
99
fileNameColumn.FixedWidth = 200;
91
101
var fileNamePixbufRenderer = new CellRendererPixbuf ();
92
102
fileNameColumn.PackStart (fileNamePixbufRenderer, false);
93
fileNameColumn.SetCellDataFunc (fileNamePixbufRenderer, new Gtk.TreeCellDataFunc (FileIconDataFunc));
103
fileNameColumn.SetCellDataFunc (fileNamePixbufRenderer, FileIconDataFunc);
95
CellRendererText fileNameRenderer = new CellRendererText ();
105
var fileNameRenderer = new CellRendererText ();
96
106
fileNameColumn.PackStart (fileNameRenderer, true);
97
fileNameColumn.SetCellDataFunc (fileNameRenderer, new Gtk.TreeCellDataFunc (FileNameDataFunc));
107
fileNameColumn.SetCellDataFunc (fileNameRenderer, FileNameDataFunc);
98
108
treeviewSearchResults.AppendColumn (fileNameColumn);
100
TreeViewColumn lineColumn = treeviewSearchResults.AppendColumn (GettextCatalog.GetString ("Line"), new Gtk.CellRendererText (), new Gtk.TreeCellDataFunc (ResultLineDataFunc));
101
lineColumn.SortColumnId = 1;
110
// TreeViewColumn lineColumn = treeviewSearchResults.AppendColumn (GettextCatalog.GetString ("Line"), new CellRendererText (), ResultLineDataFunc);
111
// lineColumn.SortColumnId = 1;
112
// lineColumn.FixedWidth = 50;
103
TreeViewColumn textColumn = treeviewSearchResults.AppendColumn (GettextCatalog.GetString ("Text"), new Gtk.CellRendererText (), new Gtk.TreeCellDataFunc (ResultTextDataFunc));
115
TreeViewColumn textColumn = treeviewSearchResults.AppendColumn (GettextCatalog.GetString ("Text"), new CellRendererText (), ResultTextDataFunc);
104
116
textColumn.SortColumnId = 2;
105
textColumn.Resizable = true;
117
textColumn.Resizable = false;
118
textColumn.FixedWidth = 300;
107
TreeViewColumn pathColumn = treeviewSearchResults.AppendColumn (GettextCatalog.GetString ("Path"), new Gtk.CellRendererText (), new Gtk.TreeCellDataFunc (ResultPathDataFunc));
121
TreeViewColumn pathColumn = treeviewSearchResults.AppendColumn (GettextCatalog.GetString ("Path"), new CellRendererText (), ResultPathDataFunc);
108
122
pathColumn.SortColumnId = 3;
109
pathColumn.Resizable = true;
110
store.SetSortFunc (0, new TreeIterCompareFunc (CompareFileNames));
111
store.SetSortFunc (1, new TreeIterCompareFunc (CompareLineNumbers));
112
store.SetSortFunc (3, new TreeIterCompareFunc (CompareFilePaths));
123
pathColumn.Resizable = false;
124
pathColumn.FixedWidth = 500;
127
store.SetSortFunc (0, CompareFileNames);
128
// store.SetSortFunc (1, CompareLineNumbers);
129
store.SetSortFunc (3, CompareFilePaths);
114
131
treeviewSearchResults.RowActivated += TreeviewSearchResultsRowActivated;
116
buttonStop = new ToolButton ("gtk-stop");
117
buttonStop.Sensitive = false;
133
buttonStop = new ToolButton (Stock.Stop) { Sensitive = false };
118
135
buttonStop.Clicked += ButtonStopClicked;
120
137
buttonStop.TooltipText = GettextCatalog.GetString ("Stop");
121
138
toolbar.Insert (buttonStop, -1);
123
ToolButton buttonClear = new ToolButton ("gtk-clear");
140
var buttonClear = new ToolButton (Gtk.Stock.Clear);
124
141
buttonClear.Clicked += ButtonClearClicked;
125
142
buttonClear.TooltipText = GettextCatalog.GetString ("Clear results");
126
143
toolbar.Insert (buttonClear, -1);
128
ToggleToolButton buttonOutput = new ToggleToolButton (MonoDevelop.Ide.Gui.Stock.OutputIcon);
145
var buttonOutput = new ToggleToolButton (Gui.Stock.OutputIcon);
129
146
buttonOutput.Clicked += ButtonOutputClicked;
130
147
buttonOutput.TooltipText = GettextCatalog.GetString ("Show output");
131
148
toolbar.Insert (buttonOutput, -1);
133
buttonPin = new ToggleToolButton ("md-pin-up");
150
buttonPin = new ToggleToolButton (Gui.Stock.PinUp);
134
151
buttonPin.Clicked += ButtonPinClicked;
135
152
buttonPin.TooltipText = GettextCatalog.GetString ("Pin results pad");
136
153
toolbar.Insert (buttonPin, -1);
187
204
public void BeginProgress ()
189
206
IdeApp.Workbench.ActiveLocationList = this;
207
newStore = new ListStore (typeof (SearchResult), typeof (bool));
192
209
buttonStop.Sensitive = true;
193
210
treeviewSearchResults.FreezeChildNotify ();
194
store.SetSortFunc (0, new TreeIterCompareFunc (DefaultSortFunc));
195
store.SetSortFunc (1, new TreeIterCompareFunc (DefaultSortFunc));
196
store.SetSortFunc (3, new TreeIterCompareFunc (DefaultSortFunc));
199
215
public void EndProgress ()
201
217
buttonStop.Sensitive = false;
202
store.SetSortFunc (0, new TreeIterCompareFunc (CompareFileNames));
203
store.SetSortFunc (1, new TreeIterCompareFunc (CompareLineNumbers));
204
store.SetSortFunc (3, new TreeIterCompareFunc (CompareFilePaths));
218
newStore.SetSortFunc (0, CompareFileNames);
219
newStore.SetSortFunc (1, CompareLineNumbers);
220
newStore.SetSortFunc (3, CompareFilePaths);
222
treeviewSearchResults.Model = newStore;
205
227
treeviewSearchResults.ThawChildNotify ();
208
230
public void FocusPad ()
210
232
treeviewSearchResults.GrabFocus ();
212
234
if (store.GetIterFirst (out iter))
213
235
treeviewSearchResults.Selection.SelectIter (iter);
305
329
labelStatus.Text = text;
308
void FileIconDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
332
void FileIconDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
310
334
if (TreeIter.Zero.Equals (iter))
312
CellRendererPixbuf fileNamePixbufRenderer = (CellRendererPixbuf) cell;
313
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
336
var fileNamePixbufRenderer = (CellRendererPixbuf) cell;
337
var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
314
338
if (searchResult == null)
316
fileNamePixbufRenderer.Pixbuf = DesktopService.GetPixbufForFile (searchResult.FileName, Gtk.IconSize.Menu);
340
fileNamePixbufRenderer.Pixbuf = DesktopService.GetPixbufForFile (searchResult.FileName, IconSize.Menu);
319
string MarkupText (string text, bool didRead, bool isSelected)
345
static string MarkupText (string text, bool didRead)
321
347
return string.Format ("<span weight=\"{1}\">{0}</span>", GLib.Markup.EscapeText (text), didRead ? "normal" : "bold");
324
void FileNameDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
350
void FileNameDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
326
352
if (TreeIter.Zero.Equals (iter))
328
CellRendererText fileNameRenderer = (CellRendererText)cell;
354
var fileNameRenderer = (CellRendererText)cell;
329
355
bool didRead = (bool)store.GetValue (iter, DidReadColumn);
330
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
356
var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
331
357
if (searchResult == null)
333
bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
335
fileNameRenderer.Markup = MarkupText (System.IO.Path.GetFileName (searchResult.FileName), didRead, isSelected);
359
Document doc = GetDocument (searchResult);
362
int lineNr = doc.OffsetToLineNumber (searchResult.Offset);
363
fileNameRenderer.Markup = MarkupText (System.IO.Path.GetFileName (searchResult.FileName) + ":" + lineNr, didRead);
338
366
int CompareLineNumbers (TreeModel model, TreeIter first, TreeIter second)
340
DocumentLocation loc1 = GetLocation ((SearchResult)model.GetValue (first, SearchResultColumn));
341
DocumentLocation loc2 = GetLocation ((SearchResult)model.GetValue (second, SearchResultColumn));
368
var loc1 = GetLocation ((SearchResult)model.GetValue (first, SearchResultColumn));
369
var loc2 = GetLocation ((SearchResult)model.GetValue (second, SearchResultColumn));
342
370
return loc1.Line.CompareTo (loc2.Line);
359
387
static int CompareFilePaths (TreeModel model, TreeIter first, TreeIter second)
361
SearchResult searchResult1 = (SearchResult)model.GetValue (first, SearchResultColumn);
362
SearchResult searchResult2 = (SearchResult)model.GetValue (second, SearchResultColumn);
389
var searchResult1 = (SearchResult)model.GetValue (first, SearchResultColumn);
390
var searchResult2 = (SearchResult)model.GetValue (second, SearchResultColumn);
363
391
if (searchResult1 == null || searchResult2 == null || searchResult1.FileName == null || searchResult2.FileName == null)
365
394
return System.IO.Path.GetDirectoryName (searchResult1.FileName).CompareTo (System.IO.Path.GetDirectoryName (searchResult2.FileName));
368
void ResultPathDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
370
if (TreeIter.Zero.Equals (iter))
372
CellRendererText pathRenderer = (CellRendererText)cell;
373
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
374
if (searchResult == null)
376
bool didRead = (bool)store.GetValue (iter, DidReadColumn);
377
bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
378
pathRenderer.Markup = MarkupText (System.IO.Path.GetDirectoryName (searchResult.FileName), didRead, isSelected);
381
void ResultLineDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
383
if (TreeIter.Zero.Equals (iter))
385
CellRendererText lineRenderer = (CellRendererText)cell;
386
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
387
if (searchResult == null)
390
Mono.TextEditor.Document doc = GetDocument (searchResult);
391
int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1;
392
bool didRead = (bool)store.GetValue (iter, DidReadColumn);
393
bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
394
lineRenderer.Markup = MarkupText (lineNr.ToString (), didRead, isSelected);
397
void ResultTextDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
399
if (TreeIter.Zero.Equals (iter))
401
CellRendererText textRenderer = (CellRendererText)cell;
402
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
403
if (searchResult == null)
406
Mono.TextEditor.Document doc = GetDocument (searchResult);
398
void ResultPathDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
400
if (TreeIter.Zero.Equals (iter))
402
var pathRenderer = (CellRendererText)cell;
403
var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
404
if (searchResult == null)
406
bool didRead = (bool)store.GetValue (iter, DidReadColumn);
407
pathRenderer.Markup = MarkupText (System.IO.Path.GetDirectoryName (searchResult.FileName), didRead);
410
// void ResultLineDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
412
// if (TreeIter.Zero.Equals (iter))
414
// var lineRenderer = (CellRendererText)cell;
415
// var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
416
// if (searchResult == null)
419
// Document doc = GetDocument (searchResult);
420
// int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1;
421
// bool didRead = (bool)store.GetValue (iter, DidReadColumn);
422
// lineRenderer.Markup = MarkupText (lineNr.ToString (), didRead);
425
void ResultTextDataFunc (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
427
if (TreeIter.Zero.Equals (iter))
429
var textRenderer = (CellRendererText)cell;
430
var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
431
if (searchResult == null || searchResult.Offset < 0) {
432
textRenderer.Markup = "Invalid search result";
436
Document doc = GetDocument (searchResult);
438
textRenderer.Markup = "Can't create document for:" + searchResult.FileName;
407
441
int lineNr = doc.OffsetToLineNumber (searchResult.Offset);
408
442
LineSegment line = doc.GetLine (lineNr);
444
textRenderer.Markup = "Invalid line number " + lineNr + " from offset: " + searchResult.Offset;
409
447
bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
412
if (doc.SyntaxMode != null) {
413
markup = doc.SyntaxMode.GetMarkup (doc, new TextEditorOptions (), highlightStyle, line.Offset, line.EditableLength, true, !isSelected, false);
415
markup = GLib.Markup.EscapeText (doc.GetTextAt (line.Offset, line.EditableLength));
448
int indent = line.GetIndentation (doc).Length;
449
string markup = doc.SyntaxMode != null ?
450
doc.SyntaxMode.GetMarkup (doc, new TextEditorOptions (), highlightStyle, line.Offset + indent, line.EditableLength - indent, true, !isSelected, false) :
451
GLib.Markup.EscapeText (doc.GetTextAt (line.Offset, line.EditableLength));
418
453
if (!isSelected) {
419
int col = searchResult.Offset - line.Offset;
454
int col = searchResult.Offset - line.Offset - indent;
421
456
int pos1 = FindPosition (markup, col, out tag);
422
457
int pos2 = FindPosition (markup, col + searchResult.Length, out tag);
423
458
if (pos1 >= 0 && pos2 >= 0) {
424
if (tag.StartsWith ("span")) {
425
markup = markup.Insert (pos2, "</span></span><" + tag + ">");
427
markup = markup.Insert (pos2, "</span>");
429
Gdk.Color searchColor = highlightStyle.SearchTextBg;
459
markup = tag.StartsWith ("span") ? markup.Insert (pos2, "</span></span><" + tag + ">") : markup.Insert (pos2, "</span>");
460
Color searchColor = Mono.TextEditor.Highlighting.Style.ToGdkColor (highlightStyle.SearchTextBg);
430
461
double b1 = HslColor.Brightness (searchColor);
431
462
double b2 = HslColor.Brightness (AdjustColor (Style.Base (StateType.Normal), highlightStyle.Default.Color));
432
463
double delta = Math.Abs (b1 - b2);
524
559
public void Add (SearchResult result)
526
store.InsertWithValues (ResultCount, result, false);
530
void OpenDocumentAt (Gtk.TreeIter iter)
532
SearchResult result = store.GetValue (iter, SearchResultColumn) as SearchResult;
561
newStore.InsertWithValues (ResultCount++, result, false);
564
public void AddRange (IEnumerable<SearchResult> results)
566
foreach (var result in results) {
571
void OpenDocumentAt (TreeIter iter)
573
var result = store.GetValue (iter, SearchResultColumn) as SearchResult;
533
574
if (result != null) {
534
575
DocumentLocation loc = GetLocation (result);
535
576
store.SetValue (iter, DidReadColumn, true);
536
IdeApp.Workbench.OpenDocument (result.FileName, loc.Line, loc.Column, true);
577
IdeApp.Workbench.OpenDocument (result.FileName, loc.Line, loc.Column);
539
581
DocumentLocation GetLocation (SearchResult searchResult)
541
Mono.TextEditor.Document doc = GetDocument (searchResult);
583
Document doc = GetDocument (searchResult);
585
return DocumentLocation.Empty;
542
586
int lineNr = doc.OffsetToLineNumber (searchResult.Offset);
543
587
LineSegment line = doc.GetLine (lineNr);
544
return new DocumentLocation (lineNr + 1, searchResult.Offset - line.Offset + 1);
588
return new DocumentLocation (lineNr, searchResult.Offset - line.Offset + 1);
547
591
public void OpenSelectedMatches ()
549
foreach (Gtk.TreePath path in treeviewSearchResults.Selection.GetSelectedRows ()) {
593
foreach (TreePath path in treeviewSearchResults.Selection.GetSelectedRows ()) {
551
595
if (!store.GetIter (out iter, path))
553
597
OpenDocumentAt (iter);
563
607
public void CopySelection ()
566
StringBuilder sb = new StringBuilder ();
567
foreach (Gtk.TreePath p in treeviewSearchResults.Selection.GetSelectedRows (out model)) {
610
var sb = new StringBuilder ();
611
foreach (TreePath p in treeviewSearchResults.Selection.GetSelectedRows (out model)) {
569
613
if (!model.GetIter (out iter, p))
571
SearchResult result = store.GetValue (iter, SearchResultColumn) as SearchResult;
615
var result = store.GetValue (iter, SearchResultColumn) as SearchResult;
572
616
if (result == null)
574
618
DocumentLocation loc = GetLocation (result);
575
Mono.TextEditor.Document doc = GetDocument (result);
576
LineSegment line = doc.GetLine (loc.Line - 1);
619
Document doc = GetDocument (result);
622
LineSegment line = doc.GetLine (loc.Line);
578
624
sb.AppendFormat ("{0} ({1}, {2}):{3}", result.FileName, loc.Line, loc.Column, doc.GetTextAt (line.Offset, line.EditableLength));
579
625
sb.AppendLine ();
581
Gtk.Clipboard clipboard = Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
627
Clipboard clipboard = Clipboard.Get (Atom.Intern ("CLIPBOARD", false));
582
628
clipboard.Text = sb.ToString ();
584
clipboard = Clipboard.Get (Gdk.Atom.Intern ("PRIMARY", false));
630
clipboard = Clipboard.Get (Atom.Intern ("PRIMARY", false));
585
631
clipboard.Text = sb.ToString ();
632
678
NavigationPoint GetLocation (TreeIter iter)
634
this.treeviewSearchResults.Selection.UnselectAll ();
680
treeviewSearchResults.Selection.UnselectAll ();
635
681
if (!store.IterIsValid (iter))
638
this.treeviewSearchResults.Selection.SelectIter (iter);
639
this.treeviewSearchResults.ScrollToCell (store.GetPath (iter), this.treeviewSearchResults.Columns[0], false, 0, 0);
640
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
641
Mono.TextEditor.Document doc = GetDocument (searchResult);
684
treeviewSearchResults.Selection.SelectIter (iter);
685
treeviewSearchResults.ScrollToCell (store.GetPath (iter), treeviewSearchResults.Columns [0], false, 0, 0);
686
var searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
687
Document doc = GetDocument (searchResult);
642
690
DocumentLocation location = doc.OffsetToLocation (searchResult.Offset);
643
return new SearchTextFileNavigationPoint (searchResult.FileName, location.Line + 1, location.Column + 1);
691
return new SearchTextFileNavigationPoint (searchResult.FileName, location.Line, location.Column);
646
694
class SearchTextFileNavigationPoint : TextFileNavigationPoint