~ubuntu-branches/ubuntu/maverick/monodevelop/maverick

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/SearchResultWidget.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
using Mono.TextEditor.Highlighting;
33
33
using System.Collections.Generic;
34
34
using MonoDevelop.Core;
35
 
using MonoDevelop.Core.Gui;
36
35
using System.Text;
37
36
using MonoDevelop.Components.Commands;
38
37
using MonoDevelop.Ide.Commands;
39
38
using System.IO;
 
39
using MonoDevelop.Ide.Gui.Content;
 
40
using MonoDevelop.Ide.Navigation;
40
41
 
41
42
 
42
43
namespace MonoDevelop.Ide.FindInFiles
43
44
{
44
45
        [System.ComponentModel.ToolboxItem(true)]
45
 
        public partial class SearchResultWidget : Gtk.Bin
 
46
        public partial class SearchResultWidget : Gtk.Bin, ILocationList
46
47
        {
47
48
                ListStore store;
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));
93
94
                        
124
125
                        buttonClear.TooltipText = GettextCatalog.GetString ("Clear results");
125
126
                        toolbar.Insert (buttonClear, -1);
126
127
                        
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);
137
138
                        store.SetSortColumnId (3, SortType.Ascending);
138
139
                        ShowAll ();
139
140
                        
140
 
                        
141
141
                        scrolledwindowLogView.Hide ();
142
142
                }
143
143
                
186
186
                
187
187
                public void BeginProgress ()
188
188
                {
 
189
                        IdeApp.Workbench.ActiveLocationList = this;
 
190
                        
189
191
                        Reset ();
190
192
                        buttonStop.Sensitive = true;
191
193
                        treeviewSearchResults.FreezeChildNotify ();
258
260
                        StringBuilder result = new StringBuilder ();
259
261
                        int idx = markup.IndexOf ("foreground=\"");
260
262
                        int offset = 0;
 
263
                        Gdk.Color baseColor;
 
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);
 
269
                        } else {
 
270
                                baseColor = treeviewSearchResults.Style.Base (treeviewSearchResults.State);
 
271
                        }
 
272
                        
261
273
                        while (idx > 0) {
262
274
                                idx += "foreground=\"".Length;
263
275
                                result.Append (markup.Substring (offset, idx - offset));
270
282
                                
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));
274
286
                                }
275
287
                                result.Append (colorStr);
276
288
                                idx = markup.IndexOf ("foreground=\"", idx);
295
307
                
296
308
                void FileIconDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
297
309
                {
298
 
                        CellRendererPixbuf fileNamePixbufRenderer = (CellRendererPixbuf)cell;
 
310
                        if (TreeIter.Zero.Equals (iter))
 
311
                                return;
 
312
                        CellRendererPixbuf fileNamePixbufRenderer = (CellRendererPixbuf) cell;
299
313
                        SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
 
314
                        if (searchResult == null)
 
315
                                return;
300
316
                        fileNamePixbufRenderer.Pixbuf = DesktopService.GetPixbufForFile (searchResult.FileName, Gtk.IconSize.Menu);
301
317
                }
302
318
                
307
323
                
308
324
                void FileNameDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
309
325
                {
 
326
                        if (TreeIter.Zero.Equals (iter))
 
327
                                return;
310
328
                        CellRendererText fileNameRenderer = (CellRendererText)cell;
311
329
                        bool didRead = (bool)store.GetValue (iter, DidReadColumn);
312
330
                        SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
313
 
                        
 
331
                        if (searchResult == null)
 
332
                                return;
314
333
                        bool isSelected = treeviewSearchResults.Selection.IterIsSelected (iter);
315
334
                        
316
335
                        fileNameRenderer.Markup = MarkupText (System.IO.Path.GetFileName (searchResult.FileName), didRead, isSelected);
348
367
                
349
368
                void ResultPathDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
350
369
                {
 
370
                        if (TreeIter.Zero.Equals (iter))
 
371
                                return;
351
372
                        CellRendererText pathRenderer = (CellRendererText)cell;
352
373
                        SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
 
374
                        if (searchResult == null)
 
375
                                return;
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);
357
380
                
358
381
                void ResultLineDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
359
382
                {
 
383
                        if (TreeIter.Zero.Equals (iter))
 
384
                                return;
360
385
                        CellRendererText lineRenderer = (CellRendererText)cell;
361
386
                        SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
 
387
                        if (searchResult == null)
 
388
                                return;
 
389
                        
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);
368
396
                
369
397
                void ResultTextDataFunc (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
370
398
                {
 
399
                        if (TreeIter.Zero.Equals (iter))
 
400
                                return;
371
401
                        CellRendererText textRenderer = (CellRendererText)cell;
372
402
                        SearchResult searchResult = (SearchResult)store.GetValue (iter, SearchResultColumn);
 
403
                        if (searchResult == null)
 
404
                                return;
373
405
                        
374
406
                        Mono.TextEditor.Document doc = GetDocument (searchResult);
375
407
                        int lineNr = doc.OffsetToLineNumber (searchResult.Offset);
520
552
                                        continue;
521
553
                                OpenDocumentAt (iter);
522
554
                        }
 
555
                        IdeApp.Workbench.ActiveLocationList = this;
523
556
                }
524
557
                
525
558
                public void SelectAll ()
552
585
                        clipboard.Text = sb.ToString ();
553
586
                }
554
587
                
555
 
                public bool GetNextLocation (out string file, out int line, out int column)
 
588
                public string ItemName {
 
589
                        get {
 
590
                                return GettextCatalog.GetString ("Search Result");
 
591
                        }
 
592
                }
 
593
                
 
594
                public NavigationPoint GetNextLocation ()
556
595
                {
557
596
                        TreeIter iter = TreeIter.Zero;
558
597
                        TreePath[] path = treeviewSearchResults.Selection.GetSelectedRows ();
563
602
                                store.GetIterFirst (out iter);
564
603
                        }
565
604
                        
566
 
                        return GetLocation (iter, out file, out line, out column);
 
605
                        return GetLocation (iter);
567
606
                }
568
607
                
569
 
                public bool GetPreviousLocation (out string file, out int line, out int column)
 
608
                public NavigationPoint GetPreviousLocation ()
570
609
                {
571
610
                        TreeIter iter;
572
611
                        TreeIter prevIter = TreeIter.Zero;
582
621
                                hasNext = store.IterNext (ref iter);
583
622
                        }
584
623
                        
585
 
                        return GetLocation (prevIter, out file, out line, out column);
 
624
                        return GetLocation (prevIter);
586
625
                }
587
626
 
588
627
                bool IsIterSelected (TreePath selPath, TreeIter iter)
590
629
                        return selPath != null && store.GetPath (iter).Equals (selPath);
591
630
                }
592
631
 
593
 
                bool GetLocation (TreeIter iter, out string file, out int line, out int column)
 
632
                NavigationPoint GetLocation (TreeIter iter)
594
633
                {
595
634
                        this.treeviewSearchResults.Selection.UnselectAll ();
596
 
                        if (!store.IterIsValid (iter)) {
597
 
                                file = null;
598
 
                                line = column = 0;
599
 
                                return false;
600
 
                        }
 
635
                        if (!store.IterIsValid (iter))
 
636
                                return null;
 
637
 
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;
609
 
                        return true;
 
643
                        return new SearchTextFileNavigationPoint (searchResult.FileName, location.Line + 1, location.Column + 1);
 
644
                }
 
645
                
 
646
                class SearchTextFileNavigationPoint : TextFileNavigationPoint 
 
647
                {
 
648
                        public SearchTextFileNavigationPoint (FilePath file, int line, int column) : base (file, line, column)
 
649
                        {
 
650
                        }
 
651
                        
 
652
                        protected override MonoDevelop.Ide.Gui.Document DoShow ()
 
653
                        {
 
654
                                var doc = base.DoShow ();
 
655
                                if (doc != null) {
 
656
                                        IEditableTextBuffer buf = doc.GetContent<IEditableTextBuffer> ();
 
657
                                        if (buf != null)
 
658
                                                buf.SetCaretTo (Math.Max (Line, 1), Math.Max (Column, 1));
 
659
                                }
 
660
                                return doc;
 
661
                        }
 
662
                        
610
663
                }
611
664
        }
612
665
}