Example #1
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));
        }
Example #2
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);
        }
Example #3
0
        /// <inheritdoc/>
        public IViewContent OpenFile(FileName fileName, bool switchToOpenedView)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            LoggingService.Info("Open file " + fileName);

            IViewContent viewContent = GetOpenFile(fileName);

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

            IDisplayBinding binding = SD.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)
            {
                RecentOpen.AddRecentFile(fileName);
            }
            return(GetOpenFile(fileName));
        }
Example #4
0
        /// <inheritdoc/>
        public IFileViewContent NewFile(string defaultName, byte[] content)
        {
            if (defaultName == null)
            {
                throw new ArgumentNullException("defaultName");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            var             displayBindingService = Altaxo.Current.GetRequiredService <IDisplayBindingService>();
            IDisplayBinding binding = displayBindingService.GetBindingPerFileName(FileName.Create(defaultName));

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

            var newContent = (IFileViewContent)binding.CreateContentForFile(file);

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

            displayBindingService.AttachSubWindows(newContent, false);

            Altaxo.Current.GetRequiredService <IWorkbench>().ShowView(newContent, true);
            return(newContent);
        }
Example #5
0
        /// <inheritdoc/>
        public IFileViewContent OpenFile(FileName fileName, bool switchToOpenedView)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            Current.Log.Info("Open file " + fileName);

            IFileViewContent viewContent = GetOpenFile(fileName);

            if (viewContent != null)
            {
                if (switchToOpenedView)
                {
                    viewContent.IsSelected = true;
                }
                return(viewContent);
            }

            IDisplayBinding binding = Altaxo.Current.GetRequiredService <IDisplayBindingService>().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)
            {
                RecentOpen.AddRecentFile(fileName);
            }
            return(GetOpenFile(fileName));
        }
Example #6
0
		/// <inheritdoc/>
		public IViewContent NewFile(string defaultName, byte[] content)
		{
			if (defaultName == null)
				throw new ArgumentNullException("defaultName");
			if (content == null)
				throw new ArgumentNullException("content");
			
			var displayBindingService = SD.DisplayBindingService;
			IDisplayBinding binding = displayBindingService.GetBindingPerFileName(FileName.Create(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);
			
			SD.Workbench.ShowView(newContent);
			return newContent;
		}
Example #7
0
		/// <inheritdoc/>
		public IViewContent OpenFile(FileName fileName, bool switchToOpenedView)
		{
			LoggingService.Info("Open file " + fileName);
			
			IViewContent viewContent = GetOpenFile(fileName);
			if (viewContent != null) {
				if (switchToOpenedView) {
					viewContent.WorkbenchWindow.SelectWindow();
				}
				return viewContent;
			}
			
			IDisplayBinding binding = SD.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) {
				RecentOpen.AddRecentFile(fileName);
			}
			return GetOpenFile(fileName);
		}
Example #8
0
        /// <inheritdoc/>
        public ViewDocumentViewModel OpenFile(FileName fileName, bool switchToOpenedView)
        {
            Log4netLogger.Instance.Info("Open file " + fileName);

            ViewDocumentViewModel view_document = GetOpenFile(fileName);
            if(view_document != null){
                if(switchToOpenedView)
                    view_document.Select();

                return view_document;
            }

            IDisplayBinding binding = display_binding_service.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)
                RecentOpen.AddRecentFile(fileName);

            return GetOpenFile(fileName);
        }
Example #9
0
        /// <inheritdoc/>
        public ViewDocumentViewModel NewFile(string defaultName, byte[] content)
        {
            if(defaultName == null)
                throw new ArgumentNullException("defaultName");

            if(content == null)
                throw new ArgumentNullException("content");

            IDisplayBinding binding = display_binding_service.GetBindingPerFileName(FileName.Create(defaultName));

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

            ViewDocumentViewModel new_doc = binding.CreateViewModelForFile(file);
            if(new_doc == null){
                Log4netLogger.Instance.Warn("Created view content was null - DefaultName:" + defaultName);
                file.CloseIfAllViewsClosed();
                return null;
            }

            //displayBindingService.AttachSubWindows(newContent, false);

            workbench.AddDocument(new_doc);
            return new_doc;
        }