mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
HexEditor: Add selection strings to the value inspector
Strings include ASCII, UTF-8, and UTF-16 Co-authored-by: Andreas Krohn <hamburger1984@gmail.com>
This commit is contained in:
parent
815442b2b5
commit
eb27b397b8
Notes:
sideshowbarker
2024-07-17 00:24:20 +09:00
Author: https://github.com/MetallicSquid 🔰 Commit: https://github.com/SerenityOS/serenity/commit/eb27b397b8 Pull-request: https://github.com/SerenityOS/serenity/pull/16979 Issue: https://github.com/SerenityOS/serenity/issues/13655 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/ebanner Reviewed-by: https://github.com/kleinesfilmroellchen ✅
5 changed files with 40 additions and 1 deletions
|
@ -24,4 +24,4 @@ set(GENERATED_SOURCES
|
|||
)
|
||||
|
||||
serenity_app(HexEditor ICON app-hex-editor)
|
||||
target_link_libraries(HexEditor PRIVATE LibCore LibGfx LibGUI LibConfig LibDesktop LibFileSystemAccessClient LibMain)
|
||||
target_link_libraries(HexEditor PRIVATE LibCore LibGfx LibGUI LibConfig LibDesktop LibFileSystemAccessClient LibMain LibTextCodec)
|
||||
|
|
|
@ -245,6 +245,18 @@ Optional<u8> HexEditor::get_byte(size_t position)
|
|||
return {};
|
||||
}
|
||||
|
||||
ByteBuffer HexEditor::get_selected_bytes()
|
||||
{
|
||||
auto num_selected_bytes = m_selection_end - m_selection_start;
|
||||
ByteBuffer data;
|
||||
data.ensure_capacity(num_selected_bytes);
|
||||
|
||||
for (size_t i = m_selection_start; i < m_selection_end; i++)
|
||||
data.append(m_document->get(i).value);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void HexEditor::mousedown_event(GUI::MouseEvent& event)
|
||||
{
|
||||
if (event.button() != GUI::MouseButton::Primary) {
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
void open_file(NonnullOwnPtr<Core::File> file);
|
||||
ErrorOr<void> fill_selection(u8 fill_byte);
|
||||
Optional<u8> get_byte(size_t position);
|
||||
ByteBuffer get_selected_bytes();
|
||||
ErrorOr<void> save_as(NonnullOwnPtr<Core::File>);
|
||||
ErrorOr<void> save();
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <LibGUI/TextBox.h>
|
||||
#include <LibGUI/Toolbar.h>
|
||||
#include <LibGUI/ToolbarContainer.h>
|
||||
#include <LibTextCodec/Decoder.h>
|
||||
#include <string.h>
|
||||
|
||||
REGISTER_WIDGET(HexEditor, HexEditor);
|
||||
|
@ -376,8 +377,24 @@ void HexEditorWidget::update_inspector_values(size_t position)
|
|||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16, "");
|
||||
}
|
||||
|
||||
auto selected_bytes = m_editor->get_selected_bytes();
|
||||
|
||||
auto ascii_string = DeprecatedString { ReadonlyBytes { selected_bytes } };
|
||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::ASCIIString, ascii_string);
|
||||
|
||||
Utf8View utf8_string_view { ReadonlyBytes { selected_bytes } };
|
||||
utf8_string_view.validate(valid_bytes);
|
||||
if (valid_bytes == 0)
|
||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, "");
|
||||
else
|
||||
// FIXME: replace control chars with something else - we don't want line breaks here ;)
|
||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF8String, utf8_string_view.as_string());
|
||||
|
||||
// FIXME: Parse as other values like Timestamp etc
|
||||
|
||||
DeprecatedString utf16_string = TextCodec::decoder_for("utf-16le"sv)->to_utf8(StringView(selected_bytes.span()));
|
||||
value_inspector_model->set_parsed_value(ValueInspectorModel::ValueType::UTF16String, utf16_string);
|
||||
|
||||
m_value_inspector->set_model(value_inspector_model);
|
||||
m_value_inspector->update();
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@ public:
|
|||
ASCII,
|
||||
UTF8,
|
||||
UTF16,
|
||||
ASCIIString,
|
||||
UTF8String,
|
||||
UTF16String,
|
||||
__Count
|
||||
};
|
||||
|
||||
|
@ -100,6 +103,12 @@ public:
|
|||
return "UTF-8";
|
||||
case UTF16:
|
||||
return "UTF-16";
|
||||
case ASCIIString:
|
||||
return "ASCII String";
|
||||
case UTF8String:
|
||||
return "UTF-8 String";
|
||||
case UTF16String:
|
||||
return "UTF-16 String";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue