1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

LibGUI: Remove GUI::FilePicker::file_exists()

I have no idea why this existed but everyone should just use
Core::File::exists() instead. :^)
This commit is contained in:
Andreas Kling 2021-02-19 23:46:54 +01:00
parent a8e0671344
commit 4f0be55770
4 changed files with 4 additions and 18 deletions

View file

@ -199,7 +199,7 @@ bool PropertiesWindow::apply_changes()
String new_name = m_name_box->text();
String new_file = make_full_path(new_name).characters();
if (GUI::FilePicker::file_exists(new_file)) {
if (Core::File::exists(new_file)) {
GUI::MessageBox::show(this, String::formatted("A file \"{}\" already exists!", new_name), "Error", GUI::MessageBox::Type::Error);
return false;
}

View file

@ -538,7 +538,7 @@ void HackStudioWidget::reveal_action_tab(GUI::Widget& widget)
NonnullRefPtr<GUI::Action> HackStudioWidget::create_debug_action()
{
return GUI::Action::create("Debug", Gfx::Bitmap::load_from_file("/res/icons/16x16/debug-run.png"), [this](auto&) {
if (!GUI::FilePicker::file_exists(get_project_executable_path())) {
if (!Core::File::exists(get_project_executable_path())) {
GUI::MessageBox::show(window(), String::formatted("Could not find file: {}. (did you build the project?)", get_project_executable_path()), "Error", GUI::MessageBox::Type::Error);
return;
}

View file

@ -26,6 +26,7 @@
#include <AK/Function.h>
#include <AK/LexicalPath.h>
#include <LibCore/File.h>
#include <LibCore/StandardPaths.h>
#include <LibGUI/Action.h>
#include <LibGUI/BoxLayout.h>
@ -219,7 +220,7 @@ void FilePicker::on_file_return()
{
LexicalPath path(String::formatted("{}/{}", m_model->root_path(), m_filename_textbox->text()));
if (FilePicker::file_exists(path.string()) && m_mode == Mode::Save) {
if (Core::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);
if (result == MessageBox::ExecCancel)
return;
@ -229,20 +230,6 @@ void FilePicker::on_file_return()
done(ExecOK);
}
bool FilePicker::file_exists(const StringView& path)
{
struct stat st;
int rc = stat(path.to_string().characters(), &st);
if (rc < 0) {
if (errno == ENOENT)
return false;
}
if (rc == 0) {
return true;
}
return false;
}
void FilePicker::set_path(const String& path)
{
auto new_path = LexicalPath(path).string();

View file

@ -49,7 +49,6 @@ public:
static Optional<String> get_open_filepath(Window* parent_window, const String& window_title = {});
static Optional<String> get_save_filepath(Window* parent_window, const String& title, const String& extension);
static bool file_exists(const StringView& path);
virtual ~FilePicker() override;