import { state, notify, activeTab } from "../store.js"; import { t } from "../i18n.js"; import { iconMarkup } from "../icons.js"; import * as ipc from "../ipc.js"; import { openNew } from "./connectDialog.js"; import { toggle as toggleHistory } from "./historyPopup.js"; import { openMkdir, openDelete, openRename } from "./opDialogs.js"; import { openSettings } from "./settingsDialog.js"; import { queueUploadMany, queueDownloadMany, refreshLocal, refreshRemote } from "../fsActions.js"; import { shortcutLabel, isMac } from "../platform.js"; let lastSig = null; function pendingCount() { return state.queueTasks.filter((tk) => { const s = tk.state; const kind = typeof s === "string" ? s : Object.keys(s)[0]; return kind === "running" || kind === "queued"; }).length; } function currentSelection() { if (state.activePane === "remote") { return activeTab()?.remoteSelected ?? []; } return state.local.selected; } export function renderToolbar(container) { const tab = activeTab(); const connected = tab?.status === "connected"; container.innerHTML = `
`; container.querySelector('[data-action="new-connection"]').addEventListener("click", openNew); container.querySelector('[data-action="settings"]').addEventListener("click", openSettings); container.querySelector('[data-action="upload"]').addEventListener("click", () => { const t2 = activeTab(); const entries = state.local.entries.filter((e) => state.local.selected.includes(e.name)); if (t2 && entries.length > 0) queueUploadMany(t2, entries); }); container.querySelector('[data-action="download"]').addEventListener("click", () => { const t2 = activeTab(); const entries = t2?.remoteEntries.filter((e) => t2.remoteSelected.includes(e.name)) ?? []; if (t2 && entries.length > 0) queueDownloadMany(t2, entries); }); container.querySelector('[data-action="toggle-queue"]').addEventListener("click", () => { state.showQueue = !state.showQueue; notify(); }); container.querySelector('[data-action="refresh"]').addEventListener("click", () => { if (state.activePane === "remote" && tab) refreshRemote(tab); else refreshLocal(); }); container.querySelector('[data-action="new-folder"]').addEventListener("click", () => { state.opTarget = state.activePane; openMkdir(); }); container.querySelector('[data-action="delete"]').addEventListener("click", () => { const names = currentSelection(); if (names.length === 0) return; state.opTarget = state.activePane; openDelete(names); }); container.querySelector('[data-action="rename"]').addEventListener("click", () => { const names = currentSelection(); if (names.length !== 1) return; state.opTarget = state.activePane; openRename(names[0]); }); container.querySelector('[data-action="new-window"]').addEventListener("click", () => { ipc.newWindow(); }); container.querySelector('[data-action="history"]').addEventListener("click", (e) => { toggleHistory(e.currentTarget); }); lastSig = computeSig(); } function computeSig() { const tab = activeTab(); return JSON.stringify([ state.activeTabId, state.activePane, tab?.status, tab?.remoteSelected, state.local.selected, state.showQueue, state.showHistoryPopup, pendingCount(), ]); } export function updateToolbarIfNeeded(container) { const sig = computeSig(); if (sig === lastSig) return; renderToolbar(container); }