Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / client / src / interface_v3 / macrocmd_key.cpp
blob0f8055043bd6eed6bc2b94ed23de1d8e4bcaa053
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "stdpch.h"
25 // Interface
26 #include "macrocmd_key.h"
27 #include "macrocmd_manager.h"
29 #include "interface_manager.h"
30 #include "nel/gui/action_handler.h"
31 #include "nel/gui/ctrl_button.h"
32 #include "nel/gui/group_editbox.h"
33 #include "nel/gui/group_list.h"
34 #include "nel/gui/dbgroup_combo_box.h"
35 #include "nel/gui/group_container.h"
36 #include "group_modal_get_key.h"
37 #include "nel/gui/interface_expr.h"
39 // tmp
40 #include "../r2/editor.h"
43 using namespace std;
44 using namespace NLMISC;
46 #ifdef DEBUG_NEW
47 #define new DEBUG_NEW
48 #endif
50 // ***************************************************************************
51 // ***************************************************************************
52 // ***************************************************************************
53 // KEYS SHORTCUT KEYS SHORTCUT KEYS SHORTCUT KEYS SHORTCUT KEYS SHORTCUT KEYS
54 // ***************************************************************************
55 // ***************************************************************************
56 // ***************************************************************************
58 // To display all keys
60 #define WIN_KEYS "ui:interface:keys"
61 #define WIN_KEYS_GAME "ui:interface:keys_"
62 #define WIN_KEYS_EDIT "ui:interface:keys_edit"
63 #define WIN_KEYS_EDIT_CONTENT "ui:interface:keys_edit:content"
64 #define TEMPLATE_KEYS_GROUP "tk_line"
65 #define TEMPLATE_KEYS_KEY_NAME "name"
66 #define TEMPLATE_KEYS_SHORTCUT_NAME "command"
68 // To edit a key already defined
70 #define WIN_EDITKEY "ui:interface:editkey"
71 #define VIEW_EDITKEY_TEXT_CATEGORY "ui:interface:editkey:content:category"
72 #define VIEW_EDITKEY_TEXT_ACTION "ui:interface:editkey:content:action"
73 #define VIEW_EDITKEY_TEXT_FIRST_PARAM "ui:interface:editkey:content:param1"
74 #define VIEW_EDITKEY_TEXT_SECOND_PARAM "ui:interface:editkey:content:param2"
75 #define VIEW_EDITKEY_TEXT_FIRST_PARAM_NAME "ui:interface:editkey:content:param1_name"
76 #define VIEW_EDITKEY_TEXT_SECOND_PARAM_NAME "ui:interface:editkey:content:param2_name"
77 #define VIEW_EDITKEY_TEXT_KEY "ui:interface:editkey:content:txtkey"
79 // To define a key
81 #define WIN_MODAL_GET_KEY "ui:interface:assign_key"
83 // ***************************************************************************
84 // Display all keys
85 // ***************************************************************************
88 // ***************************************************************************
89 // Add the template key to the parent
90 void addKeyLine (CGroupList *pParent, const string &keyName, const string &shortcutName, bool grayed)
92 CInterfaceManager *pIM = CInterfaceManager::getInstance();
93 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
94 uint lineId= (uint)pMCM->NewKey->AllLines.size();
95 string templateId = pParent->getId() + ":k" + NLMISC::toString(lineId);
96 vector< pair<string, string> > vParams;
97 vParams.push_back(make_pair(string("id"), templateId));
98 vParams.push_back(make_pair(string("lineid"), toString(lineId)));
99 CInterfaceGroup *pKeysLine = NULL;
100 pKeysLine = CWidgetManager::getInstance()->getParser()->createGroupInstance (TEMPLATE_KEYS_GROUP, pParent->getId(), vParams);
101 if (pKeysLine == NULL) return;
103 // Put name
104 CViewText *pViewKeyName = dynamic_cast<CViewText*>(pKeysLine->getView(TEMPLATE_KEYS_KEY_NAME));
105 if (pViewKeyName != NULL)
107 pViewKeyName->setText (keyName);
108 pViewKeyName->setColor(grayed?CWidgetManager::getInstance()->getSystemOption(CWidgetManager::OptionCtrlTextGrayColor).getValColor():CRGBA::White);
111 CViewText *pViewShortcutName = dynamic_cast<CViewText*>(pKeysLine->getView(TEMPLATE_KEYS_SHORTCUT_NAME));
112 if (pViewShortcutName != NULL)
114 pViewShortcutName->setText (shortcutName);
115 pViewShortcutName->setColor(grayed?CWidgetManager::getInstance()->getSystemOption(CWidgetManager::OptionCtrlTextGrayColor).getValColor():CRGBA::White);
118 pKeysLine->setParent (pParent);
119 pParent->addChild (pKeysLine);
122 // ***************************************************************************
123 struct CComboActionName
125 CCombo Combo; // KeyCount <=> action name unbound
126 CAction::CName ActionName;
128 void buildActionToComboMap(uint8 nAM, CGroupList * /* pList */, string catName, map<string, CComboActionName> &remaped)
130 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
131 CActionsManager *pAM = pMCM->ActionManagers[nAM];
132 const CActionsManager::TComboActionMap &keyShortcut = pAM->getComboActionMap();
134 // *** Order Keys by actions
135 // parse the combo map
136 CActionsManager::TComboActionMap::const_iterator it = keyShortcut.begin();
137 while (it != keyShortcut.end())
139 const CAction::CName &rName = it->second;
143 // if match the current category parsed
144 const CCategory *pCat = pAM->getCategory(rName);
145 if (pCat != NULL)
146 if (pCat->Name == catName)
148 // see if action active in current context
149 if (pAM->isActionPresentInContext(it->second))
151 pair<string, CComboActionName> value;
152 // Don't take any risk: avoid any bug if the localisation is buggy and give same text for 2 differents CAction::CName
153 // Use the localized text first, to have correct sort according to language
154 value.first= pAM->getActionLocalizedText(rName) + rName.Name + rName.Argu;
155 value.second.Combo= it->first;
156 value.second.ActionName= it->second;
157 remaped.insert(value);
161 it++;
164 // *** Add unbound "ForceDisplay" actions
165 const CActionsManager::TActionsForceDisplaySet &actionFD = pAM->getActionsForceDisplaySet();
166 CActionsManager::TActionsForceDisplaySet::const_iterator itFD= actionFD.begin();
167 for(;itFD!=actionFD.end();itFD++)
169 const CAction::CName &rName = *itFD;
170 // const CBaseAction *baseAction = pAM->getBaseAction(rName);
172 // if match the current category parsed
173 const CCategory *pCat = pAM->getCategory(rName);
174 if (pCat != NULL)
175 if (pCat->Name == catName)
177 // see if action active in current context
178 if (pAM->isActionPresentInContext(rName))
180 pair<string, CComboActionName> value;
181 // Don't take any risk: avoid any bug if the localisation is buggy and give same text for 2 differents CAction::CName
182 // Use the localized text first, to have correct sort according to language
183 value.first= pAM->getActionLocalizedText(rName) + rName.Name + rName.Argu;
184 // if alredy added (ie combo bound)
185 if(remaped.find(value.first)!=remaped.end())
186 continue;
187 // Add this unbound action
188 value.second.Combo.Key= KeyCount;
189 value.second.Combo.KeyButtons= noKeyButton;
190 value.second.ActionName= rName;
191 remaped.insert(value);
199 // Get all the couple (combo,action) from the action manager nAM and insert them into pList (with the template)
200 void getAllComboAction(uint8 nAM, CGroupList *pList, const map<string, CComboActionName> &remaped)
202 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
203 CActionsManager *pAM = pMCM->ActionManagers[nAM];
204 // *** Fill Actions
205 map<string, CComboActionName>::const_iterator remapIT = remaped.begin();
206 while (remapIT != remaped.end())
208 string keyName;
209 if(remapIT->second.Combo.Key==KeyCount)
210 keyName= CI18N::get("uiNotAssigned");
211 else
212 keyName= remapIT->second.Combo.toString();
213 const CBaseAction *baseAction = pAM->getBaseAction(remapIT->second.ActionName);
214 if (baseAction)
216 string shortcutName = baseAction->getActionLocalizedText(remapIT->second.ActionName);
218 addKeyLine(pList, keyName, shortcutName, remapIT->second.Combo.Key==KeyCount);
219 CModalContainerEditCmd::CLine line;
220 line.ComboAM= nAM;
221 line.Combo= remapIT->second.Combo;
222 line.ActionName= remapIT->second.ActionName;
223 pMCM->NewKey->AllLines.push_back(line);
225 remapIT++;
229 // ***************************************************************************
230 // Called when we activate the keys container
231 class CHandlerKeysOpen: public IActionHandler
233 public:
234 virtual void execute(CCtrlBase * /* pCaller */, const string &/* Params */)
236 // Initialisation of category combo box
237 CInterfaceManager *pIM = CInterfaceManager::getInstance();
238 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
240 for (uint nAM = 0; nAM < pMCM->ActionManagers.size(); ++nAM)
242 CActionsManager *pAM = pMCM->ActionManagers[nAM];
243 const vector<CCategory> &rCats = pAM->getCategories();
244 CGroupContainer *pGC;
245 for (uint i = 0; i < rCats.size(); ++i)
247 string contName = string(WIN_KEYS_GAME)+rCats[i].Name;
248 pGC = dynamic_cast<CGroupContainer*>(CWidgetManager::getInstance()->getElementFromId(contName));
249 if(pGC != NULL)
251 pGC->setX(0);
252 pGC->setY(0);
257 // Ensure the Key edit is closed
258 pMCM->NewKey->deactivate();
259 pMCM->NewKey->CurAM = NULL;
260 pMCM->NewKey->AllLines.clear();
262 // Get the group to add all (keys,shortcut) couple
263 for (uint nAM = 0; nAM < pMCM->ActionManagers.size(); ++nAM)
265 CActionsManager *pAM = pMCM->ActionManagers[nAM];
266 const vector<CCategory> &rCats = pAM->getCategories();
267 for (uint i = 0; i < rCats.size(); ++i)
269 string contName = string(WIN_KEYS_GAME)+rCats[i].Name;
270 CInterfaceGroup *pCategory = dynamic_cast<CInterfaceGroup *>(CWidgetManager::getInstance()->getElementFromId(contName));
271 CGroupList *pList = dynamic_cast<CGroupList*>(CWidgetManager::getInstance()->getElementFromId(contName + ":content"));
272 if (pCategory != NULL && pList != NULL)
274 pList->clearGroups();
275 pList->setDynamicDisplaySize(true);
277 map<string, CComboActionName> remaped;
278 buildActionToComboMap(nAM, pList, rCats[i].Name, remaped);
279 if (!remaped.empty())
281 getAllComboAction(nAM, pList, remaped);
282 pCategory->setActive(true);
284 else
286 pCategory->setActive(false);
293 REGISTER_ACTION_HANDLER( CHandlerKeysOpen, "keys_open");
295 // ***************************************************************************
296 // Called when we push the new button
297 class CHandlerKeysNew: public IActionHandler
299 public:
300 virtual void execute(CCtrlBase * /* pCaller */, const string &/* Params */)
302 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
303 pMCM->NewKey->CurrentEditCmdNb = -1;
304 pMCM->NewKey->activate();
307 REGISTER_ACTION_HANDLER( CHandlerKeysNew, "keys_new");
309 // ***************************************************************************
310 class CHandlerKeysAssign: public IActionHandler
312 public:
313 virtual void execute(CCtrlBase *pCaller, const string &/* Params */)
315 CInterfaceManager *pIM = CInterfaceManager::getInstance();
316 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
318 // Setup the editkey container from line
319 if (pCaller == NULL) return;
320 string sId = pCaller->getId();
321 sId = sId.substr(sId.rfind('k')+1,sId.size());
322 sint32 nLineNb;
323 fromString(sId, nLineNb);
324 if ((nLineNb < 0) || (nLineNb >= (sint32)pMCM->NewKey->AllLines.size())) return;
326 pMCM->NewKey->CurrentEditCmdLine = pMCM->NewKey->AllLines[nLineNb];
327 pMCM->NewKey->CurAM = pMCM->ActionManagers[pMCM->NewKey->AllLines[nLineNb].ComboAM];
328 CGroupModalGetKey*pGetKey = dynamic_cast<CGroupModalGetKey*>(CWidgetManager::getInstance()->getElementFromId(WIN_MODAL_GET_KEY));
329 pGetKey->Caller = "editkey";
330 CWidgetManager::getInstance()->enableModalWindow(pCaller, WIN_MODAL_GET_KEY);
333 REGISTER_ACTION_HANDLER( CHandlerKeysAssign, "keys_assign");
336 // ***************************************************************************
337 // Called when we right click on a shortcut line and choose edit from context menu
338 class CHandlerKeysEdit: public IActionHandler
340 public:
341 virtual void execute(CCtrlBase *pCaller, const string &/* Params */)
343 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
345 // Setup the editkey container from line
346 if (pCaller == NULL) return;
347 string sId = pCaller->getId();
348 sId = sId.substr(sId.rfind('k')+1,sId.size());
349 sint32 nLineNb;
350 fromString(sId, nLineNb);
351 if ((nLineNb < 0) || (nLineNb >= (sint32)pMCM->NewKey->AllLines.size())) return;
353 pMCM->NewKey->CurrentEditCmdLine = pMCM->NewKey->AllLines[nLineNb];
354 pMCM->NewKey->CurAM = pMCM->ActionManagers[pMCM->NewKey->AllLines[nLineNb].ComboAM];
355 // The key must exist, else cannot edit the action
356 CActionsManager::TComboActionMap::const_iterator it = pMCM->NewKey->CurAM->getComboActionMap().find(pMCM->NewKey->CurrentEditCmdLine.Combo);
357 if (it != pMCM->NewKey->CurAM->getComboActionMap().end())
359 pMCM->NewKey->activateFrom (it->second.Name, it->second.Argu, nLineNb);
363 REGISTER_ACTION_HANDLER( CHandlerKeysEdit, "keys_edit");
365 // ***************************************************************************
366 class CHandlerKeysDelete: public IActionHandler
368 public:
369 virtual void execute(CCtrlBase *pCaller, const string &/* Params */)
371 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
372 if (pCaller == NULL) return;
373 string sId = pCaller->getId();
374 sId = sId.substr(sId.rfind('k')+1,sId.size());
375 sint32 nLineNb;
376 fromString(sId, nLineNb);
377 if ((nLineNb < 0) || (nLineNb >= (sint32)pMCM->NewKey->AllLines.size())) return;
378 CActionsManager *pCurAM = pMCM->ActionManagers[pMCM->NewKey->AllLines[nLineNb].ComboAM];
379 // if key not bound, skip (ie: this is a N/A action that is "ForceDisplay")
380 if(pMCM->NewKey->AllLines[nLineNb].Combo.Key==NLMISC::KeyCount)
381 return;
382 // remove the combo
383 pCurAM->removeCombo(pMCM->NewKey->AllLines[nLineNb].Combo);
384 // reset display
385 pMCM->refreshAllKeyDisplays();
388 REGISTER_ACTION_HANDLER( CHandlerKeysDelete, "keys_delete");
391 // ***************************************************************************
392 // Edit Command (can be binded to a key)
393 // ***************************************************************************
395 // ***************************************************************************
396 CModalContainerEditCmd::CModalContainerEditCmd()
398 Win = NULL;
399 CurAM = NULL;
400 _AllowAllActions= true;
403 // ***************************************************************************
404 void CModalContainerEditCmd::create(const std::string &name, bool bDefKey, bool allowAllActions)
406 CInterfaceManager *pIM = CInterfaceManager::getInstance();
407 string prefix = NLMISC::toUpperAscii(name);
408 CanDefineKey = bDefKey;
409 _AllowAllActions = allowAllActions;
410 prefix = string(DB_EDITCMD_PREFIX) + string(":") + prefix + string(":");
411 DbComboSelCat = prefix + DB_EDITCMD_COMBO_SELECT_CATEGORY;
412 DbComboSelAct = prefix + DB_EDITCMD_COMBO_SELECT_ACTION;
413 DbComboSel1P = prefix + DB_EDITCMD_COMBO_SELECT_FIRST_PARAM;
414 DbComboSel2P = prefix + DB_EDITCMD_COMBO_SELECT_SECOND_PARAM;
415 DbComboDisp1P = prefix + DB_EDITCMD_COMBO_DISPLAY_FIRST_PARAM;
416 DbComboDisp2P = prefix + DB_EDITCMD_COMBO_DISPLAY_SECOND_PARAM;
418 // Create DB entry
419 NLGUI::CDBManager::getInstance()->getDbProp(DbComboSelCat);
420 NLGUI::CDBManager::getInstance()->getDbProp(DbComboSelAct);
421 NLGUI::CDBManager::getInstance()->getDbProp(DbComboSel1P);
422 NLGUI::CDBManager::getInstance()->getDbProp(DbComboSel2P);
423 NLGUI::CDBManager::getInstance()->getDbProp(DbComboDisp1P);
424 NLGUI::CDBManager::getInstance()->getDbProp(DbComboDisp2P);
426 vector< pair<string,string> > vArgs;
427 vArgs.push_back(pair<string,string>("id",name));
428 vArgs.push_back(pair<string,string>("db_sel_cat",DbComboSelCat));
429 vArgs.push_back(pair<string,string>("db_sel_act",DbComboSelAct));
430 vArgs.push_back(pair<string,string>("db_sel_1p",DbComboSel1P));
431 vArgs.push_back(pair<string,string>("db_sel_2p",DbComboSel2P));
432 vArgs.push_back(pair<string,string>("db_disp_1p",DbComboDisp1P));
433 vArgs.push_back(pair<string,string>("db_disp_2p",DbComboDisp2P));
435 Win = dynamic_cast<CGroupContainer*>( CWidgetManager::getInstance()->getParser()->createGroupInstance(TEMPLATE_EDITCMD, "ui:interface", vArgs));
436 if (Win == NULL)
438 nlwarning ("cannot create %s", name.c_str());
439 return;
441 WinName = "ui:interface:" + name;
443 CWidgetManager::getInstance()->addWindowToMasterGroup("ui:interface", Win);
444 CInterfaceGroup *pRoot = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId("ui:interface"));
445 Win->setParent(pRoot);
446 pRoot->addGroup(Win);
448 CInterfaceGroup *pIG = dynamic_cast<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_KEY_GROUP));
449 if (pIG != NULL) pIG->setActive (CanDefineKey);
452 // ***************************************************************************
453 void CModalContainerEditCmd::setTitle(const std::string &uistr)
455 Win->setTitle(uistr);
458 // ***************************************************************************
459 void CModalContainerEditCmd::activate()
461 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
462 CurrentEditCmdLine.ActionName.Name.clear();
463 CurrentEditCmdLine.ActionName.Argu.clear();
464 CurrentEditCmdNb = -1;
465 Win->setActive(true);
466 Win->launch();
467 // Initialisation of category combo box
468 CInterfaceManager *pIM = CInterfaceManager::getInstance();
469 CDBGroupComboBox *pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( WinName+WIN_EDITCMD_COMBO_CATEGORY ));
470 if (pCB != NULL)
472 CurrentEditCmdCategories.clear();
473 pCB->resetTexts();
474 for (uint am=0; am < pMCM->ActionManagers.size(); am++)
476 const vector<CCategory> &rVCat = pMCM->ActionManagers[am]->getCategories();
477 for (uint i=0; i < rVCat.size();i++)
479 const CCategory &cat = rVCat[i];
480 // only macroisable categories (or if allow all)
481 if(_AllowAllActions || cat.Macroisable)
483 // category should have at least one action that is possible in currenyt
484 // context
485 bool found = false;
486 for (uint k = 0; k < cat.BaseActions.size(); ++k)
488 if (cat.BaseActions[k].isUsableInCurrentContext())
490 found = true;
491 break;
494 if (found)
496 pCB->addText(CI18N::get(rVCat[i].LocalizedName));
497 CurrentEditCmdCategories.push_back(rVCat[i].Name);
503 // Clean up all actions
504 pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( WinName+WIN_EDITCMD_COMBO_ACTION ));
505 if (pCB != NULL) pCB->resetTexts();
506 // Clean up
507 CurAM = NULL;
508 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelCat )->setValue32(-1);
509 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelAct )->setValue32(-1);
510 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel1P )->setValue32(-1);
511 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel2P )->setValue32(-1);
512 NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp1P )->setValue32(-1);
513 NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp2P )->setValue32(-1);
514 // reset name of params
515 CViewText *pViewParamName = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_FIRST_PARAM_NAME));
516 if (pViewParamName != NULL) pViewParamName->setText (string());
517 pViewParamName = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_SECOND_PARAM_NAME));
518 if (pViewParamName != NULL) pViewParamName->setText (string());
519 invalidCurrentCommand();
522 // ***************************************************************************
523 void CModalContainerEditCmd::deactivate()
525 if(Win) Win->setActive(false);
528 // ***************************************************************************
529 void CModalContainerEditCmd::activateFrom (const std::string &cmdName, const std::string &cmdParams, sint nRef)
531 CInterfaceManager *pIM = CInterfaceManager::getInstance();
532 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
534 CurrentEditCmdNb = nRef;
535 Win->setActive(true);
536 Win->launch();
538 activate();
540 CurrentEditCmdLine.ActionName.Name = cmdName;
541 CurrentEditCmdLine.ActionName.Argu = cmdParams;
542 CurrentEditCmdNb = nRef;
544 // Get current action manager and interface category index from cmdName
545 uint i, j, k;
546 bool bFound = false;
547 const CBaseAction *pBA = NULL;
548 CActionsManager *pAM = NULL;
549 uint catCBIndex = 0;
550 uint actCBIndex = 0;
551 for (i=0; i < pMCM->ActionManagers.size(); ++i)
553 pAM = pMCM->ActionManagers[i];
554 const vector<CCategory> &rVCat = pAM->getCategories();
555 for (j=0; j < rVCat.size(); ++j)
557 // only macroisable category (or if allow all)
558 if(_AllowAllActions || rVCat[j].Macroisable)
560 const vector<CBaseAction> &rVBA = rVCat[j].BaseActions;
561 actCBIndex = 0;
562 for (k=0; k < rVBA.size(); ++k)
564 // only macrosiable actions (or if allow all)
565 if (_AllowAllActions || rVBA[k].Macroisable)
567 if(rVBA[k].Name == cmdName)
569 bFound = true;
570 CurAM = pMCM->ActionManagers[i];
571 pBA = &rVBA[k];
572 break;
574 // actCBIndex is index in combo box here
575 actCBIndex++;
578 if (bFound) break;
579 // catIndex is index in combo box here
580 catCBIndex++;
583 if (bFound) break;
585 if (!bFound) return;
586 // Here pAM and catIndex are valid
588 // Set category : Search the right category
589 CDBGroupComboBox *pCB;
590 pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId(WinName+WIN_EDITCMD_COMBO_CATEGORY));
591 pCB->setSelection(catCBIndex);
592 onChangeCategory();
593 IngameDbMngr.flushObserverCalls();
594 NLGUI::CDBManager::getInstance()->flushObserverCalls();
595 //CAHManager::getInstance()->runActionHandler("editcmd_change_category",NULL);
596 pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId(WinName+WIN_EDITCMD_COMBO_ACTION));
597 pCB->setSelection(actCBIndex);
598 onChangeAction();
599 IngameDbMngr.flushObserverCalls();
600 NLGUI::CDBManager::getInstance()->flushObserverCalls();
601 //CAHManager::getInstance()->runActionHandler("editcmd_change_action",NULL);
603 // Count number of displayed param
604 uint nbRealParam = 0;
605 for (i = 0; i < pBA->Parameters.size(); ++i)
607 const CBaseAction::CParameter &rP = pBA->Parameters[i];
608 if (rP.Type != CBaseAction::CParameter::Hidden)
609 nbRealParam++;
612 // Set params
613 uint noParam = 0;
614 string curStr = CurrentEditCmdLine.ActionName.Argu.substr();
615 for (i = 0; i < pBA->Parameters.size(); ++i)
617 const CBaseAction::CParameter &rP = pBA->Parameters[i];
618 string sTmp;
620 // Get ith param (params are nameOfParam=argumentOfAction strings separated by |)
621 // except for the last real param (which can then contains | chars) if it is the last param
623 string::size_type pos = curStr.find('|');
625 if ((pos == string::npos) ||
626 (((noParam == nbRealParam-1) && (rP.Type != CBaseAction::CParameter::Hidden)) && (i == (pBA->Parameters.size()-1))))
628 sTmp = curStr;
629 curStr.clear();
631 else
634 sTmp = curStr.substr(0, pos);
635 curStr = curStr.substr(pos+1, curStr.size());
638 // Remove 'name='
639 if (sTmp.find('=') != string::npos)
640 sTmp = sTmp.substr(sTmp.find('=')+1,sTmp.size());
642 if (noParam >= 2) break; // NO MORE THAN 2 REAL PARAMS !
644 if (rP.Type == CBaseAction::CParameter::Hidden)
646 // Skip it
648 else if (rP.Type == CBaseAction::CParameter::Constant)
650 if (noParam == 0) NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp1P )->setValue32(0);
651 else NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp2P )->setValue32(0);
653 // Search the param value to get the position in combo box
654 bool bValFound = false;
655 uint nPinCB;
656 for(nPinCB = 0; nPinCB < rP.Values.size(); ++nPinCB)
658 if (rP.Values[nPinCB].Value == sTmp)
660 bValFound = true;
661 break;
664 if (bValFound)
666 string sCombo;
667 if (noParam == 0) sCombo = WinName+WIN_EDITCMD_COMBO_FIRST_PARAM_LIST;
668 else sCombo = WinName+WIN_EDITCMD_COMBO_SECOND_PARAM_LIST;
669 pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId(sCombo));
670 pCB->setSelection(nPinCB);
673 else if ((rP.Type == CBaseAction::CParameter::User) || (rP.Type == CBaseAction::CParameter::UserName))
675 if (noParam == 0) NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp1P )->setValue32(1);
676 else NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp2P )->setValue32(1);
678 string sEditBox;
679 if (noParam == 0) sEditBox = WinName+WIN_EDITCMD_COMBO_FIRST_PARAM_EDITBOX;
680 else sEditBox = WinName+WIN_EDITCMD_COMBO_SECOND_PARAM_EDITBOX;
681 CGroupEditBox *pEB = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId(sEditBox));
682 // sTmp is utf8
683 pEB->setInputString(sTmp);
686 // Setup the param name if any
687 if (rP.Type != CBaseAction::CParameter::Hidden)
689 string sText;
690 if (noParam == 0) sText = WinName+VIEW_EDITCMD_FIRST_PARAM_NAME;
691 else sText = WinName+VIEW_EDITCMD_SECOND_PARAM_NAME;
692 CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(sText));
693 if (pVT != NULL) pVT->setText(CI18N::get(pBA->Parameters[i].LocalizedName));
694 noParam++;
697 validCurrentCommand();
699 // Update the key name
700 const CActionsManager::TActionComboMap &actionCombo = pAM->getActionComboMap();
701 CActionsManager::TActionComboMap::const_iterator it = actionCombo.find(CurrentEditCmdLine.ActionName);
703 // Deactive the key definition (we are in edit key mode)
704 CCtrlBaseButton *pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_KEY));
705 if (pBut != NULL) pBut->setActive(false);
707 if (it != actionCombo.end())
709 CurrentEditCmdLine.Combo = it->second;
711 // Activate the key definer text
712 CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_TEXT_KEY));
713 if (pVT != NULL) pVT->setActive(true);
714 // setup the text of the key
715 pVT->setText(it->second.toString());
717 // There is already a shortcut so we can display ok button
718 pBut = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
719 if (pBut != NULL) pBut->setFrozen (false);
723 // ***************************************************************************
724 // Given the cat index in comboBox, find action manager and the real cat index depending on the AM / macrosiable categories
725 bool CModalContainerEditCmd::getCatIndexAndAM (sint32 nInCatIndex, sint32 &nOutCatIndex, CActionsManager*&nOutAM)
727 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
728 if (nInCatIndex >= (sint32)CurrentEditCmdCategories.size())
729 return false;
730 string catName = CurrentEditCmdCategories[nInCatIndex];
731 for (uint i=0; i < pMCM->ActionManagers.size(); ++i)
733 CActionsManager *pAM = pMCM->ActionManagers[i];
734 const vector<CCategory> &rVCat = pAM->getCategories();
735 for (uint j=0; j < rVCat.size(); ++j)
737 if (rVCat[j].Name == catName)
739 nOutCatIndex = j;
740 nOutAM = pAM;
741 return true;
745 return false;
748 // ***************************************************************************
749 // Give the action index in Combo box, find the action index in the category (skip not macroisable actions)
750 bool CModalContainerEditCmd::getBaseActionIndex(const CCategory &cat, sint32 nInActIndex, sint32 &nOutActIndex)
752 if(nInActIndex<0)
753 return false;
754 for(nOutActIndex=0; nOutActIndex<(sint32)cat.BaseActions.size();nOutActIndex++)
756 // only macroisable (or if allow all)
757 if(_AllowAllActions || cat.BaseActions[nOutActIndex].Macroisable)
759 // must be valid in current context
760 if (cat.BaseActions[nOutActIndex].isUsableInCurrentContext())
762 // ok, found?
763 if(nInActIndex==0) return true;
764 else nInActIndex--;
768 return false;
771 // ***************************************************************************
772 // The current command is not valid (so we cant drag it into a macro nor define a key for it)
773 void CModalContainerEditCmd::invalidCurrentCommand()
775 CInterfaceManager *pIM = CInterfaceManager::getInstance();
776 CViewText *pVT;
778 if (CurrentEditCmdNb == -1)
780 // Dont display key shortcut if we are in creation mode
781 pVT= dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId( WinName+VIEW_EDITCMD_TEXT_KEY ));
782 if (pVT != NULL) pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT));
784 // Deactivate the key definer text
785 pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_TEXT_KEY));
786 if (pVT != NULL) pVT->setActive(false);
789 // Deactivate the key definer button
790 CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_KEY));
791 if (pCB != NULL) pCB->setActive(false);
793 // Deactivate ok button
794 pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
795 if (pCB != NULL) pCB->setFrozen (true);
798 // ***************************************************************************
799 // The current command becomes valid (display key shortcut if any)
800 void CModalContainerEditCmd::validCurrentCommand()
802 CInterfaceManager *pIM = CInterfaceManager::getInstance();
803 sint32 catIndex= NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelCat )->getValue32();
804 if(catIndex < 0) return;
805 sint32 actIndex= NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelAct )->getValue32();
806 if(actIndex < 0) return;
808 CActionsManager *pAM;
809 // From ComboBox to index in category/action
810 if (!getCatIndexAndAM(catIndex,catIndex,pAM)) return;
811 if (!getBaseActionIndex(pAM->getCategories()[catIndex], actIndex,actIndex)) return;
813 // get the action
814 const CBaseAction &rBA = pAM->getCategories()[catIndex].BaseActions[actIndex];
816 // Build couple (name,param) that define a command
817 CurrentEditCmdLine.ActionName.Name = rBA.Name;
818 CurrentEditCmdLine.ActionName.Argu.clear();
819 uint noParam = 0;
820 for (uint i = 0; i < rBA.Parameters.size(); ++i)
822 const CBaseAction::CParameter &rP = rBA.Parameters[i];
824 if (noParam >= 2) break; // NO MORE THAN 2 REAL PARAMS !
825 if ((i >= 1) && (!CurrentEditCmdLine.ActionName.Argu.empty())) CurrentEditCmdLine.ActionName.Argu+= "|";
827 if (!rP.Name.empty())
828 CurrentEditCmdLine.ActionName.Argu += rP.Name + "=";
830 if (rP.Type == CBaseAction::CParameter::Hidden)
832 CurrentEditCmdLine.ActionName.Argu += rP.DefaultValue;
834 else if (rP.Type == CBaseAction::CParameter::Constant)
836 // If the param is constant get the string from the list
837 // cannot use index directly because some options may be disabled in current context
838 sint32 paramIndex;
839 const std::vector<CBaseAction::CParameter::CValue> &rVVal = rP.Values;
840 if (noParam == 0) paramIndex = NLGUI::CDBManager::getInstance()->getDbProp(DbComboSel1P)->getValue32();
841 else paramIndex = NLGUI::CDBManager::getInstance()->getDbProp(DbComboSel2P)->getValue32();
843 uint currIndex = 0;
844 for (uint k = 0; k < rVVal.size(); ++k)
846 const CBaseAction::CParameter::CValue &rVal = rVVal[k];
847 if (ActionsContext.matchContext(rVal.Contexts))
849 if (currIndex == (uint) paramIndex)
851 CurrentEditCmdLine.ActionName.Argu += rVal.Value;
852 noParam++;
854 currIndex ++;
858 else if ((rP.Type == CBaseAction::CParameter::User) || (rP.Type == CBaseAction::CParameter::UserName))
860 // If the param is user or username get the string from the edit box
861 string sWin;
862 if (noParam == 0) sWin = WinName+WIN_EDITCMD_COMBO_FIRST_PARAM_EDITBOX;
863 else sWin = WinName+WIN_EDITCMD_COMBO_SECOND_PARAM_EDITBOX;
864 CGroupEditBox *pEB= dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId( sWin ));
865 // convert to utf8
866 if (pEB != NULL)
867 CurrentEditCmdLine.ActionName.Argu += pEB->getInputString();
868 noParam++;
871 // End of build
873 // If we are in mode new shortcut display the button to setup a key
874 if (WinName == "ui:interface:newkey")
876 if (CurrentEditCmdNb == -1)
878 // Activate the key definer button
879 CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_KEY));
880 if (pCB != NULL) pCB->setActive(true);
881 // Activate the key definer text
882 CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_TEXT_KEY));
883 if (pVT != NULL) pVT->setActive(true);
884 // Does the command already exists ?
885 const CActionsManager::TActionComboMap &actionCombo = pAM->getActionComboMap();
886 CActionsManager::TActionComboMap::const_iterator it = actionCombo.find(CurrentEditCmdLine.ActionName);
887 if (it != actionCombo.end())
889 CurrentEditCmdLine.Combo = it->second;
890 // Yes ok let setup the text of the key
891 pVT->setText(it->second.toString());
892 // There is already a shortcut so we can display ok button
893 CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
894 if (pCB != NULL) pCB->setFrozen (false);
896 else
898 CurrentEditCmdLine.Combo.Key = KeyCount;
899 CurrentEditCmdLine.Combo.KeyButtons = noKeyButton;
900 // Display not assigned text
901 pVT->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT));
902 // Do not display the ok button
903 CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
904 if (pCB != NULL) pCB->setFrozen (true);
907 else
909 CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
910 if (pCB != NULL) pCB->setFrozen (false);
914 // If we are in mode new command (from macro) just turn on the ok button
915 if (WinName == "ui:interface:editcmd")
917 CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(WinName+CTRL_EDITCMD_BUTTON_OK));
918 if (pCB != NULL) pCB->setFrozen(false);
922 // ***************************************************************************
923 // Check if the param is valid depending on the type of the param
924 bool CModalContainerEditCmd::isParamValid (sint32 nParamIndex)
926 CInterfaceManager *pIM = CInterfaceManager::getInstance();
927 sint32 paramType;
928 if (nParamIndex == 0) paramType = NLGUI::CDBManager::getInstance()->getDbProp(DbComboDisp1P)->getValue32();
929 else paramType = NLGUI::CDBManager::getInstance()->getDbProp(DbComboDisp2P)->getValue32();
931 if (paramType == 0) // combo box list
933 sint32 paramListIndex;
934 if (nParamIndex == 0) paramListIndex = NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel1P )->getValue32();
935 else paramListIndex = NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel2P )->getValue32();
937 if (paramListIndex < 0) return false;
938 else return true;
940 else if (paramType == 1)
942 CGroupEditBox *pEB;
943 if (nParamIndex == 0) pEB = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId( WinName+WIN_EDITCMD_COMBO_FIRST_PARAM_EDITBOX ));
944 else pEB = dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId( WinName+WIN_EDITCMD_COMBO_SECOND_PARAM_EDITBOX ));
945 if (pEB == NULL) return false;
947 // no need to translate utf8 or not here
948 if (pEB->getInputStringRef().empty()) return false;
949 else return true;
951 return false;
954 // ***************************************************************************
955 void CModalContainerEditCmd::checkCurrentCommandValidity()
957 CInterfaceManager *pIM = CInterfaceManager::getInstance();
959 // Get the category selected
960 sint32 catIndex= NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelCat )->getValue32();
961 if(catIndex < 0) return;
963 // Get the action index selected
964 sint32 actIndex= NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelAct )->getValue32();
965 if(actIndex < 0) return;
967 CActionsManager *pAM;
968 // From ComboBox to index in category/action
969 if (!getCatIndexAndAM(catIndex,catIndex,pAM)) return;
970 if (!getBaseActionIndex(pAM->getCategories()[catIndex], actIndex,actIndex)) return;
972 // get action
973 const vector<CBaseAction> &rVBA = pAM->getCategories()[catIndex].BaseActions;
974 const vector<CBaseAction::CParameter> &rVParams = rVBA[actIndex].Parameters;
975 // Count nb real param
976 uint nbparam = 0;
977 for (uint i = 0; i < rVParams.size(); ++i)
978 if (rVParams[i].Type != CBaseAction::CParameter::Hidden)
979 nbparam ++;
980 if (nbparam == 0)
982 validCurrentCommand();
983 return;
986 // Check parameters
987 if (!isParamValid(0))
989 invalidCurrentCommand();
990 return;
993 // First param is valid
994 if (nbparam == 1) // If there is only one param requested so validate
996 validCurrentCommand();
998 else
999 { // 2 params
1000 nlassert(nbparam == 2);
1001 if (isParamValid(1))
1002 validCurrentCommand();
1003 else
1004 invalidCurrentCommand();
1008 // ***************************************************************************
1009 void CModalContainerEditCmd::onChangeCategory()
1011 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1013 // Get the category selected
1014 sint32 catIndex= NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelCat )->getValue32();
1015 if(catIndex < 0)
1016 return;
1018 // Update the combo box of actions
1019 CDBGroupComboBox *pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( WinName+WIN_EDITCMD_COMBO_ACTION ));
1020 if( pCB )
1022 pCB->resetTexts();
1024 // From combo box index to real category index
1025 if (!getCatIndexAndAM(catIndex,catIndex,CurAM)) return;
1027 const vector<CBaseAction> &rVBA = CurAM->getCategories()[catIndex].BaseActions;
1029 // add only macroisable actions (or if allow all)
1030 for (uint i = 0; i < rVBA.size(); i++)
1032 const CBaseAction &rBA = rVBA[i];
1033 if(_AllowAllActions || rBA.Macroisable)
1035 if (rBA.isUsableInCurrentContext())
1037 pCB->addText(CI18N::get(rBA.LocalizedName));
1043 // reset the action and dont display params
1044 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelAct )->setValue32(-1);
1045 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel1P )->setValue32(-1);
1046 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel2P )->setValue32(-1);
1047 NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp1P )->setValue32(-1);
1048 NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp2P )->setValue32(-1);
1049 // reset name of params
1050 CViewText *pViewParamName;
1051 pViewParamName = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_FIRST_PARAM_NAME));
1052 if (pViewParamName != NULL) pViewParamName->setText (string());
1053 pViewParamName = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_SECOND_PARAM_NAME));
1054 if (pViewParamName != NULL) pViewParamName->setText (string());
1055 // Reset key
1056 invalidCurrentCommand();
1060 // ***************************************************************************
1061 void CModalContainerEditCmd::onChangeAction()
1063 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1065 // Get the category selected
1066 sint32 catIndex= NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelCat )->getValue32();
1067 if(catIndex < 0)
1068 return;
1070 // Get the action index selected
1071 sint32 actIndex= NLGUI::CDBManager::getInstance()->getDbProp( DbComboSelAct )->getValue32();
1072 if(actIndex < 0)
1073 return;
1075 // From combo box index to cat/action index
1076 if (!getCatIndexAndAM(catIndex,catIndex,CurAM)) return;
1077 if (!getBaseActionIndex(CurAM->getCategories()[catIndex], actIndex,actIndex)) return;
1079 // Check parameters
1080 const vector<CBaseAction> &rVBA = CurAM->getCategories()[catIndex].BaseActions;
1081 const vector<CBaseAction::CParameter> &rVParams = rVBA[actIndex].Parameters;
1083 NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp1P )->setValue32(-1);
1084 NLGUI::CDBManager::getInstance()->getDbProp( DbComboDisp2P )->setValue32(-1);
1085 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel1P )->setValue32(-1);
1086 NLGUI::CDBManager::getInstance()->getDbProp( DbComboSel2P )->setValue32(-1);
1087 // reset name of params
1088 CViewText *pViewParamName;
1089 pViewParamName = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_FIRST_PARAM_NAME));
1090 if (pViewParamName != NULL) pViewParamName->setText (string());
1091 pViewParamName = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(WinName+VIEW_EDITCMD_SECOND_PARAM_NAME));
1092 if (pViewParamName != NULL) pViewParamName->setText (string());
1094 uint noParam = 0;
1095 for (uint i = 0; i < rVParams.size(); ++i)
1097 const CBaseAction::CParameter &rP = rVParams[i];
1098 if (rP.Type == CBaseAction::CParameter::Hidden)
1099 continue;
1100 string sDB;
1101 if (noParam >= 2) break; // NO MORE THAN 2 PARAMS !
1102 if (noParam == 0)
1103 sDB = DbComboDisp1P;
1104 else
1105 sDB = DbComboDisp2P;
1107 // Set the parameter name
1109 string sViewText;
1110 if (noParam == 0) sViewText = WinName+VIEW_EDITCMD_FIRST_PARAM_NAME;
1111 else sViewText = WinName+VIEW_EDITCMD_SECOND_PARAM_NAME;
1113 pViewParamName = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(sViewText));
1114 if (pViewParamName != NULL)
1115 pViewParamName->setText (CI18N::get(rP.LocalizedName));
1118 if (rP.Type == CBaseAction::CParameter::Constant)
1120 string sWin;
1121 if (noParam == 0) sWin = WinName+WIN_EDITCMD_COMBO_FIRST_PARAM_LIST;
1122 else sWin = WinName+WIN_EDITCMD_COMBO_SECOND_PARAM_LIST;
1123 CDBGroupComboBox *pCB= dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( sWin ));
1124 if( pCB )
1126 pCB->resetTexts();
1127 const std::vector<CBaseAction::CParameter::CValue> &rVVal = rP.Values;
1128 for (uint j = 0; j < rVVal.size(); j++)
1130 const CBaseAction::CParameter::CValue &rVal = rVVal[j];
1132 if (ActionsContext.matchContext(rVal.Contexts))
1134 if (NLMISC::startsWith(rVal.LocalizedValue, "ui"))
1135 pCB->addText(CI18N::get(rVal.LocalizedValue));
1136 else
1137 pCB->addText(rVal.LocalizedValue);
1141 NLGUI::CDBManager::getInstance()->getDbProp( sDB )->setValue32(0);
1143 else if ((rP.Type == CBaseAction::CParameter::User) || (rP.Type == CBaseAction::CParameter::UserName))
1145 string sWin;
1146 if (noParam == 0) sWin = WinName+WIN_EDITCMD_COMBO_FIRST_PARAM_EDITBOX;
1147 else sWin = WinName+WIN_EDITCMD_COMBO_SECOND_PARAM_EDITBOX;
1148 CGroupEditBox *pEB= dynamic_cast<CGroupEditBox*>(CWidgetManager::getInstance()->getElementFromId( sWin ));
1149 if( pEB )
1151 pEB->setInputString(std::string());
1153 NLGUI::CDBManager::getInstance()->getDbProp( sDB )->setValue32(1);
1155 noParam++;
1157 // If action do not need any params validate the command
1158 if (noParam == 0)
1159 validCurrentCommand();
1160 else
1161 invalidCurrentCommand();
1164 // ***************************************************************************
1165 // Action handlers associated to the editcmd container
1166 // ***************************************************************************
1168 // ***************************************************************************
1169 // Called at activate of macros container
1170 class CHandlerEditCmdOpen: public IActionHandler
1172 public:
1173 virtual void execute(CCtrlBase * /* pCaller */, const string &Params)
1175 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
1177 // If we are in key shortcut mode
1178 if (Params == "newkey")
1180 CGroupContainer *pGC = pMCM->NewKey->Win;
1181 //pMCM->NewKey->activate();
1183 if (pGC != NULL) pGC->setModalParentList(WIN_KEYS);
1184 if (pMCM->NewKey->CurrentEditCmdNb == -1)
1185 pMCM->NewKey->setTitle(WIN_EDITCMD_TITLE_NEW_KEY);
1186 else
1187 pMCM->NewKey->setTitle(WIN_EDITCMD_TITLE_EDIT_KEY);
1190 // If we are in macro mode
1191 if (Params == "editcmd")
1193 CGroupContainer *pGC = pMCM->EditCmd->Win;
1194 //pMCM->EditCmd->activate();
1195 if (pGC != NULL) pGC->setModalParentList(WIN_NEWMACRO);
1197 // Set right title depending if we are in new command
1198 if (pMCM->EditCmd->CurrentEditCmdNb == -1)
1199 pGC->setTitle (WIN_EDITCMD_TITLE_NEW_CMD);
1200 else // or not (edit cmd)
1201 pGC->setTitle (WIN_EDITCMD_TITLE_EDIT_CMD);
1205 REGISTER_ACTION_HANDLER( CHandlerEditCmdOpen, "editcmd_open");
1207 // ***************************************************************************
1208 // Called when we change category
1209 class CHandlerEditCmdChangeCategory : public IActionHandler
1211 public:
1212 virtual void execute(CCtrlBase * /* pCaller */, const string &Params)
1214 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
1215 if (Params == "editcmd")
1216 pMCM->EditCmd->onChangeCategory();
1217 if (Params == "newkey")
1218 pMCM->NewKey->onChangeCategory();
1221 REGISTER_ACTION_HANDLER( CHandlerEditCmdChangeCategory, "editcmd_change_category");
1223 // ***************************************************************************
1224 // Called when we change action
1225 class CHandlerEditCmdChangeAction : public IActionHandler
1227 public:
1228 virtual void execute(CCtrlBase * /* pCaller */, const string &Params)
1230 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
1231 if (Params == "editcmd")
1232 pMCM->EditCmd->onChangeAction();
1233 if (Params == "newkey")
1234 pMCM->NewKey->onChangeAction();
1237 REGISTER_ACTION_HANDLER( CHandlerEditCmdChangeAction, "editcmd_change_action");
1239 // ***************************************************************************
1240 // Called when we change the first param
1241 class CHandlerEditCmdChangeFirstParam: public IActionHandler
1243 public:
1244 virtual void execute(CCtrlBase * /* pCaller */, const string &Params)
1246 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
1247 if (Params == "editcmd")
1248 pMCM->EditCmd->checkCurrentCommandValidity();
1249 if (Params == "newkey")
1250 pMCM->NewKey->checkCurrentCommandValidity();
1253 REGISTER_ACTION_HANDLER( CHandlerEditCmdChangeFirstParam, "editcmd_change_first_param");
1255 // ***************************************************************************
1256 // Called when we change the second param
1257 class CHandlerEditCmdChangeSecondParam: public IActionHandler
1259 public:
1260 virtual void execute(CCtrlBase * /* pCaller */, const string &Params)
1262 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
1263 if (Params == "editcmd")
1264 pMCM->EditCmd->checkCurrentCommandValidity();
1265 if (Params == "newkey")
1266 pMCM->NewKey->checkCurrentCommandValidity();
1269 REGISTER_ACTION_HANDLER( CHandlerEditCmdChangeSecondParam, "editcmd_change_second_param");
1271 // ***************************************************************************
1272 // Called when we want to define a key for that command
1273 class CHandlerEditCmdDefineKey: public IActionHandler
1275 public:
1276 virtual void execute(CCtrlBase *pCaller, const string &Params)
1278 //checkCurrentCommandValidity();
1279 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1280 CGroupModalGetKey*pGetKey = dynamic_cast<CGroupModalGetKey*>(CWidgetManager::getInstance()->getElementFromId(WIN_MODAL_GET_KEY));
1281 pGetKey->Caller = Params;
1282 CWidgetManager::getInstance()->enableModalWindow(pCaller, WIN_MODAL_GET_KEY);
1285 REGISTER_ACTION_HANDLER( CHandlerEditCmdDefineKey, "editcmd_cmd_def_key");
1287 // ***************************************************************************
1288 // Called when we validate the command
1289 class CHandlerEditCmdOK: public IActionHandler
1291 public:
1292 virtual void execute(CCtrlBase *pCaller, const string &Params)
1294 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1295 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
1297 // If we are in key shortcut mode
1298 if (Params == "newkey")
1300 // Add the key !
1301 pMCM->NewKey->CurAM->addCombo(pMCM->NewKey->CurrentEditCmdLine.ActionName,
1302 pMCM->NewKey->CurrentEditCmdLine.Combo);
1303 // Refresh key containers
1304 pMCM->refreshAllKeyDisplays();
1305 pMCM->NewKey->deactivate();
1307 // If we are in new command from macro mode
1308 if (Params == "editcmd")
1310 if (pMCM->EditCmd->CurrentEditCmdNb != -1) // Edit mode ?
1312 pMCM->CurrentEditMacro.delCommand(pMCM->EditCmd->CurrentEditCmdNb);
1313 pMCM->CurrentEditMacro.addCommand (pMCM->EditCmd->CurrentEditCmdLine.ActionName.Name, pMCM->EditCmd->CurrentEditCmdLine.ActionName.Argu,
1314 pMCM->EditCmd->CurrentEditCmdNb);
1316 else
1318 pMCM->CurrentEditMacro.addCommand(pMCM->EditCmd->CurrentEditCmdLine.ActionName.Name, pMCM->EditCmd->CurrentEditCmdLine.ActionName.Argu);
1320 CAHManager::getInstance()->runActionHandler("new_macro_open", pCaller);
1321 pMCM->EditCmd->deactivate();
1325 REGISTER_ACTION_HANDLER( CHandlerEditCmdOK, "editcmd_ok");
1327 // ***************************************************************************
1328 // Called when the key defined is validated (with ok button on the assign_key modal)
1329 class CHandlerAssignKey: public IActionHandler
1331 public:
1332 virtual void execute(CCtrlBase * /* pCaller */, const string &/* Params */)
1334 CInterfaceManager *pIM = CInterfaceManager::getInstance();
1335 CMacroCmdManager *pMCM = CMacroCmdManager::getInstance();
1336 CWidgetManager::getInstance()->disableModalWindow();
1337 CGroupModalGetKey*pGetKey = dynamic_cast<CGroupModalGetKey*>(CWidgetManager::getInstance()->getElementFromId(WIN_MODAL_GET_KEY));
1338 if (pGetKey == NULL)
1339 return;
1341 // If we are in key shortcut mode
1342 if (pGetKey->Caller=="editkey")
1344 pMCM->NewKey->CurrentEditCmdLine.Combo = pGetKey->Combo;
1345 pMCM->NewKey->CurAM->addCombo(pMCM->NewKey->CurrentEditCmdLine.ActionName,
1346 pMCM->NewKey->CurrentEditCmdLine.Combo);
1347 // Refresh all keys
1348 pMCM->refreshAllKeyDisplays();
1351 // If we are in newkey mode
1352 if (pGetKey->Caller=="newkey")
1354 pMCM->NewKey->CurrentEditCmdLine.Combo = pGetKey->Combo;
1356 CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(pMCM->NewKey->WinName+VIEW_EDITCMD_TEXT_KEY));
1357 if (pVT != NULL) pVT->setText(pMCM->NewKey->CurrentEditCmdLine.Combo.toString());
1359 CCtrlBaseButton *pCB = dynamic_cast<CCtrlBaseButton*>(CWidgetManager::getInstance()->getElementFromId(pMCM->NewKey->WinName+CTRL_EDITCMD_BUTTON_OK));
1360 if (pCB != NULL) pCB->setFrozen (false);
1363 // If we are in mode macro
1364 if (pGetKey->Caller=="editcmd")
1366 pMCM->EditCmd->CurrentEditCmdLine.Combo = pGetKey->Combo;
1367 pMCM->CurrentEditMacro.Combo = pMCM->EditCmd->CurrentEditCmdLine.Combo;
1368 CViewText *pVT = dynamic_cast<CViewText*>(CWidgetManager::getInstance()->getElementFromId(VIEW_NEWMACRO_KEY));
1369 if (pVT != NULL) pVT->setText(pMCM->EditCmd->CurrentEditCmdLine.Combo.toString());
1373 REGISTER_ACTION_HANDLER( CHandlerAssignKey, "ah_assign_key");
1375 // ***************************************************************************
1376 static DECLARE_INTERFACE_USER_FCT(canEditKey)
1378 if(args.size()!=1)
1380 nlwarning("<canEditKey> requires 1 arg");
1381 return false;
1384 // cand edit?
1385 sint lineNb= (sint)args[0].getInteger();
1386 CMacroCmdManager *pMCM= CMacroCmdManager::getInstance();
1387 if(lineNb<0 || lineNb>=(sint)pMCM->NewKey->AllLines.size())
1388 result.setBool(false);
1389 else
1391 CModalContainerEditCmd::CLine &line= pMCM->NewKey->AllLines[lineNb];
1392 // get the action manager for this line
1393 nlassert(line.ComboAM<pMCM->ActionManagers.size());
1394 CActionsManager *pCurAM = pMCM->ActionManagers[line.ComboAM];
1395 nlassert(pCurAM);
1396 // can edit the action only if the action name is not "Force Display"
1397 result.setBool(!pCurAM->isActionDisplayForced(line.ActionName));
1400 return true;
1402 REGISTER_INTERFACE_USER_FCT("canEditKey", canEditKey)
1404 // ***************************************************************************
1405 static DECLARE_INTERFACE_USER_FCT(canDeleteKey)
1407 if(args.size()!=1)
1409 nlwarning("<canDeleteKey> requires 1 arg");
1410 return false;
1413 // cand delete?
1414 sint lineNb= (sint)args[0].getInteger();
1415 CMacroCmdManager *pMCM= CMacroCmdManager::getInstance();
1416 if(lineNb<0 || lineNb>=(sint)pMCM->NewKey->AllLines.size())
1417 result.setBool(false);
1418 else
1420 CModalContainerEditCmd::CLine &line= pMCM->NewKey->AllLines[lineNb];
1421 // get the action manager for this line
1422 nlassert(line.ComboAM<pMCM->ActionManagers.size());
1423 CActionsManager *pCurAM = pMCM->ActionManagers[line.ComboAM];
1424 nlassert(pCurAM);
1425 // cannot delete the action if the action name is "Force Display" AND NotAssigned (since already deleted)
1426 result.setBool( !(pCurAM->isActionDisplayForced(line.ActionName) && line.Combo.Key==KeyCount) );
1429 return true;
1431 REGISTER_INTERFACE_USER_FCT("canDeleteKey", canDeleteKey)