예제 #1
0
        protected override void Run(object ob)
        {
            NavigationHistoryItem nav = ob as NavigationHistoryItem;

            if (nav != null)
            {
                NavigationHistoryService.MoveTo(nav);
            }
        }
예제 #2
0
        protected override Task OnInitialize(ServiceProvider serviceProvider)
        {
            serviceProvider.WhenServiceInitialized <IShell> (s => {
                workbench = s;
                workbench.ActiveWorkbenchWindowChanged += OnDocumentChanged;
                workbench.WindowReordered += Workbench_WindowReordered;
                workbench.NotebookClosed  += Workbench_NotebookClosed;
            });

            serviceProvider.WhenServiceInitialized <NavigationHistoryService> (s => navigationHistoryManager = s);


            FileService.FileRemoved += CheckRemovedFile;
            FileService.FileMoved   += CheckRenamedFile;
            FileService.FileRenamed += CheckRenamedFile;
            return(Task.CompletedTask);
        }
예제 #3
0
        protected override void Update(CommandArrayInfo info)
        {
            int currentIndex;
            IList <NavigationHistoryItem> points = NavigationHistoryService.GetNavigationList(15, out currentIndex);

            if (points.Count < 1)
            {
                Document doc = IdeApp.Workbench.ActiveDocument;
                if (doc != null)
                {
                    CommandInfo item = info.Add(doc.Window.Title, null);
                    item.Checked = true;
                }
                return;
            }

            for (int i = points.Count - 1; i >= 0; i--)
            {
                CommandInfo item = info.Add(points[i].DisplayName, points[i]);
                item.Checked = (i == currentIndex);
            }
        }
예제 #4
0
 protected override void Run()
 {
     NavigationHistoryService.OpenLastClosedDocument();
 }
예제 #5
0
        public async Task <Document> OpenDocument(FileOpenInformation info)
        {
            if (string.IsNullOrEmpty(info.FileName))
            {
                return(null);
            }

            if (navigationHistoryManager == null)
            {
                navigationHistoryManager = await ServiceProvider.GetService <NavigationHistoryService> ();
            }

            // Make sure composition manager is ready since ScrollToRequestedCaretLocation will use it
            await Runtime.GetService <CompositionManager> ();

            var metadata       = CreateOpenDocumentTimerMetadata();
            var fileDescriptor = new FileDescriptor(info.FileName, null, info.Owner);

            using (Counters.OpenDocumentTimer.BeginTiming("Opening file " + info.FileName, metadata)) {
                navigationHistoryManager.LogActiveDocument();
                Counters.OpenDocumentTimer.Trace("Look for open document");
                foreach (Document doc in Documents)
                {
                    // Search all ViewContents to see if they can "re-use" this filename.
                    if (!doc.TryReuseDocument(fileDescriptor))
                    {
                        continue;
                    }

                    //if found, try to reuse or close the old view
                    // reuse the view if the binidng didn't change
                    if (info.Options.HasFlag(OpenDocumentOptions.TryToReuseViewer) || doc.DocumentControllerDescription == info.DocumentControllerDescription)
                    {
                        if (info.Owner != null && doc.Owner != info.Owner)
                        {
                            doc.AttachToProject(info.Owner);
                        }

                        ScrollToRequestedCaretLocation(doc, info);

                        if (info.Options.HasFlag(OpenDocumentOptions.BringToFront))
                        {
                            doc.Select();
                            navigationHistoryManager.LogActiveDocument();
                        }
                        return(doc);
                    }
                    else
                    {
                        if (!await doc.Close())
                        {
                            return(doc);
                        }
                        break;
                    }
                }
                Counters.OpenDocumentTimer.Trace("Initializing monitor");
                var progressMonitorManager = await ServiceProvider.GetService <ProgressMonitorManager> ();

                var pm = progressMonitorManager.GetStatusProgressMonitor(
                    GettextCatalog.GetString("Opening {0}", info.Owner is SolutionFolderItem item ?
                                             info.FileName.ToRelative(item.ParentSolution.BaseDirectory) :
                                             info.FileName),
                    Stock.StatusWorking,
                    true
                    );

                var result = await RealOpenFile(pm, info);

                pm.Dispose();

                AddOpenDocumentTimerMetadata(metadata, info, result.Content, result.Success);

                if (result.Content != null)
                {
                    Counters.OpenDocumentTimer.Trace("Wrapping document");
                    Document doc = result.Content;

                    if (doc != null && info.Options.HasFlag(OpenDocumentOptions.BringToFront))
                    {
                        doc.Select();
                    }
                    return(doc);
                }
                return(null);
            }
        }
예제 #6
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);
                }
            }
        }
예제 #7
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;
                    }
                }
            }
        }
예제 #8
0
 static IdeServices()
 {
     Runtime.ServiceProvider.WhenServiceInitialized <TextEditorService> (s => textEditorService = s);
     Runtime.ServiceProvider.WhenServiceInitialized <NavigationHistoryService> (s => navigationHistoryManager = s);
     Runtime.ServiceProvider.WhenServiceInitialized <DisplayBindingService> (s => displayBindingService       = s);
     Runtime.ServiceProvider.WhenServiceInitialized <FontService> (s => fontService                             = s);
     Runtime.ServiceProvider.WhenServiceInitialized <TypeSystemService> (s => typeSystemService                 = s);
     Runtime.ServiceProvider.WhenServiceInitialized <DesktopService> (s => desktopService                       = s);
     Runtime.ServiceProvider.WhenServiceInitialized <DocumentManager> (s => documentManager                     = s);
     Runtime.ServiceProvider.WhenServiceInitialized <RootWorkspace> (s => workspace                             = s);
     Runtime.ServiceProvider.WhenServiceInitialized <ProgressMonitorManager> (s => progressMonitorManager       = s);
     Runtime.ServiceProvider.WhenServiceInitialized <TaskService> (s => taskService                             = s);
     Runtime.ServiceProvider.WhenServiceInitialized <ProjectOperations> (s => projectOperations                 = s);
     Runtime.ServiceProvider.WhenServiceInitialized <HelpOperations> (s => helpOperations                       = s);
     Runtime.ServiceProvider.WhenServiceInitialized <DocumentControllerService> (s => documentControllerService = s);
     Runtime.ServiceProvider.WhenServiceInitialized <DocumentModelRegistry> (s => documentModelRegistry         = s);
 }
예제 #9
0
 protected override void Run()
 {
     NavigationHistoryService.MoveForward();
 }
예제 #10
0
 protected override void Run()
 {
     NavigationHistoryService.MoveBack();
 }
예제 #11
0
 protected override void Run()
 {
     NavigationHistoryService.Clear();
 }