Example #1
0
        internal static void AttachSubWindows(IWorkbenchWindow workbenchWindow, IViewDisplayBinding binding)
        {
            int index = 0;

            foreach (var o in GetBindings <object> ())
            {
                if (o == binding)
                {
                    index++;
                    continue;
                }

                var attachable = o as IAttachableDisplayBinding;
                if (attachable == null)
                {
                    continue;
                }

                if (attachable.CanAttachTo(workbenchWindow.ViewContent))
                {
                    var subViewContent = attachable.CreateViewContent(workbenchWindow.ViewContent);
                    workbenchWindow.InsertViewContent(index++, subViewContent);
                    subViewContent.WorkbenchWindow = workbenchWindow;
                }
            }
        }
Example #2
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));
        }
Example #3
0
 public LoadFileWrapper(IProgressMonitor monitor, DefaultWorkbench workbench, IViewDisplayBinding binding, FileOpenInformation fileInfo)
 {
     this.monitor   = monitor;
     this.workbench = workbench;
     this.fileInfo  = fileInfo;
     this.binding   = binding;
 }
Example #4
0
		internal FileViewer (IViewDisplayBinding binding)
		{
			this.binding = binding;
		}
Example #5
0
 internal FileViewer(IViewDisplayBinding binding)
 {
     this.binding = binding;
 }
Example #6
0
		public virtual void ShowView (ViewContent content, bool bringToFront, IViewDisplayBinding binding = null, DockNotebook notebook = null)
		{
			bool isFile = content.IsFile;
			if (!isFile) {
				try {
					isFile = File.Exists (content.ContentName);
				} catch { /*Ignore*/ }
			}

			string type;
			if (isFile) {
				type = System.IO.Path.GetExtension (content.ContentName);
				var mt = DesktopService.GetMimeTypeForUri (content.ContentName);
				if (!string.IsNullOrEmpty (mt))
					type += " (" + mt + ")";
			} else
				type = "(not a file)";

			var metadata = new Dictionary<string,string> () {
				{ "FileType", type },
				{ "DisplayBinding", content.GetType ().FullName },
			};

			if (isFile)
				metadata ["DisplayBindingAndType"] = type + " | " + content.GetType ().FullName;

			Counters.DocumentOpened.Inc (metadata);

			var mimeimage = PrepareShowView (content);
			var addToControl = notebook ?? DockNotebook.ActiveNotebook ?? tabControl;
			var tab = addToControl.AddTab ();

			SdiWorkspaceWindow sdiWorkspaceWindow = new SdiWorkspaceWindow (this, content, addToControl, tab);
			sdiWorkspaceWindow.TitleChanged += delegate { SetWorkbenchTitle (); };
			sdiWorkspaceWindow.Closed += CloseWindowEvent;
			sdiWorkspaceWindow.Show ();
			if (binding != null)
				DisplayBindingService.AttachSubWindows (sdiWorkspaceWindow, binding);

			sdiWorkspaceWindow.CreateCommandHandler ();

			tab.Content = sdiWorkspaceWindow;
			if (mimeimage != null)
				tab.Icon = mimeimage;

			if (content.Project != null)
				content.Project.NameChanged += HandleProjectNameChanged;
			if (bringToFront)
				content.WorkbenchWindow.SelectWindow();

			// The insertion of the tab may have changed the active view (or maybe not, this is checked in OnActiveWindowChanged)
			OnActiveWindowChanged (null, null);
		}
Example #7
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.Options.HasFlag(OpenDocumentOptions.BringToFront))
                        {
                            doc.Select();
                            doc.RunWhenLoaded(delegate {
                                IEditableTextBuffer ipos = doc.GetContent <IEditableTextBuffer> ();
                                if (openFileInfo.Line > 0 && ipos != null)
                                {
                                    ipos.SetCaretTo(openFileInfo.Line, Math.Max(1, openFileInfo.Column), openFileInfo.Options.HasFlag(OpenDocumentOptions.HighlightCaretLine));
                                }
                            });
                        }
                        openFileInfo.NewContent = doc.Window.ViewContent;
                        return;
                    }
                }

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

                IDisplayBinding     binding     = null;
                IViewDisplayBinding viewBinding = null;
                Project             project     = GetProjectContainingFile(fileName);

                if (openFileInfo.DisplayBinding != null)
                {
                    binding = viewBinding = openFileInfo.DisplayBinding;
                }
                else
                {
                    var bindings = DisplayBindingService.GetDisplayBindings(fileName, null, project).Where(d => d.CanUseAsDefault);
                    if (openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyInternalViewer))
                    {
                        binding     = bindings.OfType <IViewDisplayBinding>().FirstOrDefault();
                        viewBinding = (IViewDisplayBinding)binding;
                    }
                    else if (openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyExternalViewer))
                    {
                        binding     = bindings.OfType <IExternalDisplayBinding>().FirstOrDefault();
                        viewBinding = null;
                    }
                    else
                    {
                        binding     = bindings.FirstOrDefault();
                        viewBinding = binding as IViewDisplayBinding;
                    }
                }

                if (binding != null)
                {
                    if (viewBinding != null)
                    {
                        var fw = new LoadFileWrapper(workbench, viewBinding, project, openFileInfo);
                        fw.Invoke(fileName);
                    }
                    else
                    {
                        var extBinding = (IExternalDisplayBinding)binding;
                        var app        = extBinding.GetApplication(fileName, null, project);
                        app.Launch(fileName);
                    }

                    Counters.OpenDocumentTimer.Trace("Adding to recent files");
                    DesktopService.RecentFiles.AddFile(fileName, project);
                }
                else if (!openFileInfo.Options.HasFlag(OpenDocumentOptions.OnlyInternalViewer))
                {
                    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));
                    }
                }
            }
        }
Example #8
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);
                }
            }
        }
Example #9
0
 public LoadFileWrapper(DefaultWorkbench workbench, IViewDisplayBinding binding, Project project, FileOpenInformation fileInfo)
     : this(workbench, binding, fileInfo)
 {
     this.project = project;
 }
Example #10
0
 public LoadFileWrapper(DefaultWorkbench workbench, IViewDisplayBinding binding, FileOpenInformation fileInfo)
 {
     this.workbench = workbench;
     this.fileInfo  = fileInfo;
     this.binding   = binding;
 }
 OpenWithFileViewer(IViewDisplayBinding binding)
 {
     this.binding = binding;
 }