private void InitCommands()
 {
     OpenCommand              = new OpenCommand(this);
     ApplyCommand             = new ApplyCommand(this);
     FlipCommand              = new FlipCommand(this);
     HistogramEqualizeCommand = new HistogramEqualizeCommand(this);
     HistogramStretchCommand  = new HistogramStretchCommand(this);
     CropCommand              = new CropCommand(this);
     InpaintCommand           = new InpaintCommand(this);
     ResizeCommand            = new ResizeCommand(this);
     RotateCommand            = new RotateCommand(this);
     SaveAsCommand            = new SaveAsCommand(this);
     SaveCommand              = new SaveCommand(this);
     ZoomCommand              = new ZoomCommand(this);
     ResetCommand             = new ResetCommand(this);
     CloseCommand             = new CloseCommand(this);
     SelectToolCommand        = new SelectToolCommand(this);
     UndoCommand              = new UndoCommand(this);
     RedoCommand              = new RedoCommand(this);
     DropboxCommand           = new DropboxCommand(this);
     DownloadCommand          = new DownloadCommand(this);
     UploadCommand            = new UploadCommand(this);
     DCommand       = new DCommand(this);
     ECommand       = new ECommand(this);
     PrewittCommand = new PrewittCommand(this);
 }
Пример #2
0
        void Save()
        {
            // SAVE COMMAND
            SaveCommand = new CommandBase((s, e) =>
            {
                var tab = Model.Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;

                if (doc.MarkdownDocument.Filename == "untitled")
                {
                    SaveAsCommand.Execute(tab);
                }
                else if (!doc.SaveDocument())
                {
                    SaveAsCommand.Execute(tab);
                }

                Model.Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (Model.ActiveDocument == null)
                {
                    return(false);
                }

                return(Model.ActiveDocument.IsDirty);
            });
        }
        private void ReCalculateCommands()
        {
            // http://stackoverflow.com/questions/6020497/wpf-v4-mvvm-light-v4-bl16-mix11-relaycommand-canexecute-doesnt-fire
            if (null != IncludeSelectedCommand)
            {
                IncludeSelectedCommand.RaiseCanExecuteChanged();
            }

            if (null != this.ExcludeSelectedCommand)
            {
                this.ExcludeSelectedCommand.RaiseCanExecuteChanged();
            }

            if (null != this.MoveUpCommand)
            {
                this.MoveUpCommand.RaiseCanExecuteChanged();
            }

            if (null != this.MoveDownCommand)
            {
                this.MoveDownCommand.RaiseCanExecuteChanged();
            }

            if (null != SaveAsCommand)
            {
                SaveAsCommand.RaiseCanExecuteChanged();
            }

            if (null != PackageCommand)
            {
                this.PackageCommand.RaiseCanExecuteChanged();
            }
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EditorControl"/> class.
 /// </summary>
 public EditorControl()
 {
     SaveAsCommand      = new SaveAsCommand(this);
     SaveCommand        = new SaveCommand(this);
     OpenFileCommand    = new OpenFileCommand(this);
     NewFileCommand     = new NewFileCommand(this);
     InsertImageCommand = new InsertImageCommand(this);
 }
Пример #5
0
 void OnClose()
 {
     if (!EnsureSaved())
     {
         return;
     }
     ProgramProvider.Reset();
     CloseCommand.RaiseCanExecuteChanged();
     SaveAsCommand.RaiseCanExecuteChanged();
 }
Пример #6
0
        public DpdViewModel()
        {
            OpenCommand = new RelayCommand(x =>
            {
                var fd = FileDialog.Factory(Window, FileDialog.Behavior.Open, ("DPD effect", "dpd"));
                if (fd.ShowDialog() == true)
                {
                    using (var stream = File.OpenRead(fd.FileName))
                    {
                        FileName = fd.FileName;
                        Dpd      = new Dpd(stream);

                        OnPropertyChanged(nameof(SaveCommand));
                        OnPropertyChanged(nameof(SaveAsCommand));
                    }
                }
            }, x => true);

            SaveCommand = new RelayCommand(x =>
            {
                if (!string.IsNullOrEmpty(FileName))
                {
                    using (var stream = File.Open(FileName, FileMode.Create))
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    SaveAsCommand.Execute(x);
                }
            }, x => true);

            SaveAsCommand = new RelayCommand(x =>
            {
                var fd = FileDialog.Factory(Window, FileDialog.Behavior.Save, ("DPD effect", "dpd"));
                if (fd.ShowDialog() == true)
                {
                    using (var stream = File.Open(fd.FileName, FileMode.Create))
                    {
                        throw new NotImplementedException();
                    }
                }
            }, x => true);

            ExitCommand = new RelayCommand(x =>
            {
                Window.Close();
            }, x => true);

            AboutCommand = new RelayCommand(x =>
            {
                new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
            }, x => true);
        }
Пример #7
0
 void OnNew()
 {
     if (!EnsureSaved())
     {
         return;
     }
     ProgramProvider.Reset();
     CloseCommand.RaiseCanExecuteChanged();
     SaveAsCommand.RaiseCanExecuteChanged();
     StatusUpdateProvider.Publish(Resources.Strings.TitleBarViewModel_CreatedNewProgram);
 }
Пример #8
0
        public DpdViewModel()
        {
            OpenCommand = new RelayCommand(x =>
            {
                FileDialog.OnOpen(fileName =>
                {
                    using (var stream = File.OpenRead(fileName))
                    {
                        FileName = fileName;
                        Dpd      = new Dpd(stream);

                        OnPropertyChanged(nameof(SaveCommand));
                        OnPropertyChanged(nameof(SaveAsCommand));
                    }
                }, Filters);
            }, x => true);

            SaveCommand = new RelayCommand(x =>
            {
                if (!string.IsNullOrEmpty(FileName))
                {
                    using (var stream = File.Open(FileName, FileMode.Create))
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    SaveAsCommand.Execute(x);
                }
            }, x => true);

            SaveAsCommand = new RelayCommand(x =>
            {
                FileDialog.OnSave(fileName =>
                {
                    using (var stream = File.Open(fileName, FileMode.Create))
                    {
                        throw new NotImplementedException();
                    }
                }, Filters);
            }, x => true);

            ExitCommand = new RelayCommand(x =>
            {
                Window.Close();
            }, x => true);

            AboutCommand = new RelayCommand(x =>
            {
                new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
            }, x => true);
        }
Пример #9
0
 void OnLoad()
 {
     if (!EnsureSaved())
     {
         return;
     }
     if (!Load())
     {
         return;
     }
     CloseCommand.RaiseCanExecuteChanged();
     SaveAsCommand.RaiseCanExecuteChanged();
 }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExportCommandBinding&lt;TController, TModel&gt;"/> class.
        /// </summary>
        /// <param name="viewModel">The view model.</param>
        /// <param name="owner">The owner window.</param>
        public ExportCommandBinding(ShellViewModel viewModel, Window owner)
        {
            this.Command = ShellCommands.Export;

            this.CanExecute += delegate(object sender, CanExecuteRoutedEventArgs e)
            {
                e.CanExecute = SaveAsCommand <ShellController, ConfigurationModel> .CanSaveAs(viewModel);
            };

            this.Executed += delegate(object sender, ExecutedRoutedEventArgs e)
            {
                SaveAsCommand <ShellController, ConfigurationModel> .SaveAs(viewModel, owner);
            };
        }
Пример #11
0
        private void SubscribeCommands()
        {
            ProjectSettingCommand.Subscribe(x => OpenProjectSetting());

            NewProjectCommand.PublishTask(x => Editor.Value.NewProjectAsync(),
                                          e => ShowError(e, "プロジェクトの作成に失敗しました。"));
            OpenProjectCommand.PublishTask(x => Editor.Value.OpenAsync(),
                                           e => ShowError(e, "データを読み込めませんでした。"));
            SaveCommand.PublishTask(x => Editor.Value.SaveAsync(),
                                    e => ShowError(e, "保存を中止し、以前のファイルに復元しました。"));
            SaveAsCommand.PublishTask(x => Editor.Value.SaveAsAsync(),
                                      e => ShowError(e, "保存を中止しました。"));
            CloseCanceledCommand.PublishTask(x => Editor.Value.CloseProjectAsync(),
                                             e => ShowError(e, "ウィンドウを閉じることができませんでした。"));
        }
Пример #12
0
        public MainWindowModel()
        {
            recorder = new Recorder(13224);
            recorder.OnRecordCountChanged += () => recordCountDirty = true;

            StartButtonCommand  = new StartCommand(recorder);
            StopButtonCommand   = new StopCommand(recorder);
            ClearButtonCommand  = new ClearCommand(recorder);
            SaveAsButtonCommand = new SaveAsCommand(recorder);

            timer          = new DispatcherTimer();
            timer.Tick    += Timer_Tick;
            timer.Interval = TimeSpan.FromMilliseconds(100);
            timer.Start();
        }
Пример #13
0
 private void SaveCommand_Execute(object parameter)
 {
     if (string.IsNullOrWhiteSpace(_fileName))
     {
         SaveAsCommand.Execute(null);
     }
     else
     {
         XmlSerializer serializer = new XmlSerializer(_events.GetType());
         using (Stream stream = new FileStream(_fileName, FileMode.Create))
         {
             serializer.Serialize(stream, new ObservableCollection <CalendarEntry>(_events.OrderBy(x => x.StartDate)));
         }
         MessageBox.Show("Erfolgreich gespeichert!", "Erfolg", MessageBoxButton.OK, MessageBoxImage.Information);
     }
 }
Пример #14
0
 void OnSelectedItemChanged(ProjectItem oldValue, ProjectItem newValue)
 {
     if (oldValue != null)
     {
         oldValue.TextChanged -= OnTextChanged;
     }
     if (newValue != null)
     {
         newValue.TextChanged += OnTextChanged;
     }
     SaveCommand.RaiseCanExecuteChanged();
     SaveAsCommand.RaiseCanExecuteChanged();
     CloseAllTabsCommand.RaiseCanExecuteChanged();
     CloseCurrentTabCommand.RaiseCanExecuteChanged();
     AddNewFolderCommand.RaiseCanExecuteChanged();
     ContextMenuAddFolderCommand.RaiseCanExecuteChanged();
     RenameCommand.RaiseCanExecuteChanged();
 }
Пример #15
0
        public Data()
        {
            //File
            NewProjectCommand  = new NewProjectCommand();
            OpenProjectCommand = new OpenProjectCommand();
            ExitCommand        = new ExitCommand();
            SaveCommand        = new SaveCommand();
            SaveAsCommand      = new SaveAsCommand();

            //Edit
            CopyCommand   = new CopyCommand();
            CutCommand    = new CutCommand();
            DeleteCommand = new DeleteCommand();
            PasteCommand  = new PasteCommand();
            RedoCommand   = new RedoCommand();
            UndoCommand   = new UndoCommand();

            //View
            StatusbarToggleCommand = new StatusbarToggleCommand();
            ToolboxToggleCommand   = new ToolboxToggleCommand();
            ZoomInCommand          = new ZoomInCommand();
            ZoomOutCommand         = new ZoomOutCommand();

            //Insert
            NewClassCommand      = new NewClassCommand();
            NewDependencyCommand = new NewDependencyCommand();
            NewTextBoxCommand    = new NewTextBoxCommand();

            //Help
            HelpCommand  = new HelpCommand();
            AboutCommand = new AboutCommand();

            //StatusBar
            resetStatusBar();
            StatusBarVisability = "Visible";
            ToolBoxVisability   = "Visible";
        }
Пример #16
0
        private void CreateCommands()
        {
            // SAVE COMMAND
            SaveCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;

                if (doc.MarkdownDocument.Filename == "untitled")
                {
                    SaveAsCommand.Execute(tab);
                }
                else if (!doc.SaveDocument())
                {
                    SaveAsCommand.Execute(tab);
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(this.ActiveDocument.IsDirty);
            });

            // SAVEAS COMMAND
            SaveAsCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var folder = Path.GetDirectoryName(doc.MarkdownDocument.Filename);

                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter           = "Markdown files (*.md)|*.md|All files (*.*)|*.*",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = doc.MarkdownDocument.Filename,
                    CheckFileExists  = false,
                    OverwritePrompt  = false,
                    CheckPathExists  = true,
                    RestoreDirectory = true
                };

                var result = sd.ShowDialog();
                if (result != null && result.Value)
                {
                    doc.MarkdownDocument.Filename = sd.FileName;
                    if (!doc.SaveDocument())
                    {
                        MessageBox.Show(Window, $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                        "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                        SaveAsCommand.Execute(tab);
                        return;
                    }
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(true);
            });

            // SAVEASHTML COMMAND
            SaveAsHtmlCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var folder = Path.GetDirectoryName(doc.MarkdownDocument.Filename);

                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter           = "Markdown files (*.html)|*.html|All files (*.*)|*.*",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = Path.ChangeExtension(doc.MarkdownDocument.Filename, "html"),
                    CheckFileExists  = false,
                    OverwritePrompt  = false,
                    CheckPathExists  = true,
                    RestoreDirectory = true
                };

                var result = sd.ShowDialog();
                if (result != null && result.Value)
                {
                    var html = doc.RenderMarkdown(doc.GetMarkdown());

                    if (!doc.MarkdownDocument.WriteFile(sd.FileName, html))
                    {
                        MessageBox.Show(Window, $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                        "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                        SaveAsHtmlCommand.Execute(null);
                        return;
                    }
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null || ActiveEditor == null)
                {
                    return(false);
                }
                if (ActiveDocument.Filename == "untitled")
                {
                    return(true);
                }
                if (ActiveEditor.EditorSyntax != "markdown")
                {
                    return(false);
                }

                return(true);
            });

            // PREVIEW BUTTON COMMAND
            PreviewBrowserCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }

                var editor = tab.Tag as MarkdownDocumentEditor;

                Configuration.IsPreviewVisible = IsPreviewBrowserVisible;

                Window.ShowPreviewBrowser(!IsPreviewBrowserVisible);
                if (IsPreviewBrowserVisible)
                {
                    Window.PreviewMarkdown(editor);
                }
            }, null);

            // MARKDOWN EDIT COMMANDS TOOLBAR COMMAND
            ToolbarInsertMarkdownCommand = new CommandBase((s, e) =>
            {
                var editor = Window.GetActiveMarkdownEditor();
                if (editor == null || editor.AceEditor == null)
                {
                    return;
                }

                string action = s as string;

                editor.ProcessEditorUpdateCommand(action);
            }, null);

            // Settings
            SettingsCommand = new CommandBase((s, e) =>
            {
                var file = Path.Combine(mmApp.Configuration.CommonFolder, "MarkdownMonster.json");

                // save settings first so we're looking at current setting
                Configuration.Write();

                string fileText = File.ReadAllText(file);
                if (!fileText.StartsWith("//"))
                {
                    fileText = "// Reference: http://markdownmonster.west-wind.com/docs/_4nk01yq6q.htm\r\n" +
                               fileText;
                    File.WriteAllText(file, fileText);
                }

                Window.OpenTab(file, syntax: "json");
            }, null);

            // DISTRACTION FREE MODE
            DistractionFreeModeCommand = new CommandBase((s, e) =>
            {
                GridLength gl = new GridLength(0);
                if (Window.WindowGrid.RowDefinitions[1].Height == gl)
                {
                    gl = new GridLength(30);
                    IsPreviewBrowserVisible = true;
                    Window.PreviewMarkdown();
                    IsFullScreen = false;
                }
                else
                {
                    IsPreviewBrowserVisible = false;
                    Window.ShowPreviewBrowser(hide: true);
                    IsFullScreen = true;
                }

                Window.WindowGrid.RowDefinitions[1].Height = gl;
                //Window.WindowGrid.RowDefinitions[3].Height = gl;
            }, null);

            // PRINT PREVIEW
            PrintPreviewCommand = new CommandBase((s, e) =>
            {
                dynamic dom = Window.PreviewBrowser.Document;
                dom.execCommand("print", true, null);
            }, (s, e) => IsPreviewBrowserVisible);
        }
