summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorBrandon Scott <xeons@users.noreply.github.com>2019-10-26 17:41:59 -0500
committerAndreas Kling <awesomekling@gmail.com>2019-10-27 00:44:42 +0200
commit98e556fee9504dd18dc3fd5abb1feebfb989e908 (patch)
tree97277b7b88ac25d6b7c83f15d89ae0c684407b63 /Applications
parentc77fe5161c4a5686522945ae1d360f696de838f3 (diff)
downloadserenity-98e556fee9504dd18dc3fd5abb1feebfb989e908.zip
HexEditor: Created has_selection() method.
Created has_selection() method and fixed a few small issues.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/HexEditor/HexEditor.cpp8
-rw-r--r--Applications/HexEditor/HexEditor.h1
-rw-r--r--Applications/HexEditor/HexEditorWidget.cpp4
3 files changed, 7 insertions, 6 deletions
diff --git a/Applications/HexEditor/HexEditor.cpp b/Applications/HexEditor/HexEditor.cpp
index 46d00c4da1..2e675cf23b 100644
--- a/Applications/HexEditor/HexEditor.cpp
+++ b/Applications/HexEditor/HexEditor.cpp
@@ -46,7 +46,7 @@ void HexEditor::set_buffer(const ByteBuffer& buffer)
void HexEditor::fill_selection(u8 fill_byte)
{
- if (m_selection_start == -1 || m_selection_end == -1 || (m_selection_end - m_selection_start) < 0 || m_buffer.is_empty())
+ if (!has_selection())
return;
for (int i = m_selection_start; i <= m_selection_end; i++) {
@@ -104,7 +104,7 @@ bool HexEditor::write_to_file(const StringView& path)
bool HexEditor::copy_selected_hex_to_clipboard()
{
- if (m_selection_start == -1 || m_selection_end == -1 || (m_selection_end - m_selection_start) < 0 || m_buffer.is_empty())
+ if (!has_selection())
return false;
StringBuilder output_string_builder;
@@ -118,7 +118,7 @@ bool HexEditor::copy_selected_hex_to_clipboard()
bool HexEditor::copy_selected_text_to_clipboard()
{
- if (m_selection_start == -1 || m_selection_end == -1 || (m_selection_end - m_selection_start) < 0)
+ if (!has_selection())
return false;
StringBuilder output_string_builder;
@@ -132,7 +132,7 @@ bool HexEditor::copy_selected_text_to_clipboard()
bool HexEditor::copy_selected_hex_to_clipboard_as_c_code()
{
- if (m_selection_start == -1 || m_selection_end == -1 || (m_selection_end - m_selection_start) < 0 || m_buffer.is_empty())
+ if (!has_selection())
return false;
StringBuilder output_string_builder;
diff --git a/Applications/HexEditor/HexEditor.h b/Applications/HexEditor/HexEditor.h
index 4a0b5629b3..99183046dd 100644
--- a/Applications/HexEditor/HexEditor.h
+++ b/Applications/HexEditor/HexEditor.h
@@ -25,6 +25,7 @@ public:
void fill_selection(u8 fill_byte);
bool write_to_file(const StringView& path);
+ bool has_selection() const { return !(m_selection_start == -1 || m_selection_end == -1 || (m_selection_end - m_selection_start) < 0 || m_buffer.is_empty()); }
bool copy_selected_text_to_clipboard();
bool copy_selected_hex_to_clipboard();
bool copy_selected_hex_to_clipboard_as_c_code();
diff --git a/Applications/HexEditor/HexEditorWidget.cpp b/Applications/HexEditor/HexEditorWidget.cpp
index 4d8d6323c8..ec4ff7d23e 100644
--- a/Applications/HexEditor/HexEditorWidget.cpp
+++ b/Applications/HexEditor/HexEditorWidget.cpp
@@ -56,13 +56,13 @@ HexEditorWidget::HexEditorWidget()
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) {
+ if (valid && file_size > 0) {
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());
+ GMessageBox::show("Invalid file size entered.", "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window());
}
}
});