The script takes care of all aspects of the ctb: icon, caption, left and right click actions.
Save it as, say, <xyscripts>\_ctb\viewrocker.xys; then just enter
::load "<xyscripts>\_ctb\viewrocker.xys",,'f'; // adjust path
as both left- and right-click script of the ctb, and you're done.The variable $view_cycle or the permanent $P_VIEWROCKER_VIEW_TABLE is the list of views this script will cycle among.
Code: Select all
/* viewrocker.xys
** ctb script to cycle a set of viewmodes.
** set *both* left- & right-click script of a ctb as below, done.
** ::load "<xyscripts>\_ctb\viewrocker.xys",,'f'; // adjust path
*/
"_Initialize"
global $view_table, $view_cycle;
//$view_cycle: /-separated get(view) id of views to cycle among
if !(isset($P_VIEWROCKER_VIEW_CYCLE)) {
$view_cycle = '0/4'; // details/thumbs#1
} else {
$view_cycle = $P_VIEWROCKER_VIEW_CYCLE;
}
// $view_table: <get('view')>|<view cmdID>[|<view icon>[|...]]
if !(isset($P_VIEWROCKER_VIEW_TABLE)) {
$view_table = <<<#>>
0|302|:viewdetails|Details
1|303|:viewdetails|Details with Thumbnails#1
2|304|:viewlist|List
3|305|:views|Small Icons
4|306|:viewthumbs|Thumbnails #1
5|307|:viewthumbs|Thumbnails #2
6|308|:viewthumbs|Thumbnails #3
7|309|:views|Large Icons
8|313|:views|Small Tiles
9|314|:views|Large Tiles
#>>;
} else {
$view_table = $P_VIEWROCKER_VIEW_TABLE;
}
// icon and caption
$ico = ':views';
$cap = "LClick: Cycle View ($hooked_views)<crlf>RClick:Views Menu";
$lc = '_lclick'; // left-click script label(s) ;-separated
$rc = '_rclick'; // rights-click script label(s) ;-separated
if !(ctbicon()) { ctbicon($ico); }
if !(ctbname()) { ctbname($cap); }
if (get('trigger') == 1) { load '*', $lc, 's'; }
elseif (get('trigger') == 2) { load '*', $rc, 's'; }
"default" eval(); // avoids "does not contain any visible scripts."
/* == LCLICK ======================================================== */
"lclick|icon : _lclick"
global $view_table, $view_cycle;
$view_id = get('view');
$index = gettokenindex($view_id, $view_cycle, '/');
if ($index) {
$next_index = ($index == gettoken($view_cycle, 'count', '/'))
? 1 : ($index+1);
$next_view_id = gettoken($view_cycle, $next_index, '/');
$next_view_info = regexmatches($view_table, "^ *$next_view_id\|.+");
$next_view_info = trim($next_view_info, <crlf>);
if ($next_view_info) {
$next_view_cmd = gettoken($next_view_info, 2, '|');
$next_view_icon = gettoken($next_view_info, 3, '|');
ctbicon($next_view_icon ? $next_view_icon : ':views');
load "#$next_view_cmd;",, 's';
}
} else {
button 'views', 2;
}
/* == RCLICK ======================================================== */
"rclick|icon : _rclick"
button 'views', 2;