diff options
author | Brandon Scott <xeons@users.noreply.github.com> | 2019-10-26 15:31:43 -0500 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-10-27 00:44:42 +0200 |
commit | f947353a562f89200baf1a833c395dd766d3f762 (patch) | |
tree | c6a0d7880923d2c45ba0f4e53aec449a21331605 /Applications/HexEditor/HexEditorWidget.cpp | |
parent | 90c81d5c162e4b342706f156f2e4fb8ae88a844b (diff) | |
download | serenity-f947353a562f89200baf1a833c395dd766d3f762.zip |
HexEditor: Added new file action.
Added a new file action, allowing you to create a new file of a specific
size.
Diffstat (limited to 'Applications/HexEditor/HexEditorWidget.cpp')
-rw-r--r-- | Applications/HexEditor/HexEditorWidget.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp index 5264be4795..c6d42519bb 100644 --- a/Applications/HexEditor/HexEditorWidget.cpp +++ b/Applications/HexEditor/HexEditorWidget.cpp @@ -42,6 +42,31 @@ HexEditorWidget::HexEditorWidget() m_statusbar = GStatusBar::construct(5, this); + m_new_action = GAction::create("New", { Mod_Ctrl, Key_N }, GraphicsBitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GAction&) { + if (m_document_dirty) { + auto save_document_first_box = GMessageBox::construct("Save Document First?", "Warning", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window()); + auto save_document_first_result = save_document_first_box->exec(); + + if (save_document_first_result != GDialog::ExecResult::ExecOK) + return; + m_save_action->activate(); + } + + auto input_box = GInputBox::construct("Enter new file size:", "New file size", this); + if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { + auto valid = false; + auto file_size = input_box->text_value().to_int(valid); + if (valid) { + m_document_dirty = false; + m_editor->set_buffer(ByteBuffer::create_zeroed(file_size)); + set_path(FileSystemPath()); + update_title(); + } else { + GMessageBox::show(String::format("Invalid file size entered.", strerror(errno)), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window()); + } + } + }); + m_open_action = GCommonActions::make_open_action([this](auto&) { Optional<String> open_path = GFilePicker::get_open_filepath(); @@ -82,6 +107,7 @@ HexEditorWidget::HexEditorWidget() auto menubar = make<GMenuBar>(); auto app_menu = make<GMenu>("Hex Editor"); + app_menu->add_action(*m_new_action); app_menu->add_action(*m_open_action); app_menu->add_action(*m_save_action); app_menu->add_action(*m_save_as_action); |