コード例 #1
0
ファイル: Workbench.cs プロジェクト: Redth/monodevelop-1
        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();
            }
        }