コード例 #1
0
        public Document NewDocument(string defaultName, string mimeType, Stream content)
        {
            IViewDisplayBinding binding = DisplayBindingService.GetDefaultViewBinding(null, mimeType, null);

            if (binding == null)
            {
                throw new ApplicationException("Can't create display binding for mime type: " + mimeType);
            }

            IViewContent newContent = binding.CreateContent(null, mimeType, null);

            using (content) {
                newContent.LoadNew(content, mimeType);
            }

            if (newContent == null)
            {
                throw new ApplicationException(String.Format("Created view content was null{3}DefaultName:{0}{3}MimeType:{1}{3}Content:{2}",
                                                             defaultName, mimeType, content, Environment.NewLine));
            }

            newContent.UntitledName = defaultName;
            newContent.IsDirty      = true;
            workbench.ShowView(newContent, true);
            DisplayBindingService.AttachSubWindows(newContent.WorkbenchWindow);

            return(WrapDocument(newContent.WorkbenchWindow));
        }
コード例 #2
0
        public void Invoke(string fileName)
        {
            try {
                Counters.OpenDocumentTimer.Trace("Creating content");
                string mimeType = DesktopService.GetMimeTypeForUri(fileName);
                if (binding.CanHandle(fileName, mimeType, project))
                {
                    newContent = binding.CreateContent(fileName, mimeType, project);
                }
                else
                {
                    fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not be opened.", fileName), null);
                }
                if (newContent == null)
                {
                    fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not be opened.", fileName), null);
                    return;
                }

                if (project != null)
                {
                    newContent.Project = project;
                }

                Counters.OpenDocumentTimer.Trace("Loading file");

                IEncodedTextContent etc = newContent.GetContent <IEncodedTextContent> ();
                try {
                    if (fileInfo.Encoding != null && etc != null)
                    {
                        etc.Load(fileName, fileInfo.Encoding);
                    }
                    else
                    {
                        newContent.Load(fileName);
                    }
                } catch (InvalidEncodingException iex) {
                    fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not opened. {1}", fileName, iex.Message), null);
                    return;
                } catch (OverflowException oex) {
                    fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not opened. File too large.", fileName), null);
                    return;
                }
            } catch (Exception ex) {
                fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not be opened.", fileName), ex);
                return;
            }
            // content got re-used
            if (newContent.WorkbenchWindow != null)
            {
                newContent.WorkbenchWindow.SelectWindow();
                fileInfo.NewContent = newContent;
                return;
            }

            Counters.OpenDocumentTimer.Trace("Showing view");

            workbench.ShowView(newContent, fileInfo.Options.HasFlag(OpenDocumentOptions.BringToFront));
            DisplayBindingService.AttachSubWindows(newContent.WorkbenchWindow);

            newContent.WorkbenchWindow.DocumentType = binding.Name;

            IEditableTextBuffer ipos = newContent.GetContent <IEditableTextBuffer> ();

            if (fileInfo.Line > 0 && ipos != null)
            {
                if (newContent.Control.IsRealized)
                {
                    JumpToLine();
                }
                else
                {
                    newContent.Control.Realized += HandleNewContentControlRealized;
                }
            }
            fileInfo.NewContent = newContent;
        }
コード例 #3
0
ファイル: Workbench.cs プロジェクト: poke/monodevelop
        public void Invoke(string fileName)
        {
            try {
                Counters.OpenDocumentTimer.Trace("Creating content");
                if (binding.CanCreateContentForUri(fileName))
                {
                    newContent = binding.CreateContentForUri(fileName);
                }
                else
                {
                    string mimeType = DesktopService.GetMimeTypeForUri(fileName);
                    if (!binding.CanCreateContentForMimeType(mimeType))
                    {
                        fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not be opened.", fileName), null);
                        return;
                    }
                    newContent = binding.CreateContentForMimeType(mimeType, null);
                }
                if (newContent == null)
                {
                    fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not be opened.", fileName), null);
                    return;
                }

                if (project != null)
                {
                    newContent.Project = project;
                }

                Counters.OpenDocumentTimer.Trace("Loading file");

                IEncodedTextContent etc = newContent.GetContent <IEncodedTextContent> ();
                if (fileInfo.Encoding != null && etc != null)
                {
                    etc.Load(fileName, fileInfo.Encoding);
                }
                else
                {
                    newContent.Load(fileName);
                }
            } catch (Exception ex) {
                fileInfo.ProgressMonitor.ReportError(GettextCatalog.GetString("The file '{0}' could not be opened.", fileName), ex);
                return;
            }
            // content got re-used
            if (newContent.WorkbenchWindow != null)
            {
                newContent.WorkbenchWindow.SelectWindow();
                fileInfo.NewContent = newContent;
                return;
            }

            Counters.OpenDocumentTimer.Trace("Showing view");

            workbench.ShowView(newContent, fileInfo.BringToFront);
            DisplayBindingService.AttachSubWindows(newContent.WorkbenchWindow);

            newContent.WorkbenchWindow.DocumentType = binding.Name;

            IEditableTextBuffer ipos = newContent.GetContent <IEditableTextBuffer> ();

            if (fileInfo.Line != -1 && ipos != null)
            {
                GLib.Timeout.Add(10, new GLib.TimeoutHandler(JumpToLine));
            }
            fileInfo.NewContent = newContent;
        }