Exemplo n.º 1
0
        public static IWorkbenchWindow OpenFile(string fileName)
        {
            LoggingService.Info("Open file " + fileName);

            IWorkbenchWindow window = GetOpenFile(fileName);

            if (window != null)
            {
                window.SelectWindow();
                return(window);
            }

            IDisplayBinding binding = DisplayBindingService.GetBindingPerFileName(fileName);

            if (binding != null)
            {
                if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding).Invoke), fileName) == FileOperationResult.OK)
                {
                    FileService.RecentOpen.AddLastFile(fileName);
                }
            }
            else
            {
                throw new ApplicationException("Can't open " + fileName + ", no display codon found.");
            }
            return(GetOpenFile(fileName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Opens a view content for the specified file
        /// or returns the existing view content for the file if it is already open.
        /// </summary>
        /// <param name="fileName">The name of the file to open.</param>
        /// <param name="switchToOpenedView">Specifies whether to switch to the view for the specified file.</param>
        /// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
        public static IViewContent OpenFile(string fileName, bool switchToOpenedView)
        {
            fileName = FileUtility.NormalizePath(fileName);
            LoggingService.Info("Open file " + fileName);

            IViewContent viewContent = GetOpenFile(fileName);

            if (viewContent != null)
            {
                if (switchToOpenedView)
                {
                    viewContent.WorkbenchWindow.SelectWindow();
                }
                return(viewContent);
            }

            IDisplayBinding binding = DisplayBindingService.GetBindingPerFileName(fileName);

            if (binding == null)
            {
                binding = new ErrorFallbackBinding("Could not find any display binding for " + Path.GetFileName(fileName));
            }
            if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK)
            {
                FileService.RecentOpen.AddLastFile(fileName);
            }
            return(GetOpenFile(fileName));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Opens a new unsaved file.
        /// </summary>
        /// <param name="defaultName">The (unsaved) name of the to open</param>
        /// <param name="content">Content of the file to create</param>
        public static IViewContent NewFile(string defaultName, byte[] content)
        {
            if (defaultName == null)
            {
                throw new ArgumentNullException("defaultName");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            IDisplayBinding binding = DisplayBindingService.GetBindingPerFileName(defaultName);

            if (binding == null)
            {
                binding = new ErrorFallbackBinding("Can't create display binding for file " + defaultName);
            }
            OpenedFile file = CreateUntitledOpenedFile(defaultName, content);

            IViewContent newContent = binding.CreateContentForFile(file);

            if (newContent == null)
            {
                LoggingService.Warn("Created view content was null - DefaultName:" + defaultName);
                file.CloseIfAllViewsClosed();
                return(null);
            }

            DisplayBindingService.AttachSubWindows(newContent, false);

            WorkbenchSingleton.Workbench.ShowView(newContent);
            return(newContent);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Opens a view content for the specified file
        /// or returns the existing view content for the file if it is already open.
        /// </summary>
        /// <param name="fileName">The name of the file to open.</param>
        /// <param name="switchToOpenedView">Specifies whether to switch to the view for the specified file.</param>
        /// <returns>The existing or opened <see cref="IViewContent"/> for the specified file.</returns>
        public static IViewContent OpenFile(string fileName, bool switchToOpenedView)
        {
            fileName = FileUtility.NormalizePath(fileName);
            LoggingService.Info("Open file " + fileName);

            IViewContent viewContent = GetOpenFile(fileName);

            if (viewContent != null)
            {
                if (switchToOpenedView)
                {
                    viewContent.WorkbenchWindow.SelectWindow();
                }
                return(viewContent);
            }

            IDisplayBinding binding = DisplayBindingService.GetBindingPerFileName(fileName);

            if (binding != null)
            {
                if (FileUtility.ObservedLoad(new NamedFileOperationDelegate(new LoadFileWrapper(binding, switchToOpenedView).Invoke), fileName) == FileOperationResult.OK)
                {
                    FileService.RecentOpen.AddLastFile(fileName);
                }
            }
            else
            {
                throw new ApplicationException("Cannot open " + fileName + ", no display codon found.");
            }
            return(GetOpenFile(fileName));
        }