Skip to content

Commit d4408b2

Browse files
committed
Allow %N for the name of the trigger/alias in send box
1 parent f0c83c5 commit d4408b2

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

doc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,8 @@ class CMUSHclientDoc : public CDocument
16711671
const bool bExpandWildcards,
16721672
const bool bFixRegexps, // convert \ to \\ for instance
16731673
const bool bIsRegexp, // true = regexp trigger
1674-
const bool bThrowExceptions); // throw exception on error
1674+
const bool bThrowExceptions, // throw exception on error
1675+
const char * sName); // the name of the trigger/timer/alias (for %N)
16751676

16761677
#ifdef PANE
16771678

evaluate.cpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ int iCount = GetTriggerArray ().GetSize (); // how many there are
338338
false, // expand wildcards
339339
true, // convert regexps
340340
trigger_item->bRegexp, // is it regexp or normal?
341-
false); // don't throw exceptions
341+
false, // don't throw exceptions
342+
NULL); // no name substitution in match text
342343

343344

344345
LONGLONG iOldTimeTaken = 0;
@@ -420,6 +421,11 @@ int iCount = GetTriggerArray ().GetSize (); // how many there are
420421

421422
// copy contents to output area, replacing %1, %2 etc. with appropriate contents
422423

424+
// get unlabelled trigger's internal name
425+
const char * pLabel = trigger_item->strLabel;
426+
if (pLabel [0] == 0)
427+
pLabel = GetTriggerRevMap () [trigger_item].c_str ();
428+
423429
output += FixSendText (::FixupEscapeSequences (trigger_item->contents),
424430
trigger_item->iSendTo, // where it is going
425431
trigger_item->regexp, // regexp
@@ -429,7 +435,8 @@ int iCount = GetTriggerArray ().GetSize (); // how many there are
429435
true, // expand wildcards
430436
false, // convert regexps
431437
false, // is it regexp or normal?
432-
false); // don't throw exceptions
438+
false, // don't throw exceptions
439+
pLabel);
433440

434441
break; // break out of loop, we have a trigger match
435442

@@ -846,6 +853,11 @@ bool CMUSHclientDoc::ProcessOneAliasSequence (const CString strCurrentLine,
846853
else
847854
Trace ("Matched alias %s", (LPCTSTR) alias_item->strLabel);
848855

856+
// get unlabelled alias's internal name
857+
const char * pLabel = alias_item->strLabel;
858+
if (pLabel [0] == 0)
859+
pLabel = GetAliasRevMap () [alias_item].c_str ();
860+
849861
// if we have to do parameter substitution on the alias, do it now
850862

851863
CString strSendText;
@@ -863,7 +875,8 @@ bool CMUSHclientDoc::ProcessOneAliasSequence (const CString strCurrentLine,
863875
true, // expand wildcards
864876
false, // convert regexps
865877
false, // is it regexp or normal?
866-
true); // throw exceptions
878+
true, // throw exceptions
879+
pLabel);
867880
}
868881
catch (CException* e)
869882
{
@@ -1022,6 +1035,7 @@ bool CMUSHclientDoc::ExecuteAliasScript (CAlias * alias_item,
10221035
// %<22> : contents of wildcard 22
10231036
// %% : %
10241037
// %C : contents of (text) clipboard
1038+
// %N : name of trigger / timer / alias
10251039

10261040
// If bThrowExceptions is set certain conditions (such as variable not existing)
10271041
// cause an exception to be thrown (eg. for alias handling),
@@ -1037,7 +1051,8 @@ CString CMUSHclientDoc::FixSendText (const CString strSource,
10371051
const bool bExpandWildcards, // convert %x
10381052
const bool bFixRegexps, // convert \ to \\ for instance
10391053
const bool bIsRegexp, // true = regexp trigger
1040-
const bool bThrowExceptions)
1054+
const bool bThrowExceptions, // throw exception on error
1055+
const char * sName) // the name of the trigger/timer/alias (for %N)
10411056
{
10421057
CString strOutput; // result of expansion
10431058

@@ -1324,6 +1339,26 @@ const char * pText,
13241339
}
13251340
break; // end of %c
13261341

1342+
/* -------------------------------------------------------------------- *
1343+
* %N - name of the thing *
1344+
* -------------------------------------------------------------------- */
1345+
1346+
case 'N':
1347+
case 'n':
1348+
{
1349+
// copy up to the percent sign
1350+
strOutput += CString (pStartOfGroup, pText - pStartOfGroup);
1351+
1352+
if (sName)
1353+
strOutput += sName;
1354+
1355+
// get ready for next batch from beyond the 'n'
1356+
1357+
pText += 2;
1358+
pStartOfGroup = pText;
1359+
}
1360+
break; // end of %n
1361+
13271362
/* -------------------------------------------------------------------- *
13281363
* %(something else) *
13291364
* -------------------------------------------------------------------- */

0 commit comments

Comments
 (0)