mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:47:45 +00:00
HexEditor: Replace DeprecatedString in FindDialog
This commit is contained in:
parent
f38cf0ca18
commit
81afa029ac
3 changed files with 16 additions and 15 deletions
|
@ -6,7 +6,6 @@
|
||||||
|
|
||||||
#include "FindDialog.h"
|
#include "FindDialog.h"
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/Hex.h>
|
#include <AK/Hex.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
#include <Applications/HexEditor/FindDialogGML.h>
|
#include <Applications/HexEditor/FindDialogGML.h>
|
||||||
|
@ -31,14 +30,14 @@ static constexpr Array<Option, 2> options = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, DeprecatedString& out_text, ByteBuffer& out_buffer, bool& find_all)
|
GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, String& out_text, ByteBuffer& out_buffer, bool& find_all)
|
||||||
{
|
{
|
||||||
auto dialog = FindDialog::construct();
|
auto dialog = FindDialog::construct();
|
||||||
|
|
||||||
if (parent_window)
|
if (parent_window)
|
||||||
dialog->set_icon(parent_window->icon());
|
dialog->set_icon(parent_window->icon());
|
||||||
|
|
||||||
if (!out_text.is_empty() && !out_text.is_null())
|
if (!out_text.is_empty())
|
||||||
dialog->m_text_editor->set_text(out_text);
|
dialog->m_text_editor->set_text(out_text);
|
||||||
|
|
||||||
dialog->m_find_button->set_enabled(!dialog->m_text_editor->text().is_empty());
|
dialog->m_find_button->set_enabled(!dialog->m_text_editor->text().is_empty());
|
||||||
|
@ -63,25 +62,26 @@ GUI::Dialog::ExecResult FindDialog::show(GUI::Window* parent_window, DeprecatedS
|
||||||
|
|
||||||
find_all = dialog->find_all();
|
find_all = dialog->find_all();
|
||||||
|
|
||||||
dbgln("Find: value={} option={} find_all={}", out_text.characters(), (int)selected_option, find_all);
|
dbgln("Find: value={} option={} find_all={}", out_text, (int)selected_option, find_all);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<ByteBuffer, DeprecatedString> FindDialog::process_input(DeprecatedString text_value, OptionId opt)
|
Result<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId opt)
|
||||||
{
|
{
|
||||||
dbgln("process_input opt={}", (int)opt);
|
dbgln("process_input opt={}", (int)opt);
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case OPTION_ASCII_STRING: {
|
case OPTION_ASCII_STRING: {
|
||||||
if (text_value.is_empty())
|
if (text_value.is_empty())
|
||||||
return DeprecatedString("Input is empty");
|
return "Input is empty"_string;
|
||||||
|
|
||||||
return text_value.to_byte_buffer();
|
return ByteBuffer::copy(text_value.bytes()).release_value_but_fixme_should_propagate_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
case OPTION_HEX_VALUE: {
|
case OPTION_HEX_VALUE: {
|
||||||
auto decoded = decode_hex(text_value.replace(" "sv, ""sv, ReplaceMode::All));
|
auto text_no_spaces = text_value.replace(" "sv, ""sv, ReplaceMode::All).release_value_but_fixme_should_propagate_errors();
|
||||||
|
ErrorOr<ByteBuffer> decoded = decode_hex(text_no_spaces);
|
||||||
if (decoded.is_error())
|
if (decoded.is_error())
|
||||||
return DeprecatedString::formatted("Input is invalid: {}", decoded.error().string_literal());
|
return String::formatted("Input is invalid: {}", decoded.error().string_literal()).release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
||||||
return decoded.value();
|
return decoded.value();
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ FindDialog::FindDialog()
|
||||||
};
|
};
|
||||||
|
|
||||||
m_find_button->on_click = [this](auto) {
|
m_find_button->on_click = [this](auto) {
|
||||||
auto text = m_text_editor->text();
|
auto text = String::from_deprecated_string(m_text_editor->text()).release_value_but_fixme_should_propagate_errors();
|
||||||
if (!text.is_empty()) {
|
if (!text.is_empty()) {
|
||||||
m_text_value = text;
|
m_text_value = text;
|
||||||
done(ExecResult::OK);
|
done(ExecResult::OK);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Result.h>
|
#include <AK/Result.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <LibGUI/Dialog.h>
|
#include <LibGUI/Dialog.h>
|
||||||
|
|
||||||
enum OptionId {
|
enum OptionId {
|
||||||
|
@ -19,12 +20,12 @@ class FindDialog : public GUI::Dialog {
|
||||||
C_OBJECT(FindDialog);
|
C_OBJECT(FindDialog);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ExecResult show(GUI::Window* parent_window, DeprecatedString& out_tex, ByteBuffer& out_buffer, bool& find_all);
|
static ExecResult show(GUI::Window* parent_window, String& out_tex, ByteBuffer& out_buffer, bool& find_all);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Result<ByteBuffer, DeprecatedString> process_input(DeprecatedString text_value, OptionId opt);
|
Result<ByteBuffer, String> process_input(String text_value, OptionId opt);
|
||||||
|
|
||||||
DeprecatedString text_value() const { return m_text_value; }
|
String text_value() const { return m_text_value; }
|
||||||
OptionId selected_option() const { return m_selected_option; }
|
OptionId selected_option() const { return m_selected_option; }
|
||||||
bool find_all() const { return m_find_all; }
|
bool find_all() const { return m_find_all; }
|
||||||
|
|
||||||
|
@ -37,6 +38,6 @@ private:
|
||||||
RefPtr<GUI::Button> m_cancel_button;
|
RefPtr<GUI::Button> m_cancel_button;
|
||||||
|
|
||||||
bool m_find_all { false };
|
bool m_find_all { false };
|
||||||
DeprecatedString m_text_value;
|
String m_text_value;
|
||||||
OptionId m_selected_option { OPTION_INVALID };
|
OptionId m_selected_option { OPTION_INVALID };
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,7 +46,7 @@ private:
|
||||||
DeprecatedString m_extension;
|
DeprecatedString m_extension;
|
||||||
|
|
||||||
int m_goto_history { 0 };
|
int m_goto_history { 0 };
|
||||||
DeprecatedString m_search_text;
|
String m_search_text;
|
||||||
ByteBuffer m_search_buffer;
|
ByteBuffer m_search_buffer;
|
||||||
int last_found_index() const { return m_last_found_index == -1 ? 0 : m_last_found_index; }
|
int last_found_index() const { return m_last_found_index == -1 ? 0 : m_last_found_index; }
|
||||||
int m_last_found_index { -1 };
|
int m_last_found_index { -1 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue