~ubuntu-branches/ubuntu/natty/monodevelop/natty

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Workbench.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:
38
38
using MonoDevelop.Core.Execution;
39
39
using MonoDevelop.Projects;
40
40
using MonoDevelop.Core;
41
 
using MonoDevelop.Core.Gui;
42
41
using MonoDevelop.Ide.Codons;
43
42
using MonoDevelop.Ide.Gui.Content;
44
43
using MonoDevelop.Ide.Gui.Pads;
45
 
using MonoDevelop.Core.Gui.Dialogs;
 
44
using MonoDevelop.Ide.Gui.Dialogs;
 
45
using MonoDevelop.Ide.Desktop;
46
46
using Mono.Addins;
 
47
using MonoDevelop.Ide.Projects;
 
48
using MonoDevelop.Core.StringParsing;
 
49
using MonoDevelop.Ide.Navigation;
47
50
 
48
51
namespace MonoDevelop.Ide.Gui
49
52
{
67
70
                {
68
71
                        monitor.BeginTask (GettextCatalog.GetString ("Initializing Main Window"), 4);
69
72
                        try {
 
73
                                Counters.Initialization.Trace ("Creating DefaultWorkbench");
70
74
                                workbench = new DefaultWorkbench ();
71
75
                                monitor.Step (1);
72
76
                                
 
77
                                Counters.Initialization.Trace ("Initializing Workspace");
73
78
                                workbench.InitializeWorkspace();
74
79
                                monitor.Step (1);
75
80
                                
76
 
                                workbench.InitializeLayout (new SdiWorkbenchLayout ());
 
81
                                Counters.Initialization.Trace ("Initializing Layout");
 
82
                                workbench.InitializeLayout ();
77
83
                                monitor.Step (1);
78
84
                                
79
85
                                ((Gtk.Window)workbench).Visible = false;
80
86
                                workbench.ActiveWorkbenchWindowChanged += new EventHandler (OnDocumentChanged);
81
 
                                PropertyService.PropertyChanged += new EventHandler<PropertyChangedEventArgs> (TrackPropertyChanges);
82
87
                                FileService.FileRemoved += (EventHandler<FileEventArgs>) DispatchService.GuiDispatch (new EventHandler<FileEventArgs> (IdeApp.Workbench.RecentOpen.InformFileRemoved));
83
88
                                FileService.FileRenamed += (EventHandler<FileCopyEventArgs>) DispatchService.GuiDispatch (new EventHandler<FileCopyEventArgs> (IdeApp.Workbench.RecentOpen.InformFileRenamed));
84
89
                                IdeApp.Workspace.StoringUserPreferences += OnStoringWorkspaceUserPreferences;
98
103
                        }
99
104
                }
100
105
                
101
 
                /// <remarks>
102
 
                /// This method handles the redraw all event for specific changed IDE properties
103
 
                /// </remarks>
104
 
                void TrackPropertyChanges(object sender, MonoDevelop.Core.PropertyChangedEventArgs e)
105
 
                {
106
 
                        if (e.OldValue != e.NewValue) {
107
 
                                switch (e.Key) {
108
 
                                        case "MonoDevelop.Core.Gui.VisualStyle":
109
 
                                        case "CoreProperties.UILanguage":
110
 
                                                workbench.RedrawAllComponents();
111
 
                                                break;
112
 
                                }
113
 
                        }
114
 
                }
115
 
                
116
106
                internal void Show (string workbenchMemento)
117
107
                {
 
108
                        Counters.Initialization.Trace ("Realizing Root Window");
118
109
                        RootWindow.Realize ();
119
 
                        workbench.Memento = PropertyService.Get (workbenchMemento, new Properties ());
 
110
                        Counters.Initialization.Trace ("Loading memento");
 
111
                        var memento = PropertyService.Get (workbenchMemento, new Properties ());
 
112
                        Counters.Initialization.Trace ("Setting memento");
 
113
                        workbench.Memento = memento;
 
114
                        Counters.Initialization.Trace ("Making Visible");
120
115
                        RootWindow.Visible = true;
121
 
                        workbench.Context = WorkbenchContext.Edit;
 
116
                        workbench.CurrentLayout = "Default";
122
117
                        
123
118
                        // now we have an layout set notify it
 
119
                        Counters.Initialization.Trace ("Setting layout");
124
120
                        if (LayoutChanged != null)
125
121
                                LayoutChanged (this, EventArgs.Empty);
126
122
                        
 
123
                        Counters.Initialization.Trace ("Initializing monitors");
127
124
                        monitors.Initialize ();
128
125
                        
129
126
                        Present ();
131
128
                
132
129
                internal bool Close ()
133
130
                {
134
 
                        return ((DefaultWorkbench)workbench).Close();
 
131
                        return workbench.Close();
135
132
                }
136
133
                
137
134
                public RecentOpen RecentOpen {
148
145
 
149
146
                public Document ActiveDocument {
150
147
                        get {
151
 
                                if (workbench == null || workbench.ActiveWorkbenchWindow == null)
 
148
                                if (workbench.ActiveWorkbenchWindow == null)
152
149
                                        return null;
153
150
                                return WrapDocument (workbench.ActiveWorkbenchWindow); 
154
151
                        }
167
164
                        get {
168
165
                                if (pads == null) {
169
166
                                        pads = new List<Pad> ();
170
 
                                        foreach (PadCodon pc in workbench.ActivePadContentCollection)
 
167
                                        foreach (PadCodon pc in workbench.PadContentCollection)
171
168
                                                WrapPad (pc);
172
169
                                }
173
170
                                return pads;
175
172
                }
176
173
                
177
174
                
178
 
                public Gtk.Window RootWindow {
179
 
                        get { return (Gtk.Window) workbench; }
 
175
                public WorkbenchWindow RootWindow {
 
176
                        get { return workbench; }
180
177
                }
181
178
                
182
179
                /// <summary>
201
198
                        if (!PropertyService.IsMac)
202
199
                                RootWindow.Present ();
203
200
                }
204
 
                
205
 
                public WorkbenchContext Context {
206
 
                        get { return workbench.Context; }
207
 
                        set {
208
 
                                if (workbench.Context != value) {
209
 
                                        workbench.Context = value;
210
 
                                        pads = null;
211
 
                                }
212
 
                        }
213
 
                }
214
 
                
 
201
                                
215
202
                public bool FullScreen {
216
203
                        get { return workbench.FullScreen; }
217
204
                        set { workbench.FullScreen = value; }
218
205
                }
219
206
                
220
207
                public string CurrentLayout {
221
 
                        get { return workbench != null && workbench.WorkbenchLayout != null ? workbench.WorkbenchLayout.CurrentLayout : ""; }
 
208
                        get { return workbench.CurrentLayout; }
222
209
                        set {
223
 
                                if (value != workbench.WorkbenchLayout.CurrentLayout)
224
 
                                {
225
 
                                        workbench.WorkbenchLayout.CurrentLayout = value;
 
210
                                if (value != workbench.CurrentLayout) {
 
211
                                        workbench.CurrentLayout = value;
226
212
                                        if (LayoutChanged != null)
227
213
                                                LayoutChanged (this, EventArgs.Empty);
228
214
                                }
229
215
                        }
230
216
                }
231
217
 
232
 
                public string[] Layouts {
233
 
                        get { return workbench.WorkbenchLayout != null ? workbench.WorkbenchLayout.Layouts : new string[0]; }
 
218
                public IList<string> Layouts {
 
219
                        get { return workbench.Layouts; }
234
220
                }
235
221
                
236
222
                public ProgressMonitorManager ProgressMonitors {
237
223
                        get { return monitors; }
238
224
                }
239
225
                
240
 
                public MonoDevelopStatusBar StatusBar {
 
226
                public StatusBar StatusBar {
241
227
                        get {
242
 
                                return workbench.StatusBar;
 
228
                                return workbench.StatusBar.MainContext;
243
229
                        }
244
230
                }
245
231
                
253
239
                
254
240
                public void DeleteLayout (string name)
255
241
                {
256
 
                        workbench.WorkbenchLayout.DeleteLayout (name);
 
242
                        workbench.DeleteLayout (name);
257
243
                        if (LayoutChanged != null)
258
244
                                LayoutChanged (this, EventArgs.Empty);
259
245
                }
310
296
                        return WrapPad (content);
311
297
                }
312
298
 
313
 
                public Pad AddPad (IPadContent padContent, string id, string label, string defaultPlacement, string icon)
 
299
                public Pad AddPad (IPadContent padContent, string id, string label, string defaultPlacement, IconId icon)
314
300
                {
315
301
                        return AddPad (new PadCodon (padContent, id, label, defaultPlacement, icon));
316
302
                }
317
303
                
318
 
                public Pad ShowPad (IPadContent padContent, string id, string label, string defaultPlacement, string icon)
 
304
                public Pad ShowPad (IPadContent padContent, string id, string label, string defaultPlacement, IconId icon)
319
305
                {
320
306
                        return ShowPad (new PadCodon (padContent, id, label, defaultPlacement, icon));
321
307
                }
378
364
                
379
365
                internal Document OpenDocument (FilePath fileName, int line, int column, bool bringToFront, string encoding, IDisplayBinding binding, bool highlightCaretLine)
380
366
                {
381
 
                        NavigationHistoryService.LogActiveDocument ();
382
 
                        
383
 
                        foreach (Document doc in Documents) {
384
 
                                IBaseViewContent vcFound = null;
385
 
                                int vcIndex = 0;
386
 
                                
387
 
                                //search all ViewContents to see if they can "re-use" this filename
388
 
                                if (doc.Window.ViewContent.CanReuseView (fileName))
389
 
                                        vcFound = doc.Window.ViewContent;
390
 
                                
391
 
                                
392
 
                                //old method as fallback
393
 
                                if ((vcFound == null) && (doc.FileName == fileName))
394
 
                                        vcFound = doc.Window.ViewContent;
395
 
                                
396
 
                                //if found, select window and jump to line
397
 
                                if (vcFound != null) {
398
 
                                        if (bringToFront) {
399
 
                                                doc.Select ();
400
 
                                                doc.Window.SwitchView (vcIndex);
 
367
                        if (string.IsNullOrEmpty (fileName))
 
368
                                return null;
 
369
                        using (Counters.OpenDocumentTimer.BeginTiming ("Opening file " + fileName)) {
 
370
                                NavigationHistoryService.LogActiveDocument ();
 
371
                                
 
372
                                Counters.OpenDocumentTimer.Trace ("Look for open document");
 
373
                                
 
374
                                foreach (Document doc in Documents) {
 
375
                                        IBaseViewContent vcFound = null;
 
376
                                        int vcIndex = 0;
 
377
                                        
 
378
                                        //search all ViewContents to see if they can "re-use" this filename
 
379
                                        if (doc.Window.ViewContent.CanReuseView (fileName))
 
380
                                                vcFound = doc.Window.ViewContent;
 
381
                                        
 
382
                                        
 
383
                                        //old method as fallback
 
384
                                        if ((vcFound == null) && (doc.FileName == fileName))
 
385
                                                vcFound = doc.Window.ViewContent;
 
386
                                        
 
387
                                        //if found, select window and jump to line
 
388
                                        if (vcFound != null) {
 
389
                                                if (bringToFront) {
 
390
                                                        doc.Select ();
 
391
                                                        doc.Window.SwitchView (vcIndex);
 
392
                                                        Present ();
 
393
                                                }
 
394
                                                
 
395
                                                IEditableTextBuffer ipos = (IEditableTextBuffer) vcFound.GetContent (typeof(IEditableTextBuffer));
 
396
                                                if (line >= 1 && ipos != null) {
 
397
                                                        ipos.SetCaretTo (line, column >= 1 ? column : 1, highlightCaretLine);
 
398
                                                }
 
399
                                                
 
400
                                                NavigationHistoryService.LogActiveDocument ();
 
401
                                                return doc;
 
402
                                        }
 
403
                                }
 
404
                                
 
405
                                Counters.OpenDocumentTimer.Trace ("Initializing monitor");
 
406
                                IProgressMonitor pm = ProgressMonitors.GetStatusProgressMonitor (GettextCatalog.GetString ("Opening {0}", fileName), Stock.OpenFileIcon, true);
 
407
                                var openFileInfo = new FileOpenInformation () {
 
408
                                        ProgressMonitor = pm,
 
409
                                        FileName = fileName,
 
410
                                        BringToFront = bringToFront,
 
411
                                        Line = line,
 
412
                                        Column = column,
 
413
                                        DisplayBinding = binding,
 
414
                                        Encoding = encoding,
 
415
                                        HighlightCaretLine = highlightCaretLine,
 
416
                                };
 
417
                                RealOpenFile (openFileInfo);
 
418
                                
 
419
                                if (!pm.AsyncOperation.Success)
 
420
                                        return null;
 
421
                                
 
422
                                if (openFileInfo.NewContent != null) {
 
423
                                        Counters.OpenDocumentTimer.Trace ("Wrapping document");
 
424
                                        Document doc = WrapDocument (openFileInfo.NewContent.WorkbenchWindow);
 
425
                                        if (bringToFront)
401
426
                                                Present ();
402
 
                                        }
403
 
                                        
404
 
                                        IEditableTextBuffer ipos = (IEditableTextBuffer) vcFound.GetContent (typeof(IEditableTextBuffer));
405
 
                                        if (line >= 1 && ipos != null) {
406
 
                                                ipos.SetCaretTo (line, column >= 1 ? column : 1, highlightCaretLine);
407
 
                                        }
408
 
                                        
409
 
                                        NavigationHistoryService.LogActiveDocument ();
410
427
                                        return doc;
 
428
                                } else {
 
429
                                        return null;
411
430
                                }
412
431
                        }
413
 
                        
414
 
                        IProgressMonitor pm = ProgressMonitors.GetStatusProgressMonitor (GettextCatalog.GetString ("Opening {0}", fileName), Stock.OpenFileIcon, true);
415
 
                        FileInformation openFileInfo = new FileInformation();
416
 
                        openFileInfo.ProgressMonitor = pm;
417
 
                        openFileInfo.FileName = fileName;
418
 
                        openFileInfo.BringToFront = bringToFront;
419
 
                        openFileInfo.Line = line;
420
 
                        openFileInfo.Column = column;
421
 
                        openFileInfo.DisplayBinding = binding;
422
 
                        openFileInfo.Encoding = encoding;
423
 
                        openFileInfo.HighlightCaretLine = highlightCaretLine;
424
 
                        RealOpenFile (openFileInfo);
425
 
                        
426
 
                        if (!pm.AsyncOperation.Success)
427
 
                                return null;
428
 
                        
429
 
                        if (openFileInfo.NewContent != null) {
430
 
                                Document doc = WrapDocument (openFileInfo.NewContent.WorkbenchWindow);
431
 
                                NavigationHistoryService.LogActiveDocument ();
432
 
                                if (bringToFront)
433
 
                                        Present ();
434
 
                                return doc;
435
 
                        } else {
436
 
                                return null;
437
 
                        }
438
432
                }
439
433
                
440
434
                public Document OpenDocument (IViewContent content, bool bringToFront)
447
441
                
448
442
                public void ToggleMaximize ()
449
443
                {
450
 
                        SdiWorkbenchLayout sdiLayout = this.workbench.WorkbenchLayout as SdiWorkbenchLayout;
451
 
                        if (sdiLayout != null)
452
 
                                sdiLayout.ToggleFullViewMode ();
 
444
                        workbench.ToggleFullViewMode ();
453
445
                }
454
446
 
455
447
                public Document NewDocument (string defaultName, string mimeType, string content)
463
455
                
464
456
                public Document NewDocument (string defaultName, string mimeType, Stream content)
465
457
                {
466
 
                        IDisplayBinding binding = DisplayBindingService.GetBinding (null, mimeType);
 
458
                        IDisplayBinding binding = DisplayBindingService.GetDefaultBinding (null, mimeType);
467
459
                        IViewContent newContent;
468
460
                        
469
461
                        if (binding != null) {
505
497
                        try {
506
498
                                if (panelId != null)
507
499
                                        ops.SelectPanel (panelId);
508
 
                                ops.TransientFor = RootWindow;
509
 
                                if (ops.Run () == (int) Gtk.ResponseType.Ok) {
 
500
                                
 
501
                                if (MessageService.RunCustomDialog (ops, parentWindow) == (int) Gtk.ResponseType.Ok) {
510
502
                                        PropertyService.SaveProperties ();
511
503
                                }
512
504
                        } finally {
524
516
                        if (parentWindow == null)
525
517
                                parentWindow = IdeApp.Workbench.RootWindow;
526
518
 
527
 
                        MonoDevelop.Projects.Gui.Dialogs.DefaultPolicyOptionsDialog ops
528
 
                                = new MonoDevelop.Projects.Gui.Dialogs.DefaultPolicyOptionsDialog (parentWindow);
 
519
                        var ops = new DefaultPolicyOptionsDialog (parentWindow);
529
520
 
530
521
                        try {
531
522
                                if (panelId != null)
532
523
                                        ops.SelectPanel (panelId);
533
 
                                ops.TransientFor = RootWindow;
534
 
                                if (ops.Run () == (int) Gtk.ResponseType.Ok) {
 
524
                                
 
525
                                if (MessageService.RunCustomDialog (ops, parentWindow) == (int) Gtk.ResponseType.Ok) {
535
526
                                        MonoDevelop.Projects.Policies.PolicyService.SaveDefaultPolicies ();
536
527
                                }
537
528
                        } finally {
539
530
                        }
540
531
                }
541
532
                
 
533
                public StringTagModelDescription GetStringTagModelDescription ()
 
534
                {
 
535
                        StringTagModelDescription model = new StringTagModelDescription ();
 
536
                        model.Add (typeof (Project));
 
537
                        model.Add (typeof (Solution));
 
538
                        model.Add (typeof (DotNetProjectConfiguration));
 
539
                        model.Add (typeof (Workbench));
 
540
                        return model;
 
541
                }
 
542
                
 
543
                public StringTagModel GetStringTagModel ()
 
544
                {
 
545
                        StringTagModel source = new StringTagModel ();
 
546
                        source.Add (this);
 
547
                        if (IdeApp.ProjectOperations.CurrentSelectedSolutionItem != null)
 
548
                                source.Add (IdeApp.ProjectOperations.CurrentSelectedSolutionItem.GetStringTagModel (IdeApp.Workspace.ActiveConfiguration));
 
549
                        else if (IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem != null)
 
550
                                source.Add (IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.GetStringTagModel ());
 
551
                        return source;
 
552
                }
 
553
                
542
554
                internal void ShowNext ()
543
555
                {
544
556
                        // Shows the next item in a pad that implements ILocationListPad.
545
557
                        
546
 
                        Pad pad = GetLocationListPad ();
547
 
                        if (pad != null) {
548
 
                                pad.BringToFront (true);
549
 
                                ILocationListPad loc = (ILocationListPad) pad.Content;
550
 
                                string file;
551
 
                                int lin, col;
552
 
                                if (loc.GetNextLocation (out file, out lin, out col)) {
553
 
                                        if (!string.IsNullOrEmpty (file))
554
 
                                                OpenDocument (file, lin, col, true);
555
 
                                }
 
558
                        if (activeLocationList != null) {
 
559
                                NavigationPoint next = activeLocationList.GetNextLocation ();
 
560
                                if (next != null)
 
561
                                        next.Show ();
556
562
                        }
557
563
                }
558
564
                
560
566
                {
561
567
                        // Shows the previous item in a pad that implements ILocationListPad.
562
568
                        
563
 
                        Pad pad = GetLocationListPad ();
564
 
                        if (pad != null) {
565
 
                                pad.BringToFront (true);
566
 
                                ILocationListPad loc = (ILocationListPad) pad.Content;
567
 
                                string file;
568
 
                                int lin, col;
569
 
                                if (loc.GetPreviousLocation (out file, out lin, out col)) {
570
 
                                        if (!string.IsNullOrEmpty (file))
571
 
                                                OpenDocument (file, lin, col, true);
572
 
                                }
 
569
                        if (activeLocationList != null) {
 
570
                                NavigationPoint next = activeLocationList.GetPreviousLocation ();
 
571
                                if (next != null)
 
572
                                        next.Show ();
573
573
                        }
574
574
                }
575
575
                
576
 
                internal Pad GetLocationListPad ()
577
 
                {
578
 
                        // Locates a pad which implements ILocationListPad. If there are more than
579
 
                        // one, it returns the last one being focused.
580
 
                        
581
 
                        Pad active = null;
582
 
                        
583
 
                        foreach (Pad p in IdeApp.Workbench.Pads) {
584
 
                                if (!p.Visible)
585
 
                                        continue;
586
 
                                ILocationListPad loc = p.Content as ILocationListPad;
587
 
                                if (loc != null && (active == null || p.Window == PadWindow.LastActiveLocationList))
588
 
                                        active = p;
589
 
                        }
590
 
                        if (active == null)
591
 
                                return null;
592
 
                        
593
 
                        return active;
 
576
                ILocationList activeLocationList;
 
577
                
 
578
                public ILocationList ActiveLocationList {
 
579
                        get {
 
580
                                return activeLocationList;
 
581
                        }
 
582
                        set {
 
583
                                activeLocationList = value;
 
584
                        }
594
585
                }
595
586
                
596
587
                void OnDocumentChanged (object s, EventArgs a)
607
598
                        Document doc = FindDocument (window);
608
599
                        if (doc != null) return doc;
609
600
                        doc = new Document (window);
610
 
                        window.Closing += new WorkbenchWindowEventHandler (OnWindowClosing);
 
601
                        window.Closing += OnWindowClosing;
611
602
                        window.Closed += OnWindowClosed;
612
603
                        documents.Add (doc);
613
604
                        
665
656
                void OnWindowClosed (object sender, WorkbenchWindowEventArgs args)
666
657
                {
667
658
                        IWorkbenchWindow window = (IWorkbenchWindow) sender;
 
659
                        window.Closing -= OnWindowClosing;
 
660
                        window.Closed -= OnWindowClosed;
668
661
                        documents.Remove (FindDocument (window)); 
669
662
                }
670
663
                
671
 
                void RealOpenFile (object openFileInfo)
 
664
                void RealOpenFile (FileOpenInformation openFileInfo)
672
665
                {
673
666
                        FilePath fileName;
674
 
                        FileInformation oFileInfo = openFileInfo as FileInformation;
675
 
                        IProgressMonitor monitor = oFileInfo.ProgressMonitor;
 
667
                        IProgressMonitor monitor = openFileInfo.ProgressMonitor;
676
668
 
677
669
                        using (monitor)
678
670
                        {
679
 
                                string origName = oFileInfo.FileName;
 
671
                                Counters.OpenDocumentTimer.Trace ("Checking file");
 
672
                                
 
673
                                string origName = openFileInfo.FileName;
680
674
 
681
675
                                if (origName == null) {
682
676
                                        monitor.ReportError (GettextCatalog.GetString ("Invalid file name"), null);
703
697
                                                foreach (Document doc in Documents) {
704
698
                                                        if (doc.Window.ViewContent.IsUntitled && doc.Window.ViewContent.UntitledName == origName) {
705
699
                                                                doc.Select ();
706
 
                                                                oFileInfo.NewContent = doc.Window.ViewContent;
 
700
                                                                openFileInfo.NewContent = doc.Window.ViewContent;
707
701
                                                                return;
708
702
                                                        }
709
703
                                                }
716
710
                                
717
711
                                foreach (Document doc in Documents) {
718
712
                                        if (doc.FileName == fileName) {
719
 
                                                if (oFileInfo.BringToFront) {
 
713
                                                if (openFileInfo.BringToFront) {
720
714
                                                        doc.Select ();
721
715
                                                        IEditableTextBuffer ipos = doc.GetContent <IEditableTextBuffer> ();
722
 
                                                        if (oFileInfo.Line != -1 && ipos != null) {
723
 
                                                                ipos.SetCaretTo (oFileInfo.Line, oFileInfo.Column != -1 ? oFileInfo.Column : 0, oFileInfo.HighlightCaretLine);
 
716
                                                        if (openFileInfo.Line != -1 && ipos != null) {
 
717
                                                                ipos.SetCaretTo (openFileInfo.Line, openFileInfo.Column != -1 ? openFileInfo.Column : 0, openFileInfo.HighlightCaretLine);
724
718
                                                        }
725
719
                                                }
726
 
                                                oFileInfo.NewContent = doc.Window.ViewContent;
 
720
                                                openFileInfo.NewContent = doc.Window.ViewContent;
727
721
                                                return;
728
722
                                        }
729
723
                                }
730
724
                                
 
725
                                Counters.OpenDocumentTimer.Trace ("Looking for binding");
 
726
                                
731
727
                                IDisplayBinding binding;
732
728
                                
733
 
                                if (oFileInfo.DisplayBinding != null) {
734
 
                                        binding = oFileInfo.DisplayBinding;
 
729
                                if (openFileInfo.DisplayBinding != null) {
 
730
                                        binding = openFileInfo.DisplayBinding;
735
731
                                } else {
736
 
                                        binding = DisplayBindingService.GetBinding (fileName, DesktopService.GetMimeTypeForUri (fileName));
 
732
                                        binding = DisplayBindingService.GetDefaultBinding (fileName, DesktopService.GetMimeTypeForUri (fileName));
737
733
                                }
738
734
                                
739
735
                                if (binding != null) {
758
754
                                                project = IdeApp.Workspace.GetProjectContainingFile (fileName);
759
755
                                        }
760
756
                                        
761
 
                                        LoadFileWrapper fw = new LoadFileWrapper (workbench, binding, project, oFileInfo);
 
757
                                        LoadFileWrapper fw = new LoadFileWrapper (workbench, binding, project, openFileInfo);
762
758
                                        fw.Invoke (fileName);
 
759
                                        
 
760
                                        Counters.OpenDocumentTimer.Trace ("Adding to recent files");
763
761
                                        RecentOpen.AddLastFile (fileName, project != null ? project.Name : null);
764
762
                                } else {
765
763
                                        try {
 
764
                                                Counters.OpenDocumentTimer.Trace ("Showing in browser");
766
765
                                                // FIXME: this doesn't seem finished yet in Gtk#
767
766
                                                //MimeType mimetype = new MimeType (new Uri ("file://" + fileName));
768
767
                                                //if (mimetype != null) {
870
869
                
871
870
                internal void ReorderDocuments (int oldPlacement, int newPlacement)
872
871
                {
873
 
                        IViewContent content = workbench.ViewContentCollection[oldPlacement];
 
872
                        IViewContent content = workbench.InternalViewContentCollection[oldPlacement];
874
873
                        workbench.InternalViewContentCollection.RemoveAt (oldPlacement);
875
874
                        workbench.InternalViewContentCollection.Insert (newPlacement, content);
876
875
                        
963
962
        }
964
963
        
965
964
 
966
 
        class FileInformation
 
965
        public class FileOpenInformation
967
966
        {
968
 
                public IProgressMonitor ProgressMonitor;
969
 
                public string FileName;
970
 
                public bool BringToFront;
971
 
                public int Line;
972
 
                public int Column;
973
 
                public IDisplayBinding DisplayBinding;
974
 
                public IViewContent NewContent;
975
 
                public string Encoding;
976
 
                public bool HighlightCaretLine;
 
967
                public IProgressMonitor ProgressMonitor { get; set; }
 
968
                public string FileName { get; set; }
 
969
                public bool BringToFront { get; set; }
 
970
                public int Line { get; set; }
 
971
                public int Column { get; set; }
 
972
                public IDisplayBinding DisplayBinding { get; set; }
 
973
                public IViewContent NewContent { get; set; }
 
974
                public string Encoding { get; set; }
 
975
                public bool HighlightCaretLine { get; set; }
 
976
                
 
977
                public FileOpenInformation ()
 
978
                {
 
979
                }
 
980
                
 
981
                public FileOpenInformation (string fileName, int line, int column, bool bringToFront) 
 
982
                {
 
983
                        this.FileName = fileName;
 
984
                        this.Line = line;
 
985
                        this.Column = column;
 
986
                        this.BringToFront = bringToFront;
 
987
                }
977
988
        }
978
989
        
979
990
        class LoadFileWrapper
980
991
        {
981
992
                IDisplayBinding binding;
982
993
                Project project;
983
 
                FileInformation fileInfo;
984
 
                IWorkbench workbench;
 
994
                FileOpenInformation fileInfo;
 
995
                DefaultWorkbench workbench;
985
996
                IViewContent newContent;
986
997
                
987
 
                public LoadFileWrapper (IWorkbench workbench, IDisplayBinding binding, FileInformation fileInfo)
 
998
                public LoadFileWrapper (DefaultWorkbench workbench, IDisplayBinding binding, FileOpenInformation fileInfo)
988
999
                {
989
1000
                        this.workbench = workbench;
990
1001
                        this.fileInfo = fileInfo;
991
1002
                        this.binding = binding;
992
1003
                }
993
1004
                
994
 
                public LoadFileWrapper (IWorkbench workbench, IDisplayBinding binding, Project project, FileInformation fileInfo)
 
1005
                public LoadFileWrapper (DefaultWorkbench workbench, IDisplayBinding binding, Project project, FileOpenInformation fileInfo)
 
1006
                        : this (workbench, binding, fileInfo)
995
1007
                {
996
 
                        this.workbench = workbench;
997
 
                        this.fileInfo = fileInfo;
998
 
                        this.binding = binding;
999
1008
                        this.project = project;
1000
1009
                }
1001
1010
                
1002
1011
                public void Invoke (string fileName)
1003
1012
                {
1004
1013
                        try {
 
1014
                                Counters.OpenDocumentTimer.Trace ("Creating content");
1005
1015
                                if (binding.CanCreateContentForUri (fileName)) {
1006
1016
                                        newContent = binding.CreateContentForUri (fileName);
1007
1017
                                } else {
1020
1030
                                if (project != null)
1021
1031
                                        newContent.Project = project;
1022
1032
                                
 
1033
                                Counters.OpenDocumentTimer.Trace ("Loading file");
 
1034
                                
1023
1035
                                IEncodedTextContent etc = (IEncodedTextContent) newContent.GetContent (typeof(IEncodedTextContent));
1024
1036
                                if (fileInfo.Encoding != null && etc != null)
1025
1037
                                        etc.Load (fileName, fileInfo.Encoding);
1036
1048
                                return;
1037
1049
                        }
1038
1050
                        
 
1051
                        Counters.OpenDocumentTimer.Trace ("Showing view");
 
1052
                        
1039
1053
                        workbench.ShowView (newContent, fileInfo.BringToFront);
1040
1054
                        DisplayBindingService.AttachSubWindows (newContent.WorkbenchWindow);
1041
1055