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";
|
2025-03-20 19:54:09 +02:00
|
|
|
import appContext, { type CommandNames } from "../components/app_context.js";
|
2025-01-04 22:00:39 +02:00
|
|
|
import utils from "../services/utils.js";
|
2021-05-17 21:46:18 +02:00
|
|
|
|
2025-04-01 23:24:21 +03: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();
|
|
|
|
|
2021-06-05 14:12:17 +02:00
|
|
|
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);
|
2021-06-05 14:12:17 +02:00
|
|
|
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");
|
|
|
|
|
2025-03-20 19:54:09 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
2022-12-25 10:33:31 +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
|
|
|
}
|
|
|
|
}
|