Пример #17
0
 public FileCommand(NewCommand newCommand, OpenCommand openCommand, SaveCommand saveCommand, SaveAsCommand saveAsCommand,
                    PrintCommand printCommand, PrintPreviewCommand printPreviewCommand, ExitCommand exitCommand) : base(MenuStrings.fileToolStripMenuItem_Text)
 {
     ChildrenCommands = new List <IToolbarCommand>
     {
         newCommand,
         openCommand,
         null,
         saveCommand,
         saveAsCommand,
         null,
         printCommand,
         printPreviewCommand,
         null,
         exitCommand
     };
 }
Пример #18
0
        private void CreateCommands()
        {
            // SAVE COMMAND
            SaveCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;

                if (doc.MarkdownDocument.Filename == "untitled")
                {
                    SaveAsCommand.Execute(tab);
                }
                else if (!doc.SaveDocument())
                {
                    SaveAsCommand.Execute(tab);
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(this.ActiveDocument.IsDirty);
            });

            // SAVEAS COMMAND
            SaveAsCommand = new CommandBase((parameter, e) =>
            {
                bool isEncrypted = parameter != null && parameter.ToString() == "Secure";

                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var filename = doc.MarkdownDocument.Filename;
                var folder   = Path.GetDirectoryName(doc.MarkdownDocument.Filename);

                if (filename == "untitled")
                {
                    folder = mmApp.Configuration.LastFolder;

                    var match = Regex.Match(doc.GetMarkdown(), @"^# (\ *)(?<Header>.+)", RegexOptions.Multiline);

                    if (match.Success)
                    {
                        filename = match.Groups["Header"].Value;
                        if (!string.IsNullOrEmpty(filename))
                        {
                            filename = mmFileUtils.SafeFilename(filename);
                        }
                    }
                }

                if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
                {
                    folder = mmApp.Configuration.LastFolder;
                    if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
                    {
                        folder = KnownFolders.GetPath(KnownFolder.Libraries);
                    }
                }


                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter           = "Markdown files (*.md)|*.md|Markdown files (*.markdown)|*.markdown|All files (*.*)|*.*",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = filename,
                    CheckFileExists  = false,
                    OverwritePrompt  = false,
                    CheckPathExists  = true,
                    RestoreDirectory = true
                };

                bool?result = null;
                try
                {
                    result = sd.ShowDialog();
                }
                catch (Exception ex)
                {
                    mmApp.Log("Unable to save file: " + doc.MarkdownDocument.Filename, ex);
                    MessageBox.Show(
                        $@"Unable to open file:\r\n\r\n" + ex.Message,
                        "An error occurred trying to open a file",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }

                if (!isEncrypted)
                {
                    doc.MarkdownDocument.Password = null;
                }
                else
                {
                    var pwdDialog = new FilePasswordDialog(doc.MarkdownDocument, false)
                    {
                        Owner = Window
                    };
                    bool?pwdResult = pwdDialog.ShowDialog();
                }

                if (result != null && result.Value)
                {
                    doc.MarkdownDocument.Filename = sd.FileName;
                    if (!doc.SaveDocument())
                    {
                        MessageBox.Show(Window, $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                        "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                        SaveAsCommand.Execute(tab);
                        return;
                    }
                }

                mmApp.Configuration.LastFolder = folder;

                Window.SetWindowTitle();
                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(true);
            });

            // SAVEASHTML COMMAND
            SaveAsHtmlCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                var doc = tab?.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var folder = Path.GetDirectoryName(doc.MarkdownDocument.Filename);

                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter           = "Html files (Html only) (*.html)|*.html|Html files (Html and dependencies in a folder)|*.html",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = Path.ChangeExtension(doc.MarkdownDocument.Filename, "html"),
                    CheckFileExists  = false,
                    OverwritePrompt  = false,
                    CheckPathExists  = true,
                    RestoreDirectory = true
                };

                bool?result = null;
                try
                {
                    result = sd.ShowDialog();
                }catch (Exception ex)
                {
                    mmApp.Log("Unable to save html file: " + doc.MarkdownDocument.Filename, ex);
                    MessageBox.Show(
                        $@"Unable to open file:\r\n\r\n" + ex.Message,
                        "An error occurred trying to open a file",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }

                if (result != null && result.Value)
                {
                    if (sd.FilterIndex != 2)
                    {
                        var html = doc.RenderMarkdown(doc.GetMarkdown(), mmApp.Configuration.MarkdownOptions.RenderLinksAsExternal);

                        if (!doc.MarkdownDocument.WriteFile(sd.FileName, html))
                        {
                            MessageBox.Show(Window,
                                            $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                            "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                            SaveAsHtmlCommand.Execute(null);
                            return;
                        }
                    }
                    else
                    {
                        string msg   = @"This feature is not available yet.

For now, you can use 'View in Web Browser' to view the document in your favorite Web Browser and use 'Save As...' to save the Html document with all CSS and Image dependencies.

Do you want to View in Browser now?
";
                        var mbResult = MessageBox.Show(msg,
                                                       mmApp.ApplicationName,
                                                       MessageBoxButton.YesNo,
                                                       MessageBoxImage.Asterisk,
                                                       MessageBoxResult.Yes);

                        if (mbResult == MessageBoxResult.Yes)
                        {
                            Window.Model.ViewInExternalBrowserCommand.Execute(null);
                        }
                    }
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null || ActiveEditor == null)
                {
                    return(false);
                }
                if (ActiveDocument.Filename == "untitled")
                {
                    return(true);
                }
                if (ActiveEditor.EditorSyntax != "markdown")
                {
                    return(false);
                }

                return(true);
            });

            // NEW DOCUMENT COMMAND (ctrl-n)
            NewDocumentCommand = new CommandBase((s, e) =>
            {
                Window.OpenTab("untitled");
            });

            // OPEN DOCUMENT COMMAND
            OpenDocumentCommand = new CommandBase((s, e) =>
            {
                var fd = new OpenFileDialog
                {
                    DefaultExt = ".md",
                    Filter     = "Markdown files (*.md,*.markdown)|*.md;*.markdown|" +
                                 "Html files (*.htm,*.html)|*.htm;*.html|" +
                                 "Javascript files (*.js)|*.js|" +
                                 "Typescript files (*.ts)|*.ts|" +
                                 "Json files (*.json)|*.json|" +
                                 "Css files (*.css)|*.css|" +
                                 "Xml files (*.xml,*.config)|*.xml;*.config|" +
                                 "C# files (*.cs)|*.cs|" +
                                 "C# Razor files (*.cshtml)|*.cshtml|" +
                                 "Foxpro files (*.prg)|*.prg|" +
                                 "Powershell files (*.ps1)|*.ps1|" +
                                 "Php files (*.php)|*.php|" +
                                 "Python files (*.py)|*.py|" +
                                 "All files (*.*)|*.*",
                    CheckFileExists  = true,
                    RestoreDirectory = true,
                    Multiselect      = true,
                    Title            = "Open Markdown File"
                };

                if (!string.IsNullOrEmpty(mmApp.Configuration.LastFolder))
                {
                    fd.InitialDirectory = mmApp.Configuration.LastFolder;
                }

                bool?res = null;
                try
                {
                    res = fd.ShowDialog();
                }
                catch (Exception ex)
                {
                    mmApp.Log("Unable to open file.", ex);
                    MessageBox.Show(
                        $@"Unable to open file:\r\n\r\n" + ex.Message,
                        "An error occurred trying to open a file",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    return;
                }
                if (res == null || !res.Value)
                {
                    return;
                }

                foreach (var file in fd.FileNames)
                {
                    // TODO: Check AddRecentFile and make sure Tab Selection works
                    Window.OpenTab(file, rebindTabHeaders: true);
                    //Window.AddRecentFile(file);
                }
            });

            // CLOSE ACTIVE DOCUMENT COMMAND
            CloseActiveDocumentCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }

                if (Window.CloseTab(tab))
                {
                    Window.TabControl.Items.Remove(tab);
                }
            }, null)
            {
                Caption = "_Close Document",
                ToolTip = "Closes the active tab and asks to save the document."
            };


            // COMMIT TO GIT Command
            CommitToGitCommand = new CommandBase(async(s, e) =>
            {
                string file = ActiveDocument?.Filename;
                if (string.IsNullOrEmpty(file))
                {
                    return;
                }

                Window.ShowStatus("Committing and pushing to Git...");
                WindowUtilities.DoEvents();

                string error = null;

                bool pushToGit = mmApp.Configuration.GitCommitBehavior == GitCommitBehaviors.CommitAndPush;
                bool result    = await Task.Run(() => mmFileUtils.CommitFileToGit(file, pushToGit, out error));

                if (result)
                {
                    Window.ShowStatus($"File {Path.GetFileName(file)} committed and pushed.", 6000);
                }
                else
                {
                    Window.ShowStatus(error, 7000);
                    Window.SetStatusIcon(FontAwesomeIcon.Warning, Colors.Red);
                }
            }, (s, e) => IsEditorActive);


            // PREVIEW BUTTON COMMAND
            PreviewBrowserCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }

                var editor = tab.Tag as MarkdownDocumentEditor;

                Configuration.IsPreviewVisible = IsPreviewBrowserVisible;

                if (!IsPreviewBrowserVisible && IsPresentationMode)
                {
                    PresentationModeCommand.Execute(null);
                }


                Window.ShowPreviewBrowser(!IsPreviewBrowserVisible);
                if (IsPreviewBrowserVisible)
                {
                    Window.PreviewMarkdown(editor);
                }
            }, null);

            // SHOW FILE BROWSER COMMAND
            ShowFolderBrowserCommand = new CommandBase((s, e) =>
            {
                mmApp.Configuration.FolderBrowser.Visible = !mmApp.Configuration.FolderBrowser.Visible;

                mmApp.Model.Window.ShowFolderBrowser(!mmApp.Configuration.FolderBrowser.Visible);
            });

            // WORD WRAP COMMAND
            WordWrapCommand = new CommandBase((parameter, command) =>
            {
                //MessageBox.Show("alt-z WPF");
                mmApp.Model.Configuration.EditorWrapText = !mmApp.Model.Configuration.EditorWrapText;
                mmApp.Model.ActiveEditor?.SetWordWrap(mmApp.Model.Configuration.EditorWrapText);
            }, (p, c) => IsEditorActive);

            // MARKDOWN EDIT COMMANDS TOOLBAR COMMAND
            ToolbarInsertMarkdownCommand = new CommandBase((s, e) =>
            {
                string action = s as string;

                var editor = Window.GetActiveMarkdownEditor();
                editor?.ProcessEditorUpdateCommand(action);
            }, null);

            // Settings
            SettingsCommand = new CommandBase((s, e) =>
            {
                var file = Path.Combine(mmApp.Configuration.CommonFolder, "MarkdownMonster.json");

                // save settings first so we're looking at current setting
                Configuration.Write();

                string fileText = File.ReadAllText(file);
                if (!fileText.StartsWith("//"))
                {
                    fileText = "// Reference: http://markdownmonster.west-wind.com/docs/_4nk01yq6q.htm\r\n" +
                               fileText;
                    File.WriteAllText(file, fileText);
                }

                Window.OpenTab(file, syntax: "json");
            }, null);

            // DISTRACTION FREE MODE
            DistractionFreeModeCommand = new CommandBase((s, e) =>
            {
                GridLength glToolbar = new GridLength(0);
                GridLength glMenu    = new GridLength(0);
                GridLength glStatus  = new GridLength(0);

                GridLength glFileBrowser = new GridLength(0);

                if (Window.ToolbarGridRow.Height == glToolbar)
                {
                    Window.SaveSettings();

                    glToolbar = GridLength.Auto;
                    glMenu    = GridLength.Auto;
                    glStatus  = GridLength.Auto;

                    //mmApp.Configuration.WindowPosition.IsTabHeaderPanelVisible = true;
                    Window.TabControl.IsHeaderPanelVisible = true;

                    IsPreviewBrowserVisible = true;
                    Window.PreviewMarkdown();

                    Window.WindowState = mmApp.Configuration.WindowPosition.WindowState;

                    IsFullScreen = false;

                    Window.ShowFolderBrowser(!mmApp.Configuration.FolderBrowser.Visible);
                }
                else
                {
                    var tokens = mmApp.Configuration.DistractionFreeModeHideOptions.ToLower().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                    if (tokens.All(d => d != "menu"))
                    {
                        glMenu = GridLength.Auto;
                    }

                    if (tokens.All(d => d != "toolbar"))
                    {
                        glToolbar = GridLength.Auto;
                    }

                    if (tokens.All(d => d != "statusbar"))
                    {
                        glStatus = GridLength.Auto;
                    }

                    if (tokens.Any(d => d == "tabs"))
                    {
                        Window.TabControl.IsHeaderPanelVisible = false;
                    }

                    if (tokens.Any(d => d == "preview"))
                    {
                        IsPreviewBrowserVisible = false;
                        Window.ShowPreviewBrowser(hide: true);
                    }

                    mmApp.Configuration.WindowPosition.WindowState = Window.WindowState;
                    if (tokens.Any(d => d == "maximized"))
                    {
                        Window.WindowState = WindowState.Maximized;
                    }

                    Window.ShowFolderBrowser(true);

                    IsFullScreen = true;
                }

                // toolbar
                Window.MainMenuGridRow.Height  = glMenu;
                Window.ToolbarGridRow.Height   = glToolbar;
                Window.StatusBarGridRow.Height = glStatus;
            }, null);

            // PRESENTATION MODE
            PresentationModeCommand = new CommandBase((s, e) =>
            {
                if (IsFullScreen)
                {
                    DistractionFreeModeCommand.Execute(null);
                }

                GridLength gl = new GridLength(0);
                if (Window.WindowGrid.RowDefinitions[1].Height == gl)
                {
                    gl = GridLength.Auto; // toolbar height

                    Window.MainWindowEditorColumn.Width    = new GridLength(1, GridUnitType.Star);
                    Window.MainWindowSeparatorColumn.Width = new GridLength(0);
                    Window.MainWindowPreviewColumn.Width   = new GridLength(mmApp.Configuration.WindowPosition.SplitterPosition);

                    Window.PreviewMarkdown();

                    Window.ShowFolderBrowser(!mmApp.Configuration.FolderBrowser.Visible);

                    IsPresentationMode = false;
                }
                else
                {
                    Window.SaveSettings();

                    mmApp.Configuration.WindowPosition.SplitterPosition =
                        Convert.ToInt32(Window.MainWindowPreviewColumn.Width.Value);

                    // don't allow presentation mode for non-Markdown documents
                    var editor = Window.GetActiveMarkdownEditor();
                    if (editor != null)
                    {
                        var file = editor.MarkdownDocument.Filename.ToLower();
                        var ext  = Path.GetExtension(file);
                        if (file != "untitled" && ext != ".md" && ext != ".htm" && ext != ".html")
                        {
                            // don't allow presentation mode for non markdown files
                            IsPresentationMode      = false;
                            IsPreviewBrowserVisible = false;
                            Window.ShowPreviewBrowser(true);
                            return;
                        }
                    }

                    Window.ShowPreviewBrowser();
                    Window.ShowFolderBrowser(true);

                    Window.MainWindowEditorColumn.Width    = gl;
                    Window.MainWindowSeparatorColumn.Width = gl;
                    Window.MainWindowPreviewColumn.Width   = new GridLength(1, GridUnitType.Star);

                    IsPresentationMode      = true;
                    IsPreviewBrowserVisible = true;
                }

                Window.WindowGrid.RowDefinitions[1].Height = gl;
                //Window.WindowGrid.RowDefinitions[3].Height = gl;
            }, null);

            // EXTERNAL BROWSER VIEW
            ViewInExternalBrowserCommand = new CommandBase((p, e) =>
            {
                if (ActiveDocument == null)
                {
                    return;
                }
                mmFileUtils.ShowExternalBrowser(ActiveDocument.HtmlRenderFilename);
            }, (p, e) => IsPreviewBrowserVisible);

            ViewHtmlSourceCommand = new CommandBase((p, e) =>
            {
                if (ActiveDocument == null)
                {
                    return;
                }
                Window.OpenTab(ActiveDocument.HtmlRenderFilename);
            }, (p, e) => IsPreviewBrowserVisible);


            // PRINT PREVIEW
            PrintPreviewCommand = new CommandBase((s, e) =>
            {
                dynamic dom = Window.PreviewBrowser.Document;
                dom.execCommand("print", true, null);
            }, (s, e) => IsPreviewBrowserVisible);

            // PDF GENERATION PREVIEW
            GeneratePdfCommand = new CommandBase((s, e) =>
            {
                var form = new GeneratePdfWindow()
                {
                    Owner = mmApp.Model.Window
                };
                form.Show();
            }, (s, e) => IsPreviewBrowserVisible);

            // F1 Help Command - Pass option CommandParameter="TopicId"
            HelpCommand = new CommandBase((topicId, e) =>
            {
                string url = mmApp.Urls.DocumentationBaseUrl;

                if (topicId != null)
                {
                    url = mmApp.GetDocumentionUrl(topicId as string);
                }

                ShellUtils.GoUrl(url);
            }, (s, e) => IsPreviewBrowserVisible);
        }
Пример #19
0
        public ImageViewerViewModel()
        {
            OpenCommand = new RelayCommand(x =>
            {
                FileDialog.OnOpen(fileName =>
                {
                    LoadImage(fileName);
                }, OpenFilters);
            }, x => !IsTool);

            SaveCommand = new RelayCommand(x =>
            {
                if (IsTool)
                {
                    Save(_toolInvokeDesc.SelectedEntry.Stream);
                }
                else if (!string.IsNullOrEmpty(FileName))
                {
                    using (var stream = File.Open(FileName, FileMode.Create))
                    {
                        Save(stream);
                    }
                }
                else
                {
                    SaveAsCommand.Execute(x);
                }
            }, x => ImageFormat != null);

            SaveAsCommand = new RelayCommand(x =>
            {
                var filter = new List <FileDialogFilter>().AddExtensions($"{ImageFormat.Name} format", ImageFormat.Extension);
                FileDialog.OnSave(fileName =>
                {
                    using (var stream = File.Open(fileName, FileMode.Create))
                    {
                        Save(stream);
                    }
                }, filter);
            }, x => ImageFormat != null && !IsTool);

            ExitCommand = new RelayCommand(x =>
            {
                Window.Close();
            }, x => true);

            AboutCommand = new RelayCommand(x =>
            {
                new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
            }, x => true);

            ExportCommand = new RelayCommand(x =>
            {
                FileDialog.OnSave(fileName =>
                {
                    var imageFormat = _imageFormatService.GetFormatByFileName(fileName);
                    if (imageFormat == null)
                    {
                        var extension = Path.GetExtension(fileName);
                        MessageBox.Show($"The format with extension {extension} is not supported for export.",
                                        "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    File.OpenWrite(fileName).Using(stream => Save(stream, imageFormat));
                }, ExportFilters);
            }, x => true);

            ImportCommand = new RelayCommand(x =>
            {
                var defaultFileName = $"{Path.GetFileNameWithoutExtension(FileName)}.png";
                FileDialog.OnOpen(fileName =>
                {
                    using (var fStream = File.OpenRead(fileName))
                    {
                        throw new NotImplementedException();
                    }
                }, new List <FileDialogFilter>().AddExtensions("PNG image", "png"));
            }, x => false);

            ZoomLevel = ZoomLevelFit;
        }
Пример #20
0
        public ImageViewerViewModel()
        {
            OpenCommand = new RelayCommand(x =>
            {
                FileDialog.OnOpen(fileName =>
                {
                    LoadImage(fileName);
                }, OpenFilters);
            }, x => !IsTool);

            SaveCommand = new RelayCommand(x =>
            {
                if (IsTool)
                {
                    // Clear current bar entry content before saving.
                    _toolInvokeDesc.SelectedEntry.Stream.SetLength(0);

                    Save(_toolInvokeDesc.SelectedEntry.Stream);
                }
                else if (!string.IsNullOrEmpty(FileName))
                {
                    using (var stream = File.Open(FileName, FileMode.Create))
                    {
                        Save(stream);
                    }
                }
                else
                {
                    SaveAsCommand.Execute(x);
                }
            }, x => ImageFormat != null);

            SaveAsCommand = new RelayCommand(x =>
            {
                var filter = new List <FileDialogFilter>().AddExtensions($"{ImageFormat.Name} format", ImageFormat.Extension);
                FileDialog.OnSave(fileName =>
                {
                    using (var stream = File.Open(fileName, FileMode.Create))
                    {
                        Save(stream);
                    }
                }, filter);
            }, x => ImageFormat != null && !IsTool);

            ExitCommand = new RelayCommand(x =>
            {
                Window.Close();
            }, x => true);

            AboutCommand = new RelayCommand(x =>
            {
                new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
            }, x => true);

            ExportCurrentCommand = new RelayCommand(x =>
            {
                var singleImage = Image?.Source;
                if (singleImage != null)
                {
                    FileDialog.OnSave(fileName =>
                    {
                        var imageFormat = _imageFormatService.GetFormatByFileName(fileName);
                        if (imageFormat == null)
                        {
                            var extension = Path.GetExtension(fileName);
                            MessageBox.Show($"The format with extension {extension} is not supported for export.",
                                            "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }

                        File.OpenWrite(fileName).Using(
                            stream =>
                        {
                            if (imageFormat.IsContainer)
                            {
                                imageFormat.As <IImageMultiple>().Write(
                                    stream,
                                    new ImageFormatService.ImageContainer(new IImageRead[] { singleImage })
                                    );
                            }
                            else
                            {
                                imageFormat.As <IImageSingle>().Write(
                                    stream,
                                    singleImage
                                    );
                            }
                        }
                            );
                    }, ExportToSingleImageFilters);
                }
            }, x => true);

            ExportAllCommand = new RelayCommand(x =>
            {
                var multiImages = GetImagesForExport();
                if (multiImages.Any())
                {
                    FileDialog.OnSave(fileName =>
                    {
                        var imageFormat = _imageFormatService.GetFormatByFileName(fileName);
                        if (imageFormat == null)
                        {
                            var extension = Path.GetExtension(fileName);
                            MessageBox.Show($"The format with extension {extension} is not supported for export.",
                                            "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }

                        var imageContainer = new ImageFormatService.ImageContainer(multiImages);

                        File.OpenWrite(fileName).Using(stream => imageFormat.As <IImageMultiple>().Write(stream, imageContainer));
                    }, ExportToContainerFilters);
                }
            }, x => true);

            ImportCommand = new RelayCommand(
                parameter =>
            {
                AddImage(Enum.Parse <AddPosition>($"{parameter}"));
            },
                x => IsMultipleImageFormat
                );

            CreateNewImgzCommand = new RelayCommand(
                x =>
            {
                if (IsSingleImageFormat || IsMultipleImageFormat)
                {
                    if (MessageBoxResult.OK != MessageBox.Show("This will discard all of existing images.", null, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation))
                    {
                        return;
                    }
                }

                FileName = null;

                EditImageList(
                    currentImageList =>
                {
                    var newImage = CreateDummyImage();
                    return(new EditResult
                    {
                        imageList = new IImageRead[] { newImage },
                        selection = newImage,
                    });
                }
                    );
            }
                );

            ConvertToImgzCommand = new RelayCommand(
                x =>
            {
                FileName = null;

                EditImageList(
                    currentImageList =>
                {
                    return(new EditResult
                    {
                        imageList = new IImageRead[] { Image.Source },
                        selection = Image.Source
                    });
                }
                    );
            },
                x => IsSingleImageFormat
                );

            InsertEmptyImageCommand = new RelayCommand(
                x =>
            {
                AddEmptyImage(AddPosition.BeforeCurrent);
            },
                x => IsMultipleImageFormat
                );

            RemoveImageCommand = new RelayCommand(
                x =>
            {
                EditImageList(
                    currentImageList =>
                {
                    return(new EditResult
                    {
                        imageList = currentImageList.Except(new IImageRead[] { Image?.Source })
                    });
                }
                    );
            },
                x => IsMultipleImageFormat && ImageContainer.Count >= 1
                );

            ConvertBitsPerPixelCommand = new RelayCommand(
                parameter =>
            {
                try
                {
                    EditImageList(
                        currentImageList =>
                    {
                        var sourceImage = Image.Source;

                        var bpp = Convert.ToInt32(parameter);

                        var newImage = ImgdBitmapUtil.ToImgd(
                            sourceImage.CreateBitmap(),
                            bpp,
                            QuantizerFactory.MakeFrom(
                                bpp,
                                UsePngquant ?? false
                                )
                            );

                        return(new EditResult
                        {
                            imageList = currentImageList
                                        .Select(it => ReferenceEquals(it, sourceImage) ? newImage : it),

                            selection = newImage,
                        });
                    }
                        );
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}",
                                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            },
                x => IsMultipleImageFormat && ImageContainer.Count >= 1
                );

            CheckQuant = new RelayCommand(x =>
            {
                if (UsePngquant == true)
                {
                    if (!File.Exists("pngquant.exe"))
                    {
                        UsePngquant = false;

                        string _msg = "PNGQuant was not located in OpenKH's root folder.\n" +
                                      "Please acquire PNGQuant from the link below and\n" +
                                      "place it in the same folder as this viewer.";

                        new MessageDialog(_msg, "https://pngquant.org/pngquant-windows.zip").ShowDialog();
                        OnPropertyChanged(nameof(UsePngquant));
                    }
                }
            });

            ZoomLevel = ZoomLevelFit;
        }
Пример #21
0
        private void CreateCommands()
        {
            // SAVE COMMAND
            SaveCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;

                if (doc.MarkdownDocument.Filename == "untitled")
                {
                    SaveAsCommand.Execute(tab);
                }
                else
                {
                    doc.SaveDocument();
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(this.ActiveDocument.IsDirty);
            });

            // SAVEAS COMMAND
            SaveAsCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var folder = Path.GetDirectoryName(doc.MarkdownDocument.Filename);

                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter           = "Markdown files (*.md)|*.md|All files (*.*)|*.*",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = doc.MarkdownDocument.Filename,
                    CheckFileExists  = false,
                    OverwritePrompt  = false,
                    CheckPathExists  = true,
                    RestoreDirectory = true
                };

                var result = sd.ShowDialog();
                if (result != null && result.Value)
                {
                    doc.MarkdownDocument.Filename = sd.FileName;
                    doc.SaveDocument();
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(true);
            });

            // PREVIEW BUTTON COMMAND
            PreviewBrowserCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }

                var editor = tab.Tag as MarkdownDocumentEditor;

                Configuration.IsPreviewVisible = IsPreviewBrowserVisible;

                Window.ShowPreviewBrowser(!IsPreviewBrowserVisible);
                if (IsPreviewBrowserVisible)
                {
                    Window.PreviewMarkdown(editor);
                }
            }, null);

            // MARKDOWN EDIT COMMANDS TOOLBAR COMMAND
            ToolbarInsertMarkdownCommand = new CommandBase((s, e) =>
            {
                var editor = Window.GetActiveMarkdownEditor();
                if (editor == null || editor.AceEditor == null)
                {
                    return;
                }

                string action = s as string;

                editor.ProcessEditorUpdateCommand(action);
            }, null);

            // Settings
            SettingsCommand = new CommandBase((s, e) =>
            {
                var file = Path.Combine(mmApp.Configuration.CommonFolder, "MarkdownMonster.json");

                // save settings first so we're looking at current setting
                Configuration.Write();

                Window.OpenTab(file, syntax: "json");
            }, null);
        }
Пример #22
0
        public ImageViewerViewModel()
        {
            OpenCommand = new RelayCommand(x =>
            {
                FileDialog.OnOpen(fileName =>
                {
                    LoadImage(fileName);
                }, OpenFilters);
            }, x => !IsTool);

            SaveCommand = new RelayCommand(x =>
            {
                if (IsTool)
                {
                    Save(_toolInvokeDesc.SelectedEntry.Stream);
                }
                else if (!string.IsNullOrEmpty(FileName))
                {
                    using (var stream = File.Open(FileName, FileMode.Create))
                    {
                        Save(stream);
                    }
                }
                else
                {
                    SaveAsCommand.Execute(x);
                }
            }, x => ImageFormat != null);

            SaveAsCommand = new RelayCommand(x =>
            {
                var filter = new List <FileDialogFilter>().AddExtensions($"{ImageFormat.Name} format", ImageFormat.Extension);
                FileDialog.OnSave(fileName =>
                {
                    using (var stream = File.Open(fileName, FileMode.Create))
                    {
                        Save(stream);
                    }
                }, filter);
            }, x => ImageFormat != null && !IsTool);

            ExitCommand = new RelayCommand(x =>
            {
                Window.Close();
            }, x => true);

            AboutCommand = new RelayCommand(x =>
            {
                new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
            }, x => true);

            ExportCommand = new RelayCommand(x =>
            {
                FileDialog.OnSave(fileName =>
                {
                    var imageFormat = _imageFormatService.GetFormatByFileName(fileName);
                    if (imageFormat == null)
                    {
                        var extension = Path.GetExtension(fileName);
                        MessageBox.Show($"The format with extension {extension} is not supported for export.",
                                        "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    File.OpenWrite(fileName).Using(stream => Save(stream, imageFormat));
                }, ExportFilters);
            }, x => true);

            ImportCommand = new RelayCommand(
                parameter =>
            {
                AddImage(Enum.Parse <AddPosition>($"{parameter}"));
            },
                x => IsMultipleImageFormat
                );

            CreateNewImgzCommand = new RelayCommand(
                x =>
            {
                if (IsSingleImageFormat || IsMultipleImageFormat)
                {
                    if (MessageBoxResult.OK != MessageBox.Show("This will discard all of existing images.", null, MessageBoxButton.OKCancel, MessageBoxImage.Exclamation))
                    {
                        return;
                    }
                }

                FileName = null;

                EditImageList(
                    currentImageList =>
                {
                    var newImage = CreateDummyImage();
                    return(new EditResult
                    {
                        imageList = new IImageRead[] { newImage },
                        selection = newImage,
                    });
                }
                    );
            }
                );

            ConvertToImgzCommand = new RelayCommand(
                x =>
            {
                FileName = null;

                EditImageList(
                    currentImageList =>
                {
                    return(new EditResult
                    {
                        imageList = new IImageRead[] { Image.Source },
                        selection = Image.Source
                    });
                }
                    );
            },
                x => IsSingleImageFormat
                );

            InsertEmptyImageCommand = new RelayCommand(
                x =>
            {
                AddEmptyImage(AddPosition.BeforeCurrent);
            },
                x => IsMultipleImageFormat
                );

            RemoveImageCommand = new RelayCommand(
                x =>
            {
                EditImageList(
                    currentImageList =>
                {
                    return(new EditResult
                    {
                        imageList = currentImageList.Except(new IImageRead[] { Image?.Source })
                    });
                }
                    );
            },
                x => IsMultipleImageFormat && ImageContainer.Count >= 1
                );

            ConvertBitsPerPixelCommand = new RelayCommand(
                parameter =>
            {
                try
                {
                    EditImageList(
                        currentImageList =>
                    {
                        var sourceImage = Image.Source;

                        var bpp = Convert.ToInt32(parameter);

                        var newImage = ImgdBitmapUtil.ToImgd(
                            sourceImage.CreateBitmap(),
                            bpp,
                            QuantizerFactory.MakeFrom(
                                bpp,
                                UsePngquant ?? false
                                )
                            );

                        return(new EditResult
                        {
                            imageList = currentImageList
                                        .Select(it => ReferenceEquals(it, sourceImage) ? newImage : it),

                            selection = newImage,
                        });
                    }
                        );
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"{ex.Message}",
                                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            },
                x => IsMultipleImageFormat && ImageContainer.Count >= 1
                );

            ZoomLevel = ZoomLevelFit;
        }
Пример #23
0
        private void CreateCommands()
        {
            // SAVE COMMAND
            SaveCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;

                if (doc.MarkdownDocument.Filename == "untitled")
                {
                    SaveAsCommand.Execute(tab);
                }
                else if (!doc.SaveDocument())
                {
                    SaveAsCommand.Execute(tab);
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(this.ActiveDocument.IsDirty);
            });

            // SAVEAS COMMAND
            SaveAsCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }
                var doc = tab.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var filename = doc.MarkdownDocument.Filename;

                var folder = Path.GetDirectoryName(doc.MarkdownDocument.Filename);
                if (filename == "untitled")
                {
                    folder = mmApp.Configuration.LastFolder;

                    var match = Regex.Match(doc.GetMarkdown(), @"^# (\ *)(?<Header>.+)", RegexOptions.Multiline);

                    if (match.Success)
                    {
                        filename = match.Groups["Header"].Value;
                        if (!string.IsNullOrEmpty(filename))
                        {
                            filename = mmFileUtils.SafeFilename(filename);
                        }
                    }
                }

                if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
                {
                    folder = mmApp.Configuration.LastFolder;
                    if (string.IsNullOrEmpty(folder) || !Directory.Exists(folder))
                    {
                        folder = KnownFolders.GetPath(KnownFolder.Libraries);
                    }
                }

                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter           = "Markdown files (*.md)|*.md|Markdown files (*.markdown)|*.markdown|All files (*.*)|*.*",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = filename,
                    CheckFileExists  = false,
                    OverwritePrompt  = false,
                    CheckPathExists  = true,
                    RestoreDirectory = true
                };

                bool?result = null;
                try
                {
                    result = sd.ShowDialog();
                }
                catch (Exception ex)
                {
                    mmApp.Log("Unable to save file: " + doc.MarkdownDocument.Filename, ex);
                    MessageBox.Show(
                        $@"Unable to open file:\r\n\r\n" + ex.Message,
                        "An error occurred trying to open a file",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }


                if (result != null && result.Value)
                {
                    doc.MarkdownDocument.Filename = sd.FileName;
                    if (!doc.SaveDocument())
                    {
                        MessageBox.Show(Window, $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                        "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                        SaveAsCommand.Execute(tab);
                        return;
                    }
                }

                mmApp.Configuration.LastFolder = folder;

                Window.SetWindowTitle();
                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null)
                {
                    return(false);
                }

                return(true);
            });

            // SAVEASHTML COMMAND
            SaveAsHtmlCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl?.SelectedItem as TabItem;
                var doc = tab?.Tag as MarkdownDocumentEditor;
                if (doc == null)
                {
                    return;
                }

                var folder = Path.GetDirectoryName(doc.MarkdownDocument.Filename);

                SaveFileDialog sd = new SaveFileDialog
                {
                    Filter           = "Html files (Html only) (*.html)|*.html|Html files (Html and dependencies in a folder)|*.html",
                    FilterIndex      = 1,
                    InitialDirectory = folder,
                    FileName         = Path.ChangeExtension(doc.MarkdownDocument.Filename, "html"),
                    CheckFileExists  = false,
                    OverwritePrompt  = false,
                    CheckPathExists  = true,
                    RestoreDirectory = true
                };

                bool?result = null;
                try
                {
                    result = sd.ShowDialog();
                }catch (Exception ex)
                {
                    mmApp.Log("Unable to save html file: " + doc.MarkdownDocument.Filename, ex);
                    MessageBox.Show(
                        $@"Unable to open file:\r\n\r\n" + ex.Message,
                        "An error occurred trying to open a file",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }

                if (result != null && result.Value)
                {
                    if (sd.FilterIndex != 2)
                    {
                        var html = doc.RenderMarkdown(doc.GetMarkdown(), mmApp.Configuration.MarkdownOptions.RenderLinksAsExternal);

                        if (!doc.MarkdownDocument.WriteFile(sd.FileName, html))
                        {
                            MessageBox.Show(Window,
                                            $"{sd.FileName}\r\n\r\nThis document can't be saved in this location. The file is either locked or you don't have permissions to save it. Please choose another location to save the file.",
                                            "Unable to save Document", MessageBoxButton.OK, MessageBoxImage.Warning);
                            SaveAsHtmlCommand.Execute(null);
                            return;
                        }
                    }
                    else
                    {
                        string msg   = @"This feature is not available yet.

For now, you can use 'View in Web Browser' to view the document in your favorite Web Browser and use 'Save As...' to save the Html document with all CSS and Image dependencies.

Do you want to View in Browser now?
";
                        var mbResult = MessageBox.Show(msg,
                                                       mmApp.ApplicationName,
                                                       MessageBoxButton.YesNo,
                                                       MessageBoxImage.Asterisk,
                                                       MessageBoxResult.Yes);

                        if (mbResult == MessageBoxResult.Yes)
                        {
                            Window.ButtonViewInBrowser_Click(Window, null);
                        }
                    }
                }

                Window.PreviewMarkdown(doc, keepScrollPosition: true);
            }, (s, e) =>
            {
                if (ActiveDocument == null || ActiveEditor == null)
                {
                    return(false);
                }
                if (ActiveDocument.Filename == "untitled")
                {
                    return(true);
                }
                if (ActiveEditor.EditorSyntax != "markdown")
                {
                    return(false);
                }

                return(true);
            });

            // NEW DOCUMENT COMMAND (ctrl-n)
            NewDocumentCommand = new CommandBase((s, e) =>
            {
                Window.OpenTab("untitled");
            });

            // OPEN DOCUMENT COMMAND
            OpenDocumentCommand = new CommandBase((s, e) =>
            {
                var fd = new OpenFileDialog
                {
                    DefaultExt = ".md",
                    Filter     = "Markdown files (*.md,*.markdown)|*.md;*.markdown|" +
                                 "Html files (*.htm,*.html)|*.htm;*.html|" +
                                 "Javascript files (*.js)|*.js|" +
                                 "Typescript files (*.ts)|*.ts|" +
                                 "Json files (*.json)|*.json|" +
                                 "Css files (*.css)|*.css|" +
                                 "Xml files (*.xml,*.config)|*.xml;*.config|" +
                                 "C# files (*.cs)|*.cs|" +
                                 "C# Razor files (*.cshtml)|*.cshtml|" +
                                 "Foxpro files (*.prg)|*.prg|" +
                                 "Powershell files (*.ps1)|*.ps1|" +
                                 "Php files (*.php)|*.php|" +
                                 "Python files (*.py)|*.py|" +
                                 "All files (*.*)|*.*",
                    CheckFileExists  = true,
                    RestoreDirectory = true,
                    Multiselect      = true,
                    Title            = "Open Markdown File"
                };

                if (!string.IsNullOrEmpty(mmApp.Configuration.LastFolder))
                {
                    fd.InitialDirectory = mmApp.Configuration.LastFolder;
                }

                bool?res = null;
                try
                {
                    res = fd.ShowDialog();
                }
                catch (Exception ex)
                {
                    mmApp.Log("Unable to open file.", ex);
                    MessageBox.Show(
                        $@"Unable to open file:\r\n\r\n" + ex.Message,
                        "An error occurred trying to open a file",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    return;
                }
                if (res == null || !res.Value)
                {
                    return;
                }

                foreach (var file in fd.FileNames)
                {
                    Window.OpenTab(file, rebindTabHeaders: true);
                    Window.AddRecentFile(file);
                }
            });

            CloseActiveDocumentCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }

                if (Window.CloseTab(tab))
                {
                    Window.TabControl.Items.Remove(tab);
                }
            }, (s, e) => IsEditorActive)
            {
                Caption = "_Close Document",
                ToolTip = "Closes the active tab and asks to save the document."
            };


            // PREVIEW BUTTON COMMAND
            PreviewBrowserCommand = new CommandBase((s, e) =>
            {
                var tab = Window.TabControl.SelectedItem as TabItem;
                if (tab == null)
                {
                    return;
                }

                var editor = tab.Tag as MarkdownDocumentEditor;

                Configuration.IsPreviewVisible = IsPreviewBrowserVisible;

                if (!IsPreviewBrowserVisible && IsPresentationMode)
                {
                    PresentationModeCommand.Execute(null);
                }


                Window.ShowPreviewBrowser(!IsPreviewBrowserVisible);
                if (IsPreviewBrowserVisible)
                {
                    Window.PreviewMarkdown(editor);
                }
            }, null);

            // MARKDOWN EDIT COMMANDS TOOLBAR COMMAND
            ToolbarInsertMarkdownCommand = new CommandBase((s, e) =>
            {
                var editor = Window.GetActiveMarkdownEditor();
                if (editor == null || editor.AceEditor == null)
                {
                    return;
                }

                string action = s as string;

                editor.ProcessEditorUpdateCommand(action);
            }, null);

            // Settings
            SettingsCommand = new CommandBase((s, e) =>
            {
                var file = Path.Combine(mmApp.Configuration.CommonFolder, "MarkdownMonster.json");

                // save settings first so we're looking at current setting
                Configuration.Write();

                string fileText = File.ReadAllText(file);
                if (!fileText.StartsWith("//"))
                {
                    fileText = "// Reference: http://markdownmonster.west-wind.com/docs/_4nk01yq6q.htm\r\n" +
                               fileText;
                    File.WriteAllText(file, fileText);
                }

                Window.OpenTab(file, syntax: "json");
            }, null);

            // DISTRACTION FREE MODE
            DistractionFreeModeCommand = new CommandBase((s, e) =>
            {
                GridLength gl = new GridLength(0);
                if (Window.WindowGrid.RowDefinitions[1].Height == gl)
                {
                    gl = new GridLength(30);
                    IsPreviewBrowserVisible = true;
                    Window.PreviewMarkdown();
                    IsFullScreen = false;
                }
                else
                {
                    IsPreviewBrowserVisible = false;
                    Window.ShowPreviewBrowser(hide: true);
                    IsFullScreen = true;
                }

                Window.WindowGrid.RowDefinitions[1].Height = gl;
                //Window.WindowGrid.RowDefinitions[3].Height = gl;
            }, null);

            // PRESENTATION MODE
            PresentationModeCommand = new CommandBase((s, e) =>
            {
                if (IsFullScreen)
                {
                    DistractionFreeModeCommand.Execute(null);
                }

                GridLength gl = new GridLength(0);
                if (Window.WindowGrid.RowDefinitions[1].Height == gl)
                {
                    gl = new GridLength(30); // toolbar height

                    Window.ContentGrid.ColumnDefinitions[0].Width = new GridLength(1, GridUnitType.Star);
                    Window.ContentGrid.ColumnDefinitions[1].Width = new GridLength(0);
                    Window.ContentGrid.ColumnDefinitions[2].Width = new GridLength(mmApp.Configuration.WindowPosition.SplitterPosition);
                    Window.PreviewMarkdown();
                    IsPresentationMode = false;
                }
                else
                {
                    mmApp.Configuration.WindowPosition.SplitterPosition =
                        Convert.ToInt32(Window.ContentGrid.ColumnDefinitions[2].Width.Value);

                    // don't allow presentation mode for non-Markdown documents
                    var editor = Window.GetActiveMarkdownEditor();
                    if (editor != null)
                    {
                        var file = editor.MarkdownDocument.Filename.ToLower();
                        var ext  = Path.GetExtension(file);
                        if (file != "untitled" && ext != ".md" && ext != ".htm" && ext != ".html")
                        {
                            // don't allow presentation mode for non markdown files
                            IsPresentationMode      = false;
                            IsPreviewBrowserVisible = false;
                            Window.ShowPreviewBrowser(true);
                            return;
                        }
                    }

                    Window.ShowPreviewBrowser();

                    Window.ContentGrid.ColumnDefinitions[0].Width = gl;
                    Window.ContentGrid.ColumnDefinitions[1].Width = gl;
                    Window.ContentGrid.ColumnDefinitions[2].Width = new GridLength(1, GridUnitType.Star);

                    IsPresentationMode      = true;
                    IsPreviewBrowserVisible = true;
                }

                Window.WindowGrid.RowDefinitions[1].Height = gl;
                //Window.WindowGrid.RowDefinitions[3].Height = gl;
            }, null);

            // PRINT PREVIEW
            PrintPreviewCommand = new CommandBase((s, e) =>
            {
                dynamic dom = Window.PreviewBrowser.Document;
                dom.execCommand("print", true, null);
            }, (s, e) => IsPreviewBrowserVisible);
        }
