public DisplayBindingDescriptor(IDisplayBinding binding)
		{
			if (binding == null)
				throw new ArgumentNullException("binding");
			
			this.isSecondary = false;
			this.binding = binding;
		}
        /// <summary>
        /// Creates an item with the specified sub items. And the current
        /// Condition status for this item.
        /// </summary>
        public override object BuildItem(object owner, ArrayList subItems, ConditionCollection conditions)
        {
            //			if (subItems == null || subItems.Count > 0) {
            //				throw new ApplicationException("Tried to buil a command with sub commands, please check the XML definition.");
            //			}

            Debug.Assert(Class != null && Class.Length > 0);

            object o = AddIn.CreateObject(Class);
            displayBinding          = o as IDisplayBinding;
            secondaryDisplayBinding = o as ISecondaryDisplayBinding;

            return this;
        }
Beispiel #3
0
			public LoadFileWrapper(IDisplayBinding binding, bool switchToOpenedView)
			{
				this.binding = binding;
				this.switchToOpenedView = switchToOpenedView;
			}
Beispiel #4
0
		/// <inheritdoc/>
		public IViewContent OpenFileWith(FileName fileName, IDisplayBinding displayBinding, bool switchToOpenedView)
		{
			if (displayBinding == null)
				throw new ArgumentNullException("displayBinding");
			if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(displayBinding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK) {
				RecentOpen.AddRecentFile(fileName);
			}
			return GetOpenFile(fileName);
		}
 public LoadFileWrapper(IDisplayBinding binding)
 {
     this.binding = binding;
 }
		internal FileViewer (IDisplayBinding binding)
		{
			this.binding = binding;
		}
 public LoadFileWrapper(IDisplayBinding binding, Project project, FileInformation fileInfo)
 {
     this.fileInfo = fileInfo;
     this.binding = binding;
     this.project = project;
 }
 public LoadFileWrapper(IDisplayBinding binding, FileInformation fileInfo)
 {
     this.fileInfo = fileInfo;
     this.binding = binding;
 }
Beispiel #9
0
 public static void RegisterRuntimeDisplayBinding(IDisplayBinding binding)
 {
     runtimeBindings.Add(binding);
 }
Beispiel #10
0
 public void DeregisterRuntimeDisplayBinding(IDisplayBinding binding)
 {
     runtimeBindings.Remove(binding);
 }
Beispiel #11
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;
                    }
                }
                try {
                    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));
                        }
                    }
                } catch (Exception ex) {
                    monitor.ReportError("", ex);
                }
            }
        }