1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

FileManager+FileOperation: Switch to east const

(And some adjustments based on MaxWipfli's feedback)
This commit is contained in:
Sam Atkins 2021-06-17 11:23:12 +01:00 committed by Andreas Kling
parent 5217875f6a
commit ca039e6ba1
10 changed files with 93 additions and 93 deletions

View file

@ -33,7 +33,7 @@ void spawn_terminal(String const& directory)
posix_spawn_file_actions_addchdir(&spawn_actions, directory.characters()); posix_spawn_file_actions_addchdir(&spawn_actions, directory.characters());
pid_t pid; pid_t pid;
const char* argv[] = { "Terminal", nullptr }; char const* argv[] = { "Terminal", nullptr };
if ((errno = posix_spawn(&pid, "/bin/Terminal", &spawn_actions, nullptr, const_cast<char**>(argv), environ))) { if ((errno = posix_spawn(&pid, "/bin/Terminal", &spawn_actions, nullptr, const_cast<char**>(argv), environ))) {
perror("posix_spawn"); perror("posix_spawn");
} else { } else {
@ -49,7 +49,7 @@ enum class FileOperation {
static HashTable<RefPtr<GUI::Window>> file_operation_windows; static HashTable<RefPtr<GUI::Window>> file_operation_windows;
static void run_file_operation([[maybe_unused]] FileOperation operation, const String& source, const String& destination, GUI::Window* parent_window) static void run_file_operation([[maybe_unused]] FileOperation operation, String const& source, String const& destination, GUI::Window* parent_window)
{ {
int pipe_fds[2]; int pipe_fds[2];
if (pipe(pipe_fds) < 0) { if (pipe(pipe_fds) < 0) {
@ -98,7 +98,7 @@ static void run_file_operation([[maybe_unused]] FileOperation operation, const S
window->show(); window->show();
} }
NonnullRefPtr<GUI::Action> LauncherHandler::create_launch_action(Function<void(const LauncherHandler&)> launch_handler) NonnullRefPtr<GUI::Action> LauncherHandler::create_launch_action(Function<void(LauncherHandler const&)> launch_handler)
{ {
auto icon = GUI::FileIconProvider::icon_for_executable(details().executable).bitmap_for_size(16); auto icon = GUI::FileIconProvider::icon_for_executable(details().executable).bitmap_for_size(16);
return GUI::Action::create(details().name, move(icon), [this, launch_handler = move(launch_handler)](auto&) { return GUI::Action::create(details().name, move(icon), [this, launch_handler = move(launch_handler)](auto&) {
@ -106,7 +106,7 @@ NonnullRefPtr<GUI::Action> LauncherHandler::create_launch_action(Function<void(c
}); });
} }
RefPtr<LauncherHandler> DirectoryView::get_default_launch_handler(const NonnullRefPtrVector<LauncherHandler>& handlers) RefPtr<LauncherHandler> DirectoryView::get_default_launch_handler(NonnullRefPtrVector<LauncherHandler> const& handlers)
{ {
// If this is an application, pick it first // If this is an application, pick it first
for (size_t i = 0; i < handlers.size(); i++) { for (size_t i = 0; i < handlers.size(); i++) {
@ -131,7 +131,7 @@ RefPtr<LauncherHandler> DirectoryView::get_default_launch_handler(const NonnullR
return {}; return {};
} }
NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(const URL& url) NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(URL const& url)
{ {
NonnullRefPtrVector<LauncherHandler> handlers; NonnullRefPtrVector<LauncherHandler> handlers;
for (auto& h : Desktop::Launcher::get_handlers_with_details_for_url(url)) { for (auto& h : Desktop::Launcher::get_handlers_with_details_for_url(url)) {
@ -140,12 +140,12 @@ NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(const UR
return handlers; return handlers;
} }
NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(const String& path) NonnullRefPtrVector<LauncherHandler> DirectoryView::get_launch_handlers(String const& path)
{ {
return get_launch_handlers(URL::create_with_file_protocol(path)); return get_launch_handlers(URL::create_with_file_protocol(path));
} }
void DirectoryView::handle_activation(const GUI::ModelIndex& index) void DirectoryView::handle_activation(GUI::ModelIndex const& index)
{ {
if (!index.is_valid()) if (!index.is_valid())
return; return;
@ -207,14 +207,14 @@ DirectoryView::DirectoryView(Mode mode)
set_view_mode(ViewMode::Icon); set_view_mode(ViewMode::Icon);
} }
const GUI::FileSystemModel::Node& DirectoryView::node(const GUI::ModelIndex& index) const GUI::FileSystemModel::Node const& DirectoryView::node(GUI::ModelIndex const& index) const
{ {
return model().node(m_sorting_model->map_to_source(index)); return model().node(m_sorting_model->map_to_source(index));
} }
void DirectoryView::setup_model() void DirectoryView::setup_model()
{ {
m_model->on_directory_change_error = [this](int, const char* error_string) { m_model->on_directory_change_error = [this](int, char const* error_string) {
auto failed_path = m_model->root_path(); auto failed_path = m_model->root_path();
auto error_message = String::formatted("Could not read {}:\n{}", failed_path, error_string); auto error_message = String::formatted("Could not read {}:\n{}", failed_path, error_string);
m_error_label->set_text(error_message); m_error_label->set_text(error_message);
@ -229,7 +229,7 @@ void DirectoryView::setup_model()
on_path_change(failed_path, false, false); on_path_change(failed_path, false, false);
}; };
m_model->on_rename_error = [this](int, const char* error_string) { m_model->on_rename_error = [this](int, char const* error_string) {
GUI::MessageBox::show_error(window(), String::formatted("Unable to rename file: {}", error_string)); GUI::MessageBox::show_error(window(), String::formatted("Unable to rename file: {}", error_string));
}; };
@ -423,7 +423,7 @@ void DirectoryView::open(String const& path)
model().set_root_path(real_path); model().set_root_path(real_path);
} }
void DirectoryView::set_status_message(const StringView& message) void DirectoryView::set_status_message(StringView const& message)
{ {
if (on_status_message) if (on_status_message)
on_status_message(message); on_status_message(message);
@ -477,7 +477,7 @@ void DirectoryView::update_statusbar()
size_t selected_byte_count = 0; size_t selected_byte_count = 0;
current_view().selection().for_each_index([&](auto& index) { current_view().selection().for_each_index([&](auto& index) {
const auto& node = this->node(index); auto const& node = this->node(index);
selected_byte_count += node.size; selected_byte_count += node.size;
}); });
@ -499,17 +499,17 @@ void DirectoryView::set_should_show_dotfiles(bool show_dotfiles)
m_model->set_should_show_dotfiles(show_dotfiles); m_model->set_should_show_dotfiles(show_dotfiles);
} }
void DirectoryView::launch(const URL&, const LauncherHandler& launcher_handler) const void DirectoryView::launch(URL const&, LauncherHandler const& launcher_handler) const
{ {
pid_t child; pid_t child;
if (launcher_handler.details().launcher_type == Desktop::Launcher::LauncherType::Application) { if (launcher_handler.details().launcher_type == Desktop::Launcher::LauncherType::Application) {
const char* argv[] = { launcher_handler.details().name.characters(), nullptr }; char const* argv[] = { launcher_handler.details().name.characters(), nullptr };
posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, nullptr, const_cast<char**>(argv), environ); posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, nullptr, const_cast<char**>(argv), environ);
if (disown(child) < 0) if (disown(child) < 0)
perror("disown"); perror("disown");
} else { } else {
for (auto& path : selected_file_paths()) { for (auto& path : selected_file_paths()) {
const char* argv[] = { launcher_handler.details().name.characters(), path.characters(), nullptr }; char const* argv[] = { launcher_handler.details().name.characters(), path.characters(), nullptr };
posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, nullptr, const_cast<char**>(argv), environ); posix_spawn(&child, launcher_handler.details().executable.characters(), nullptr, nullptr, const_cast<char**>(argv), environ);
if (disown(child) < 0) if (disown(child) < 0)
perror("disown"); perror("disown");
@ -522,7 +522,7 @@ Vector<String> DirectoryView::selected_file_paths() const
Vector<String> paths; Vector<String> paths;
auto& view = current_view(); auto& view = current_view();
auto& model = *view.model(); auto& model = *view.model();
view.selection().for_each_index([&](const GUI::ModelIndex& index) { view.selection().for_each_index([&](GUI::ModelIndex const& index) {
auto parent_index = model.parent_index(index); auto parent_index = model.parent_index(index);
auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_index); auto name_index = model.index(index.row(), GUI::FileSystemModel::Column::Name, parent_index);
auto path = name_index.data(GUI::ModelRole::Custom).to_string(); auto path = name_index.data(GUI::ModelRole::Custom).to_string();
@ -553,7 +553,7 @@ void DirectoryView::handle_selection_change()
void DirectoryView::setup_actions() void DirectoryView::setup_actions()
{ {
m_mkdir_action = GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { m_mkdir_action = GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"), [&](GUI::Action const&) {
String value; String value;
if (GUI::InputBox::show(window(), value, "Enter name:", "New directory") == GUI::InputBox::ExecOK && !value.is_empty()) { if (GUI::InputBox::show(window(), value, "Enter name:", "New directory") == GUI::InputBox::ExecOK && !value.is_empty()) {
auto new_dir_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value)); auto new_dir_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value));
@ -565,7 +565,7 @@ void DirectoryView::setup_actions()
} }
}); });
m_touch_action = GUI::Action::create("New &File...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) { m_touch_action = GUI::Action::create("New &File...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"), [&](GUI::Action const&) {
String value; String value;
if (GUI::InputBox::show(window(), value, "Enter name:", "New file") == GUI::InputBox::ExecOK && !value.is_empty()) { if (GUI::InputBox::show(window(), value, "Enter name:", "New file") == GUI::InputBox::ExecOK && !value.is_empty()) {
auto new_file_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value)); auto new_file_path = LexicalPath::canonicalized_path(String::formatted("{}/{}", path(), value));
@ -607,7 +607,7 @@ void DirectoryView::setup_actions()
window()); window());
} }
void DirectoryView::handle_drop(const GUI::ModelIndex& index, const GUI::DropEvent& event) void DirectoryView::handle_drop(GUI::ModelIndex const& index, GUI::DropEvent const& event)
{ {
if (!event.mime_data().has_urls()) if (!event.mime_data().has_urls())
return; return;

View file

@ -24,13 +24,13 @@ void spawn_terminal(String const& directory);
class LauncherHandler : public RefCounted<LauncherHandler> { class LauncherHandler : public RefCounted<LauncherHandler> {
public: public:
LauncherHandler(const NonnullRefPtr<Desktop::Launcher::Details>& details) LauncherHandler(NonnullRefPtr<Desktop::Launcher::Details> const& details)
: m_details(details) : m_details(details)
{ {
} }
NonnullRefPtr<GUI::Action> create_launch_action(Function<void(const LauncherHandler&)>); NonnullRefPtr<GUI::Action> create_launch_action(Function<void(LauncherHandler const&)>);
const Desktop::Launcher::Details& details() const { return *m_details; } Desktop::Launcher::Details const& details() const { return *m_details; }
private: private:
NonnullRefPtr<Desktop::Launcher::Details> m_details; NonnullRefPtr<Desktop::Launcher::Details> m_details;
@ -56,18 +56,18 @@ public:
void open_next_directory(); void open_next_directory();
int path_history_size() const { return m_path_history.size(); } int path_history_size() const { return m_path_history.size(); }
int path_history_position() const { return m_path_history_position; } int path_history_position() const { return m_path_history_position; }
static RefPtr<LauncherHandler> get_default_launch_handler(const NonnullRefPtrVector<LauncherHandler>& handlers); static RefPtr<LauncherHandler> get_default_launch_handler(NonnullRefPtrVector<LauncherHandler> const& handlers);
static NonnullRefPtrVector<LauncherHandler> get_launch_handlers(const URL& url); static NonnullRefPtrVector<LauncherHandler> get_launch_handlers(URL const& url);
static NonnullRefPtrVector<LauncherHandler> get_launch_handlers(const String& path); static NonnullRefPtrVector<LauncherHandler> get_launch_handlers(String const& path);
void refresh(); void refresh();
void launch(const URL&, const LauncherHandler&) const; void launch(URL const&, LauncherHandler const&) const;
Function<void(const StringView& path, bool can_read_in_path, bool can_write_in_path)> on_path_change; Function<void(StringView const& path, bool can_read_in_path, bool can_write_in_path)> on_path_change;
Function<void(GUI::AbstractView&)> on_selection_change; Function<void(GUI::AbstractView&)> on_selection_change;
Function<void(const GUI::ModelIndex&, const GUI::ContextMenuEvent&)> on_context_menu_request; Function<void(GUI::ModelIndex const&, GUI::ContextMenuEvent const&)> on_context_menu_request;
Function<void(const StringView&)> on_status_message; Function<void(StringView const&)> on_status_message;
Function<void(int done, int total)> on_thumbnail_progress; Function<void(int done, int total)> on_thumbnail_progress;
Function<void()> on_accepted_drop; Function<void()> on_accepted_drop;
@ -94,7 +94,7 @@ public:
} }
} }
const GUI::AbstractView& current_view() const GUI::AbstractView const& current_view() const
{ {
return const_cast<DirectoryView*>(this)->current_view(); return const_cast<DirectoryView*>(this)->current_view();
} }
@ -112,7 +112,7 @@ public:
void set_should_show_dotfiles(bool); void set_should_show_dotfiles(bool);
const GUI::FileSystemModel::Node& node(const GUI::ModelIndex&) const; GUI::FileSystemModel::Node const& node(GUI::ModelIndex const&) const;
bool is_desktop() const { return m_mode == Mode::Desktop; } bool is_desktop() const { return m_mode == Mode::Desktop; }
@ -128,11 +128,11 @@ public:
private: private:
explicit DirectoryView(Mode); explicit DirectoryView(Mode);
const GUI::FileSystemModel& model() const { return *m_model; } GUI::FileSystemModel const& model() const { return *m_model; }
GUI::FileSystemModel& model() { return *m_model; } GUI::FileSystemModel& model() { return *m_model; }
void handle_selection_change(); void handle_selection_change();
void handle_drop(const GUI::ModelIndex&, const GUI::DropEvent&); void handle_drop(GUI::ModelIndex const&, GUI::DropEvent const&);
void do_delete(bool should_confirm); void do_delete(bool should_confirm);
// ^GUI::ModelClient // ^GUI::ModelClient
@ -144,9 +144,9 @@ private:
void setup_columns_view(); void setup_columns_view();
void setup_table_view(); void setup_table_view();
void handle_activation(const GUI::ModelIndex&); void handle_activation(GUI::ModelIndex const&);
void set_status_message(const StringView&); void set_status_message(StringView const&);
void update_statusbar(); void update_statusbar();
Mode m_mode { Mode::Normal }; Mode m_mode { Mode::Normal };

View file

@ -92,7 +92,7 @@ void FileOperationProgressWidget::did_finish()
window()->close(); window()->close();
} }
void FileOperationProgressWidget::did_error(const String message) void FileOperationProgressWidget::did_error(String const message)
{ {
// FIXME: Communicate more with the user about errors. // FIXME: Communicate more with the user about errors.
close_pipe(); close_pipe();
@ -134,7 +134,7 @@ String FileOperationProgressWidget::estimate_time(off_t bytes_done, off_t total_
return String::formatted("{} hours and {} minutes", hours_remaining, minutes_remaining); return String::formatted("{} hours and {} minutes", hours_remaining, minutes_remaining);
} }
void FileOperationProgressWidget::did_progress(off_t bytes_done, off_t total_byte_count, size_t files_done, size_t total_file_count, [[maybe_unused]] off_t current_file_done, [[maybe_unused]] off_t current_file_size, const StringView& current_filename) void FileOperationProgressWidget::did_progress(off_t bytes_done, off_t total_byte_count, size_t files_done, size_t total_file_count, [[maybe_unused]] off_t current_file_done, [[maybe_unused]] off_t current_file_size, StringView const& current_filename)
{ {
auto& files_copied_label = *find_descendant_of_type_named<GUI::Label>("files_copied_label"); auto& files_copied_label = *find_descendant_of_type_named<GUI::Label>("files_copied_label");
auto& current_file_label = *find_descendant_of_type_named<GUI::Label>("current_file_label"); auto& current_file_label = *find_descendant_of_type_named<GUI::Label>("current_file_label");

View file

@ -22,7 +22,7 @@ private:
void did_finish(); void did_finish();
void did_error(String message); void did_error(String message);
void did_progress(off_t bytes_done, off_t total_byte_count, size_t files_done, size_t total_file_count, off_t current_file_done, off_t current_file_size, const StringView& current_filename); void did_progress(off_t bytes_done, off_t total_byte_count, size_t files_done, size_t total_file_count, off_t current_file_done, off_t current_file_size, StringView const& current_filename);
void close_pipe(); void close_pipe();

View file

@ -14,7 +14,7 @@
namespace FileUtils { namespace FileUtils {
void delete_path(const String& path, GUI::Window* parent_window) void delete_path(String const& path, GUI::Window* parent_window)
{ {
struct stat st; struct stat st;
if (lstat(path.characters(), &st)) { if (lstat(path.characters(), &st)) {
@ -43,7 +43,7 @@ void delete_path(const String& path, GUI::Window* parent_window)
} }
} }
void delete_paths(const Vector<String>& paths, bool should_confirm, GUI::Window* parent_window) void delete_paths(Vector<String> const& paths, bool should_confirm, GUI::Window* parent_window)
{ {
String message; String message;
if (paths.size() == 1) { if (paths.size() == 1) {

View file

@ -18,6 +18,6 @@ enum class FileOperation {
Cut Cut
}; };
void delete_path(const String&, GUI::Window*); void delete_path(String const&, GUI::Window*);
void delete_paths(const Vector<String>&, bool should_confirm, GUI::Window*); void delete_paths(Vector<String> const&, bool should_confirm, GUI::Window*);
} }

View file

@ -26,7 +26,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
PropertiesWindow::PropertiesWindow(const String& path, bool disable_rename, Window* parent_window) PropertiesWindow::PropertiesWindow(String const& path, bool disable_rename, Window* parent_window)
: Window(parent_window) : Window(parent_window)
{ {
auto lexical_path = LexicalPath(path); auto lexical_path = LexicalPath(path);
@ -184,7 +184,7 @@ void PropertiesWindow::permission_changed(mode_t mask, bool set)
m_apply_button->set_enabled(m_name_dirty || m_permissions_dirty); m_apply_button->set_enabled(m_name_dirty || m_permissions_dirty);
} }
String PropertiesWindow::make_full_path(const String& name) String PropertiesWindow::make_full_path(String const& name)
{ {
return String::formatted("{}/{}", m_parent_path, name); return String::formatted("{}/{}", m_parent_path, name);
} }

View file

@ -21,7 +21,7 @@ public:
virtual ~PropertiesWindow() override; virtual ~PropertiesWindow() override;
private: private:
PropertiesWindow(const String& path, bool disable_rename, Window* parent = nullptr); PropertiesWindow(String const& path, bool disable_rename, Window* parent = nullptr);
struct PropertyValuePair { struct PropertyValuePair {
String property; String property;
@ -35,7 +35,7 @@ private:
mode_t execute; mode_t execute;
}; };
static const String get_description(const mode_t mode) static String const get_description(mode_t const mode)
{ {
if (S_ISREG(mode)) if (S_ISREG(mode))
return "File"; return "File";
@ -62,7 +62,7 @@ private:
void permission_changed(mode_t mask, bool set); void permission_changed(mode_t mask, bool set);
bool apply_changes(); bool apply_changes();
void update(); void update();
String make_full_path(const String& name); String make_full_path(String const& name);
RefPtr<GUI::Button> m_apply_button; RefPtr<GUI::Button> m_apply_button;
RefPtr<GUI::TextBox> m_name_box; RefPtr<GUI::TextBox> m_name_box;

View file

@ -57,12 +57,12 @@ using namespace FileManager;
static int run_in_desktop_mode(RefPtr<Core::ConfigFile>); static int run_in_desktop_mode(RefPtr<Core::ConfigFile>);
static int run_in_windowed_mode(RefPtr<Core::ConfigFile>, String initial_location, String entry_focused_on_init); static int run_in_windowed_mode(RefPtr<Core::ConfigFile>, String initial_location, String entry_focused_on_init);
static void do_copy(const Vector<String>& selected_file_paths, FileUtils::FileOperation file_operation); static void do_copy(Vector<String> const& selected_file_paths, FileUtils::FileOperation file_operation);
static void do_paste(const String& target_directory, GUI::Window* window); static void do_paste(String const& target_directory, GUI::Window* window);
static void do_create_link(const Vector<String>& selected_file_paths, GUI::Window* window); static void do_create_link(Vector<String> const& selected_file_paths, GUI::Window* window);
static void do_unzip_archive(const Vector<String>& selected_file_paths, GUI::Window* window); static void do_unzip_archive(Vector<String> const& selected_file_paths, GUI::Window* window);
static void show_properties(const String& container_dir_path, const String& path, const Vector<String>& selected, GUI::Window* window); static void show_properties(String const& container_dir_path, String const& path, Vector<String> const& selected, GUI::Window* window);
static bool add_launch_handler_actions_to_menu(RefPtr<GUI::Menu>& menu, const DirectoryView& directory_view, const String& full_path, RefPtr<GUI::Action>& default_action, NonnullRefPtrVector<LauncherHandler>& current_file_launch_handlers); static bool add_launch_handler_actions_to_menu(RefPtr<GUI::Menu>& menu, DirectoryView const& directory_view, String const& full_path, RefPtr<GUI::Action>& default_action, NonnullRefPtrVector<LauncherHandler>& current_file_launch_handlers);
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
@ -131,7 +131,7 @@ int main(int argc, char** argv)
return run_in_windowed_mode(move(config), initial_location, focused_entry); return run_in_windowed_mode(move(config), initial_location, focused_entry);
} }
void do_copy(const Vector<String>& selected_file_paths, FileUtils::FileOperation file_operation) void do_copy(Vector<String> const& selected_file_paths, FileUtils::FileOperation file_operation)
{ {
if (selected_file_paths.is_empty()) if (selected_file_paths.is_empty())
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
@ -147,7 +147,7 @@ void do_copy(const Vector<String>& selected_file_paths, FileUtils::FileOperation
GUI::Clipboard::the().set_data(copy_text.build().bytes(), "text/uri-list"); GUI::Clipboard::the().set_data(copy_text.build().bytes(), "text/uri-list");
} }
void do_paste(const String& target_directory, GUI::Window* window) void do_paste(String const& target_directory, GUI::Window* window)
{ {
auto data_and_type = GUI::Clipboard::the().data_and_type(); auto data_and_type = GUI::Clipboard::the().data_and_type();
if (data_and_type.mime_type != "text/uri-list") { if (data_and_type.mime_type != "text/uri-list") {
@ -185,7 +185,7 @@ void do_paste(const String& target_directory, GUI::Window* window)
} }
} }
void do_create_link(const Vector<String>& selected_file_paths, GUI::Window* window) void do_create_link(Vector<String> const& selected_file_paths, GUI::Window* window)
{ {
auto path = selected_file_paths.first(); auto path = selected_file_paths.first();
auto destination = String::formatted("{}/{}", Core::StandardPaths::desktop_directory(), LexicalPath::basename(path)); auto destination = String::formatted("{}/{}", Core::StandardPaths::desktop_directory(), LexicalPath::basename(path));
@ -195,7 +195,7 @@ void do_create_link(const Vector<String>& selected_file_paths, GUI::Window* wind
} }
} }
void do_unzip_archive(const Vector<String>& selected_file_paths, GUI::Window* window) void do_unzip_archive(Vector<String> const& selected_file_paths, GUI::Window* window)
{ {
String archive_file_path = selected_file_paths.first(); String archive_file_path = selected_file_paths.first();
String output_directory_path = archive_file_path.substring(0, archive_file_path.length() - 4); String output_directory_path = archive_file_path.substring(0, archive_file_path.length() - 4);
@ -221,7 +221,7 @@ void do_unzip_archive(const Vector<String>& selected_file_paths, GUI::Window* wi
} }
} }
void show_properties(const String& container_dir_path, const String& path, const Vector<String>& selected, GUI::Window* window) void show_properties(String const& container_dir_path, String const& path, Vector<String> const& selected, GUI::Window* window)
{ {
RefPtr<PropertiesWindow> properties; RefPtr<PropertiesWindow> properties;
if (selected.is_empty()) { if (selected.is_empty()) {
@ -236,7 +236,7 @@ void show_properties(const String& container_dir_path, const String& path, const
properties->show(); properties->show();
} }
bool add_launch_handler_actions_to_menu(RefPtr<GUI::Menu>& menu, const DirectoryView& directory_view, const String& full_path, RefPtr<GUI::Action>& default_action, NonnullRefPtrVector<LauncherHandler>& current_file_launch_handlers) bool add_launch_handler_actions_to_menu(RefPtr<GUI::Menu>& menu, DirectoryView const& directory_view, String const& full_path, RefPtr<GUI::Action>& default_action, NonnullRefPtrVector<LauncherHandler>& current_file_launch_handlers)
{ {
current_file_launch_handlers = directory_view.get_launch_handlers(full_path); current_file_launch_handlers = directory_view.get_launch_handlers(full_path);
@ -276,7 +276,7 @@ bool add_launch_handler_actions_to_menu(RefPtr<GUI::Menu>& menu, const Directory
int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config) int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
{ {
static constexpr const char* process_name = "FileManager (Desktop)"; static constexpr char const* process_name = "FileManager (Desktop)";
set_process_name(process_name, strlen(process_name)); set_process_name(process_name, strlen(process_name));
pthread_setname_np(pthread_self(), process_name); pthread_setname_np(pthread_self(), process_name);
@ -288,7 +288,7 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
auto& desktop_widget = window->set_main_widget<FileManager::DesktopWidget>(); auto& desktop_widget = window->set_main_widget<FileManager::DesktopWidget>();
desktop_widget.set_layout<GUI::VerticalBoxLayout>(); desktop_widget.set_layout<GUI::VerticalBoxLayout>();
[[maybe_unused]] auto& directory_view = desktop_widget.add<DirectoryView>(DirectoryView::Mode::Desktop); auto& directory_view = desktop_widget.add<DirectoryView>(DirectoryView::Mode::Desktop);
auto cut_action = GUI::CommonActions::make_cut_action( auto cut_action = GUI::CommonActions::make_cut_action(
[&](auto&) { [&](auto&) {
@ -317,7 +317,7 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
auto unzip_archive_action auto unzip_archive_action
= GUI::Action::create( = GUI::Action::create(
"E&xtract Here", "E&xtract Here",
[&](const GUI::Action&) { [&](GUI::Action const&) {
auto paths = directory_view.selected_file_paths(); auto paths = directory_view.selected_file_paths();
if (paths.is_empty()) if (paths.is_empty())
return; return;
@ -326,7 +326,7 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
}, },
window); window);
directory_view.on_selection_change = [&](const GUI::AbstractView& view) { directory_view.on_selection_change = [&](GUI::AbstractView const& view) {
cut_action->set_enabled(!view.selection().is_empty()); cut_action->set_enabled(!view.selection().is_empty());
copy_action->set_enabled(!view.selection().is_empty()); copy_action->set_enabled(!view.selection().is_empty());
}; };
@ -341,23 +341,23 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
window); window);
auto paste_action = GUI::CommonActions::make_paste_action( auto paste_action = GUI::CommonActions::make_paste_action(
[&](const GUI::Action&) { [&](GUI::Action const&) {
do_paste(directory_view.path(), directory_view.window()); do_paste(directory_view.path(), directory_view.window());
}, },
window); window);
paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "text/uri-list" && access(directory_view.path().characters(), W_OK) == 0); paste_action->set_enabled(GUI::Clipboard::the().mime_type() == "text/uri-list" && access(directory_view.path().characters(), W_OK) == 0);
GUI::Clipboard::the().on_change = [&](const String& data_type) { GUI::Clipboard::the().on_change = [&](String const& data_type) {
paste_action->set_enabled(data_type == "text/uri-list" && access(directory_view.path().characters(), W_OK) == 0); paste_action->set_enabled(data_type == "text/uri-list" && access(directory_view.path().characters(), W_OK) == 0);
}; };
auto desktop_view_context_menu = GUI::Menu::construct("Directory View"); auto desktop_view_context_menu = GUI::Menu::construct("Directory View");
auto file_manager_action = GUI::Action::create("Show in File &Manager", {}, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-file-manager.png"), [&](const GUI::Action&) { auto file_manager_action = GUI::Action::create("Show in File &Manager", {}, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-file-manager.png"), [&](GUI::Action const&) {
Desktop::Launcher::open(URL::create_with_file_protocol(directory_view.path())); Desktop::Launcher::open(URL::create_with_file_protocol(directory_view.path()));
}); });
auto display_properties_action = GUI::Action::create("&Display Settings", {}, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-display-settings.png"), [&](const GUI::Action&) { auto display_properties_action = GUI::Action::create("&Display Settings", {}, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/app-display-settings.png"), [&](GUI::Action const&) {
Desktop::Launcher::open(URL::create_with_file_protocol("/bin/DisplaySettings")); Desktop::Launcher::open(URL::create_with_file_protocol("/bin/DisplaySettings"));
}); });
@ -383,7 +383,7 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
NonnullRefPtrVector<LauncherHandler> current_file_handlers; NonnullRefPtrVector<LauncherHandler> current_file_handlers;
RefPtr<GUI::Action> file_context_menu_action_default_action; RefPtr<GUI::Action> file_context_menu_action_default_action;
directory_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) { directory_view.on_context_menu_request = [&](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) {
if (index.is_valid()) { if (index.is_valid()) {
auto& node = directory_view.node(index); auto& node = directory_view.node(index);
if (node.is_directory()) { if (node.is_directory()) {
@ -527,7 +527,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto tree_view_directory_context_menu = GUI::Menu::construct("Tree View Directory"); auto tree_view_directory_context_menu = GUI::Menu::construct("Tree View Directory");
auto tree_view_context_menu = GUI::Menu::construct("Tree View"); auto tree_view_context_menu = GUI::Menu::construct("Tree View");
auto open_parent_directory_action = GUI::Action::create("Open &Parent Directory", { Mod_Alt, Key_Up }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open-parent-directory.png"), [&](const GUI::Action&) { auto open_parent_directory_action = GUI::Action::create("Open &Parent Directory", { Mod_Alt, Key_Up }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open-parent-directory.png"), [&](GUI::Action const&) {
directory_view.open_parent_directory(); directory_view.open_parent_directory();
}); });
@ -608,7 +608,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
RefPtr<GUI::Action> view_as_columns_action; RefPtr<GUI::Action> view_as_columns_action;
view_as_icons_action = GUI::Action::create_checkable( view_as_icons_action = GUI::Action::create_checkable(
"View as &Icons", { Mod_Ctrl, KeyCode::Key_1 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/icon-view.png"), [&](const GUI::Action&) { "View as &Icons", { Mod_Ctrl, KeyCode::Key_1 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/icon-view.png"), [&](GUI::Action const&) {
directory_view.set_view_mode(DirectoryView::ViewMode::Icon); directory_view.set_view_mode(DirectoryView::ViewMode::Icon);
config->write_entry("DirectoryView", "ViewMode", "Icon"); config->write_entry("DirectoryView", "ViewMode", "Icon");
config->sync(); config->sync();
@ -616,7 +616,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
window); window);
view_as_table_action = GUI::Action::create_checkable( view_as_table_action = GUI::Action::create_checkable(
"View as &Table", { Mod_Ctrl, KeyCode::Key_2 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/table-view.png"), [&](const GUI::Action&) { "View as &Table", { Mod_Ctrl, KeyCode::Key_2 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/table-view.png"), [&](GUI::Action const&) {
directory_view.set_view_mode(DirectoryView::ViewMode::Table); directory_view.set_view_mode(DirectoryView::ViewMode::Table);
config->write_entry("DirectoryView", "ViewMode", "Table"); config->write_entry("DirectoryView", "ViewMode", "Table");
config->sync(); config->sync();
@ -624,7 +624,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
window); window);
view_as_columns_action = GUI::Action::create_checkable( view_as_columns_action = GUI::Action::create_checkable(
"View as &Columns", { Mod_Ctrl, KeyCode::Key_3 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/columns-view.png"), [&](const GUI::Action&) { "View as &Columns", { Mod_Ctrl, KeyCode::Key_3 }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/columns-view.png"), [&](GUI::Action const&) {
directory_view.set_view_mode(DirectoryView::ViewMode::Columns); directory_view.set_view_mode(DirectoryView::ViewMode::Columns);
config->write_entry("DirectoryView", "ViewMode", "Columns"); config->write_entry("DirectoryView", "ViewMode", "Columns");
config->sync(); config->sync();
@ -640,7 +640,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto tree_view_selected_file_paths = [&] { auto tree_view_selected_file_paths = [&] {
Vector<String> paths; Vector<String> paths;
auto& view = tree_view; auto& view = tree_view;
view.selection().for_each_index([&](const GUI::ModelIndex& index) { view.selection().for_each_index([&](GUI::ModelIndex const& index) {
paths.append(directories_model->full_path(index)); paths.append(directories_model->full_path(index));
}); });
return paths; return paths;
@ -726,7 +726,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
"Create Desktop &Shortcut", "Create Desktop &Shortcut",
{}, {},
Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-symlink.png"), Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-symlink.png"),
[&](const GUI::Action&) { [&](GUI::Action const&) {
auto paths = directory_view.selected_file_paths(); auto paths = directory_view.selected_file_paths();
if (paths.is_empty()) { if (paths.is_empty()) {
return; return;
@ -738,7 +738,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
auto unzip_archive_action auto unzip_archive_action
= GUI::Action::create( = GUI::Action::create(
"E&xtract Here", "E&xtract Here",
[&](const GUI::Action&) { [&](GUI::Action const&) {
auto paths = directory_view.selected_file_paths(); auto paths = directory_view.selected_file_paths();
if (paths.is_empty()) if (paths.is_empty())
return; return;
@ -768,7 +768,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
window); window);
auto paste_action = GUI::CommonActions::make_paste_action( auto paste_action = GUI::CommonActions::make_paste_action(
[&](const GUI::Action& action) { [&](GUI::Action const& action) {
String target_directory; String target_directory;
if (action.activator() == directory_context_menu) if (action.activator() == directory_context_menu)
target_directory = directory_view.selected_file_paths()[0]; target_directory = directory_view.selected_file_paths()[0];
@ -780,7 +780,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
window); window);
auto folder_specific_paste_action = GUI::CommonActions::make_paste_action( auto folder_specific_paste_action = GUI::CommonActions::make_paste_action(
[&](const GUI::Action& action) { [&](GUI::Action const& action) {
String target_directory; String target_directory;
if (action.activator() == directory_context_menu) if (action.activator() == directory_context_menu)
target_directory = directory_view.selected_file_paths()[0]; target_directory = directory_view.selected_file_paths()[0];
@ -809,7 +809,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
}, },
window); window);
GUI::Clipboard::the().on_change = [&](const String& data_type) { GUI::Clipboard::the().on_change = [&](String const& data_type) {
auto current_location = directory_view.path(); auto current_location = directory_view.path();
paste_action->set_enabled(data_type == "text/uri-list" && access(current_location.characters(), W_OK) == 0); paste_action->set_enabled(data_type == "text/uri-list" && access(current_location.characters(), W_OK) == 0);
}; };
@ -832,12 +832,12 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
}); });
focus_dependent_delete_action->set_enabled(false); focus_dependent_delete_action->set_enabled(false);
auto mkdir_action = GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) { auto mkdir_action = GUI::Action::create("&New Directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/mkdir.png"), [&](GUI::Action const&) {
directory_view.mkdir_action().activate(); directory_view.mkdir_action().activate();
refresh_tree_view(); refresh_tree_view();
}); });
auto touch_action = GUI::Action::create("New &File...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"), [&](const GUI::Action&) { auto touch_action = GUI::Action::create("New &File...", { Mod_Ctrl | Mod_Shift, Key_F }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/new.png"), [&](GUI::Action const&) {
directory_view.touch_action().activate(); directory_view.touch_action().activate();
refresh_tree_view(); refresh_tree_view();
}); });
@ -930,7 +930,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
main_toolbar.add_action(*view_as_table_action); main_toolbar.add_action(*view_as_table_action);
main_toolbar.add_action(*view_as_columns_action); main_toolbar.add_action(*view_as_columns_action);
directory_view.on_path_change = [&](const String& new_path, bool can_read_in_path, bool can_write_in_path) { directory_view.on_path_change = [&](String const& new_path, bool can_read_in_path, bool can_write_in_path) {
auto icon = GUI::FileIconProvider::icon_for_path(new_path); auto icon = GUI::FileIconProvider::icon_for_path(new_path);
auto* bitmap = icon.bitmap_for_size(16); auto* bitmap = icon.bitmap_for_size(16);
window->set_icon(bitmap); window->set_icon(bitmap);
@ -1011,7 +1011,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
refresh_tree_view(); refresh_tree_view();
}; };
directory_view.on_status_message = [&](const StringView& message) { directory_view.on_status_message = [&](StringView const& message) {
statusbar.set_text(message); statusbar.set_text(message);
}; };
@ -1070,7 +1070,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
NonnullRefPtrVector<LauncherHandler> current_file_handlers; NonnullRefPtrVector<LauncherHandler> current_file_handlers;
RefPtr<GUI::Action> file_context_menu_action_default_action; RefPtr<GUI::Action> file_context_menu_action_default_action;
directory_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) { directory_view.on_context_menu_request = [&](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) {
if (index.is_valid()) { if (index.is_valid()) {
auto& node = directory_view.node(index); auto& node = directory_view.node(index);
@ -1106,7 +1106,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
}; };
tree_view.on_selection_change = [&] { tree_view.on_selection_change = [&] {
const auto& index = tree_view.selection().first(); auto const& index = tree_view.selection().first();
if (directories_model->m_previously_selected_index.is_valid()) if (directories_model->m_previously_selected_index.is_valid())
directories_model->update_node_on_selection(directories_model->m_previously_selected_index, false); directories_model->update_node_on_selection(directories_model->m_previously_selected_index, false);
@ -1130,18 +1130,18 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
directory_view.delete_action().set_enabled(!tree_view.selection().is_empty()); directory_view.delete_action().set_enabled(!tree_view.selection().is_empty());
}; };
tree_view.on_focus_change = [&]([[maybe_unused]] const bool has_focus, [[maybe_unused]] const GUI::FocusSource source) { tree_view.on_focus_change = [&](bool has_focus, [[maybe_unused]] GUI::FocusSource const source) {
focus_dependent_delete_action->set_enabled((!tree_view.selection().is_empty() && has_focus) focus_dependent_delete_action->set_enabled((!tree_view.selection().is_empty() && has_focus)
|| !directory_view.current_view().selection().is_empty()); || !directory_view.current_view().selection().is_empty());
}; };
tree_view.on_context_menu_request = [&](const GUI::ModelIndex& index, const GUI::ContextMenuEvent& event) { tree_view.on_context_menu_request = [&](GUI::ModelIndex const& index, GUI::ContextMenuEvent const& event) {
if (index.is_valid()) { if (index.is_valid()) {
tree_view_directory_context_menu->popup(event.screen_position()); tree_view_directory_context_menu->popup(event.screen_position());
} }
}; };
auto copy_urls_to_directory = [&](const Vector<URL>& urls, const String& directory) { auto copy_urls_to_directory = [&](Vector<URL> const& urls, String const& directory) {
if (urls.is_empty()) { if (urls.is_empty()) {
dbgln("No files to copy"); dbgln("No files to copy");
return; return;
@ -1165,7 +1165,7 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
refresh_tree_view(); refresh_tree_view();
}; };
breadcrumbbar.on_segment_drop = [&](size_t segment_index, const GUI::DropEvent& event) { breadcrumbbar.on_segment_drop = [&](size_t segment_index, GUI::DropEvent const& event) {
if (!event.mime_data().has_urls()) if (!event.mime_data().has_urls())
return; return;
copy_urls_to_directory(event.mime_data().urls(), breadcrumbbar.segment_data(segment_index)); copy_urls_to_directory(event.mime_data().urls(), breadcrumbbar.segment_data(segment_index));
@ -1176,11 +1176,11 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
event.accept(); event.accept();
}; };
breadcrumbbar.on_doubleclick = [&](const GUI::MouseEvent&) { breadcrumbbar.on_doubleclick = [&](GUI::MouseEvent const&) {
go_to_location_action->activate(); go_to_location_action->activate();
}; };
tree_view.on_drop = [&](const GUI::ModelIndex& index, const GUI::DropEvent& event) { tree_view.on_drop = [&](GUI::ModelIndex const& index, GUI::DropEvent const& event) {
if (!event.mime_data().has_urls()) if (!event.mime_data().has_urls())
return; return;
auto& target_node = directories_model->node(index); auto& target_node = directories_model->node(index);

View file

@ -12,7 +12,7 @@
#include <sched.h> #include <sched.h>
#include <sys/stat.h> #include <sys/stat.h>
static int perform_copy(const String& source, const String& destination); static int perform_copy(String const& source, String const& destination);
static void report_error(String message); static void report_error(String message);
static void report_warning(String message); static void report_warning(String message);
@ -56,7 +56,7 @@ static void report_warning(String message)
outln("WARN {}", message); outln("WARN {}", message);
} }
static bool collect_work_items(const String& source, const String& destination, Vector<WorkItem>& items) static bool collect_work_items(String const& source, String const& destination, Vector<WorkItem>& items)
{ {
struct stat st = {}; struct stat st = {};
if (stat(source.characters(), &st) < 0) { if (stat(source.characters(), &st) < 0) {
@ -98,7 +98,7 @@ static bool collect_work_items(const String& source, const String& destination,
return true; return true;
} }
int perform_copy(const String& source, const String& destination) int perform_copy(String const& source, String const& destination)
{ {
Vector<WorkItem> items; Vector<WorkItem> items;