Пример #24
0
        public BarViewModel() : base(new BarEntryModel[0])
        {
            Types = new EnumModel <Bar.EntryType>();

            NewCommand = new RelayCommand(x =>
            {
                FileName = "untitled.bar";
                Items.Clear();
                MotionsetType = 0;
            }, x => true);

            OpenCommand = new RelayCommand(x =>
            {
                FileDialog.OnOpen(fileName =>
                {
                    OpenFileName(fileName);
                    FileName = fileName;
                }, Filters);
            }, x => true);

            SaveCommand = new RelayCommand(x =>
            {
                if (!string.IsNullOrEmpty(FileName))
                {
                    SaveToFile(FileName);
                }
                else
                {
                    SaveAsCommand.Execute(x);
                }
            }, x => true);

            SaveAsCommand = new RelayCommand(x =>
            {
                FileDialog.OnSave(fileName =>
                {
                    SaveToFile(fileName);
                }, Filters, Path.GetFileName(FileName));
            }, x => true);

            ExitCommand = new RelayCommand(x =>
            {
                Window.Close();
            }, x => true);

            AboutCommand = new RelayCommand(x =>
            {
                new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
            }, x => true);

            OpenItemCommand = new RelayCommand(x =>
            {
                try
                {
                    var tempFileName = SaveToTempraryFile();
                    switch (ToolsLoaderService.OpenTool(FileName, tempFileName, SelectedItem.Entry))
                    {
                    case Common.ToolInvokeDesc.ContentChangeInfo.File:
                        ReloadFromTemporaryFile(tempFileName);
                        break;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                OnPropertyChanged(nameof(SelectedItem));
            }, x => true);

            ExportCommand = new RelayCommand(x =>
            {
                var defaultFileName = GetSuggestedFileName(SelectedItem.Entry);

                FileDialog.OnSave(fileName =>
                {
                    using var fStream = File.OpenWrite(fileName);
                    SelectedItem.Entry.Stream.Position = 0;
                    SelectedItem.Entry.Stream.CopyTo(fStream);
                }, Filters, defaultFileName);
            }, x => IsItemSelected);

            ExportAllCommand = new RelayCommand(x =>
            {
                FileDialog.OnFolder(folder =>
                {
                    foreach (var item in Items.Select(item => item.Entry))
                    {
                        var fileName         = GetSuggestedFileName(item);
                        using var fStream    = File.OpenWrite(Path.Combine(folder, fileName));
                        item.Stream.Position = 0;
                        item.Stream.CopyTo(fStream);
                    }
                });
            }, x => true);

            ImportCommand = new RelayCommand(x =>
            {
                FileDialog.OnOpen(fileName =>
                {
                    var fStream   = File.OpenRead(fileName);
                    var memStream = new MemoryStream((int)fStream.Length);
                    fStream.CopyTo(memStream);
                    SelectedItem.Entry.Stream = memStream;

                    OnPropertyChanged(nameof(SelectedItem));
                }, Filters);
            }, x => IsItemSelected);
        }
Пример #25
0
        public BarViewModel(IEnumerable <BarEntryModel> list) :
            base(list)
        {
            Types = new EnumModel <Bar.EntryType>();

            OpenCommand = new RelayCommand(x =>
            {
                var fd = FileDialog.Factory(Window, FileDialog.Behavior.Open, FileDialog.Type.Any);
                if (fd.ShowDialog() == true)
                {
                    using (var stream = File.Open(fd.FileName, FileMode.Open))
                    {
                        FileName = fd.FileName;
                        Items.Clear();
                        foreach (var item in Bar.Read(stream))
                        {
                            Items.Add(new BarEntryModel(item));
                        }
                    }
                }
            }, x => true);

            SaveCommand = new RelayCommand(x =>
            {
                if (!string.IsNullOrEmpty(FileName))
                {
                    using (var stream = File.Open(FileName, FileMode.Create))
                    {
                        Bar.Write(stream, Items.Select(item => item.Entry));
                    }
                }
                else
                {
                    SaveAsCommand.Execute(x);
                }
            }, x => true);

            SaveAsCommand = new RelayCommand(x =>
            {
                var fd = FileDialog.Factory(Window, FileDialog.Behavior.Save, FileDialog.Type.Any);
                if (fd.ShowDialog() == true)
                {
                    using (var stream = File.Open(fd.FileName, FileMode.Create))
                    {
                        Bar.Write(stream, Items.Select(item => item.Entry));
                    }
                }
            }, x => true);

            ExitCommand = new RelayCommand(x =>
            {
                Window.Close();
            }, x => true);

            AboutCommand = new RelayCommand(x =>
            {
                new AboutDialog(Assembly.GetExecutingAssembly()).ShowDialog();
            }, x => true);

            OpenItemCommand = new RelayCommand(x =>
            {
                try
                {
                    ToolsLoaderService.OpenTool(SelectedItem.Entry.Stream, SelectedItem.Type);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                OnPropertyChanged(nameof(SelectedItem));
            }, x => true);

            ExportCommand = new RelayCommand(x =>
            {
                var fd             = FileDialog.Factory(Window, FileDialog.Behavior.Save);
                fd.DefaultFileName = $"{SelectedItem.Entry.Name}.bin";

                if (fd.ShowDialog() == true)
                {
                    using (var fStream = File.OpenWrite(fd.FileName))
                    {
                        SelectedItem.Entry.Stream.Position = 0;
                        SelectedItem.Entry.Stream.CopyTo(fStream);
                    }
                }
            }, x => IsItemSelected);

            ExportAllCommand = new RelayCommand(x =>
            {
                var fd = FileDialog.Factory(Window, FileDialog.Behavior.Folder);

                if (fd.ShowDialog() == true)
                {
                    var basePath = fd.FileName;
                    foreach (var item in Items.Select(item => item.Entry))
                    {
                        var fileName = $"{item.Name}.bin";
                        using (var fStream = File.OpenWrite(Path.Combine(basePath, fileName)))
                        {
                            item.Stream.Position = 0;
                            item.Stream.CopyTo(fStream);
                        }
                    }
                }
            }, x => true);

            ImportCommand = new RelayCommand(x =>
            {
                var fd = FileDialog.Factory(Window, FileDialog.Behavior.Open);
                if (fd.ShowDialog() == true)
                {
                    using (var fStream = File.OpenRead(fd.FileName))
                    {
                        var memStream = new MemoryStream((int)fStream.Length);
                        fStream.CopyTo(memStream);
                        SelectedItem.Entry.Stream = memStream;
                    }

                    OnPropertyChanged(nameof(SelectedItem.Size));
                }
            }, x => IsItemSelected);
            SearchCommand = new RelayCommand(x => { }, x => false);
        }