Merge pull request #13070 from resilient-tech/switch-theme-keys

feat: switch theme with left/right keys
This commit is contained in:
Suraj Shetty 2021-05-03 09:43:03 +05:30 committed by GitHub
commit faaf6ce8d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,6 +11,34 @@ frappe.ui.ThemeSwitcher = class ThemeSwitcher {
title: __("Switch Theme")
});
this.body = $(`<div class="theme-grid"></div>`).appendTo(this.dialog.$body);
this.bind_events();
}
bind_events() {
this.dialog.$wrapper.on('keydown', (e) => {
if (!this.themes) return;
const key = frappe.ui.keys.get_key(e);
let increment_by;
if (key === "right") {
increment_by = 1;
} else if (key === "left") {
increment_by = -1;
} else {
return;
}
const current_index = this.themes.findIndex(theme => {
return theme.name === this.current_theme;
});
const new_theme = this.themes[current_index + increment_by];
if (!new_theme) return;
new_theme.$html.click();
return false;
});
}
refresh() {