mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
Userland: Set Button text using the new String class
This commit is contained in:
parent
b5cb9a9ebb
commit
e39adc4772
49 changed files with 134 additions and 127 deletions
|
@ -289,7 +289,7 @@ void Action::set_text(DeprecatedString text)
|
|||
return;
|
||||
m_text = move(text);
|
||||
for_each_toolbar_button([&](auto& button) {
|
||||
button.set_text_deprecated(m_text);
|
||||
button.set_text(String::from_deprecated_string(m_text).release_value_but_fixme_should_propagate_errors());
|
||||
});
|
||||
for_each_menu_item([&](auto& menu_item) {
|
||||
menu_item.update_from_action({});
|
||||
|
|
|
@ -75,7 +75,7 @@ void Breadcrumbbar::append_segment(DeprecatedString text, Gfx::Bitmap const* ico
|
|||
{
|
||||
auto& button = add<BreadcrumbButton>();
|
||||
button.set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||
button.set_text_deprecated(text);
|
||||
button.set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors());
|
||||
button.set_icon(icon);
|
||||
button.set_tooltip(move(tooltip));
|
||||
button.set_focus_policy(FocusPolicy::TabFocus);
|
||||
|
|
|
@ -234,14 +234,14 @@ void ColorPicker::build_ui()
|
|||
button_container.layout()->add_spacer();
|
||||
|
||||
auto& ok_button = button_container.add<DialogButton>();
|
||||
ok_button.set_text_deprecated("OK");
|
||||
ok_button.set_text(String::from_utf8_short_string("OK"sv));
|
||||
ok_button.on_click = [this](auto) {
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
ok_button.set_default(true);
|
||||
|
||||
auto& cancel_button = button_container.add<DialogButton>();
|
||||
cancel_button.set_text_deprecated("Cancel");
|
||||
cancel_button.set_text(String::from_utf8_short_string("Cancel"sv));
|
||||
cancel_button.on_click = [this](auto) {
|
||||
done(ExecResult::Cancel);
|
||||
};
|
||||
|
@ -416,7 +416,7 @@ void ColorPicker::build_ui_custom(Widget& root_container)
|
|||
make_spinbox(Blue, m_color.blue());
|
||||
make_spinbox(Alpha, m_color.alpha());
|
||||
|
||||
m_selector_button = vertical_container.add<GUI::Button>("Select on screen");
|
||||
m_selector_button = vertical_container.add<GUI::Button>(String::from_utf8("Select on screen"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_selector_button->on_click = [this](auto) {
|
||||
auto selector = ColorSelectOverlay::construct();
|
||||
auto original_color = m_color;
|
||||
|
|
|
@ -217,14 +217,14 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, StringView filename, St
|
|||
};
|
||||
|
||||
auto& ok_button = *widget->find_descendant_of_type_named<GUI::Button>("ok_button");
|
||||
ok_button.set_text_deprecated(ok_button_name(m_mode));
|
||||
ok_button.set_text(ok_button_name(m_mode));
|
||||
ok_button.on_click = [this](auto) {
|
||||
on_file_return();
|
||||
};
|
||||
ok_button.set_enabled(m_mode == Mode::OpenFolder || !m_filename_textbox->text().is_empty());
|
||||
|
||||
auto& cancel_button = *widget->find_descendant_of_type_named<GUI::Button>("cancel_button");
|
||||
cancel_button.set_text_deprecated("Cancel");
|
||||
cancel_button.set_text(String::from_utf8_short_string("Cancel"sv));
|
||||
cancel_button.on_click = [this](auto) {
|
||||
done(ExecResult::Cancel);
|
||||
};
|
||||
|
|
|
@ -48,17 +48,17 @@ private:
|
|||
|
||||
FilePicker(Window* parent_window, Mode type = Mode::Open, StringView filename = "Untitled"sv, StringView path = Core::StandardPaths::home_directory(), ScreenPosition screen_position = Dialog::ScreenPosition::CenterWithinParent, Optional<Vector<FileTypeFilter>> allowed_file_types = {});
|
||||
|
||||
static DeprecatedString ok_button_name(Mode mode)
|
||||
static String ok_button_name(Mode mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case Mode::Open:
|
||||
case Mode::OpenMultiple:
|
||||
case Mode::OpenFolder:
|
||||
return "Open";
|
||||
return String::from_utf8_short_string("Open"sv);
|
||||
case Mode::Save:
|
||||
return "Save";
|
||||
return String::from_utf8_short_string("Save"sv);
|
||||
default:
|
||||
return "OK";
|
||||
return String::from_utf8_short_string("OK"sv);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ IncrementalSearchBanner::IncrementalSearchBanner(TextEditor& editor)
|
|||
};
|
||||
|
||||
m_close_button = find_descendant_of_type_named<Button>("incremental_search_banner_close_button");
|
||||
m_close_button->set_text_deprecated("\xE2\x9D\x8C");
|
||||
m_close_button->set_text(String::from_utf8_short_string("\xE2\x9D\x8C"sv));
|
||||
m_close_button->on_click = [this](auto) {
|
||||
hide();
|
||||
};
|
||||
|
|
|
@ -107,7 +107,7 @@ void InputBox::build()
|
|||
button_container_inner.layout()->add_spacer();
|
||||
|
||||
m_ok_button = button_container_inner.add<DialogButton>();
|
||||
m_ok_button->set_text_deprecated("OK");
|
||||
m_ok_button->set_text(String::from_utf8_short_string("OK"sv));
|
||||
m_ok_button->on_click = [this](auto) {
|
||||
dbgln("GUI::InputBox: OK button clicked");
|
||||
done(ExecResult::OK);
|
||||
|
@ -115,7 +115,7 @@ void InputBox::build()
|
|||
m_ok_button->set_default(true);
|
||||
|
||||
m_cancel_button = button_container_inner.add<DialogButton>();
|
||||
m_cancel_button->set_text_deprecated("Cancel");
|
||||
m_cancel_button->set_text(String::from_utf8_short_string("Cancel"sv));
|
||||
m_cancel_button->on_click = [this](auto) {
|
||||
dbgln("GUI::InputBox: Cancel button clicked");
|
||||
done(ExecResult::Cancel);
|
||||
|
|
|
@ -49,9 +49,12 @@ Dialog::ExecResult MessageBox::ask_about_unsaved_changes(Window* parent_window,
|
|||
if (parent_window)
|
||||
box->set_icon(parent_window->icon());
|
||||
|
||||
box->m_yes_button->set_text_deprecated(path.is_empty() ? "Save As..." : "Save");
|
||||
box->m_no_button->set_text_deprecated("Discard");
|
||||
box->m_cancel_button->set_text_deprecated("Cancel");
|
||||
if (path.is_empty())
|
||||
box->m_yes_button->set_text(String::from_utf8("Save As..."sv).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
box->m_yes_button->set_text(String::from_utf8_short_string("Save"sv));
|
||||
box->m_no_button->set_text(String::from_utf8_short_string("Discard"sv));
|
||||
box->m_cancel_button->set_text(String::from_utf8_short_string("Cancel"sv));
|
||||
|
||||
return box->exec();
|
||||
}
|
||||
|
@ -151,11 +154,11 @@ void MessageBox::build()
|
|||
constexpr int button_width = 80;
|
||||
int button_count = 0;
|
||||
|
||||
auto add_button = [&](DeprecatedString label, ExecResult result) -> GUI::Button& {
|
||||
auto add_button = [&](String label, ExecResult result) -> GUI::Button& {
|
||||
auto& button = button_container.add<Button>();
|
||||
button.set_fixed_width(button_width);
|
||||
button.set_text_deprecated(label);
|
||||
button.on_click = [this, label, result](auto) {
|
||||
button.set_text(move(label));
|
||||
button.on_click = [this, result](auto) {
|
||||
done(result);
|
||||
};
|
||||
++button_count;
|
||||
|
@ -164,13 +167,13 @@ void MessageBox::build()
|
|||
|
||||
button_container.layout()->add_spacer();
|
||||
if (should_include_ok_button())
|
||||
m_ok_button = add_button("OK", ExecResult::OK);
|
||||
m_ok_button = add_button(String::from_utf8_short_string("OK"sv), ExecResult::OK);
|
||||
if (should_include_yes_button())
|
||||
m_yes_button = add_button("Yes", ExecResult::Yes);
|
||||
m_yes_button = add_button(String::from_utf8_short_string("Yes"sv), ExecResult::Yes);
|
||||
if (should_include_no_button())
|
||||
m_no_button = add_button("No", ExecResult::No);
|
||||
m_no_button = add_button(String::from_utf8_short_string("No"sv), ExecResult::No);
|
||||
if (should_include_cancel_button())
|
||||
m_cancel_button = add_button("Cancel", ExecResult::Cancel);
|
||||
m_cancel_button = add_button(String::from_utf8_short_string("Cancel"sv), ExecResult::Cancel);
|
||||
button_container.layout()->add_spacer();
|
||||
|
||||
int width = (button_count * button_width) + ((button_count - 1) * button_container.layout()->spacing()) + 32;
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
ProcessChooser::ProcessChooser(StringView window_title, StringView button_label, Gfx::Bitmap const* window_icon, GUI::Window* parent_window)
|
||||
ProcessChooser::ProcessChooser(StringView window_title, String button_label, Gfx::Bitmap const* window_icon, GUI::Window* parent_window)
|
||||
: Dialog(parent_window)
|
||||
, m_window_title(window_title)
|
||||
, m_button_label(button_label)
|
||||
, m_button_label(move(button_label))
|
||||
, m_window_icon(window_icon)
|
||||
{
|
||||
set_title(m_window_title);
|
||||
|
@ -62,7 +62,7 @@ ProcessChooser::ProcessChooser(StringView window_title, StringView button_label,
|
|||
auto index = m_table_view->selection().first();
|
||||
set_pid_from_index_and_close(index);
|
||||
};
|
||||
auto& cancel_button = button_container.add<GUI::Button>("Cancel");
|
||||
auto& cancel_button = button_container.add<GUI::Button>(String::from_utf8_short_string("Cancel"sv));
|
||||
cancel_button.set_fixed_width(80);
|
||||
cancel_button.on_click = [this](auto) {
|
||||
done(ExecResult::Cancel);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibGUI/Dialog.h>
|
||||
#include <LibGUI/RunningProcessesModel.h>
|
||||
|
@ -22,14 +23,14 @@ public:
|
|||
pid_t pid() const { return m_pid; }
|
||||
|
||||
private:
|
||||
ProcessChooser(StringView window_title = "Process Chooser"sv, StringView button_label = "Select"sv, Gfx::Bitmap const* window_icon = nullptr, GUI::Window* parent_window = nullptr);
|
||||
ProcessChooser(StringView window_title = "Process Chooser"sv, String button_label = String::from_utf8_short_string("Select"sv), Gfx::Bitmap const* window_icon = nullptr, GUI::Window* parent_window = nullptr);
|
||||
|
||||
void set_pid_from_index_and_close(ModelIndex const&);
|
||||
|
||||
pid_t m_pid { 0 };
|
||||
|
||||
DeprecatedString m_window_title;
|
||||
DeprecatedString m_button_label;
|
||||
String m_button_label;
|
||||
RefPtr<Gfx::Bitmap> m_window_icon;
|
||||
RefPtr<TableView> m_table_view;
|
||||
RefPtr<RunningProcessesModel> m_process_model;
|
||||
|
|
|
@ -46,7 +46,7 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(DeprecatedString t
|
|||
button_container->layout()->set_spacing(6);
|
||||
|
||||
if (show_defaults_button == ShowDefaultsButton::Yes) {
|
||||
window->m_reset_button = TRY(button_container->try_add<GUI::DialogButton>("Defaults"));
|
||||
window->m_reset_button = TRY(button_container->try_add<GUI::DialogButton>(TRY(String::from_utf8("Defaults"sv))));
|
||||
window->m_reset_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
|
||||
window->reset_default_values();
|
||||
};
|
||||
|
@ -54,19 +54,19 @@ ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(DeprecatedString t
|
|||
|
||||
TRY(button_container->layout()->try_add_spacer());
|
||||
|
||||
window->m_ok_button = TRY(button_container->try_add<GUI::DialogButton>("OK"));
|
||||
window->m_ok_button = TRY(button_container->try_add<GUI::DialogButton>(String::from_utf8_short_string("OK"sv)));
|
||||
window->m_ok_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
|
||||
window->apply_settings();
|
||||
GUI::Application::the()->quit();
|
||||
};
|
||||
|
||||
window->m_cancel_button = TRY(button_container->try_add<GUI::DialogButton>("Cancel"));
|
||||
window->m_cancel_button = TRY(button_container->try_add<GUI::DialogButton>(String::from_utf8_short_string("Cancel"sv)));
|
||||
window->m_cancel_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
|
||||
window->cancel_settings();
|
||||
GUI::Application::the()->quit();
|
||||
};
|
||||
|
||||
window->m_apply_button = TRY(button_container->try_add<GUI::DialogButton>("Apply"));
|
||||
window->m_apply_button = TRY(button_container->try_add<GUI::DialogButton>(String::from_utf8_short_string("Apply"sv)));
|
||||
window->m_apply_button->set_enabled(false);
|
||||
window->m_apply_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) {
|
||||
window->apply_settings();
|
||||
|
|
|
@ -56,18 +56,18 @@ private:
|
|||
if (action.icon())
|
||||
set_icon(action.icon());
|
||||
else
|
||||
set_text_deprecated(action.text());
|
||||
set_text(String::from_deprecated_string(action.text()).release_value_but_fixme_should_propagate_errors());
|
||||
set_button_style(Gfx::ButtonStyle::Coolbar);
|
||||
}
|
||||
|
||||
virtual void set_text_deprecated(DeprecatedString text) override
|
||||
virtual void set_text(String text) override
|
||||
{
|
||||
auto const* action = this->action();
|
||||
VERIFY(action);
|
||||
|
||||
set_tooltip(tooltip(*action));
|
||||
if (!action->icon())
|
||||
Button::set_text_deprecated(move(text));
|
||||
Button::set_text(move(text));
|
||||
}
|
||||
|
||||
DeprecatedString tooltip(Action const& action) const
|
||||
|
|
|
@ -46,12 +46,12 @@ WizardDialog::WizardDialog(Window* parent_window)
|
|||
nav_container_widget.layout()->set_spacing(0);
|
||||
nav_container_widget.layout()->add_spacer();
|
||||
|
||||
m_back_button = nav_container_widget.add<DialogButton>("< Back");
|
||||
m_back_button = nav_container_widget.add<DialogButton>(String::from_utf8_short_string("< Back"sv));
|
||||
m_back_button->on_click = [&](auto) {
|
||||
pop_page();
|
||||
};
|
||||
|
||||
m_next_button = nav_container_widget.add<DialogButton>("Next >");
|
||||
m_next_button = nav_container_widget.add<DialogButton>(String::from_utf8_short_string("Next >"sv));
|
||||
m_next_button->on_click = [&](auto) {
|
||||
VERIFY(has_pages());
|
||||
|
||||
|
@ -68,7 +68,7 @@ WizardDialog::WizardDialog(Window* parent_window)
|
|||
auto& button_spacer = nav_container_widget.add<Widget>();
|
||||
button_spacer.set_fixed_width(10);
|
||||
|
||||
m_cancel_button = nav_container_widget.add<DialogButton>("Cancel");
|
||||
m_cancel_button = nav_container_widget.add<DialogButton>(String::from_utf8_short_string("Cancel"sv));
|
||||
m_cancel_button->on_click = [&](auto) {
|
||||
handle_cancel();
|
||||
};
|
||||
|
@ -122,9 +122,12 @@ void WizardDialog::update_navigation()
|
|||
m_back_button->set_enabled(m_page_stack.size() > 1);
|
||||
if (has_pages()) {
|
||||
m_next_button->set_enabled(current_page().is_final_page() || current_page().can_go_next());
|
||||
m_next_button->set_text_deprecated(current_page().is_final_page() ? "Finish" : "Next >");
|
||||
if (current_page().is_final_page())
|
||||
m_next_button->set_text(String::from_utf8_short_string("Finish"sv));
|
||||
else
|
||||
m_next_button->set_text(String::from_utf8_short_string("Next >"sv));
|
||||
} else {
|
||||
m_next_button->set_text_deprecated("Next >");
|
||||
m_next_button->set_text(String::from_utf8_short_string("Next >"sv));
|
||||
m_next_button->set_enabled(false);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue