Пример #1
0
        private void OnCreateFile(object sender, EventArgs e)
        {
            if (!TrySaveModified())
            {
                return;
            }

            var dialog = new NewFileDialog("Create file", true)
            {
                StartPosition = FormStartPosition.CenterParent
            };

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                _textViewModel.Base64Key = _cryptoServiceFacade.EncryptPassword(dialog.Password);
                TextArea.Enabled         = true;

                if (dialog.Path == "")
                {
                    TextArea.Text = "";
                    ActiveControl = TextArea;
                }
                else
                {
                    TextArea.Lines = _cryptoServiceFacade
                                     .ImportFromTextFile(dialog.Path)
                                     .ToArray();
                }

                Name = "new* - " + Constants.ApplicationTitle;
                _textViewModel.FileStatus = FileStatus.NotCreated;
            }
        }
Пример #2
0
        private void OnOpenFile(object sender, EventArgs e)
        {
            string[]      lines;
            NewFileDialog dialog;

            if (!TrySaveModified())
            {
                return;
            }

            if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _textViewModel.FilePath = openDialog.FileName;
                dialog = new NewFileDialog("Open file")
                {
                    StartPosition = FormStartPosition.CenterParent
                };

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    _textViewModel.Base64Key = _cryptoServiceFacade.EncryptPassword(dialog.Password);
                    lines = _cryptoServiceFacade
                            .LoadFile(_textViewModel.FilePath, _textViewModel.Base64Key)
                            .ToArray();

                    if (lines != null)
                    {
                        TextArea.Lines = lines;
                    }
                    TextArea.Enabled          = true;
                    Text                      = Path.GetFileNameWithoutExtension(openDialog.FileName) + " - " + Constants.ApplicationTitle;
                    _textViewModel.FileStatus = FileStatus.Saved;
                }
            }
        }
Пример #3
0
        private void OnChangePassword(object sender, EventArgs e)
        {
            if (_textViewModel.FileStatus == FileStatus.Null)
            {
                return;
            }
            NewFileDialog dialog = new NewFileDialog("New password");

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                _textViewModel.Base64Key = _cryptoServiceFacade.EncryptPassword(dialog.Password);
                Save();
                MessageBox.Show("Password updated!");
                _textViewModel.FileStatus = FileStatus.Saved;
            }
        }