From c4111cc94816a9f0bd66bd1eb909e84661da2300 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Wed, 26 Jun 2019 22:41:42 -0500 Subject: [PATCH] Added shortcut-key support to bulk action extension --- ext/bulk_actions/main.php | 32 +++++++++++++++++++++++--------- ext/bulk_actions/theme.php | 8 ++++---- ext/pools/main.php | 4 ++-- ext/rating/main.php | 8 ++++---- ext/regen_thumb/main.php | 2 +- ext/transcode/main.php | 11 ++++++++++- ext/trash/main.php | 2 +- 7 files changed, 45 insertions(+), 22 deletions(-) diff --git a/ext/bulk_actions/main.php b/ext/bulk_actions/main.php index b945f727..f9294ac1 100644 --- a/ext/bulk_actions/main.php +++ b/ext/bulk_actions/main.php @@ -16,22 +16,29 @@ class BulkActionBlockBuildingEvent extends Event public $search_terms = []; - public function add_action(String $action, string $button_text, String $confirmation_message = "", String $block = "", int $position = 40) + public function add_action(String $action, string $button_text, string $access_key = null, String $confirmation_message = "", String $block = "", int $position = 40) { if ($block == null) { $block = ""; } - array_push( - $this->actions, - [ + if(!empty($access_key)) { + assert(strlen($access_key)==1); + foreach ($this->actions as $existing) { + if($existing["access_key"]==$access_key) { + throw new SCoreException("Access key $access_key is already in use"); + } + } + } + + $this->actions[] =[ "block" => $block, + "access_key" => $access_key, "confirmation_message" => $confirmation_message, "action" => $action, "button_text" => $button_text, "position" => $position - ] - ); + ]; } } @@ -79,15 +86,22 @@ class BulkActions extends Extension global $user; if ($user->can("delete_image")) { - $event->add_action("bulk_delete", "Delete", "Delete selected images?", "", 10); + $event->add_action("bulk_delete", "(D)elete", "d", "Delete selected images?", "", 10); } if ($user->can("bulk_edit_image_tag")) { - $event->add_action("bulk_tag", "Tag", "", $this->theme->render_tag_input(), 10); + + $event->add_action( + "bulk_tag", + "Tag", + "t", + "", + $this->theme->render_tag_input(), + 10); } if ($user->can("bulk_edit_image_source")) { - $event->add_action("bulk_source", "Set Source", "", $this->theme->render_source_input(), 10); + $event->add_action("bulk_source", "Set (S)ource", "s","", $this->theme->render_source_input(), 10); } } diff --git a/ext/bulk_actions/theme.php b/ext/bulk_actions/theme.php index 538c74df..30eac633 100644 --- a/ext/bulk_actions/theme.php +++ b/ext/bulk_actions/theme.php @@ -2,14 +2,14 @@ class BulkActionsTheme extends Themelet { - public function display_selector(Page $page, $actions, $query) + public function display_selector(Page $page, array $actions, string $query) { global $user; $body = " - +