Exemplo n.º 1
0
        // When looking for the project to which the file belongs, look first
        // in the active project, then the active solution, and so on
        static Project GetProjectContainingFile(FilePath fileName)
        {
            Project project = null;

            if (IdeApp.ProjectOperations.CurrentSelectedProject != null)
            {
                if (IdeApp.ProjectOperations.CurrentSelectedProject.Files.GetFile(fileName) != null)
                {
                    project = IdeApp.ProjectOperations.CurrentSelectedProject;
                }
            }
            if (project == null && IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem != null)
            {
                project = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.GetProjectContainingFile(fileName);
                if (project == null)
                {
                    WorkspaceItem it = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.ParentWorkspace;
                    while (it != null && project == null)
                    {
                        project = it.GetProjectContainingFile(fileName);
                        it      = it.ParentWorkspace;
                    }
                }
            }
            if (project == null)
            {
                project = IdeApp.Workspace.GetProjectContainingFile(fileName);
            }
            return(project);
        }
Exemplo n.º 2
0
        private static Project GetProjectContainingFile(FilePath fileName)
        {
            Project project = (Project)null;

            if (Services.ProjectOperations.CurrentSelectedProject != null && Services.ProjectOperations.CurrentSelectedProject.FileName == fileName)
            {
                project = Services.ProjectOperations.CurrentSelectedProject;
            }
            if (project == null && Services.ProjectOperations.CurrentSelectedWorkspaceItem != null)
            {
                project = Services.ProjectOperations.CurrentSelectedWorkspaceItem.GetProjectContainingFile(fileName);
                if (project == null)
                {
                    for (WorkspaceItem parentWorkspace = (WorkspaceItem)Services.ProjectOperations.CurrentSelectedWorkspaceItem.ParentWorkspace; parentWorkspace != null && project == null; parentWorkspace = (WorkspaceItem)parentWorkspace.ParentWorkspace)
                    {
                        project = parentWorkspace.GetProjectContainingFile(fileName);
                    }
                }
            }
            return(project);
        }
Exemplo n.º 3
0
        void RealOpenFile(FileOpenInformation openFileInfo)
        {
            FilePath         fileName;
            IProgressMonitor monitor = openFileInfo.ProgressMonitor;

            using (monitor)
            {
                Counters.OpenDocumentTimer.Trace("Checking file");

                string origName = openFileInfo.FileName;

                if (origName == null)
                {
                    monitor.ReportError(GettextCatalog.GetString("Invalid file name"), null);
                    return;
                }

                if (origName.StartsWith("file://"))
                {
                    fileName = new Uri(origName).LocalPath;
                }
                else
                {
                    fileName = origName;
                }

                if (!origName.StartsWith("http://"))
                {
                    fileName = fileName.FullPath;
                }

                //Debug.Assert(FileService.IsValidPath(fileName));
                if (FileService.IsDirectory(fileName))
                {
                    monitor.ReportError(GettextCatalog.GetString("{0} is a directory", fileName), null);
                    return;
                }
                // test, if file fileName exists
                if (!origName.StartsWith("http://"))
                {
                    // test, if an untitled file should be opened
                    if (!System.IO.Path.IsPathRooted(origName))
                    {
                        foreach (Document doc in Documents)
                        {
                            if (doc.Window.ViewContent.IsUntitled && doc.Window.ViewContent.UntitledName == origName)
                            {
                                doc.Select();
                                openFileInfo.NewContent = doc.Window.ViewContent;
                                return;
                            }
                        }
                    }
                    if (!File.Exists(fileName))
                    {
                        monitor.ReportError(GettextCatalog.GetString("File not found: {0}", fileName), null);
                        return;
                    }
                }

                foreach (Document doc in Documents)
                {
                    if (doc.FileName == fileName)
                    {
                        if (openFileInfo.BringToFront)
                        {
                            doc.Select();
                            IEditableTextBuffer ipos = doc.GetContent <IEditableTextBuffer> ();
                            if (openFileInfo.Line != -1 && ipos != null)
                            {
                                ipos.SetCaretTo(openFileInfo.Line, openFileInfo.Column != -1 ? openFileInfo.Column : 0, openFileInfo.HighlightCaretLine);
                            }
                        }
                        openFileInfo.NewContent = doc.Window.ViewContent;
                        return;
                    }
                }

                Counters.OpenDocumentTimer.Trace("Looking for binding");

                IDisplayBinding binding;

                if (openFileInfo.DisplayBinding != null)
                {
                    binding = openFileInfo.DisplayBinding;
                }
                else
                {
                    binding = DisplayBindingService.GetDefaultBinding(fileName, DesktopService.GetMimeTypeForUri(fileName));
                }

                if (binding != null)
                {
                    // When looking for the project to which the file belongs, look first
                    // in the active project, then the active solution, and so on
                    Project project = null;
                    if (IdeApp.ProjectOperations.CurrentSelectedProject != null)
                    {
                        if (IdeApp.ProjectOperations.CurrentSelectedProject.Files.GetFile(fileName) != null)
                        {
                            project = IdeApp.ProjectOperations.CurrentSelectedProject;
                        }
                    }
                    if (project == null && IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem != null)
                    {
                        project = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.GetProjectContainingFile(fileName);
                        if (project == null)
                        {
                            WorkspaceItem it = IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem.ParentWorkspace;
                            while (it != null && project == null)
                            {
                                project = it.GetProjectContainingFile(fileName);
                                it      = it.ParentWorkspace;
                            }
                        }
                    }
                    if (project == null)
                    {
                        project = IdeApp.Workspace.GetProjectContainingFile(fileName);
                    }

                    LoadFileWrapper fw = new LoadFileWrapper(workbench, binding, project, openFileInfo);
                    fw.Invoke(fileName);

                    Counters.OpenDocumentTimer.Trace("Adding to recent files");
                    DesktopService.RecentFiles.AddFile(fileName, project);
                }
                else
                {
                    try {
                        Counters.OpenDocumentTimer.Trace("Showing in browser");
                        DesktopService.OpenFile(fileName);
                    } catch (Exception ex) {
                        LoggingService.LogError("Error opening file: " + fileName, ex);
                        MessageService.ShowError(GettextCatalog.GetString("File '{0}' could not be opened", fileName));
                    }
                }
            }
        }