110 lines
2.7 KiB
JavaScript
110 lines
2.7 KiB
JavaScript
class TaskbarObject {
|
|
parentManager;
|
|
taskbarObject;
|
|
|
|
taskbarStart;
|
|
|
|
children;
|
|
|
|
constructor(manager) {
|
|
this.parentManager = manager;
|
|
this.taskbarObject = TaskbarObject.createTaskbar(this);
|
|
this.parentManager.addExtension(this, "taskbarObject");
|
|
this.parentManager.overscan_bottom = "2.5625em";
|
|
|
|
this.taskbarStart = this.taskbarObject.querySelector(".taskbar-start");
|
|
|
|
this.children = [];
|
|
|
|
this.parentManager.managerObject.addEventListener("windowcreate", (e) =>
|
|
this.addToTabs(e)
|
|
);
|
|
|
|
this.parentManager.managerObject.addEventListener("windowdestroy", (e) =>
|
|
this.removeFromTabs(e)
|
|
);
|
|
|
|
this.parentManager.managerObject.addEventListener("windowfocus", (e) =>
|
|
this.refocusTabs(e)
|
|
);
|
|
|
|
this.parentManager.managerObject.addEventListener(
|
|
"windowmanager_title",
|
|
(e) => this.updateTab(e)
|
|
);
|
|
}
|
|
|
|
addToTabs(e) {
|
|
const button = document.createElement("button");
|
|
button.classList.add("taskbar-button");
|
|
|
|
button.addEventListener("click", (e2) => this.event_raiseWindow(e, e2));
|
|
|
|
console.log(button);
|
|
|
|
this.children.splice(e.detail.windowId, 0, button);
|
|
this.taskbarStart.appendChild(button);
|
|
}
|
|
|
|
removeFromTabs(e) {
|
|
const button = this.children[e.detail.windowId];
|
|
|
|
console.log(this.children, e.detail.windowId);
|
|
|
|
this.children.splice(e.detail.windowId, 1);
|
|
this.taskbarStart.removeChild(button);
|
|
}
|
|
|
|
updateTab(e, mode) {
|
|
const button = this.children[e.detail.windowId];
|
|
|
|
button.textContent = e.detail.title;
|
|
}
|
|
|
|
refocusTabs(e) {
|
|
this.parentManager.children.forEach((child) => {
|
|
if (child.focusOrder <= 0) {
|
|
this.children[child.windowId].classList.add("taskbar-button-focusing");
|
|
} else
|
|
this.children[child.windowId].classList.remove(
|
|
"taskbar-button-focusing"
|
|
);
|
|
});
|
|
}
|
|
|
|
destroy() {
|
|
this.parentManager.overscan_bottom = "0px";
|
|
}
|
|
|
|
event_raiseWindow(e, e2) {
|
|
if (e.detail.focusOrder <= 0) {
|
|
e.detail.minimizeWindow();
|
|
} else {
|
|
this.parentManager.raiseWindow(e.detail);
|
|
}
|
|
refocusTabs();
|
|
}
|
|
|
|
static createTaskbar(taskbarRef) {
|
|
const taskbarObject = document.createElement("div");
|
|
taskbarObject.classList.add("taskbar-object");
|
|
taskbarObject.tabIndex = "0";
|
|
taskbarObject.style.zIndex = taskbarRef.parentManager.maxZIndex + 1;
|
|
|
|
{
|
|
const taskbarStart = document.createElement("div");
|
|
taskbarStart.classList.add("taskbar-start");
|
|
|
|
taskbarObject.appendChild(taskbarStart);
|
|
}
|
|
|
|
{
|
|
const taskbarEnd = document.createElement("div");
|
|
taskbarEnd.classList.add("taskbar-end");
|
|
|
|
taskbarObject.appendChild(taskbarEnd);
|
|
}
|
|
|
|
return taskbarObject;
|
|
}
|
|
}
|