示例#1
0
        async Task <Document> ShowView(DocumentOpenInformation documentOpenInfo)
        {
            if (IdeApp.Workbench != null)
            {
                IdeApp.Workbench.EnsureShown();
            }

            await InitDesktopService();

            var commandHandler = new ViewCommandHandlers();

            // If the controller has not been initialized, do it now
            if (!documentOpenInfo.DocumentController.Initialized)
            {
                await documentOpenInfo.DocumentController.Initialize(null, null);
            }

            // Make sure the shell is now initialized
            await ServiceProvider.GetService <IShell> ();

            var window = await workbench.ShowView(documentOpenInfo.DocumentController, documentOpenInfo.DockNotebook, commandHandler);

            var doc = new Document(this, workbench, documentOpenInfo.DocumentController, documentOpenInfo.DocumentControllerDescription, window);

            // Don't wait for the view to be initialized. The document can be made visible and can be functional before getting the view.
            doc.InitializeViewAsync().Ignore();

            doc.Closing += OnWindowClosing;
            doc.Closed  += OnWindowClosed;
            doc.Window.NotebookChanged += Window_NotebookChanged;
            documents = documents.Add(doc);
            WatchDocument(doc);

            OnDocumentOpened(new DocumentEventArgs(doc));

            if (documentOpenInfo.Options.HasFlag(OpenDocumentOptions.BringToFront) || documents.Count == 1)
            {
                doc.Select();
            }

            // Ensure the active document is up to date
            OnDocumentChanged(null, null);

            commandHandler.Initialize(doc);

            CountFileOpened(documentOpenInfo.DocumentController);

            return(doc);
        }
示例#2
0
        public async Task <Document> OpenDocument(DocumentController controller, bool bringToFront = true)
        {
            controller.ServiceProvider = ServiceProvider;

            var docOpenInfo = new DocumentOpenInformation {
                DocumentController = controller
            };

            if (!bringToFront)
            {
                docOpenInfo.Options &= ~OpenDocumentOptions.BringToFront;
            }

            var doc = await ShowView(docOpenInfo);

            if (bringToFront)
            {
                workbench.Present();
            }
            return(doc);
        }