32
32
using Mono.TextEditor.Highlighting;
33
33
using System.Collections.Generic;
34
34
using MonoDevelop.Core;
35
using MonoDevelop.Core.Gui;
37
36
using MonoDevelop.Components.Commands;
38
37
using MonoDevelop.Ide.Commands;
39
using MonoDevelop.Ide.Gui.Content;
40
using MonoDevelop.Ide.Navigation;
42
43
namespace MonoDevelop.Ide.FindInFiles
44
45
[System.ComponentModel.ToolboxItem(true)]
45
public partial class SearchResultWidget : Gtk.Bin
46
public partial class SearchResultWidget : Gtk.Bin, ILocationList
48
49
ToolButton buttonStop;
87
88
fileNameColumn.Resizable = true;
88
89
fileNameColumn.SortColumnId = 0;
89
90
fileNameColumn.Title = GettextCatalog.GetString ("File");
90
CellRendererPixbuf fileNamePixbufRenderer = new CellRendererPixbuf ();
91
var fileNamePixbufRenderer = new CellRendererPixbuf ();
91
92
fileNameColumn.PackStart (fileNamePixbufRenderer, false);
92
93
fileNameColumn.SetCellDataFunc (fileNamePixbufRenderer, new Gtk.TreeCellDataFunc (FileIconDataFunc));
124
125
buttonClear.TooltipText = GettextCatalog.GetString ("Clear results");
125
126
toolbar.Insert (buttonClear, -1);
127
ToggleToolButton buttonOutput = new ToggleToolButton (MonoDevelop.Core.Gui.Stock.OutputIcon);
128
ToggleToolButton buttonOutput = new ToggleToolButton (MonoDevelop.Ide.Gui.Stock.OutputIcon);
128
129
buttonOutput.Clicked += ButtonOutputClicked;
129
130
buttonOutput.TooltipText = GettextCatalog.GetString ("Show output");
130
131
toolbar.Insert (buttonOutput, -1);
258
260
StringBuilder result = new StringBuilder ();
259
261
int idx = markup.IndexOf ("foreground=\"");
264
// This is a workaround for Bug 559804 - Strings in search result pad are near-invisible
265
// On mac it's not possible to get the white background color with the Base or Background
266
// methods. If this bug is fixed or a better work around is found - remove this hack.
267
if (Platform.IsMac) {
268
baseColor = treeviewSearchResults.Style.Light (treeviewSearchResults.State);
270
baseColor = treeviewSearchResults.Style.Base (treeviewSearchResults.State);
261
273
while (idx > 0) {
262
274
idx += "foreground=\"".Length;
263
275
result.Append (markup.Substring (offset, idx - offset));
271
283
Gdk.Color color = Gdk.Color.Zero;
272
284
if (Gdk.Color.Parse (colorStr, ref color)) {
273
colorStr = SyntaxMode.ColorToPangoMarkup (AdjustColor (Style.Base (StateType.Normal), color));
285
colorStr = SyntaxMode.ColorToPangoMarkup (AdjustColor (baseColor, color));
275
287
result.Append (colorStr);
276
288
idx = markup.IndexOf ("foreground=\"", idx);
296
308
void FileIconDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
298
CellRendererPixbuf fileNamePixbufRenderer = (CellRendererPixbuf)cell;
310
if (TreeIter.Zero.Equals (iter))
312
CellRendererPixbuf fileNamePixbufRenderer = (CellRendererPixbuf) cell;
299
313
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
314
if (searchResult == null)
300
316
fileNamePixbufRenderer.Pixbuf = DesktopService.GetPixbufForFile (searchResult.FileName, Gtk.IconSize.Menu);
308
324
void FileNameDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
326
if (TreeIter.Zero.Equals (iter))
310
328
CellRendererText fileNameRenderer = (CellRendererText)cell;
311
329
bool didRead = (bool)store.GetValue (iter, DidReadColumn);
312
330
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
331
if (searchResult == null)
314
333
bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
316
335
fileNameRenderer.Markup = MarkupText (System.IO.Path.GetFileName (searchResult.FileName), didRead, isSelected);
349
368
void ResultPathDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
370
if (TreeIter.Zero.Equals (iter))
351
372
CellRendererText pathRenderer = (CellRendererText)cell;
352
373
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
374
if (searchResult == null)
353
376
bool didRead = (bool)store.GetValue (iter, DidReadColumn);
354
377
bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
355
378
pathRenderer.Markup = MarkupText (System.IO.Path.GetDirectoryName (searchResult.FileName), didRead, isSelected);
358
381
void ResultLineDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
383
if (TreeIter.Zero.Equals (iter))
360
385
CellRendererText lineRenderer = (CellRendererText)cell;
361
386
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
387
if (searchResult == null)
362
390
Mono.TextEditor.Document doc = GetDocument (searchResult);
363
391
int lineNr = doc.OffsetToLineNumber (searchResult.Offset) + 1;
364
392
bool didRead = (bool)store.GetValue (iter, DidReadColumn);
369
397
void ResultTextDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
399
if (TreeIter.Zero.Equals (iter))
371
401
CellRendererText textRenderer = (CellRendererText)cell;
372
402
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
403
if (searchResult == null)
374
406
Mono.TextEditor.Document doc = GetDocument (searchResult);
375
407
int lineNr = doc.OffsetToLineNumber (searchResult.Offset);
552
585
clipboard.Text = sb.ToString ();
555
public bool GetNextLocation (out string file, out int line, out int column)
588
public string ItemName {
590
return GettextCatalog.GetString ("Search Result");
594
public NavigationPoint GetNextLocation ()
557
596
TreeIter iter = TreeIter.Zero;
558
597
TreePath[] path = treeviewSearchResults.Selection.GetSelectedRows ();
563
602
store.GetIterFirst (out iter);
566
return GetLocation (iter, out file, out line, out column);
605
return GetLocation (iter);
569
public bool GetPreviousLocation (out string file, out int line, out int column)
608
public NavigationPoint GetPreviousLocation ()
572
611
TreeIter prevIter = TreeIter.Zero;
582
621
hasNext = store.IterNext (ref iter);
585
return GetLocation (prevIter, out file, out line, out column);
624
return GetLocation (prevIter);
588
627
bool IsIterSelected (TreePath selPath, TreeIter iter)
590
629
return selPath != null && store.GetPath (iter).Equals (selPath);
593
bool GetLocation (TreeIter iter, out string file, out int line, out int column)
632
NavigationPoint GetLocation (TreeIter iter)
595
634
this.treeviewSearchResults.Selection.UnselectAll ();
596
if (!store.IterIsValid (iter)) {
635
if (!store.IterIsValid (iter))
601
638
this.treeviewSearchResults.Selection.SelectIter (iter);
602
639
this.treeviewSearchResults.ScrollToCell (store.GetPath (iter), this.treeviewSearchResults.Columns[0], false, 0, 0);
603
640
SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
604
file = searchResult.FileName;
605
641
Mono.TextEditor.Document doc = GetDocument (searchResult);
606
642
DocumentLocation location = doc.OffsetToLocation (searchResult.Offset);
607
line = location.Line;
608
column = location.Column;
643
return new SearchTextFileNavigationPoint (searchResult.FileName, location.Line + 1, location.Column + 1);
646
class SearchTextFileNavigationPoint : TextFileNavigationPoint
648
public SearchTextFileNavigationPoint (FilePath file, int line, int column) : base (file, line, column)
652
protected override MonoDevelop.Ide.Gui.Document DoShow ()
654
var doc = base.DoShow ();
656
IEditableTextBuffer buf = doc.GetContent<IEditableTextBuffer> ();
658
buf.SetCaretTo (Math.Max (Line, 1), Math.Max (Column, 1));