Changes to action system:

- Change selected to not start at global root - fixes key handler only working for 1 app
 - Add depth limit for finding action / object (depth first search)
 - Use depth limit when looking for top level application action/object to avoid crossing apps
This commit is contained in:
Nathan Gray 2014-01-18 11:21:53 +00:00
parent 7879e7ac2e
commit 35c70fea93
5 changed files with 53 additions and 28 deletions

View File

@ -400,7 +400,8 @@ var et2_DOMWidget = et2_widget.extend(et2_IDOMNode,
}
// Initialize the action manager and add some actions to it
var gam = egw_getAppActionManager();
// Only look 1 level deep
var gam = egw_getActionManager(this.egw().appName,true,1);
if(typeof this._actionManager != "object")
{
if(gam.getActionById(this.id) != null)

View File

@ -327,14 +327,16 @@ var et2_dataview_selectionManager = Class.extend(
}
function getElementRelatively (_step) {
var count = self._total;
// Get a reasonable number of iterations - not all
var total = Math.max(1,Math.min(Object.keys(self._indexMap).length,50));
var count = total;
var element = null;
var idx = _entry.idx;
while(element == null && count > 0 && idx <= self._total)
while(element == null && count > 0 && idx <= total)
{
count--;
element = getIndexAO(Math.max(0,
Math.min(self._total - 1, idx += _step)));
Math.min(self._total||total - 1, idx += _step)));
}
return element;
};

View File

@ -127,12 +127,8 @@ var et2_nextmatch_controller = et2_dataview_controller.extend(et2_IDataProvider,
if(_actions == null) _actions = [];
// Initialize the action manager and add some actions to it
// To work around a bug in action system we call global actionManger
// of an application NOT just appname, but prefix it with "__"
// If it is called just appname, actionLinks of actions with id
// of an application fetch that applications menu as children,
// if that applications tab is open in toplevel window.
var gam = egw_getActionManager('__'+this.egw.appName);
// Only look 1 level deep
var gam = egw_getActionManager(this.egw.appName,true,1);
this._actionManager = gam.addAction("actionManager", uid);
this._actionManager.updateActions(_actions, this.egw.appName);
var data = this._actionManager.data;
@ -166,8 +162,9 @@ var et2_nextmatch_controller = et2_dataview_controller.extend(et2_IDataProvider,
}, this));
}
// Initialize the object manager
var gom = egw_getObjectManager(this.egw.appName);
// Initialize the object manager - look for application
// object manager 1 level deep
var gom = egw_getObjectManager(this.egw.appName,true,1);
this._objectManager = gom.addObject(
new egwActionObjectManager(uid, this._actionManager));
this._objectManager.flags = this._objectManager.flags

View File

@ -329,7 +329,8 @@ var et2_tree = et2_inputWidget.extend(
_link_actions: function(actions)
{
// Get the top level element for the tree
var objectManager = egw_getAppObjectManager(true);
// Only look 1 level deep for application object manager
var objectManager = egw_getObjectManager(this.egw().appName,true,1);
var treeObj = objectManager.getObjectById(this.id);
if (treeObj == null) {
// Add a new container to the object manager which will hold the tree

View File

@ -28,11 +28,18 @@ var egw_globalObjectManager = null;
* @param _id is the name of the sub-actionManager which should be returned.
* If the action manager does not exist right now, it is created. If the
* parameter is ommited or null, the global action manager is returned.
* @param {boolean} [_create=true] If an objectManager with the given id is not
* found, it will be created at the top level.
* @param {number} [_search_depth=Infinite] How deep into existing action children
* to search.
*/
function egw_getActionManager(_id, _create) {
function egw_getActionManager(_id, _create,_search_depth) {
if (typeof _create == 'undefined') {
_create = true;
}
if (typeof _search_depth == "undefined") {
_search_depth = Number.MAX_VALUE;
}
// Check whether the global action manager had been created, if not do so
var res = egw_globalActionManager;
@ -42,7 +49,7 @@ function egw_getActionManager(_id, _create) {
// Check whether the sub-action manager exists, if not, create it
if (typeof _id != 'undefined' && _id != null) {
res = egw_globalActionManager.getActionById(_id);
res = egw_globalActionManager.getActionById(_id,_search_depth);
if (res == null && _create) {
res = egw_globalActionManager.addAction("actionManager", _id);
}
@ -58,11 +65,18 @@ function egw_getActionManager(_id, _create) {
* @param _id is the name of the sub-object manager should be returned. If the
* object manager does not exists right now, it is created. If the parameter
* is ommited or null, the global object manager is returned.
* @param {boolean} [_create=true] If an objectManager with the given id is not
* found, it will be created at the top level.
* @param {number} [_search_depth=Infinite] How deep into existing action children
* to search.
*/
function egw_getObjectManager(_id, _create) {
function egw_getObjectManager(_id, _create, _search_depth) {
if (typeof _create == "undefined") {
_create = true;
}
if (typeof _search_depth == "undefined") {
_search_depth = Number.MAX_VALUE;
}
// Check whether the global object manager exists
var res = egw_globalObjectManager;
@ -74,7 +88,7 @@ function egw_getObjectManager(_id, _create) {
// Check whether the sub-object manager exists, if not, create it
if (typeof _id != 'undefined' && _id != null) {
res = egw_globalObjectManager.getObjectById(_id);
res = egw_globalObjectManager.getObjectById(_id, _search_depth);
if (res == null && _create) {
res = new egwActionObjectManager(_id,
egw_getActionManager(_id));
@ -89,14 +103,14 @@ function egw_getObjectManager(_id, _create) {
* Returns the object manager for the current application
*/
function egw_getAppObjectManager(_create) {
return egw_getObjectManager(egw_getAppName(), _create);
return egw_getObjectManager(egw_getAppName(), _create,1);
}
/**
* Returns the action manager for the current application
*/
function egw_getAppActionManager(_create) {
return egw_getActionManager(egw_getAppName(), _create);
return egw_getActionManager(egw_getAppName(), _create,1);
}
@ -185,22 +199,31 @@ egwAction.prototype.remove = function () {
/**
* Searches for a specific action with the given id
*
* @param {string|number} id ID of the action to find
* @param {number} [_search_depth=Infinite] How deep into existing action children
* to search.
*
* @return {egwAction|null}
*/
egwAction.prototype.getActionById = function(_id)
egwAction.prototype.getActionById = function(_id,_search_depth)
{
// If the current action object has the given id, return this object
if (this.id == _id)
{
return this;
}
if (typeof _search_depth == "undefined") {
_search_depth = Number.MAX_VALUE;
}
// If this element is capable of having children, search those for the given
// action id
if (this.canHaveChildren)
{
for (var i = 0; i < this.children.length; i++)
for (var i = 0; i < this.children.length && _search_depth > 0; i++)
{
var elem = this.children[i].getActionById(_id);
var elem = this.children[i].getActionById(_id,_search_depth-1);
if (elem)
{
return elem;
@ -933,16 +956,19 @@ egwActionObject.prototype.setAOI = function(_aoi)
* Returns the object from the tree with the given ID
*/
//TODO: Add search function to egw_action_commons.js
egwActionObject.prototype.getObjectById = function(_id)
egwActionObject.prototype.getObjectById = function(_id, _search_depth)
{
if (this.id == _id)
{
return this;
}
if (typeof _search_depth == "undefined") {
_search_depth = Number.MAX_VALUE;
}
for (var i = 0; i < this.children.length; i++)
for (var i = 0; i < this.children.length && _search_depth > 0; i++)
{
var obj = this.children[i].getObjectById(_id);
var obj = this.children[i].getObjectById(_id, _search_depth - 1);
if (obj)
{
return obj;
@ -1268,9 +1294,7 @@ egwActionObject.prototype.getIndex = function()
*/
egwActionObject.prototype.getFocusedObject = function()
{
/*var cr = this.getContainerRoot();*/
var cr = this.getRootObject();
return cr ? cr.focusedChild : null;
return this.focusedChild || null;
}
/**