Skip to content

Commit

Permalink
feat: common context menu for all grid items
Browse files Browse the repository at this point in the history
  • Loading branch information
WillsterJohnsonAtZenesis committed Nov 6, 2024
1 parent 2730868 commit e0cbd4f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
11 changes: 10 additions & 1 deletion source/class/qxl/datagrid/DataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ qx.Class.define("qxl.datagrid.DataGrid", {
init: "none",
check: ["rows", "columns", "both", "none"],
event: "changeDynamicSizing"
},

widgetsContextMenu: {
check: "qx.ui.menu.Menu",
init: null,
nullable: true,
event: "changeWidgetsContextMenu"
}
},

Expand All @@ -111,7 +118,9 @@ qx.Class.define("qxl.datagrid.DataGrid", {
},

widgetPane() {
return new qxl.datagrid.ui.WidgetPane(this.__sizeCalculator, this.getQxObject("paneWidgetFactory"), this.getDataSource(), this.__selectionManager);
let widgetPane = new qxl.datagrid.ui.WidgetPane(this.__sizeCalculator, this.getQxObject("paneWidgetFactory"), this.getDataSource(), this.__selectionManager);
this.bind("widgetsContextMenu", widgetPane, "widgetsContextMenu");
return widgetPane;
},

headerWidgetFactory() {
Expand Down
43 changes: 36 additions & 7 deletions source/class/qxl/datagrid/ui/WidgetPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ qx.Class.define("qxl.datagrid.ui.WidgetPane", {
check: "Boolean",
init: true,
event: "changeShouldDiscardWidgets"
},

/**
* The context menu to be used for widgets on the pane which do not have their own context menu
*/
widgetsContextMenu: {
check: "qx.ui.menu.Menu",
init: null,
nullable: true,
event: "changeWidgetsContextMenu",
apply: "_applyWidgetsContextMenu"
}
},

Expand All @@ -91,6 +102,15 @@ qx.Class.define("qxl.datagrid.ui.WidgetPane", {
/**@type {Record<string, qx.ui.core.Widget>}*/
__children: null,

_applyWidgetsContextMenu(value, old) {
for (let child of Object.values(this.__children)) {
let ctxMenu = child.getContextMenu();
if (!ctxMenu || ctxMenu === old) {
child.setContextMenu(value);
}
}
},

/**
* Invalidates all widgets, meaning that they will be recalculated next time `updateWidget` is called
*/
Expand Down Expand Up @@ -145,17 +165,21 @@ qx.Class.define("qxl.datagrid.ui.WidgetPane", {
let invalidateAll = this.__invalidateAll;
this.__invalidateAll = false;

let children = this.__children;
qx.lang.Array.clone(this._getChildren()).forEach(child => {
for (let child of qx.lang.Array.clone(this._getChildren())) {
let cellData = child.getUserData("qxl.datagrid.cellData");
let id = cellData.row + ":" + cellData.column;
// prettier-ignore
if (invalidateAll || cellData.row < minDataRowIndex || cellData.row > maxRowIndex || cellData.column < minColumnIndex || cellData.column > maxColumnIndex) {
this.__fullDiscardWidget(child, id);
} else {
children[id] = child;
this.__children[id] = child;
}
});
}

for (let child of Object.values(this.__children)) {
if (!child.getContextMenu()) {
child.setContextMenu(this.getWidgetsContextMenu());
}
}

let horizontalSpacing = styling.getHorizontalSpacing();
let verticalSpacing = styling.getVerticalSpacing();
Expand All @@ -182,7 +206,7 @@ qx.Class.define("qxl.datagrid.ui.WidgetPane", {
let id = rowSizeData.rowIndex + ":" + columnSizeData.columnIndex;
let filledWidth = columnSizeData.width;

let child = children[id];
let child = this.__children[id];

if (relativeColumnIndex < lastColSpanEndIndex || fillFromColumnIndex !== null) {
this.__fullDiscardWidget(child, id);
Expand All @@ -192,7 +216,7 @@ qx.Class.define("qxl.datagrid.ui.WidgetPane", {
let model = dataSource.getModelForPosition(new qxl.datagrid.source.Position(rowSizeData.rowIndex, columnSizeData.columnIndex));
if (!child || invalidateAll) {
child = this.__widgetFactory.getWidgetFor(rowSizeData.rowIndex, columnSizeData.columnIndex);
children[id] = child;
this.__children[id] = child;
child.setUserData("qxl.datagrid.cellData", {
row: rowSizeData.rowIndex,
column: columnSizeData.columnIndex,
Expand Down Expand Up @@ -293,6 +317,11 @@ qx.Class.define("qxl.datagrid.ui.WidgetPane", {
return this.__children[`${row}:${column}`] ?? null;
},

getPositionOfChild(child) {
let cellData = child.getUserData("qxl.datagrid.cellData");
return cellData ? new qxl.datagrid.source.Position(cellData.row, cellData.column) : null;
},

/**
* Event handler for tap events
*/
Expand Down

0 comments on commit e0cbd4f

Please sign in to comment.