示例#1
0
 public LoadFileWrapper(IProgressMonitor monitor, MainWindow workbench, IViewDisplayBuilder binding, Project project, FileOpenInfo fileInfo)
 {
     this.monitor   = monitor;
     this.workbench = workbench;
     this.fileInfo  = fileInfo;
     this.builder   = binding;
     this.project   = project;
 }
示例#2
0
        public CocoStudio.Core.Document OpenDocument(FilePath file, Project project, bool bringToFront = true)
        {
            if (string.IsNullOrEmpty(file.FileName))
            {
                return((CocoStudio.Core.Document)null);
            }
            foreach (CocoStudio.Core.Document document in this.Documents)
            {
                IBaseViewContent baseViewContent = (IBaseViewContent)null;
                if (document.Window.ViewContent.CanReuseView((string)file))
                {
                    baseViewContent = (IBaseViewContent)document.Window.ViewContent;
                }
                if (baseViewContent != null)
                {
                    if (project != null && document.Project != project)
                    {
                        document.SetProject(project);
                    }
                    if (bringToFront)
                    {
                        document.Select();
                        document.Window.SelectWindow();
                    }
                    return(document);
                }
            }
            IProgressMonitor statusProgressMonitor = this.ProgressMonitors.GetStatusProgressMonitor();
            FileOpenInfo     openFileInfo          = new FileOpenInfo(file, project, bringToFront);

            this.RealOpenFile(statusProgressMonitor, openFileInfo);
            statusProgressMonitor.Dispose();
            if (openFileInfo.NewContent == null)
            {
                return((CocoStudio.Core.Document)null);
            }
            CocoStudio.Core.Document doc = this.WrapDocument(openFileInfo.NewContent.WorkbenchWindow);
            if (doc != null && openFileInfo.BringToFront)
            {
                doc.RunWhenLoaded((System.Action)(() =>
                {
                    if (doc.Window == null)
                    {
                        return;
                    }
                    doc.Window.SelectWindow();
                }));
            }
            doc.SetProject(project);
            return(doc);
        }
示例#3
0
        private void RealOpenFile(IProgressMonitor monitor, FileOpenInfo openFileInfo)
        {
            FilePath fileName = openFileInfo.FileName;

            if (fileName == (FilePath)((string)null))
            {
                monitor.ReportError("Invalid file name", (Exception)null);
            }
            else if (fileName.IsDirectory)
            {
                monitor.ReportError(string.Format("{0} is a directory", (object)fileName), (Exception)null);
            }
            else if (!File.Exists((string)fileName))
            {
                monitor.ReportError(string.Format("File not found: {0}", (object)fileName), (Exception)null);
            }
            else
            {
                Project             project = openFileInfo.Project;
                IViewDisplayBuilder binding;
                IDisplayBuilder     displayBuilder;
                if (openFileInfo.DisplayBuilder != null)
                {
                    displayBuilder = (IDisplayBuilder)(binding = openFileInfo.DisplayBuilder);
                }
                else
                {
                    displayBuilder = DisplayBuilderService.GetDisplayBuilders(fileName, (string)null, project).FirstOrDefault <IDisplayBuilder>((Func <IDisplayBuilder, bool>)(d => d.CanUseAsDefault));
                    binding        = displayBuilder as IViewDisplayBuilder;
                }
                try
                {
                    if (displayBuilder != null && binding != null)
                    {
                        new LoadFileWrapper(monitor, this.mainWindow, binding, project, openFileInfo).Invoke((string)fileName);
                    }
                }
                catch (Exception ex)
                {
                    monitor.ReportError("Create ViewContent failed.", ex);
                }
            }
        }