mirror of
https://github.com/discourse/discourse.git
synced 2024-12-16 10:33:40 +08:00
7ab7e6bb23
Previous to this change there is no clean way to apply keyboard shortcuts to things such as "add poll" and other hidden options in the toolbar This allows shortcuts to be specified similar to how they are on the toolbar Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
import { PLATFORM_KEY_MODIFIER } from "discourse/lib/keyboard-shortcuts";
|
|
import { translateModKey } from "discourse/lib/utilities";
|
|
import I18n from "discourse-i18n";
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
|
|
|
export default DropdownSelectBoxComponent.extend({
|
|
pluginApiIdentifiers: ["toolbar-popup-menu-options"],
|
|
classNames: ["toolbar-popup-menu-options"],
|
|
|
|
selectKitOptions: {
|
|
showFullTitle: false,
|
|
filterable: false,
|
|
autoFilterable: false,
|
|
preventHeaderFocus: true,
|
|
customStyle: true,
|
|
},
|
|
|
|
modifyContent(contents) {
|
|
return contents
|
|
.map((content) => {
|
|
if (content.condition) {
|
|
let label;
|
|
if (content.label) {
|
|
label = I18n.t(content.label);
|
|
if (content.shortcut) {
|
|
label += ` <kbd class="shortcut">${translateModKey(
|
|
PLATFORM_KEY_MODIFIER
|
|
)}+${translateModKey(content.shortcut)}</kbd>`;
|
|
}
|
|
}
|
|
|
|
let title;
|
|
if (content.title) {
|
|
title = I18n.t(content.title);
|
|
if (content.shortcut) {
|
|
title += ` (${translateModKey(
|
|
PLATFORM_KEY_MODIFIER
|
|
)}+${translateModKey(content.shortcut)})`;
|
|
}
|
|
}
|
|
|
|
let name = content.name;
|
|
if (!name && content.label) {
|
|
name = I18n.t(content.label);
|
|
}
|
|
|
|
return {
|
|
icon: content.icon,
|
|
label,
|
|
title,
|
|
name,
|
|
id: { name: content.name, action: content.action },
|
|
};
|
|
}
|
|
})
|
|
.filter(Boolean);
|
|
},
|
|
});
|