aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Fabio Bas2010-12-28 22:08:20 +0000
committerGravatar Fabio Bas2010-12-28 22:08:20 +0000
commit4afcd6e33529dc781bfd1d2c548942b7acf69f5d (patch)
tree0a9146045d10ceef3c7176a6332c0a3b1c86a7ef
parentnigthly round of documentation fixes by OmegaPhil (diff)
downloadKVIrc-4afcd6e33529dc781bfd1d2c548942b7acf69f5d.tar.gz
KVIrc-4afcd6e33529dc781bfd1d2c548942b7acf69f5d.tar.bz2
KVIrc-4afcd6e33529dc781bfd1d2c548942b7acf69f5d.zip
permit popup self modification in epilogues and prologues;
store the triggered item popup id and return it in $popup.currentItemId() git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5249 17fca916-40b9-46aa-a4ea-0a15b648b75c
-rw-r--r--src/kvirc/kvs/KviKvsPopupMenu.cpp12
-rw-r--r--src/kvirc/kvs/KviKvsRunTimeContext.cpp8
-rw-r--r--src/kvirc/kvs/KviKvsRunTimeContext.h20
-rw-r--r--src/modules/popup/libkvipopup.cpp62
4 files changed, 91 insertions, 11 deletions
diff --git a/src/kvirc/kvs/KviKvsPopupMenu.cpp b/src/kvirc/kvs/KviKvsPopupMenu.cpp
index ced03c86d..7ab70b13b 100644
--- a/src/kvirc/kvs/KviKvsPopupMenu.cpp
+++ b/src/kvirc/kvs/KviKvsPopupMenu.cpp
@@ -821,15 +821,13 @@ void KviKvsPopupMenu::setupMenuContents()
return;
}
-
- lock(true);
-
-
if(!g_pApp->windowExists(d->window()))d->setWindow(g_pApp->activeConsole());
if(!d->testMode())
executePrologues(d);
+ lock(true);
+
// Fill this menu contents
int idx = 0;
for(KviKvsPopupMenuItem * it = m_pItemList->first();it;it = m_pItemList->next())
@@ -838,11 +836,11 @@ void KviKvsPopupMenu::setupMenuContents()
++idx;
}
+ lock(false);
+
if(!d->testMode())
executeEpilogues(d);
- lock(false);
-
}
void KviKvsPopupMenu::executePrologues(KviKvsPopupMenuTopLevelData * pData)
@@ -894,6 +892,8 @@ void KviKvsPopupMenu::itemClicked(int itemId)
// FIXME: we could avoid locking since scripts can be shared now!
// see KviKvsTimerManager implementation
lock(true);
+ if(d->extendedRunTimeData())
+ d->extendedRunTimeData()->setPopupId(new QString(it->name()));
((KviKvsPopupMenuItemItem *)it)->kvsCode()->run(
d->window(),
d->parameters(),
diff --git a/src/kvirc/kvs/KviKvsRunTimeContext.cpp b/src/kvirc/kvs/KviKvsRunTimeContext.cpp
index 4d41e5d3d..07b16cf24 100644
--- a/src/kvirc/kvs/KviKvsRunTimeContext.cpp
+++ b/src/kvirc/kvs/KviKvsRunTimeContext.cpp
@@ -40,9 +40,17 @@ KviKvsExtendedRunTimeData::~KviKvsExtendedRunTimeData()
if(m_pAliasSwitchList) delete m_pAliasSwitchList;
if(m_pThisObject) delete m_pThisObject;
if(m_pScriptFilePath) delete m_pScriptFilePath;
+ // don't delete m_pPopupId;
}
}
+void KviKvsExtendedRunTimeData::setPopupId(QString * pPopupId)
+{
+/* if(m_pPopupId)
+ delete m_pPopupId;*/
+ m_pPopupId=pPopupId;
+};
+
KviKvsRunTimeContext::KviKvsRunTimeContext(KviKvsScript * pScript,KviWindow * pWnd,KviKvsVariantList * pParams,KviKvsVariant * pRetVal,KviKvsExtendedRunTimeData * pExtData)
{
m_bError = false;
diff --git a/src/kvirc/kvs/KviKvsRunTimeContext.h b/src/kvirc/kvs/KviKvsRunTimeContext.h
index f39f21db6..e2c5d7e22 100644
--- a/src/kvirc/kvs/KviKvsRunTimeContext.h
+++ b/src/kvirc/kvs/KviKvsRunTimeContext.h
@@ -49,6 +49,7 @@ protected:
KviKvsObject * m_pThisObject; // the current object for object function calls
QString * m_pScriptFilePath; // the current script file path, shallow, may be 0
bool m_bAutoDelete;
+ QString * m_pPopupId;
public:
// all shallow data, all may be 0
KviKvsExtendedRunTimeData()
@@ -56,35 +57,40 @@ public:
m_pAliasSwitchList(0),
m_pThisObject(0),
m_pScriptFilePath(0),
- m_bAutoDelete(FALSE)
+ m_bAutoDelete(FALSE),
+ m_pPopupId(0)
{};
KviKvsExtendedRunTimeData(KviKvsHash * pExtScopeVariables,bool autoDelete=FALSE)
: m_pExtendedScopeVariables(pExtScopeVariables),
m_pAliasSwitchList(0),
m_pThisObject(0),
m_pScriptFilePath(0),
- m_bAutoDelete(autoDelete)
+ m_bAutoDelete(autoDelete),
+ m_pPopupId(0)
{};
KviKvsExtendedRunTimeData(KviKvsSwitchList * pAliasSwitchList,bool autoDelete=FALSE)
: m_pExtendedScopeVariables(0),
m_pAliasSwitchList(pAliasSwitchList),
m_pThisObject(0),
m_pScriptFilePath(0),
- m_bAutoDelete(autoDelete)
+ m_bAutoDelete(autoDelete),
+ m_pPopupId(0)
{};
KviKvsExtendedRunTimeData(KviKvsObject * pThisObject,bool autoDelete=FALSE)
: m_pExtendedScopeVariables(0),
m_pAliasSwitchList(0),
m_pThisObject(pThisObject),
m_pScriptFilePath(0),
- m_bAutoDelete(autoDelete)
+ m_bAutoDelete(autoDelete),
+ m_pPopupId(0)
{};
KviKvsExtendedRunTimeData(QString * pScriptFilePath,bool autoDelete=FALSE)
: m_pExtendedScopeVariables(0),
m_pAliasSwitchList(0),
m_pThisObject(0),
m_pScriptFilePath(pScriptFilePath),
- m_bAutoDelete(autoDelete)
+ m_bAutoDelete(autoDelete),
+ m_pPopupId(0)
{};
~KviKvsExtendedRunTimeData();
public:
@@ -92,6 +98,8 @@ public:
KviKvsSwitchList * aliasSwitchList(){ return m_pAliasSwitchList; };
KviKvsObject * thisObject(){ return m_pThisObject; };
QString * scriptFilePath(){ return m_pScriptFilePath; };
+ QString * popupId(){ return m_pPopupId; };
+ void setPopupId(QString * pPopupId);
};
@@ -173,6 +181,8 @@ public:
{ return m_pExtendedData ? m_pExtendedData->thisObject() : 0; };
QString * scriptFilePath()
{ return m_pExtendedData ? m_pExtendedData->scriptFilePath() : 0; };
+ QString * popupId()
+ { return m_pExtendedData ? m_pExtendedData->popupId() : 0; };
// this MUST be called before any blocking call that might return to the main event loop
// and eventually quit kvirc or close the window that this command is associated to
diff --git a/src/modules/popup/libkvipopup.cpp b/src/modules/popup/libkvipopup.cpp
index e28d1bd08..5a4101245 100644
--- a/src/modules/popup/libkvipopup.cpp
+++ b/src/modules/popup/libkvipopup.cpp
@@ -184,6 +184,9 @@ static bool popup_kvs_cmd_addItem(KviKvsModuleCallbackCommandCall * c)
<item_id> is the optional item id - if not specified, it will be generated automatically.[br]
<command> will be executed just before the popup is filled at [cmd]popup.show[/cmd] command call.
<command> can be a simple instruction or an instruction block delimited by curly brackets.[br]
+ WARNING: Please note that some instructions are not allowed here, an can potentially make kvirc
+ crash. You tipically don't want to delete the popup that's running (calling [cmd]popup.clear[/cmd] or
+ [cmd]popup.destroy[/cmd]) or create an infinite loop (calling [cmd]popup.addPrologue[/cmd])
@seealso:
[cmd]defpopup[/cmd], [cmd]popup.show[/cmd], [cmd]popup.addEpilogue[/cmd]
*/
@@ -229,6 +232,9 @@ static bool popup_kvs_cmd_addPrologue(KviKvsModuleCallbackCommandCall * c)
<item_id> is the optional item id - if not specified, it will be generated automatically.[br]
<command> will be executed just after the popup is filled at [cmd]popup.show[/cmd] command call.
<command> can be a simple instruction or an instruction block delimited by curly brackets.[br]
+ WARNING: Please note that some instructions are not allowed here, an can potentially make kvirc
+ crash. You tipically don't want to delete the popup that's running (calling [cmd]popup.clear[/cmd] or
+ [cmd]popup.destroy[/cmd]) or create an infinite loop (calling [cmd]popup.addEpilogue[/cmd])
@seealso:
[cmd]defpopup[/cmd], [cmd]popup.show[/cmd], [cmd]popup.addPrologue[/cmd]
*/
@@ -692,6 +698,60 @@ static bool popup_kvs_fnc_isEmpty(KviKvsModuleFunctionCall * c)
}
/*
+ @doc: popup.currentItemId
+ @type:
+ function
+ @title:
+ $popup.currentItemId
+ @syntax:
+ $popup.currentItemId()
+ @short:
+ Returns the current id popup
+ @description:
+ When called inside a popup item's callback, this functions returns the id of that popup item.
+ This function returns $null when called outside a popup item's callback.
+ @examples:
+ [example]
+ #clean any previous popup by the same name
+ setmenu test
+ popup.clear test
+ popup.destroy test
+ #create the popup
+ popup.create test
+ popup.addPrologue(test)
+ {
+ # loop ten times
+ foreach(%i,0,1,2,3,4,5,6,7,8,9)
+ {
+ # delete previous created item to avoid duplication
+ popup.delItem test %i
+ # create a test item using %i as its "item id"
+ popup.addItem(test, item%i, , %i)
+ {
+ #get back "item id" inside the callback
+ debug "chosen item $popup.currentItemId()";
+ }
+ }
+ }
+ setmenu test test
+ [/example]
+ @seealso:
+ [cmd]popup.show[/cmd], [cmd]popup.addItem[/cmd]
+*/
+
+static bool popup_kvs_fnc_currentItemId(KviKvsModuleFunctionCall * c)
+{
+ QString * pPopupId = c->context()->popupId();
+ if(pPopupId)
+ {
+ c->returnValue()->setString(pPopupId);
+ } else {
+ c->returnValue()->setNothing();
+ }
+ return true;
+}
+
+/*
@doc: popup.show
@type:
command
@@ -794,6 +854,8 @@ static bool popup_module_init(KviModule *m)
KVSM_REGISTER_FUNCTION(m,"exists",popup_kvs_fnc_exists);
KVSM_REGISTER_FUNCTION(m,"isEmpty",popup_kvs_fnc_isEmpty);
+ KVSM_REGISTER_FUNCTION(m,"currentItemId",popup_kvs_fnc_currentItemId);
+
return true;
}