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;
47
using MonoDevelop.Ide.Projects;
48
using MonoDevelop.Core.StringParsing;
49
using MonoDevelop.Ide.Navigation;
48
51
namespace MonoDevelop.Ide.Gui
68
71
monitor.BeginTask (GettextCatalog.GetString ("Initializing Main Window"), 4);
73
Counters.Initialization.Trace ("Creating DefaultWorkbench");
70
74
workbench = new DefaultWorkbench ();
77
Counters.Initialization.Trace ("Initializing Workspace");
73
78
workbench.InitializeWorkspace();
76
workbench.InitializeLayout (new SdiWorkbenchLayout ());
81
Counters.Initialization.Trace ("Initializing Layout");
82
workbench.InitializeLayout ();
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;
102
/// This method handles the redraw all event for specific changed IDE properties
104
void TrackPropertyChanges(object sender, MonoDevelop.Core.PropertyChangedEventArgs e)
106
if (e.OldValue != e.NewValue) {
108
case "MonoDevelop.Core.Gui.VisualStyle":
109
case "CoreProperties.UILanguage":
110
workbench.RedrawAllComponents();
116
106
internal void Show (string workbenchMemento)
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";
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);
123
Counters.Initialization.Trace ("Initializing monitors");
127
124
monitors.Initialize ();
201
198
if (!PropertyService.IsMac)
202
199
RootWindow.Present ();
205
public WorkbenchContext Context {
206
get { return workbench.Context; }
208
if (workbench.Context != value) {
209
workbench.Context = value;
215
202
public bool FullScreen {
216
203
get { return workbench.FullScreen; }
217
204
set { workbench.FullScreen = value; }
220
207
public string CurrentLayout {
221
get { return workbench != null && workbench.WorkbenchLayout != null ? workbench.WorkbenchLayout.CurrentLayout : ""; }
208
get { return workbench.CurrentLayout; }
223
if (value != workbench.WorkbenchLayout.CurrentLayout)
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);
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; }
236
222
public ProgressMonitorManager ProgressMonitors {
237
223
get { return monitors; }
240
public MonoDevelopStatusBar StatusBar {
226
public StatusBar StatusBar {
242
return workbench.StatusBar;
228
return workbench.StatusBar.MainContext;
310
296
return WrapPad (content);
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)
315
301
return AddPad (new PadCodon (padContent, id, label, defaultPlacement, icon));
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)
320
306
return ShowPad (new PadCodon (padContent, id, label, defaultPlacement, icon));
379
365
internal Document OpenDocument (FilePath fileName, int line, int column, bool bringToFront, string encoding, IDisplayBinding binding, bool highlightCaretLine)
381
NavigationHistoryService.LogActiveDocument ();
383
foreach (Document doc in Documents) {
384
IBaseViewContent vcFound = null;
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;
392
//old method as fallback
393
if ((vcFound == null) && (doc.FileName == fileName))
394
vcFound = doc.Window.ViewContent;
396
//if found, select window and jump to line
397
if (vcFound != null) {
400
doc.Window.SwitchView (vcIndex);
367
if (string.IsNullOrEmpty (fileName))
369
using (Counters.OpenDocumentTimer.BeginTiming ("Opening file " + fileName)) {
370
NavigationHistoryService.LogActiveDocument ();
372
Counters.OpenDocumentTimer.Trace ("Look for open document");
374
foreach (Document doc in Documents) {
375
IBaseViewContent vcFound = null;
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;
383
//old method as fallback
384
if ((vcFound == null) && (doc.FileName == fileName))
385
vcFound = doc.Window.ViewContent;
387
//if found, select window and jump to line
388
if (vcFound != null) {
391
doc.Window.SwitchView (vcIndex);
395
IEditableTextBuffer ipos = (IEditableTextBuffer) vcFound.GetContent (typeof(IEditableTextBuffer));
396
if (line >= 1 && ipos != null) {
397
ipos.SetCaretTo (line, column >= 1 ? column : 1, highlightCaretLine);
400
NavigationHistoryService.LogActiveDocument ();
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,
410
BringToFront = bringToFront,
413
DisplayBinding = binding,
415
HighlightCaretLine = highlightCaretLine,
417
RealOpenFile (openFileInfo);
419
if (!pm.AsyncOperation.Success)
422
if (openFileInfo.NewContent != null) {
423
Counters.OpenDocumentTimer.Trace ("Wrapping document");
424
Document doc = WrapDocument (openFileInfo.NewContent.WorkbenchWindow);
404
IEditableTextBuffer ipos = (IEditableTextBuffer) vcFound.GetContent (typeof(IEditableTextBuffer));
405
if (line >= 1 && ipos != null) {
406
ipos.SetCaretTo (line, column >= 1 ? column : 1, highlightCaretLine);
409
NavigationHistoryService.LogActiveDocument ();
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);
426
if (!pm.AsyncOperation.Success)
429
if (openFileInfo.NewContent != null) {
430
Document doc = WrapDocument (openFileInfo.NewContent.WorkbenchWindow);
431
NavigationHistoryService.LogActiveDocument ();
440
434
public Document OpenDocument (IViewContent content, bool bringToFront)
524
516
if (parentWindow == null)
525
517
parentWindow = IdeApp.Workbench.RootWindow;
527
MonoDevelop.Projects.Gui.Dialogs.DefaultPolicyOptionsDialog ops
528
= new MonoDevelop.Projects.Gui.Dialogs.DefaultPolicyOptionsDialog (parentWindow);
519
var ops = new DefaultPolicyOptionsDialog (parentWindow);
531
522
if (panelId != null)
532
523
ops.SelectPanel (panelId);
533
ops.TransientFor = RootWindow;
534
if (ops.Run () == (int) Gtk.ResponseType.Ok) {
525
if (MessageService.RunCustomDialog (ops, parentWindow) == (int) Gtk.ResponseType.Ok) {
535
526
MonoDevelop.Projects.Policies.PolicyService.SaveDefaultPolicies ();
533
public StringTagModelDescription GetStringTagModelDescription ()
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));
543
public StringTagModel GetStringTagModel ()
545
StringTagModel source = new StringTagModel ();
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 ());
542
554
internal void ShowNext ()
544
556
// Shows the next item in a pad that implements ILocationListPad.
546
Pad pad = GetLocationListPad ();
548
pad.BringToFront (true);
549
ILocationListPad loc = (ILocationListPad) pad.Content;
552
if (loc.GetNextLocation (out file, out lin, out col)) {
553
if (!string.IsNullOrEmpty (file))
554
OpenDocument (file, lin, col, true);
558
if (activeLocationList != null) {
559
NavigationPoint next = activeLocationList.GetNextLocation ();
561
567
// Shows the previous item in a pad that implements ILocationListPad.
563
Pad pad = GetLocationListPad ();
565
pad.BringToFront (true);
566
ILocationListPad loc = (ILocationListPad) pad.Content;
569
if (loc.GetPreviousLocation (out file, out lin, out col)) {
570
if (!string.IsNullOrEmpty (file))
571
OpenDocument (file, lin, col, true);
569
if (activeLocationList != null) {
570
NavigationPoint next = activeLocationList.GetPreviousLocation ();
576
internal Pad GetLocationListPad ()
578
// Locates a pad which implements ILocationListPad. If there are more than
579
// one, it returns the last one being focused.
583
foreach (Pad p in IdeApp.Workbench.Pads) {
586
ILocationListPad loc = p.Content as ILocationListPad;
587
if (loc != null && (active == null || p.Window == PadWindow.LastActiveLocationList))
576
ILocationList activeLocationList;
578
public ILocationList ActiveLocationList {
580
return activeLocationList;
583
activeLocationList = value;
596
587
void OnDocumentChanged (object s, EventArgs a)
665
656
void OnWindowClosed (object sender, WorkbenchWindowEventArgs args)
667
658
IWorkbenchWindow window = (IWorkbenchWindow) sender;
659
window.Closing -= OnWindowClosing;
660
window.Closed -= OnWindowClosed;
668
661
documents.Remove (FindDocument (window));
671
void RealOpenFile (object openFileInfo)
664
void RealOpenFile (FileOpenInformation openFileInfo)
673
666
FilePath fileName;
674
FileInformation oFileInfo = openFileInfo as FileInformation;
675
IProgressMonitor monitor = oFileInfo.ProgressMonitor;
667
IProgressMonitor monitor = openFileInfo.ProgressMonitor;
679
string origName = oFileInfo.FileName;
671
Counters.OpenDocumentTimer.Trace ("Checking file");
673
string origName = openFileInfo.FileName;
681
675
if (origName == null) {
682
676
monitor.ReportError (GettextCatalog.GetString ("Invalid file name"), null);
717
711
foreach (Document doc in Documents) {
718
712
if (doc.FileName == fileName) {
719
if (oFileInfo.BringToFront) {
713
if (openFileInfo.BringToFront) {
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);
726
oFileInfo.NewContent = doc.Window.ViewContent;
720
openFileInfo.NewContent = doc.Window.ViewContent;
725
Counters.OpenDocumentTimer.Trace ("Looking for binding");
731
727
IDisplayBinding binding;
733
if (oFileInfo.DisplayBinding != null) {
734
binding = oFileInfo.DisplayBinding;
729
if (openFileInfo.DisplayBinding != null) {
730
binding = openFileInfo.DisplayBinding;
736
binding = DisplayBindingService.GetBinding (fileName, DesktopService.GetMimeTypeForUri (fileName));
732
binding = DisplayBindingService.GetDefaultBinding (fileName, DesktopService.GetMimeTypeForUri (fileName));
739
735
if (binding != null) {
758
754
project = IdeApp.Workspace.GetProjectContainingFile (fileName);
761
LoadFileWrapper fw = new LoadFileWrapper (workbench, binding, project, oFileInfo);
757
LoadFileWrapper fw = new LoadFileWrapper (workbench, binding, project, openFileInfo);
762
758
fw.Invoke (fileName);
760
Counters.OpenDocumentTimer.Trace ("Adding to recent files");
763
761
RecentOpen.AddLastFile (fileName, project != null ? project.Name : null);
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) {
966
class FileInformation
965
public class FileOpenInformation
968
public IProgressMonitor ProgressMonitor;
969
public string FileName;
970
public bool BringToFront;
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; }
977
public FileOpenInformation ()
981
public FileOpenInformation (string fileName, int line, int column, bool bringToFront)
983
this.FileName = fileName;
985
this.Column = column;
986
this.BringToFront = bringToFront;
979
990
class LoadFileWrapper
981
992
IDisplayBinding binding;
983
FileInformation fileInfo;
984
IWorkbench workbench;
994
FileOpenInformation fileInfo;
995
DefaultWorkbench workbench;
985
996
IViewContent newContent;
987
public LoadFileWrapper (IWorkbench workbench, IDisplayBinding binding, FileInformation fileInfo)
998
public LoadFileWrapper (DefaultWorkbench workbench, IDisplayBinding binding, FileOpenInformation fileInfo)
989
1000
this.workbench = workbench;
990
1001
this.fileInfo = fileInfo;
991
1002
this.binding = binding;
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)
996
this.workbench = workbench;
997
this.fileInfo = fileInfo;
998
this.binding = binding;
999
1008
this.project = project;
1002
1011
public void Invoke (string fileName)
1014
Counters.OpenDocumentTimer.Trace ("Creating content");
1005
1015
if (binding.CanCreateContentForUri (fileName)) {
1006
1016
newContent = binding.CreateContentForUri (fileName);