Exemplo n.º 1
0
        internal Document OpenDocument(FilePath fileName, int line, int column, OpenDocumentOptions options, string encoding, IViewDisplayBinding binding)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return(null);
            }
            using (Counters.OpenDocumentTimer.BeginTiming("Opening file " + fileName)) {
                NavigationHistoryService.LogActiveDocument();

                Counters.OpenDocumentTimer.Trace("Look for open document");

                foreach (Document doc in Documents)
                {
                    IBaseViewContent vcFound = null;
                    int vcIndex = 0;

                    //search all ViewContents to see if they can "re-use" this filename
                    if (doc.Window.ViewContent.CanReuseView(fileName))
                    {
                        vcFound = doc.Window.ViewContent;
                    }


                    //old method as fallback
                    if ((vcFound == null) && (doc.FileName == fileName))
                    {
                        vcFound = doc.Window.ViewContent;
                    }

                    //if found, select window and jump to line
                    if (vcFound != null)
                    {
                        IEditableTextBuffer ipos = vcFound.GetContent <IEditableTextBuffer> ();
                        if (line >= 1 && ipos != null)
                        {
                            ipos.SetCaretTo(line, column >= 1 ? column : 1, options.HasFlag(OpenDocumentOptions.HighlightCaretLine));
                        }

                        if (options.HasFlag(OpenDocumentOptions.BringToFront))
                        {
                            doc.Select();
                            doc.Window.SwitchView(vcIndex);
                            doc.Window.SelectWindow();
                            NavigationHistoryService.LogActiveDocument();
                            Present();
                        }
                        return(doc);
                    }
                }

                Counters.OpenDocumentTimer.Trace("Initializing monitor");
                IProgressMonitor pm = ProgressMonitors.GetStatusProgressMonitor(GettextCatalog.GetString("Opening {0}", fileName), Stock.OpenFileIcon, true);
                var openFileInfo    = new FileOpenInformation()
                {
                    ProgressMonitor = pm,
                    FileName        = fileName,
                    Options         = options,
                    Line            = line,
                    Column          = column,
                    DisplayBinding  = binding,
                    Encoding        = encoding
                };
                RealOpenFile(openFileInfo);

                if (!pm.AsyncOperation.Success)
                {
                    return(null);
                }

                if (openFileInfo.NewContent != null)
                {
                    Counters.OpenDocumentTimer.Trace("Wrapping document");
                    Document doc = WrapDocument(openFileInfo.NewContent.WorkbenchWindow);
                    if (options.HasFlag(OpenDocumentOptions.BringToFront))
                    {
                        Present();
                        doc.RunWhenLoaded(() => doc.Window.SelectWindow());
                    }
                    return(doc);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 2
0
        async Task OnLoadingWorkspaceUserPreferences(object s, UserPreferencesEventArgs args)
        {
            WorkbenchUserPrefs prefs = args.Properties.GetValue <WorkbenchUserPrefs> ("MonoDevelop.Ide.Workbench");

            if (prefs == null)
            {
                return;
            }

            try {
                IdeApp.Workbench.LockActiveWindowChangeEvent();
                IdeServices.NavigationHistoryService.LogActiveDocument();

                var      docViews        = new List <Tuple <Document, string> > ();
                FilePath baseDir         = args.Item.BaseDirectory;
                var      floatingWindows = new List <DockWindow> ();

                using (ProgressMonitor pm = ProgressMonitors.GetStatusProgressMonitor(GettextCatalog.GetString("Loading workspace documents"), Stock.StatusSolutionOperation, true)) {
                    var docList = prefs.Files.Distinct(new DocumentUserPrefsFilenameComparer()).OrderBy(d => d.NotebookId).ToList();
                    await OpenDocumentsInContainer(pm, baseDir, docViews, docList, workbench.TabControl.Container);

                    foreach (var fw in prefs.FloatingWindows)
                    {
                        var dockWindow = new DockWindow();
                        dockWindow.Move(fw.X, fw.Y);
                        dockWindow.Resize(fw.Width, fw.Height);
                        docList = fw.Files.Distinct(new DocumentUserPrefsFilenameComparer()).OrderBy(d => d.NotebookId).ToList();
                        await OpenDocumentsInContainer(pm, baseDir, docViews, docList, dockWindow.Container);

                        floatingWindows.Add(dockWindow);
                    }

                    // Note: At this point, the progress monitor will be disposed which causes the gtk main-loop to be pumped.
                    // This is EXTREMELY important, because without this main-loop pumping action, the next foreach() loop will
                    // not cause the Solution tree-view to properly expand, nor will the ActiveDocument be set properly.
                }

                string currentFileName = prefs.ActiveDocument != null?baseDir.Combine(prefs.ActiveDocument).FullPath : null;

                Document activeDoc = null;
                foreach (var t in docViews)
                {
                    if (t.Item2 == currentFileName)
                    {
                        activeDoc = t.Item1;
                    }
                }

                if (activeDoc == null && docViews.Count > 0)
                {
                    activeDoc = docViews [0].Item1;
                }

                foreach (PadUserPrefs pi in prefs.Pads)
                {
                    foreach (Pad pad in IdeApp.Workbench.Pads)
                    {
                        if (pi.Id == pad.Id)
                        {
                            pad.InternalContent.SetPreferences(pi);
                            break;
                        }
                    }
                }

                foreach (var w in floatingWindows)
                {
                    w.ShowAll();
                }

                if (activeDoc != null)
                {
                    activeDoc.RunWhenLoaded(activeDoc.Select);
                }
            } finally {
                IdeApp.Workbench.UnlockActiveWindowChangeEvent();
            }
        }
Exemplo n.º 3
0
        void OnLoadingWorkspaceUserPreferences(object s, UserPreferencesEventArgs args)
        {
            WorkbenchUserPrefs prefs = args.Properties.GetValue <WorkbenchUserPrefs> ("MonoDevelop.Ide.Workbench");

            if (prefs == null)
            {
                return;
            }

            NavigationHistoryService.LogActiveDocument();

            List <IViewContent> docViews    = new List <IViewContent> ();
            FilePath            baseDir     = args.Item.BaseDirectory;
            IViewContent        currentView = null;

            using (IProgressMonitor pm = ProgressMonitors.GetStatusProgressMonitor(GettextCatalog.GetString("Loading workspace documents"), Stock.OpenFileIcon, true)) {
                string currentFileName = prefs.ActiveDocument != null?baseDir.Combine(prefs.ActiveDocument).FullPath : null;

                foreach (DocumentUserPrefs doc in prefs.Files.Distinct(new DocumentUserPrefsFilenameComparer()))
                {
                    string fileName = baseDir.Combine(doc.FileName).FullPath;
                    if (File.Exists(fileName))
                    {
                        var view = IdeApp.Workbench.BatchOpenDocument(pm, fileName, doc.Line, doc.Column);
                        if (fileName == currentFileName)
                        {
                            currentView = view;
                        }

                        if (view != null)
                        {
                            docViews.Add(view);
                        }
                    }
                }

                // Note: At this point, the progress monitor will be disposed which causes the gtk main-loop to be pumped.
                // This is EXTREMELY important, because without this main-loop pumping action, the next foreach() loop will
                // not cause the Solution tree-view to properly expand, nor will the ActiveDocument be set properly.
            }

            foreach (var view in docViews)
            {
                Document doc = WrapDocument(view.WorkbenchWindow);
                if (view == currentView)
                {
                    Present();
                    doc.RunWhenLoaded(() => {
                        var window = doc.Window;
                        if (window != null)
                        {
                            window.SelectWindow();
                        }
                    });
                }
            }

            foreach (PadUserPrefs pi in prefs.Pads)
            {
                foreach (Pad pad in IdeApp.Workbench.Pads)
                {
                    if (pi.Id == pad.Id && pad.Content is IMementoCapable)
                    {
                        try {
                            string          xml         = pi.State.OuterXml;
                            IMementoCapable m           = (IMementoCapable)pad.Content;
                            XmlReader       innerReader = new XmlTextReader(new StringReader(xml));
                            innerReader.MoveToContent();
                            ICustomXmlSerializer cs = (ICustomXmlSerializer)m.Memento;
                            if (cs != null)
                            {
                                m.Memento = cs.ReadFrom(innerReader);
                            }
                        } catch (Exception ex) {
                            LoggingService.LogError("Error loading view memento.", ex);
                        }
                        break;
                    }
                }
            }
        }