Example #1
0
        void LoadViewContentMemento(IViewContent viewContent)
        {
            IMementoCapable mementoCapable = viewContent as IMementoCapable;

            if (mementoCapable != null && LoadDocumentProperties)
            {
                if (viewContent.PrimaryFileName == null)
                {
                    return;
                }

                try {
                    string key = GetMementoKeyName(viewContent);
                    LoggingService.Debug("Trying to restore memento of '" + viewContent.ToString() + "' from key '" + key + "'");

                    Properties memento = this.LoadOrCreateViewContentMementos().Get <Properties>(key, null);
                    if (memento != null)
                    {
                        mementoCapable.SetMemento(memento);
                    }
                } catch (Exception e) {
                    MessageService.ShowException(e, "Can't get/set memento");
                }
            }
        }
Example #2
0
        static Properties GetMemento(IViewContent viewContent)
        {
            IMementoCapable mementoCapable = viewContent as IMementoCapable;

            if (mementoCapable == null)
            {
                return(null);
            }
            else
            {
                return(mementoCapable.CreateMemento());
            }
        }
Example #3
0
        private static VelerSoftware.SZC.Debugger.Core.Properties GetMemento(IViewContent viewContent)
        {
            IMementoCapable mementoCapable = viewContent as IMementoCapable;

            if (mementoCapable == null)
            {
                return(null);
            }
            else
            {
                return(mementoCapable.CreateMemento());
            }
        }
Example #4
0
        void OnLoadingWorkspaceUserPreferences(object s, UserPreferencesEventArgs args)
        {
            WorkbenchUserPrefs prefs = args.Properties.GetValue <WorkbenchUserPrefs> ("MonoDevelop.Ide.Workbench");

            if (prefs == null)
            {
                return;
            }

            string currentFileName = prefs.ActiveDocument != null?Path.GetFullPath(Path.Combine(args.Item.BaseDirectory, prefs.ActiveDocument)) : null;

            foreach (DocumentUserPrefs doc in prefs.Files)
            {
                FilePath fileName = args.Item.BaseDirectory.Combine(doc.FileName).FullPath;
                if (File.Exists(fileName))
                {
                    OpenDocumentOptions ops = OpenDocumentOptions.OnlyInternalViewer;
                    if (fileName == currentFileName)
                    {
                        ops |= OpenDocumentOptions.BringToFront;
                    }
                    IdeApp.Workbench.OpenDocument(fileName, doc.Line, doc.Column, ops, null, null);
                }
            }

            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;
                    }
                }
            }
        }
Example #5
0
        public void Reload()
        {
            ICustomXmlSerializer memento = null;
            IMementoCapable      mc      = GetContent <IMementoCapable> ();

            if (mc != null)
            {
                memento = mc.Memento;
            }
            window.ViewContent.Load(window.ViewContent.ContentName);
            if (memento != null)
            {
                mc.Memento = memento;
            }
        }
Example #6
0
        void OnStoringWorkspaceUserPreferences(object s, UserPreferencesEventArgs args)
        {
            WorkbenchUserPrefs prefs = new WorkbenchUserPrefs();

            foreach (Document document in Documents)
            {
                if (!String.IsNullOrEmpty(document.FileName))
                {
                    DocumentUserPrefs dp = new DocumentUserPrefs();
                    dp.FileName = FileService.AbsoluteToRelativePath(args.Item.BaseDirectory, document.FileName);
                    if (document.Editor != null)
                    {
                        dp.Line   = document.Editor.Caret.Line;
                        dp.Column = document.Editor.Caret.Column;
                    }
                    prefs.Files.Add(dp);
                }
            }

            foreach (Pad pad in Pads)
            {
                IMementoCapable mc = pad.GetMementoCapable();
                if (mc != null)
                {
                    ICustomXmlSerializer mem = mc.Memento;
                    if (mem != null)
                    {
                        PadUserPrefs data = new PadUserPrefs();
                        data.Id = pad.Id;
                        StringWriter  w  = new StringWriter();
                        XmlTextWriter tw = new XmlTextWriter(w);
                        mem.WriteTo(tw);
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(w.ToString());
                        data.State = doc.DocumentElement;
                        prefs.Pads.Add(data);
                    }
                }
            }

            if (ActiveDocument != null)
            {
                prefs.ActiveDocument = FileService.AbsoluteToRelativePath(args.Item.BaseDirectory, ActiveDocument.FileName);
            }

            args.Properties.SetValue("MonoDevelop.Ide.Workbench", prefs);
        }
