summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-13 22:00:47 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-13 22:00:47 +0200
commit3a02bd40f8778ec51b2c4577c3f4275437412f91 (patch)
tree26b1e738078eb2406b1f5395c785b8a629aa6c09
parentf360858836525e4a8305a7596f6ec30f1ef7979b (diff)
downloadserenity-3a02bd40f8778ec51b2c4577c3f4275437412f91.zip
FileManager: Add a basic context menu with copy/paste/delete/...
I also added a dummy "Properties..." action just to fill out the menu a little bit. :^) Fixes #270.
-rw-r--r--Applications/FileManager/DirectoryView.cpp22
-rw-r--r--Applications/FileManager/DirectoryView.h1
-rw-r--r--Applications/FileManager/main.cpp13
3 files changed, 34 insertions, 2 deletions
diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp
index 31bdb6cce1..e37ae0acee 100644
--- a/Applications/FileManager/DirectoryView.cpp
+++ b/Applications/FileManager/DirectoryView.cpp
@@ -68,12 +68,21 @@ DirectoryView::DirectoryView(GWidget* parent)
m_item_view->set_model_column(GDirectoryModel::Column::Name);
- m_table_view->model()->on_update = [this] {
- update_statusbar();
+ m_model->on_path_change = [this] {
+ m_table_view->selection().clear();
+ m_item_view->selection().clear();
if (on_path_change)
on_path_change(model().path());
};
+ // NOTE: We're using the on_update hook on the GSortingProxyModel here instead of
+ // the GDirectoryModel's hook. This is because GSortingProxyModel has already
+ // installed an on_update hook on the GDirectoryModel internally.
+ // FIXME: This is an unfortunate design. We should come up with something better.
+ m_table_view->model()->on_update = [this] {
+ update_statusbar();
+ };
+
m_model->on_thumbnail_progress = [this](int done, int total) {
if (on_thumbnail_progress)
on_thumbnail_progress(done, total);
@@ -98,6 +107,15 @@ DirectoryView::DirectoryView(GWidget* parent)
on_selection_change(*m_item_view);
};
+ m_table_view->on_context_menu_request = [this](auto& index, auto& event) {
+ if (on_context_menu_request)
+ on_context_menu_request(*m_table_view, index, event);
+ };
+ m_item_view->on_context_menu_request = [this](auto& index, auto& event) {
+ if (on_context_menu_request)
+ on_context_menu_request(*m_item_view, index, event);
+ };
+
set_view_mode(ViewMode::Icon);
}
diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h
index 458f8cf065..78e8755a08 100644
--- a/Applications/FileManager/DirectoryView.h
+++ b/Applications/FileManager/DirectoryView.h
@@ -25,6 +25,7 @@ public:
Function<void(const StringView&)> on_path_change;
Function<void(GAbstractView&)> on_selection_change;
+ Function<void(const GAbstractView&, const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request;
Function<void(const StringView&)> on_status_message;
Function<void(int done, int total)> on_thumbnail_progress;
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index 257c77955c..f2d52c0a5a 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -178,6 +178,8 @@ int main(int argc, char** argv)
}
});
+ auto properties_action = GAction::create("Properties...", { Mod_Alt, Key_Return }, [](auto&) {});
+
auto delete_action = GAction::create("Delete", GraphicsBitmap::load_from_file("/res/icons/16x16/delete.png"), [](const GAction&) {
dbgprintf("'Delete' action activated!\n");
});
@@ -271,6 +273,17 @@ int main(int argc, char** argv)
progressbar->set_visible(true);
};
+ auto context_menu = make<GMenu>();
+ context_menu->add_action(copy_action);
+ context_menu->add_action(paste_action);
+ context_menu->add_action(delete_action);
+ context_menu->add_separator();
+ context_menu->add_action(properties_action);
+
+ directory_view->on_context_menu_request = [&](const GAbstractView&, const GModelIndex&, const GContextMenuEvent& event) {
+ context_menu->popup(event.screen_position());
+ };
+
// our initial location is defined as, in order of precedence:
// 1. the first command-line argument (e.g. FileManager /bin)
// 2. the user's home directory