2023-05-30 02:24:56 +08:00
|
|
|
import OnClickButtonWidget from "./onclick_button.js";
|
|
|
|
|
import appContext from "../../components/app_context.js";
|
2024-08-01 14:20:33 +08:00
|
|
|
import { t } from "../../services/i18n.js";
|
2023-05-30 02:24:56 +08:00
|
|
|
|
|
|
|
|
export default class MovePaneButton extends OnClickButtonWidget {
|
2023-06-01 00:48:37 +08:00
|
|
|
constructor(isMovingLeft) {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
this.isMovingLeft = isMovingLeft;
|
|
|
|
|
|
|
|
|
|
this.icon(isMovingLeft ? "bx-chevron-left" : "bx-chevron-right")
|
2024-08-01 14:20:33 +08:00
|
|
|
.title(isMovingLeft ? t("move_pane_button.move_left") : t("move_pane_button.move_right"))
|
2023-06-01 00:48:37 +08:00
|
|
|
.titlePlacement("bottom")
|
|
|
|
|
.onClick(async (widget, e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
widget.triggerCommand("moveThisNoteSplit", {ntxId: widget.getClosestNtxId(), isMovingLeft: this.isMovingLeft});
|
|
|
|
|
})
|
|
|
|
|
.class("icon-action");
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-30 02:24:56 +08:00
|
|
|
isEnabled() {
|
2023-06-01 00:48:37 +08:00
|
|
|
if (!super.isEnabled()) {
|
2023-05-30 02:24:56 +08:00
|
|
|
return false;
|
2023-06-01 00:48:37 +08:00
|
|
|
}
|
|
|
|
|
|
2023-05-30 02:24:56 +08:00
|
|
|
if (this.isMovingLeft) {
|
|
|
|
|
// movable if the current context is not a main context, i.e. non-null mainNtxId
|
|
|
|
|
return !!this.noteContext?.mainNtxId;
|
|
|
|
|
} else {
|
|
|
|
|
const currentIndex = appContext.tabManager.noteContexts.findIndex(c => c.ntxId === this.ntxId);
|
|
|
|
|
const nextContext = appContext.tabManager.noteContexts[currentIndex + 1];
|
|
|
|
|
// movable if the next context is not null and not a main context, i.e. non-null mainNtxId
|
|
|
|
|
return !!nextContext?.mainNtxId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 00:48:37 +08:00
|
|
|
async noteContextRemovedEvent() {
|
2023-05-30 02:24:56 +08:00
|
|
|
this.refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 00:48:37 +08:00
|
|
|
async newNoteContextCreatedEvent() {
|
2023-05-30 02:24:56 +08:00
|
|
|
this.refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-01 00:48:37 +08:00
|
|
|
async noteContextReorderEvent() {
|
2023-05-30 02:24:56 +08:00
|
|
|
this.refresh();
|
|
|
|
|
}
|
2023-06-03 05:59:53 +08:00
|
|
|
|
|
|
|
|
async contextsReopenedEvent() {
|
|
|
|
|
this.refresh();
|
|
|
|
|
}
|
2023-05-30 02:24:56 +08:00
|
|
|
}
|