cables_dev/cables_ui/src/ui/components/tabs/tab_spreadsheet.js
- import { Port, utils } from "cables";
- import { ele, Events, Logger } from "cables-shared-client";
- import TabPanel from "../../elements/tabpanel/tabpanel.js";
- import Tab from "../../elements/tabpanel/tab.js";
- import { gui } from "../../gui.js";
- import { editorSession } from "../../elements/tabpanel/editor_session.js";
- import undo from "../../utils/undo.js";
- export default class SpreadSheetTab extends Events
- {
- static TABSESSION_NAME = "spreadsheet";
- #log = new Logger("SpreadSheetTab");
- #cellMate = null;
- #port = null;
- #options = null;
- #tab = null;
-
- #tabs = null;
- #currentId;
-
- constructor(tabs, port, options)
- {
- super();
- if (!port)
- {
- console.log("spreadsheettab missing args");
- return;
- }
- this.#tabs = tabs;
- this.#currentId = port.op.id + "_" + port.name;
- options = options || {};
- if (options.colNames && !options.numColumns)options.numColumns = options.colNames.length;
- this.#port = port;
- this.#options = options;
- this.#tab = new Tab(options.title || port.op.getTitle(), {
- "icon": "spreadsheet",
- "infotext": "tab_spreadsheet",
- "padding": true,
- "singleton": false });
- this.#tabs.addTab(this.#tab, true);
- this.#tab.on("close", () =>
- {
- editorSession.remove(SpreadSheetTab.TABSESSION_NAME, this.#currentId);
- this.#cellMate.dispose();
- });
- this.#tab.on(Tab.EVENT_RESIZE, () =>
- {
- this.#cellMate.resize();
- });
- this.#tab.on(Tab.EVENT_ACTIVATE, () =>
- {
- this.#cellMate.resize();
- });
- this.#tab.addButton("export csv", () =>
- {
- this.#cellMate.download("cables.csv", this.#cellMate.toCsv());
- });
- this.#tab.addButton("delete line", () =>
- {
- this.#cellMate.deleteCurrentLine();
- });
- this.#tab.addButton("insert line", () =>
- {
- this.#cellMate.insertLineAtCursor();
- });
- editorSession.rememberOpenEditor(SpreadSheetTab.TABSESSION_NAME, this.#currentId, {
- "portname": port.name,
- "opid": port.op.id,
- }, true);
- this.show();
- gui.maintabPanel.show(true);
- }
- show()
- {
- let html = "<div></div>";
- this.#tab.html(html);
- this.#cellMate = new CellMate(this.#tab.contentEle,
- {
- "undo": undo,
- "onChange": this.onChange.bind(this)
- });
- this.#cellMate.fromObj(this.#port.get());
- }
- onChange()
- {
- console.log(this.#cellMate.toObj());
- this.#port.setRef(this.#cellMate.toObj());
- }
- }
- editorSession.addListener(SpreadSheetTab.TABSESSION_NAME, (id, data) =>
- {
- const op = gui.corePatch().getOpById(data.opid);
- if (!op) return console.log("no spread op found..");
- new SpreadSheetTab(gui.mainTabs, op.getPortByName(data.portname));
- });