These are the changes I've submitted to Kovid. They might change during his review.
- A "with" statement in the template language that for the duration of the associated code block changes the "current book" to the one specified by the book id.
- A formatter function selected_books() that returns the book ids of the currently selected books
- A formatter function selected_column() that returns the lookup name of the column containing the selected cell.
- A formatter function sort_book_ids() that sorts the books specified by book_ids.
- A formatter function show_dialog() that opens a dialog to display plain text or html.
- Add check boxes to the template tester to control "run as you type" and to restrict test runs to the first selected book. These are very useful if generating reports using selected books.
Here is an example using several of the new features. It generates a report of book sizes for the selected books.
Code:
program:
ids = sort_book_ids(selected_books(), 'series', 1, 'title', 1);
res = '<style> th, td {padding: 2px;}</style> <h2>Book Size Report</h2><p><table>';
total = 0;
def table_row(title, series, size):
return strcat('<tr><td>', title, '</td>',
'<td>', series, '</td>',
'<td>', if size !=# 0 then human_readable(size) else '0' fi, '</td>',
'</tr>', character('newline'))
fed;
for id in ids:
with id:
s = booksize();
total = total + s;
res = strcat(res, table_row($title, $series, s))
htiw
rof;
res = strcat(res, table_row('TOTAL', '', total));
res = strcat(res, '</table>');
show_dialog(res)
EDIT: The above changes are now in calibre source