Skip to content

Commit

Permalink
Provide getMenuHeader function for custom cases
Browse files Browse the repository at this point in the history
Better handling class names within namespaces
  • Loading branch information
linev committed Dec 9, 2024
1 parent 527489e commit 4f0d113
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
12 changes: 6 additions & 6 deletions modules/base/ObjectPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,12 @@ class ObjectPainter extends BasePainter {
/** @summary Fill context menu for the object
* @private */
fillContextMenu(menu) {
const name = this.getObjectName();
let cl = this.getClassName();
const p = cl.lastIndexOf('::');
if (p > 0) cl = cl.slice(p+2);
const hdr = (cl && name) ? `${cl}:${name}` : (cl || name || 'object'),
url = (p < 0) ? `${urlClassPrefix}${cl}.html` : '';
const cl = this.getClassName(),
name = this.getObjectName(),
p = cl.lastIndexOf('::'),
cl0 = (p > 0) ? cl.slice(p+2) : cl,
hdr = (cl0 && name) ? `${cl0}:${name}` : (cl0 || name || 'object'),
url = cl ? `${urlClassPrefix}${cl.replaceAll('::', '_1_1')}.html` : '';

menu.header(hdr, url);

Expand Down
7 changes: 6 additions & 1 deletion modules/draw/TWebPaintingPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ class TWebPaintingPainter extends ObjectPainter {
return true;
}

/** @summary Provides menu header */
getMenuHeader() {
return this.getObject()?.fClassName || 'TWebPainting';
}

/** @summary Fill context menu
* @desc Create only header, items will be requested from server */
fillContextMenu(menu) {
const cl = this.getObject()?.fClassName || 'TWebPainting';
const cl = this.getMenuHeader();
menu.header(cl, `${urlClassPrefix}${cl}.html`);
return true;
}
Expand Down
14 changes: 10 additions & 4 deletions modules/gpad/TPadPainter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2485,10 +2485,16 @@ class TPadPainter extends ObjectPainter {
const shown = [];
this.painters.forEach((pp, indx) => {
const obj = pp?.getObject();
if (!obj || (shown.indexOf(obj) >= 0)) return;
let name = isFunc(pp.getClassName) ? pp.getClassName() : (obj._typename || '');
if (name) name += '::';
name += isFunc(pp.getObjectName) ? pp.getObjectName() : (obj.fName || `item${indx}`);
if (!obj || (shown.indexOf(obj) >= 0))
return;
let name = '';
if (isFunc(pp.getMenuHeader))
name = pp.getMenuHeader();
else {
name = isFunc(pp.getClassName) ? pp.getClassName() : (obj._typename || '');
if (name) name += '::';
name += isFunc(pp.getObjectName) ? pp.getObjectName() : (obj.fName || `item${indx}`);
}
menu.add(name, indx, this.itemContextMenu);
shown.push(obj);
});
Expand Down

0 comments on commit 4f0d113

Please sign in to comment.