1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibGUI: Use String::formatted() and String::number() more

This commit is contained in:
Andreas Kling 2021-01-03 14:51:17 +01:00
parent 5e157eaf37
commit f181ddb56a
9 changed files with 17 additions and 20 deletions

View file

@ -43,7 +43,7 @@ AboutDialog::AboutDialog(const StringView& name, const Gfx::Bitmap* icon, Window
, m_icon(icon)
{
resize(413, 205);
set_title(String::format("About %s", m_name.characters()));
set_title(String::formatted("About {}", m_name));
set_resizable(false);
if (parent_window)

View file

@ -246,9 +246,9 @@ void Calendar::update_tiles(unsigned int target_year, unsigned int target_month)
const String Calendar::selected_calendar_text(bool long_names)
{
if (mode() == Month)
return String::format("%s %u", long_names ? long_month_names[m_selected_month - 1] : short_month_names[m_selected_month - 1], m_selected_year);
return String::formatted("{} {}", long_names ? long_month_names[m_selected_month - 1] : short_month_names[m_selected_month - 1], m_selected_year);
else
return String::format("%u", m_selected_year);
return String::number(m_selected_year);
}
void Calendar::set_selected_calendar(unsigned int year, unsigned int month)
@ -285,7 +285,7 @@ void Calendar::CalendarTile::update_values(int index, Core::DateTime date_time)
{
m_index = index;
m_date_time = date_time;
m_display_date = (m_date_time.day() == 1) ? String::format("%s %u", short_month_names[m_date_time.month() - 1], m_date_time.day()) : String::number(m_date_time.day());
m_display_date = (m_date_time.day() == 1) ? String::formatted("{} {}", short_month_names[m_date_time.month() - 1], m_date_time.day()) : String::number(m_date_time.day());
}
Calendar::CalendarTile::~CalendarTile()

View file

@ -65,7 +65,7 @@ Optional<String> FilePicker::get_open_filepath(Window* parent_window, const Stri
Optional<String> FilePicker::get_save_filepath(Window* parent_window, const String& title, const String& extension, Options options)
{
auto picker = FilePicker::construct(parent_window, Mode::Save, options, String::format("%s.%s", title.characters(), extension.characters()));
auto picker = FilePicker::construct(parent_window, Mode::Save, options, String::formatted("{}.{}", title, extension));
if (picker->exec() == Dialog::ExecOK) {
String file_path = picker->selected_file().string();
@ -136,7 +136,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
};
auto open_parent_directory_action = Action::create("Open parent directory", { Mod_Alt, Key_Up }, Gfx::Bitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [this](const Action&) {
set_path(String::format("%s/..", m_model->root_path().characters()));
set_path(String::formatted("{}/..", m_model->root_path()));
});
toolbar.add_action(*open_parent_directory_action);
@ -149,13 +149,10 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, Options options, const
auto mkdir_action = Action::create("New directory...", Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const Action&) {
String value;
if (InputBox::show(value, this, "Enter name:", "New directory") == InputBox::ExecOK && !value.is_empty()) {
auto new_dir_path = LexicalPath(String::format("%s/%s",
m_model->root_path().characters(),
value.characters()))
.string();
auto new_dir_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", m_model->root_path(), value));
int rc = mkdir(new_dir_path.characters(), 0777);
if (rc < 0) {
MessageBox::show(this, String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", MessageBox::Type::Error);
MessageBox::show(this, String::formatted("mkdir(\"{}\") failed: {}", new_dir_path, strerror(errno)), "Error", MessageBox::Type::Error);
} else {
m_model->update();
}
@ -301,7 +298,7 @@ void FilePicker::clear_preview()
void FilePicker::on_file_return()
{
LexicalPath path(String::format("%s/%s", m_model->root_path().characters(), m_filename_textbox->text().characters()));
LexicalPath path(String::formatted("{}/{}", m_model->root_path(), m_filename_textbox->text()));
if (FilePicker::file_exists(path.string()) && m_mode == Mode::Save) {
auto result = MessageBox::show(this, "File already exists, overwrite?", "Existing File", MessageBox::Type::Warning, MessageBox::InputType::OKCancel);

View file

@ -123,7 +123,7 @@ void FileSystemModel::Node::traverse_if_needed()
quick_sort(child_names);
for (auto& name : child_names) {
String child_path = String::format("%s/%s", full_path.characters(), name.characters());
String child_path = String::formatted("{}/{}", full_path, name);
auto child = adopt_own(*new Node(m_model));
bool ok = child->fetch_data(child_path, false);
if (!ok)

View file

@ -274,7 +274,7 @@ void HeaderView::paint_vertical(Painter& painter)
bool pressed = section == m_pressed_section && m_pressed_section_is_pressed;
bool hovered = false;
Gfx::StylePainter::paint_button(painter, cell_rect, palette(), Gfx::ButtonStyle::Normal, pressed, hovered);
String text = String::format("%d", section);
String text = String::number(section);
auto text_rect = cell_rect.shrunken(m_table_view.horizontal_padding() * 2, 0);
if (pressed)
text_rect.move_by(1, 1);

View file

@ -94,8 +94,8 @@ void IconImpl::set_bitmap_for_size(int size, RefPtr<Gfx::Bitmap>&& bitmap)
Icon Icon::default_icon(const StringView& name)
{
auto bitmap16 = Gfx::Bitmap::load_from_file(String::format("/res/icons/16x16/%s.png", name.to_string().characters()));
auto bitmap32 = Gfx::Bitmap::load_from_file(String::format("/res/icons/32x32/%s.png", name.to_string().characters()));
auto bitmap16 = Gfx::Bitmap::load_from_file(String::formatted("/res/icons/16x16/{}.png", name));
auto bitmap32 = Gfx::Bitmap::load_from_file(String::formatted("/res/icons/32x32/{}.png", name));
return Icon(move(bitmap16), move(bitmap32));
}

View file

@ -42,8 +42,8 @@ Variant ModelIndex::data(ModelRole role) const
const LogStream& operator<<(const LogStream& stream, const ModelIndex& value)
{
if (value.internal_data())
return stream << String::format("ModelIndex(%d,%d,%p)", value.row(), value.column(), value.internal_data());
return stream << String::format("ModelIndex(%d,%d)", value.row(), value.column());
return stream << String::formatted("ModelIndex({},{},{:p})", value.row(), value.column(), value.internal_data());
return stream << String::formatted("ModelIndex({},{})", value.row(), value.column());
}
}

View file

@ -61,7 +61,7 @@ inline const LogStream& operator<<(const LogStream& stream, const TextPosition&
{
if (!value.is_valid())
return stream << "GUI::TextPosition(Invalid)";
return stream << String::format("(%zu,%zu)", value.line(), value.column());
return stream << String::formatted("({},{})", value.line(), value.column());
}
}

View file

@ -435,7 +435,7 @@ String Variant::to_string() const
case Type::Rect:
return as_rect().to_string();
case Type::Font:
return String::format("[Font: %s]", as_font().name().characters());
return String::formatted("[Font: {}]", as_font().name());
case Type::TextAlignment: {
switch (m_value.as_text_alignment) {
case Gfx::TextAlignment::Center: