Api: Fix auto copy/paste nm actions

This commit is contained in:
nathan 2025-01-10 15:30:35 -07:00
parent 8be9ffa47b
commit 5aef3df2e8
4 changed files with 45 additions and 32 deletions

View File

@ -12,21 +12,22 @@ import {EgwActionLink} from "./EgwActionLink";
import {EgwActionManager} from "./EgwActionManager";
import {egwBitIsSet, egwObjectLength, egwQueueCallback, egwSetBit} from "./egw_action_common";
import {
EGW_AO_EXEC_SELECTED, EGW_AO_EXEC_THIS,
EGW_AO_FLAG_IS_CONTAINER,
EGW_AO_SHIFT_STATE_BLOCK,
EGW_AO_SHIFT_STATE_MULTI,
EGW_AO_SHIFT_STATE_NONE,
EGW_AO_STATE_FOCUSED,
EGW_AO_STATE_NORMAL,
EGW_AO_STATE_SELECTED,
EGW_AO_STATE_VISIBLE,
EGW_KEY_A,
EGW_KEY_ARROW_DOWN,
EGW_KEY_ARROW_UP,
EGW_KEY_PAGE_DOWN,
EGW_KEY_PAGE_UP,
EGW_KEY_SPACE
EGW_AO_EXEC_SELECTED,
EGW_AO_EXEC_THIS,
EGW_AO_FLAG_IS_CONTAINER,
EGW_AO_SHIFT_STATE_BLOCK,
EGW_AO_SHIFT_STATE_MULTI,
EGW_AO_SHIFT_STATE_NONE,
EGW_AO_STATE_FOCUSED,
EGW_AO_STATE_NORMAL,
EGW_AO_STATE_SELECTED,
EGW_AO_STATE_VISIBLE,
EGW_KEY_A,
EGW_KEY_ARROW_DOWN,
EGW_KEY_ARROW_UP,
EGW_KEY_PAGE_DOWN,
EGW_KEY_PAGE_UP,
EGW_KEY_SPACE
} from "./egw_action_constants";
import type {EgwActionObjectInterface} from "./EgwActionObjectInterface";
import {egwActionObjectInterface} from "./egw_action";
@ -973,9 +974,10 @@ export class EgwActionObject {
* an array of links/selected objects-
*/
getSelectedLinks(_actionType) {
getSelectedLinks(_actionType, useSelf = false)
{
// Get all objects in this container which are currently selected
const selected = this.getContainerRoot().getSelectedObjects();
const selected = useSelf ? [this] : this.getContainerRoot().getSelectedObjects();
return this._getLinks(selected, _actionType);
};

View File

@ -167,6 +167,13 @@ export class EgwMenuShoelace extends LitElement
menuItem.checked = _links[actionId].actionObj.checked ?? false;
}
});
// Copy caption changes
let osClipboard;
if(_links.egw_os_clipboard && (osClipboard = <SlMenuItem>this.shadowRoot.querySelector("[data-action-id='egw_os_clipboard']")))
{
osClipboard.innerText = _links.egw_os_clipboard.actionObj.caption;
}
}
public hide()
{

View File

@ -122,6 +122,7 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
{
menu = _selected[0].parent.manager.data.menu
}
this._addCopyPaste(_links, _selected);
if(!menu)
{
menu = this._buildMenu(_links, _selected, _target);
@ -324,7 +325,7 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
_context.parent.manager.data.menu = {}; // Set it to something or it will do this for every row
window.setTimeout(() =>
{
_context.parent.manager.data.menu = this._buildMenu(_context.actionLinks.filter(l => l.actionObj.type == "popup"), [_context], null);
_context.parent.manager.data.menu = this._buildMenu(_context.actionLinks, [_context], null);
_context.parent.manager.data.menu.showAt(0, 0);
_context.parent.manager.data.menu.hide();
}, 0);
@ -396,7 +397,7 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
// Check whether the link group of the current element already exists,
// if not, create the group
const grp = popupAction.group;
const grp = popupAction.group ?? 999;
if (typeof link_groups[grp] == "undefined") {
link_groups[grp] = [];
}
@ -448,8 +449,8 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
}
groups.sort(function (a, b) {
const ia = parseInt(a.grp);
const ib = parseInt(b.grp);
const ia = parseFloat(a.grp);
const ib = parseFloat(b.grp);
return (ia > ib) ? 1 : ((ia < ib) ? -1 : 0);
});
@ -552,14 +553,17 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
const tree = {"root": []};
// Automatically add in Drag & Drop actions
if(this.auto_paste && !window.egwIsMobile() && this._context?.event && !this._context.event?.type.match(/touch/))
if(this.auto_paste && !window.egwIsMobile() && (!this._context?.event || this._context?.event && !this._context.event?.type.match(/touch/)))
{
this._addCopyPaste(_links, _selected);
}
for (const k in _links) {
_links[k].actionObj.appendToTree(tree);
}
if(_links[k].actionObj.type == "popup")
{
_links[k].actionObj.appendToTree(tree);
}
}
// We need the dummy object container in order to pass the array by
// reference
@ -599,8 +603,8 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
*/
private _addCopyPaste = (_links, _selected:EgwActionObject[])=> {
// Get a list of drag & drop actions
const drag = _selected[0].getSelectedLinks('drag').links;
const drop = _selected[0].getSelectedLinks('drop').links;
const drag = _selected[0].getSelectedLinks('drag', true).links;
const drop = _selected[0].getSelectedLinks('drop', true).links;
// No drags & no drops means early exit (only by default added egw_cancel_drop does NOT count!)
if ((!drag || jQuery.isEmptyObject(drag)) &&
@ -621,7 +625,8 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
position: {top: 0, left: 0},
offset: {top: 0, left: 0}
};
if (this._context.event) {
if(this._context?.event)
{
const event = this._context.event.originalEvent || this._context.event;
ui.position = {top: event.pageY, left: event.pageX};
ui.offset = {top: event.offsetY, left: event.offsetX};
@ -707,8 +712,9 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
clipboard_action.group = 2.5;
}
let os_clipboard_caption = "";
if (this._context.event) {
os_clipboard_caption = this._context.event.target.innerText.trim()
if(this._context?.event)
{
os_clipboard_caption = this._context.event.target.innerText.trim().replaceAll("\n", " ");
clipboard_action.set_caption(window.egw.lang('Copy "%1"', os_clipboard_caption.length > 20 ? os_clipboard_caption.substring(0, 20) + '...' : os_clipboard_caption));
clipboard_action.data.target = this._context.target;
}
@ -750,7 +756,7 @@ export class EgwPopupActionImplementation implements EgwActionImplementation {
_links[clipboard_action.id] = {
"actionObj": clipboard_action,
"enabled": os_clipboard_caption.length > 0,
"visible": os_clipboard_caption.length > 0,
"visible": this._context ? os_clipboard_caption.length > 0 : true,
"cnt": 0
};
}

View File

@ -195,8 +195,6 @@ export class egwMenu
_egw_active_menu = null;
});
return true;
return false;
}