ACC SHELL
/**
* File: Greasemonkey.ycp
* Package: yast2-storage
* Summary: Expert Partitioner
* Authors: Arvin Schnell <aschnell@suse.de>
*
* Lets see if this turns out to be useful.
*/
{
module "Greasemonkey";
import "Directory";
term VStackFrames(term old)
{
list<term> frames = (list<term>) argsof(old);
term new = `VBox();
foreach(term frame, frames, {
if (size(new) != 0)
new = add(new, `VSpacing(0.45));
new = add(new, frame);
});
return new;
}
term FrameWithMarginBox(term old)
{
string title = old[0]:"error";
list args = sublist(argsof(old), 1);
return `Frame(title, toterm(`MarginBox, union([1.45, 0.45], args)));
}
/*
* ComboBoxSelected
*
* `ComboBoxSelected(`id(`wish), `opt(`notify), "Wish",
* [ `item(`id(`time), "Time"),
* `item(`id(`love), "Love"),
* `item(`id(`money), "Money") ],
* `id(`love))
*
* `ComboBox(`id(`wish), `opt(`notify), "Wish",
* [ `item(`id(`time), "Time", false),
* `item(`id(`love), "Love", true),
* `item(`id(`money), "Money", false) ])
*/
term ComboBoxSelected(term old)
{
list args = argsof(old);
list tmp = sublist(args, 0, size(args)-2);
list<term> items = args[size(args)-2]:[];
term id = args[size(args)-1]:`id();
items = maplist(term item, items, { return `item(item[0]:nil, item[1]:nil, item[0]:nil == id); });
return toterm(`ComboBox, add(tmp, items));
}
/*
* LeftRadioButton
*
* `LeftRadioButton(`id(), `opt(), "text")
*
* `Left(`RadioButton(`id(), `opt(), "text"))
*/
term LeftRadioButton(term old)
{
return `Left(toterm(`RadioButton, argsof(old)));
}
/*
* LeftRadioButtonWithAttachment
*
* `LeftRadioButtonWithAttachment(`id(), `opt(), "text", contents)
*
* `VBox(
* `Left(`Radiobutton(`id(), `opt(), "text")),
* `HBox(`HSpacing(4), contents)
* )
*/
term LeftRadioButtonWithAttachment(term old)
{
list args = argsof(old);
list tmp1 = sublist(args, 0, size(args)-1);
any tmp2 = args[size(args)-1]:nil;
if (tmp2 == `Empty())
return `VBox(toterm(`LeftRadioButton, tmp1));
else
return `VBox(toterm(`LeftRadioButton, tmp1),
`HBox(`HSpacing(4), tmp2));
}
/*
* LeftCheckBox
*
* `LeftCheckBox(`id(), `opt(), "text")
*
* `Left(`CheckBox(`id(), `opt(), "text"))
*/
term LeftCheckBox(term old)
{
return `Left(toterm(`CheckBox, argsof(old)));
}
/*
* LeftCheckBoxWithAttachment
*
* `LeftCheckBoxWithAttachment(`id(), `opt(), "text", contents)
*
* `VBox(
* `Left(`Radiobutton(`id(), `opt(), "text")),
* `HBox(`HSpacing(4), contents)
* )
*/
term LeftCheckBoxWithAttachment(term old)
{
list args = argsof(old);
list tmp1 = sublist(args, 0, size(args)-1);
any tmp2 = args[size(args)-1]:nil;
if (tmp2 == `Empty())
return `VBox(toterm(`LeftCheckBox, tmp1));
else
return `VBox(toterm(`LeftCheckBox, tmp1),
`HBox(`HSpacing(4), tmp2));
}
/*
* IconAndHeading
*
* `IconAndHeading("title", "icon")
*
* `Left(`HBox(`Image("icon", ""),
* `Heading("title")));
*/
term IconAndHeading(term old)
{
list args = argsof(old);
string title = args[0]:"";
string icon = Directory::icondir + "22x22/apps/" + args[1]:"";
return `Left(`HBox(`Image(icon, ""),
`Heading(title)));
}
map<symbol, term(term)> handlers = $[
`VStackFrames : VStackFrames,
`FrameWithMarginBox : FrameWithMarginBox,
`ComboBoxSelected : ComboBoxSelected,
`LeftRadioButton : LeftRadioButton,
`LeftRadioButtonWithAttachment : LeftRadioButtonWithAttachment,
`LeftCheckBox : LeftCheckBox,
`LeftCheckBoxWithAttachment : LeftCheckBoxWithAttachment,
`IconAndHeading : IconAndHeading
];
global boolean Register(symbol s, term(term) handler)
{
if (haskey(handlers, s))
{
y2error("handler for %1 already registered", s);
return false;
}
else
{
handlers[s] = handler;
return true;
}
}
global term Transform(term old)
{
symbol s = symbolof(old);
term(term) handler = handlers[s]:nil;
if (handler != nil)
return Transform(handler(old));
term new = list::reduce(term tmp, any arg, toterm(s), argsof(old), {
if (is(arg, term))
arg = Transform((term) arg);
return add(tmp, arg);
});
return new;
}
}
ACC SHELL 2018