summaryrefslogtreecommitdiff
path: root/Userland/Applications/FileManager
diff options
context:
space:
mode:
authorLeonardo Nicolas <leonicolas@gmail.com>2022-01-04 19:45:55 -0800
committerAndreas Kling <kling@serenityos.org>2022-01-09 00:47:48 +0100
commit9aa0cf326510372e766f3c79deb676dce56995f4 (patch)
treec631be5adb58a812fbbf873f3f540afdbb106fa2 /Userland/Applications/FileManager
parent0a1b34c753e83632688e925a7971ab5d08ffa605 (diff)
downloadserenity-9aa0cf326510372e766f3c79deb676dce56995f4.zip
FileManager: Do not allow rename files that cannot be modified
Pressing the F2 key on files that the user doesn't have permission was opening the file name for editing. This patch fixes the issue disabling the file name editing when the user doesn't have permission to do it. To reproduce the issue: 1) Open the File Manager 2) Click on the /etc directory 3) Select any file 4) Press the F2 key 5) Update the file name
Diffstat (limited to 'Userland/Applications/FileManager')
-rw-r--r--Userland/Applications/FileManager/DirectoryView.cpp11
-rw-r--r--Userland/Applications/FileManager/DirectoryView.h1
2 files changed, 9 insertions, 3 deletions
diff --git a/Userland/Applications/FileManager/DirectoryView.cpp b/Userland/Applications/FileManager/DirectoryView.cpp
index e31b748eb3..08e02c7903 100644
--- a/Userland/Applications/FileManager/DirectoryView.cpp
+++ b/Userland/Applications/FileManager/DirectoryView.cpp
@@ -519,14 +519,18 @@ void DirectoryView::do_delete(bool should_confirm)
delete_paths(paths, should_confirm, window());
}
+bool DirectoryView::can_modify_current_selection()
+{
+ return !current_view().selection().is_empty() && access(path().characters(), W_OK) == 0;
+}
+
void DirectoryView::handle_selection_change()
{
update_statusbar();
- bool can_modify = !current_view().selection().is_empty() && access(path().characters(), W_OK) == 0;
+ bool can_modify = can_modify_current_selection();
m_delete_action->set_enabled(can_modify);
m_force_delete_action->set_enabled(can_modify);
- m_rename_action->set_enabled(can_modify);
if (on_selection_change)
on_selection_change(current_view());
@@ -578,7 +582,8 @@ void DirectoryView::setup_actions()
m_delete_action = GUI::CommonActions::make_delete_action([this](auto&) { do_delete(true); }, window());
m_rename_action = GUI::CommonActions::make_rename_action([this](auto&) {
- current_view().begin_editing(current_view().cursor_index());
+ if (can_modify_current_selection())
+ current_view().begin_editing(current_view().cursor_index());
},
window());
diff --git a/Userland/Applications/FileManager/DirectoryView.h b/Userland/Applications/FileManager/DirectoryView.h
index 00dbf2b304..5570ecaee3 100644
--- a/Userland/Applications/FileManager/DirectoryView.h
+++ b/Userland/Applications/FileManager/DirectoryView.h
@@ -158,6 +158,7 @@ private:
void set_status_message(StringView);
void update_statusbar();
+ bool can_modify_current_selection();
Mode m_mode { Mode::Normal };
ViewMode m_view_mode { Invalid };