Beispiel #1
0
        private void OpenFileInternal(string filename)
        {
            var exitingFile = _openFiles.FirstOrDefault(openfile => openfile.FileName == filename);

            if (exitingFile != null)
            {
                SelectedFile = exitingFile;
                return;
            }

            var file = new OpenFileViewModel(this);

            file.Ready += delegate {
                Dispatcher.CurrentDispatcher.InvokeAsync(() => {
                    try {
                        file.OpenFile(filename);
                    }
                    catch (Exception ex) {
                        OpenFiles.Remove(file);
                        MessageBoxService.ShowMessage($"Error: {ex.Message}", Constants.AppTitle);
                    }
                });
            };
            OpenFiles.Add(file);
            _recentFiles.Remove(filename);
            _recentFiles.Insert(0, filename);
            if (_recentFiles.Count > 10)
            {
                _recentFiles.RemoveAt(9);
            }
            SelectedFile = file;
        }
        public void AddFile(string path)
        {
            var vm = new EdataFileViewModel(this);

            vm.LoadFile(path);

            OpenFiles.Add(vm);

            CollectionViewSource.GetDefaultView(OpenFiles).MoveCurrentTo(vm);
        }
Beispiel #3
0
        public FileAccessor OpenFile(string path, OpenMode mode)
        {
            IFile file = FileSystem.OpenFile(path, mode);

            var accessor = new FileAccessor(file, this, mode);

            lock (_locker)
            {
                OpenFiles.Add(accessor);
            }

            return(accessor);
        }
        /// <summary>
        /// Opens a file from the given filename.
        /// </summary>
        /// <param name="filename">Full path of the file to open.</param>
        /// <param name="modelType">Type of the model of the file.</param>
        /// <remarks>This overload is intended to open files on disk, using a specific file type, that are not associated with a project.
        /// To open a project file, use <see cref="OpenFile(Object, Project)"/>.
        /// To open a file that is not necessarily on disk, use <see cref="OpenFile(Object, Boolean)"/>.
        /// To open a file, auto-detecting the file type, use <see cref="OpenFile(String)"/>.
        ///
        /// When the file is closed, the underlying model will be disposed.</remarks>
        public virtual async Task OpenFile(string filename, TypeInfo modelType)
        {
            var model = await IOHelper.OpenFile(filename, modelType, CurrentPluginManager);

            if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model)))
            {
                var wrapper = CreateViewModel(model);
                wrapper.Filename       = filename;
                wrapper.DisposeOnClose = true;
                OpenFiles.Add(wrapper);
                FileOpened?.Invoke(this, new FileOpenedEventArguments {
                    File = model, FileViewModel = wrapper, DisposeOnExit = true
                });
            }
        }
        /// <summary>
        /// Opens the given file
        /// </summary>
        /// <param name="model">The model to open</param>
        /// <param name="disposeOnClose">True to call the file's dispose method (if IDisposable) when closed.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is null.</exception>
        public virtual void OpenFile(object model, bool disposeOnClose)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model)))
            {
                var wrapper = CreateViewModel(model);
                wrapper.DisposeOnClose = disposeOnClose;
                OpenFiles.Add(wrapper);
                FileOpened?.Invoke(this, new FileOpenedEventArguments {
                    File = model, FileViewModel = wrapper, DisposeOnExit = disposeOnClose
                });
            }
        }
Beispiel #6
0
        public Result OpenFile(out FileAccessor file, U8Span path, OpenMode mode)
        {
            file = default;

            Result rc = FileSystem.OpenFile(out IFile rawFile, path, mode);

            if (rc.IsFailure())
            {
                return(rc);
            }

            var accessor = new FileAccessor(rawFile, this, mode);

            lock (_locker)
            {
                OpenFiles.Add(accessor);
            }

            file = accessor;
            return(Result.Success);
        }
        /// <summary>
        /// Opens the given file
        /// </summary>
        /// <param name="model">File to open</param>
        /// <param name="parentProject">Project the file belongs to.  If the file does not belong to a project, don't use this overload.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> or <paramref name="parentProject"/> is null.</exception>
        public virtual void OpenFile(object model, Project parentProject)
        {
            if (ReferenceEquals(model, null))
            {
                throw (new ArgumentNullException(nameof(model)));
            }
            if (ReferenceEquals(parentProject, null))
            {
                throw (new ArgumentNullException(nameof(parentProject)));
            }

            if (!OpenFiles.Any(x => ReferenceEquals(x.Model, model)))
            {
                var wrapper = CreateViewModel(model);
                wrapper.DisposeOnClose = false;
                wrapper.ParentProject  = parentProject;
                OpenFiles.Add(wrapper);
                FileOpened?.Invoke(this, new FileOpenedEventArguments {
                    File = model, FileViewModel = wrapper, DisposeOnExit = false, ParentProject = parentProject
                });
            }
        }
Beispiel #8
0
    /// <summary>
    /// Called at the end of opening this workspace.
    /// </summary>
    public void LoadState(bool expandFolders = false, bool openFiles = false)
    {
        if (DB == null)
        {
            return;
        }
        try {
            Save.LoadingState = true;

            if (expandFolders)
            {
                if (DB.Get(out string s, "SELECT data FROM _misc WHERE key='expanded'") && !s.NE())
                {
                    foreach (var v in s.Segments(" "))
                    {
                        var f = FindById(s[v.Range]);
                        //if (f != null) TreeControl.Expand(f, true);
                        if (f != null)
                        {
                            f.SetIsExpanded(true);
                        }
                    }
                }
            }

            if (openFiles)
            {
                if (DB.Get(out string s, "SELECT data FROM _misc WHERE key='open'") && !s.NE())
                {
                    //format: indexOfActiveDocOrMinusOne id1 id2 ...
                    int      i = -2, iActive = s.ToInt();
                    FileNode fnActive = null;
                    //perf.first();
                    foreach (var v in s.Segments(" "))
                    {
                        i++; if (i < 0)
                        {
                            continue;
                        }
                        var fn = FindById(s[v.Range]); if (fn == null)
                        {
                            continue;
                        }
                        OpenFiles.Add(fn);
                        if (i == iActive)
                        {
                            fnActive = fn;
                        }
                    }
                    //perf.next();
                    if (fnActive == null || !SetCurrentFile(fnActive))
                    {
                        _UpdateOpenFiles(null);                                                                    //disable Previous command
                    }
                    //perf.nw();
                }
            }
        }
        catch (Exception ex) { Debug_.Print(ex); }
        finally { Save.LoadingState = false; }
    }
 public void New()
 {
     OpenFiles.Add(new TextEditorViewModel {
     });
 }