modifier key settings, #32

pull/33/head
AlUlkesh 2023-02-11 09:57:58 +01:00
parent 94082b3885
commit 0416810adf
3 changed files with 31 additions and 3 deletions

View File

@ -38,6 +38,8 @@ Please be aware that when scanning a directory for the first time, the png-cache
| `Ctrl + Arrow Left` | Goes to the previous page of images |
| `Ctrl + Arrow Right` | Goes to the next page of images |
(Ctrl can be changed in settings)
## Credit
Credit goes to the original maintainer of this extension: https://github.com/yfszzx and to major contributor https://github.com/Klace

View File

@ -240,6 +240,22 @@ gradioApp().addEventListener("keydown", function(event) {
}
}
let mod_keys = gradioApp().querySelector(`#${tabname}_image_browser_mod_keys textarea`).value;
let modifiers_pressed = false;
if (mod_keys.indexOf("C") !== -1 && mod_keys.indexOf("S") !== -1) {
if (event.ctrlKey && event.shiftKey) {
modifiers_pressed = true;
}
} else if (mod_keys.indexOf("S") !== -1) {
if (!event.ctrlKey && event.shiftKey) {
modifiers_pressed = true;
}
} else {
if (event.ctrlKey && !event.shiftKey) {
modifiers_pressed = true;
}
}
if (event.code == "KeyF") {
if (tabname == "Favorites") {
return;
@ -258,12 +274,12 @@ gradioApp().addEventListener("keydown", function(event) {
deleteBtn.dispatchEvent(new Event("click"));
}
if (event.code == "ArrowLeft" && event.ctrlKey) {
if (event.code == "ArrowLeft" && modifiers_pressed) {
let prevBtn = gradioApp().getElementById(tabname + "_image_browser_prev_page");
prevBtn.dispatchEvent(new Event("click"));
}
if (event.code == "ArrowRight" && event.ctrlKey) {
if (event.code == "ArrowRight" && modifiers_pressed) {
let nextBtn = gradioApp().getElementById(tabname + "_image_browser_next_page");
nextBtn.dispatchEvent(new Event("click"));
}

View File

@ -642,6 +642,12 @@ def create_tab(tabname):
turn_page_switch = gr.Number(value=1, label="turn_page_switch")
img_path_add = gr.Textbox(value="add")
img_path_remove = gr.Textbox(value="remove")
mod_keys = ""
if opts.image_browser_mod_ctrl_shift:
mod_keys = f"{mod_keys}CS"
elif opts.image_browser_mod_shift:
mod_keys = f"{mod_keys}S"
image_browser_mod_keys = gr.Textbox(value=mod_keys, elem_id=f"{tabname}_image_browser_mod_keys")
change_dir_outputs = [warning_box, main_panel, img_path_browser, path_recorder, load_switch, img_path, img_path_depth]
img_path.submit(change_dir, inputs=[img_path, path_recorder, load_switch, img_path_browser, img_path_depth, img_path], outputs=change_dir_outputs)
@ -798,6 +804,9 @@ def on_ui_settings():
image_browser_options.append(("image_browser_logger_debug", False, "Print debug logs to the console", "images_logger_debug"))
image_browser_options.append(("image_browser_delete_recycle", False, "Use recycle bin when deleting images", "images_delete_recycle"))
image_browser_options.append(("image_browser_scan_exif", True, "Scan Exif-/.txt-data (slower, but required for exif-keyword-search)", "images_scan_exif"))
image_browser_options.append(("image_browser_mod_shift", False, "Change CTRL keybindings to SHIFT", None))
image_browser_options.append(("image_browser_mod_ctrl_shift", False, "or to CTRL+SHIFT", None))
image_browser_options.append(("image_browser_page_columns", 6, "Number of columns on the page", "images_history_page_columns"))
image_browser_options.append(("image_browser_page_rows", 6, "Number of rows on the page", "images_history_page_rows"))
image_browser_options.append(("image_browser_pages_perload", 20, "Minimum number of pages per load", "images_history_pages_perload"))
@ -806,7 +815,8 @@ def on_ui_settings():
# Move historic setting names to current names
added = 0
for i in range(len(image_browser_options)):
added = move_setting(image_browser_options[i], section, added)
if image_browser_options[i][3] is not None:
added = move_setting(image_browser_options[i], section, added)
if added > 0:
shared.opts.save(shared.config_filename)