44 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-09-24 09:57:16 +08:00
import { t } from "../services/i18n.js";
2021-05-17 21:46:18 +02:00
import BasicWidget from "./basic_widget.js";
2022-12-22 14:57:00 +01:00
import contextMenu from "../menus/context_menu.js";
import appContext, { type CommandNames } from "../components/app_context.js";
import utils from "../services/utils.js";
2021-05-17 21:46:18 +02:00
const TPL = /*html*/`<div class="spacer"></div>`;
2021-05-17 21:46:18 +02:00
export default class SpacerWidget extends BasicWidget {
2025-01-04 21:59:35 +02:00
private baseSize: number;
private growthFactor: number;
2022-08-06 13:47:27 +02:00
constructor(baseSize = 0, growthFactor = 1000) {
2021-05-24 22:29:49 +02:00
super();
this.baseSize = baseSize;
2022-08-06 13:47:27 +02:00
this.growthFactor = growthFactor;
2021-05-24 22:29:49 +02:00
}
2021-05-17 21:46:18 +02:00
doRender() {
this.$widget = $(TPL);
this.$widget.css("flex-basis", this.baseSize);
2022-08-06 13:47:27 +02:00
this.$widget.css("flex-grow", this.growthFactor);
this.$widget.css("flex-shrink", 1000);
2022-12-22 14:57:00 +01:00
2025-01-09 18:07:02 +02:00
this.$widget.on("contextmenu", (e) => {
2022-12-22 14:57:00 +01:00
this.$widget.tooltip("hide");
contextMenu.show<CommandNames>({
2022-12-22 14:57:00 +01:00
x: e.pageX,
y: e.pageY,
2025-01-09 18:07:02 +02:00
items: [{ title: t("spacer.configure_launchbar"), command: "showLaunchBarSubtree", uiIcon: "bx " + (utils.isMobile() ? "bx-mobile" : "bx-sidebar") }],
selectMenuItemHandler: ({ command }) => {
2025-01-04 21:59:35 +02:00
if (command) {
appContext.triggerCommand(command);
}
2022-12-22 14:57:00 +01:00
}
});
return false; // blocks default browser right click menu
2022-12-22 14:57:00 +01:00
});
2021-05-17 21:46:18 +02:00
}
}