it emulates the popup menu from the comments column, since apparently it's not accessible anywhere else.
it also adds a few useful commands.
PS: "set last comment" refers to the last comment set using the script.
Code: Select all
"_settings"
global $sing_multi,$last_file;
$sing_multi=s; // "s" for single, "m" for multi-line input
$last_file="%temp%\xy_last_comment.tmp"; // file used to remember the last comment
"Edit Comment... : _edit" //use these labels to call the commands directly
global $label;
$label = edit;
sub menu;
"Set Last Comment : _last"
global $label;
$label = last;
sub menu;
"Prepend Comment : _prepend"
global $label;
$label = prepend;
sub menu;
"Append Comment : _append"
global $label;
$label = append;
sub menu;
"Replacer : _replacer"
global $label;
$label = replacer;
sub menu;
"Eraser : _eraser"
global $label;
$label = eraser;
sub menu;
"Copy Comment : _copy"
global $label;
$label = copy;
sub menu;
"Paste Comment : _paste"
global $label;
$label = paste;
sub menu;
"Remove Comment : _remove"
global $label;
$label = remove;
sub menu;
"menu : menu"
global $label,$clipboard,$crlf,$items,$sing_multi,$last_file;
$total=getinfo(countselected);
if($total<1){
status "Nothing Selected",ffcc00,alert;
end 1;}
sub _settings;
$last=(exists("$last_file")==1)?(readfile("$last_file")):(""); //read last used comment
strlen $len,$last;
substr $last,$last,0,20; //trim to 20 chars
replace $last,$last,"<crlf>","¶"; //replace some dangerous chars
replace $last,$last,'"',"''"; // “
replace $last,$last,'&',"ε";
replace $last,$last,":",":";
if($len>20){$last=$last.'...';} //add "..." if the string was trimmed
$cliptemp=<clipboard>; //save clipboard to a temp variable
strlen $len,$cliptemp;
substr $clip,$cliptemp,0,20;
replace $clip,$clip,"<crlf>","¶";
replace $clip,$clip,'"',"''";
replace $clip,$clip,'&',"ε";
replace $clip,$clip,":",":";
if($len>20){$clip=$clip.'...';}
substr $itemstemp,report("|{fullname}",1),1;
$crlf='$crlf';
$clipboard='$clipboard';
$items='$items';
//create the script
$script=<<<COMMENTSCRIPT
"Edit Comment... : edit"
global $crlf,$items;
$comment=gettoken(report("{fullname}|{comment}$crlf"),2,"<focitem>|"); //get comment from focused item
$comment=gettoken($comment,1,$crlf);
regexreplace $comment,$comment,"¶",$crlf;
$comment = input("Enter New Comment",,"$comment",$sing_multi); //enter new comment
comment $comment,"$items"; //apply comment to selected items
writefile("$last_file",$comment); //save "last used comment"
"Set Last Comment (''$last'') : last"
global $items;
$comment=(exists("$last_file")==1)?(readfile("$last_file")):("");
comment $comment,"$items";
-
"Prepend Comment : prepend"
global $crlf;
$comment=input("Prepend Comment",,(exists("$last_file")==1)?(readfile("$last_file")):(""),$sing_multi);
$itemlist=report("{fullname}$crlf",1);
$commlist=report("{comment}$crlf",1);
$counter=1;
while($counter<=$total){
$curitem=gettoken($itemlist,$counter,$crlf);
$curcomm=gettoken($commlist,$counter,$crlf);
comment "$comment$curcomm",$curitem;
$counter++;}
writefile("$last_file",$comment);
"Append Comment : append"
global $crlf;
$comment=input("Append Comment",,(exists("$last_file")==1)?(readfile("$last_file")):(""),$sing_multi);
$itemlist=report("{fullname}$crlf",1);
$commlist=report("{comment}$crlf",1);
$counter=1;
while($counter<=$total){
$curitem=gettoken($itemlist,$counter,"$crlf");
$curcomm=gettoken($commlist,$counter,"$crlf");
comment "$curcomm$comment",$curitem;
$counter++;}
writefile("$last_file",$comment);
"Replacer : replacer"
global $crlf;
$old=input("Replace this",,,$sing_multi);
$new=input("With this",,,$sing_multi);
$itemlist=report("{fullname}$crlf",1);
$commlist=report("{comment}$crlf",1);
$counter=1;
while($counter<=$total){
$curitem=gettoken($itemlist,$counter,$crlf);
$curcomm=gettoken($commlist,$counter,$crlf);
replace $curcomm,$curcomm,$old,$new;
comment "$curcomm",$curitem;
$counter++;}
"Eraser : eraser"
global $crlf;
$erase=input("Erase this",,,$sing_multi);
$itemlist=report("{fullname}$crlf",1);
$commlist=report("{comment}$crlf",1);
$counter=1;
while($counter<=$total){
$curitem=gettoken($itemlist,$counter,$crlf);
$curcomm=gettoken($commlist,$counter,$crlf);
replace $curcomm,$curcomm,$erase,"";
comment "$curcomm",$curitem;
$counter++;}
-
"Copy Comment : copy"
global $crlf,$items;
$comment=gettoken(report("{fullname}|{comment}$crlf",1),2,"<curitem>|"); //get comment from current item
$comment=gettoken($comment,1,$crlf);
regexreplace $comment,$comment,"¶",$crlf;
if("$comment"!=""){copytext $comment;} //if the comment exists,copy to clipboard
else{status "Current item doesn't have a comment",ffaa00,alert;} //else,print a message
"Paste Comment (''$clip'') : paste"
global $clipboard,$items;
comment $clipboard,"$items"; //paste comment from clipboard
writefile("$last_file",$clipboard);
-
"Remove Comment : remove"
global $items;
comment "","$items";
-
"Cancel : cancel"
end 1;
COMMENTSCRIPT;
$crlf="<crlf>";
$clipboard="$cliptemp";
$items="$itemstemp";
load $script,($label)?($label):(),s; //load the script