public override async Task ExecuteAsync()
        {
            if (_docInfoService.IsModifiedDocument)
            {
                MessageDialogResult messageDialogResult = await _messageDialog.ShowDialogAsync(
                    new MessageDialogOptions { Title = "Notepad", Content = $"Do you want to save the {_docInfoService.UsedFileNameWithExtension} changes?", Button = MessageBoxButton.YesNoCancel });

                switch (messageDialogResult.MessageDialogResultType)
                {
                case MessageDialogResultType.Yes:
                {
                    if (_docInfoService.IsOpenedDocument)
                    {
                        await _textFileWriter.WriteAsync(new WriteTextFileModel { FilePath = _docInfoService.UsedFilePath, Content = CallerViewModel.InputTextBoxViewModel.Content });
                    }
                    else
                    {
                        SaveFileDialogResult saveFileDialogResult = await _saveFileDialog.ShowDialogAsync(new SaveFileDialogOptions { FileFilters = GetSaveFileDialogFilters() });

                        if (saveFileDialogResult.SaveFileDialogResultType == SaveFileDialogResultType.Ok)
                        {
                            await _textFileWriter.WriteAsync(new WriteTextFileModel { FilePath = saveFileDialogResult.SavedFilePath, Content = CallerViewModel.InputTextBoxViewModel.Content });

                            _docInfoService.SetFilePath(saveFileDialogResult.SavedFilePath);
                        }
                        else if (saveFileDialogResult.SaveFileDialogResultType == SaveFileDialogResultType.Cancel)
                        {
                            return;
                        }
                    }

                    _docInfoService.SetUnmodifiedDocumentState();
                    CallerViewModel.WindowSettingsViewModel.Title = _docInfoService.UsedFileNameWithoutExtension;

                    break;
                }

                case MessageDialogResultType.Cancel:
                {
                    return;
                }
                }
            }

            OpenFileDialogResult openFileDialogResult = await _openFileDialog.ShowDialogAsync(new OpenFileDialogOptions { FileFilters = GetOpenFileDialogFilters() });

            if (openFileDialogResult.OpenFileDialogResultType == OpenFileDialogResultType.Ok)
            {
                CallerViewModel.InputTextBoxViewModel.Content = await _textFileReader.ReadAsync <string>(new ReadTextFileModel { FilePath = openFileDialogResult.FilePath });

                _docInfoService.SetFilePath(openFileDialogResult.FilePath);
                _docInfoService.SetUnmodifiedDocumentState();

                CallerViewModel.WindowSettingsViewModel.Title = _docInfoService.UsedFileNameWithoutExtension;
            }
        }
예제 #2
0
        public override async Task ExecuteAsync(GoToLineWindow window)
        {
            if (IsLineNumberGreaterThanDocumentLines(CallerViewModel.LineNumber !.Value, _docInfoService.ContentLines))
            {
                MessageDialogOptions dialogOptions = new() { Content = "The line number exceeds the total line number", Title = window.Title, Button = MessageBoxButton.OK, Icon = MessageBoxImage.Warning };
                await _messageDialog.ShowDialogAsync(dialogOptions);

                return;
            }

            window.DialogResult = true;
        }
예제 #3
0
        private async void ShowUnhandledException(ErrorModel errorModel)
        {
            IMessageDialog messageDialog = _host.Services.GetRequiredService <IMessageDialog>();

            await messageDialog.ShowDialogAsync(new MessageDialogOptions
            {
                Content = $"An application error occurred.\n\n{errorModel.Message}.\n\n{errorModel.Exception}",
                Title   = "Application Error",
                Button  = MessageBoxButton.OK,
                Icon    = MessageBoxImage.Error
            });

            Current.Shutdown();
        }
        private async void FindNextTextToReplace()
        {
            int searchedTextStartIndex = GetNextSearchedTextStartIndex();

            if (searchedTextStartIndex == -1)
            {
                await _messageDialog.ShowDialogAsync(
                    new MessageDialogOptions { Title = "Notepad", Content = $"'{_findNextAndReplaceConditionsService.FindWhat}' was not found!", Button = MessageBoxButton.OK, Icon = MessageBoxImage.Information });
            }
            else
            {
                CallerViewModel.InputTextBoxViewModel.CaretIndex      = searchedTextStartIndex;
                CallerViewModel.InputTextBoxViewModel.SelectionLength = _findNextAndReplaceConditionsService.FindWhat.Length;
            }

            CallerViewModel.WindowSettingsViewModel.Activated = true;
        }
        public override async Task ExecuteAsync(CancelEventArgs eventArgs)
        {
            if (_docInfoService.IsModifiedDocument)
            {
                MessageDialogResult messageDialogResult = await _messageDialog.ShowDialogAsync(
                    new MessageDialogOptions { Title = "Notepad", Content = $"Do you want to save the {_docInfoService.UsedFileNameWithExtension} changes?", Button = MessageBoxButton.YesNoCancel });

                switch (messageDialogResult.MessageDialogResultType)
                {
                case MessageDialogResultType.Yes:
                {
                    if (_docInfoService.IsOpenedDocument)
                    {
                        await _textFileWriter.WriteAsync(new WriteTextFileModel { FilePath = _docInfoService.UsedFilePath, Content = CallerViewModel.InputTextBoxViewModel.Content });
                    }
                    else
                    {
                        SaveFileDialogResult saveFileDialogResult = await _saveFileDialog.ShowDialogAsync(new SaveFileDialogOptions { FileFilters = GetSaveFileDialogFilters() });

                        if (saveFileDialogResult.SaveFileDialogResultType == SaveFileDialogResultType.Ok)
                        {
                            await _textFileWriter.WriteAsync(new WriteTextFileModel { FilePath = saveFileDialogResult.SavedFilePath, Content = CallerViewModel.InputTextBoxViewModel.Content });
                        }
                        else if (saveFileDialogResult.SaveFileDialogResultType == SaveFileDialogResultType.Cancel)
                        {
                            eventArgs.Cancel = true;
                            return;
                        }
                    }

                    break;
                }

                case MessageDialogResultType.Cancel:
                {
                    eventArgs.Cancel = true;
                    return;
                }
                }
            }

            System.Windows.Application.Current.Shutdown();
        }