mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
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.
This commit is contained in:
parent
f360858836
commit
3a02bd40f8
Notes:
sideshowbarker
2024-07-19 12:07:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3a02bd40f87
3 changed files with 34 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue