mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:37:35 +00:00
FileManager+HackStudio+SpaceAnalyzer: Use File::can_delete_or_move
This commit is contained in:
parent
b810f7f88a
commit
e45434c0c7
3 changed files with 3 additions and 13 deletions
|
@ -555,7 +555,7 @@ bool DirectoryView::can_modify_current_selection()
|
|||
// FIXME: remove once Clang formats this properly.
|
||||
// clang-format off
|
||||
return selections.first_matching([&](auto& index) {
|
||||
return !Core::System::access(node(index.parent()).full_path(), W_OK).is_error();
|
||||
return Core::File::can_delete_or_move(node(index).full_path());
|
||||
}).has_value();
|
||||
// clang-format on
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include <LibGUI/Statusbar.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static constexpr auto APP_NAME = "Space Analyzer"sv;
|
||||
|
||||
|
@ -137,15 +136,6 @@ static ErrorOr<void> analyze(RefPtr<Tree> tree, SpaceAnalyzer::TreeMapWidget& tr
|
|||
return {};
|
||||
}
|
||||
|
||||
static bool is_removable(DeprecatedString const& absolute_path)
|
||||
{
|
||||
VERIFY(!absolute_path.is_empty());
|
||||
int access_result = access(LexicalPath::dirname(absolute_path).characters(), W_OK);
|
||||
if (access_result != 0 && errno != EACCES)
|
||||
perror("access");
|
||||
return access_result == 0;
|
||||
}
|
||||
|
||||
static DeprecatedString get_absolute_path_to_selected_node(SpaceAnalyzer::TreeMapWidget const& treemapwidget, bool include_last_node = true)
|
||||
{
|
||||
StringBuilder path_builder;
|
||||
|
@ -288,7 +278,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
DeprecatedString selected_node_path = get_absolute_path_to_selected_node(treemapwidget);
|
||||
if (selected_node_path.is_empty())
|
||||
return;
|
||||
delete_action->set_enabled(is_removable(selected_node_path));
|
||||
delete_action->set_enabled(Core::File::can_delete_or_move(selected_node_path));
|
||||
if (Core::File::is_directory(selected_node_path)) {
|
||||
open_folder_action->set_visible(true);
|
||||
open_containing_folder_action->set_visible(false);
|
||||
|
|
|
@ -1245,7 +1245,7 @@ void HackStudioWidget::configure_project_tree_view()
|
|||
|
||||
auto selections = m_project_tree_view->selection().indices();
|
||||
auto it = selections.find_if([&](auto selected_file) {
|
||||
return access(m_project->model().full_path(selected_file.parent()).characters(), W_OK) == 0;
|
||||
return Core::File::can_delete_or_move(m_project->model().full_path(selected_file));
|
||||
});
|
||||
bool has_permissions = it != selections.end();
|
||||
m_tree_view_rename_action->set_enabled(has_permissions);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue