Esempio n. 1
0
        public void CloseFile()
        {
            var localFilePath = this.filePath;

            FileClosing?.Invoke(this, new FileClosingEventArgs(localFilePath));

            this.filePath = null;
            this.memory   = null;

            FileClosed?.Invoke(this, new FileClosedEventArgs(localFilePath));
        }
        private void File_OnClosed(object sender, EventArgs e)
        {
            var args = new FileClosingEventArgs();

            args.File = sender;

            FileClosing?.Invoke(this, args);

            if (!args.Cancel)
            {
                // Doing the cast again in case something changed args
                CloseFile(sender as FileViewModel);
            }
        }
        /// <summary>
        /// Closes the file
        /// </summary>
        /// <param name="File">File to close</param>
        public virtual void CloseFile(FileViewModel file)
        {
            if (file != null)
            {
                var args = new FileClosingEventArgs();
                args.File = file;

                FileClosing?.Invoke(this, args);

                if (!args.Cancel)
                {
                    for (var i = OpenFiles.Count - 1; i >= 0; i--)
                    {
                        if (ReferenceEquals(OpenFiles[i], file))
                        {
                            OpenFiles[i].Dispose();

                            var openFilesCount = OpenFiles.Count;
                            try
                            {
                                OpenFiles.RemoveAt(i);
                            }
                            catch (NullReferenceException)
                            {
                                // There's been a bug in a dependency where OpenFiles.RemoveAt fails because of UI stuff.
                                // If the same exception is encountered, and the file has actually been removed, then ignore it.
                                if (openFilesCount <= OpenFiles.Count) // OpenFiles.Count should have decreased by 1. If it has not, then throw the exception.
                                {
                                    throw;
                                }
                            }
                        }
                    }

                    if (ReferenceEquals(file, SelectedFile))
                    {
                        SelectedFile = null;
                    }

                    FileClosed?.Invoke(this, new FileClosedEventArgs {
                        File = file.Model
                    });
                }
            }
        }
 private void OnFileClosing()
 {
     Log.Info("Closing file...");
     FileClosing?.Invoke(this, EventArgs.Empty);
 }