Rearranging a list of placeholders using a dialog.
Rearranging a list of placeholders using a dialog. The list of placeholders can be reordered manually with the arrow buttons of the dialog, with Drag And Drop and by keyboard with ALT + arrow keys. By clicking on the column headers, the list can be sorted by the respective column. In the first column, the original order can be restored.
The contents of the dialog columns displayed in the dialog must be defined beforehand with link::set_ui_value for each link. This step is necessary so that the list entries can display arbitrary values. Please note that link::set_ui_value expects texts (char* or String) as input. If numbers are to be shown, they must first be converted to text using appropriate functions (e.g. itoa, sprintf or string::set).
If the dialog is confirmed successfully, the input list will be re-sorted according to the dialog list. Using link::get_ui_value (.., 0) you can geht the original original position of the entries. The return value of link::get_ui_value is a int in this (and only in this case!).
If you want to use the result list to update the placeholders, you may have to determine the placeholders again from the document (or better from the respective frame): When updating, the positions of all placeholders in the following text will change their positions - but of course the list does not 'know' about this.
Name | Type | Default | Description |
Return | int | 0 : Dialog ended with Okay otherwise : Error or Cancel |
|
lli | LinkList | - | List of placeholders. The contents displayed in the list must be defined beforehand with link::set_ui_value. Otherwise the columns will remain empty. |
title | String oder char* | 0 | Dialog title 0 or empty : No title |
description | String oder char* | 0 | Short (blue) description text above the list 0 or empty : No description |
col1 | String oder char* | 0 | Name of the first column (after the '•' column) of the list 0 or empty : "Number" |
col2 | String oder char* | 0 | Name of the second column (after the '•' column) of the list 0 or empty : "Product" |
col3 | String oder char* | 0 | Name of the third column o(after the '•' column) f the list 0 or empty : "Frame" |
col4 | String oder char* | 0 | Name of the forth column (after the '•' column) of the list 0 or empty : "Page" |
Here is a simple example.
#include "internal/types.h" #include "internal/text.h"
int main () { LinkList lli = linklist::alloc (0); Link li; int result;
// Get a list of placeholders // linklist::collect_any (lli, 1, "", kFirstIgnore, kSortRowwise, 40, 0, 1, -5);
// Define the content to show in the dialog // for (li = linklist::first (lli); li; li = linklist::next (lli)) { link::set_ui_value (li, 1, itoa (link::id (li)-1)); link::set_ui_value (li, 2, link::content (li)); link::set_ui_value (li, 3, itoa (item::getint (link::frame (li)))); link::set_ui_value (li, 4, itoa (link::pos (li))); wlog ("", "Before : %s\n", link::get_ui_value (li, 1)); }
// Call the dialog // result = sortlinks_dialog (lli, "Rearrange", 0, "ID", "Text", "Frame", "Pos");
// Handle result // if (result == 0) { for (li = linklist::first (lli); li; li = linklist::next (lli)) { wlog ("", "After : %s\n", link::get_ui_value (li, 1)); } } else { wlog ("", "Dialog Canceled by User\n"); }
linklist::release (lli);
return 0; }
Alphabetic index HTML hierarchy of classes or Java