Example #7
0
        async Task ReloadTask()
        {
            ICustomXmlSerializer memento = null;
            IMementoCapable      mc      = GetContent <IMementoCapable> ();

            if (mc != null)
            {
                memento = mc.Memento;
            }
            window.ViewContent.DiscardChanges();
            await window.ViewContent.Load(new FileOpenInformation (window.ViewContent.ContentName) { IsReloadOperation = true });

            if (memento != null)
            {
                mc.Memento = memento;
            }
        }
Example #8
0
        /// <summary>
        /// Stores the memento for the view content.
        /// Such mementos are automatically loaded in ShowView().
        /// </summary>
        public void StoreMemento(IViewContent viewContent)
        {
            IMementoCapable mementoCapable = viewContent as IMementoCapable;

            if (mementoCapable != null && LoadDocumentProperties)
            {
                if (viewContent.PrimaryFileName == null)
                {
                    return;
                }

                string key = GetMementoKeyName(viewContent);
                LoggingService.Debug("Saving memento of '" + viewContent.ToString() + "' to key '" + key + "'");

                Properties memento = mementoCapable.CreateMemento();
                Properties p       = this.LoadOrCreateViewContentMementos();
                p.Set(key, memento);
                FileUtility.ObservedSave(new NamedFileOperationDelegate(p.Save), this.ViewContentMementosFileName, FileErrorPolicy.Inform);
            }
        }
Example #9
0
        void OnStoringWorkspaceUserPreferences(object s, UserPreferencesEventArgs args)
        {
            WorkbenchUserPrefs prefs = new WorkbenchUserPrefs();
            var nbId = 0;
            var fwId = 1;

            foreach (var window in DockWindow.GetAllWindows())
            {
                int x, y;
                window.GetPosition(out x, out y);
                var fwp = new FloatingWindowUserPrefs {
                    WindowId = fwId,
                    X        = x,
                    Y        = y,
                    Width    = window.Allocation.Width,
                    Height   = window.Allocation.Height
                };

                foreach (var nb in window.Container.GetNotebooks())
                {
                    AddNotebookDocuments(args, fwp.Files, nb, nbId++);
                }

                if (fwp.Files.Count > 0)
                {
                    prefs.FloatingWindows.Add(fwp);
                    fwId++;
                }
            }

            var mainContainer = workbench.TabControl.Container;

            foreach (var nb in mainContainer.GetNotebooks())
            {
                AddNotebookDocuments(args, prefs.Files, nb, nbId++);
            }

            foreach (Pad pad in Pads)
            {
                IMementoCapable mc = pad.GetMementoCapable();
                if (mc != null)
                {
                    ICustomXmlSerializer mem = mc.Memento;
                    if (mem != null)
                    {
                        PadUserPrefs data = new PadUserPrefs();
                        data.Id = pad.Id;
                        StringWriter  w  = new StringWriter();
                        XmlTextWriter tw = new XmlTextWriter(w);
                        mem.WriteTo(tw);
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(w.ToString());
                        data.State = doc.DocumentElement;
                        prefs.Pads.Add(data);
                    }
                }
            }

            if (ActiveDocument != null)
            {
                prefs.ActiveDocument = FileService.AbsoluteToRelativePath(args.Item.BaseDirectory, ActiveDocument.FileName);
            }

            args.Properties.SetValue("MonoDevelop.Ide.Workbench", prefs);
        }
Example #10
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;
                    }
                }
            }
        }