|
| 1 | +-- This example shows how to create a sequence of dialogs that are |
| 2 | +-- like pages of a wizard-like interface. |
| 3 | + |
| 4 | +-- Create three dialogs, one for each page |
| 5 | +local dlg1 = Dialog("Wizard (Step 1)") |
| 6 | +local dlg2 = Dialog("Wizard (Step 2)") |
| 7 | +local dlg3 = Dialog("Wizard (Step 3)") |
| 8 | +local dlgs = { dlg1, dlg2, dlg3 } |
| 9 | + |
| 10 | +local function finalOK() |
| 11 | + print("Data 1 = " .. dlg1.data.data1) |
| 12 | + print("Data 2 = " .. dlg2.data.data2) |
| 13 | + print("Data 3 = " .. dlg3.data.data3) |
| 14 | +end |
| 15 | + |
| 16 | +local function cancelWizard(dlg) |
| 17 | + dlg:close() |
| 18 | +end |
| 19 | + |
| 20 | +local function prevPage(dlg) |
| 21 | + dlg:close() |
| 22 | + for i = 2,#dlgs do |
| 23 | + if dlg == dlgs[i] then |
| 24 | + local newDlg = dlgs[i-1] |
| 25 | + newDlg.bounds = Rectangle(dlg.bounds.x, dlg.bounds.y, |
| 26 | + newDlg.bounds.width, newDlg.bounds.height) |
| 27 | + newDlg:show{ wait=false } |
| 28 | + return |
| 29 | + end |
| 30 | + end |
| 31 | +end |
| 32 | + |
| 33 | +local function nextPage(dlg) |
| 34 | + dlg:close() |
| 35 | + for i = 1,#dlgs do |
| 36 | + if dlg == dlgs[i] then |
| 37 | + if i == #dlgs then |
| 38 | + finalOK() |
| 39 | + else |
| 40 | + local newDlg = dlgs[i+1] |
| 41 | + newDlg.bounds = Rectangle(dlg.bounds.x, dlg.bounds.y, |
| 42 | + newDlg.bounds.width, newDlg.bounds.height) |
| 43 | + newDlg:show{ wait=false } |
| 44 | + end |
| 45 | + return |
| 46 | + end |
| 47 | + end |
| 48 | +end |
| 49 | + |
| 50 | +local function addFooter(dlg, first, last) |
| 51 | + dlg:separator() |
| 52 | + if first then |
| 53 | + dlg:button{ text="&Cancel",onclick=function() cancelWizard(dlg) end } |
| 54 | + else |
| 55 | + dlg:button{ text="&Previous",onclick=function() prevPage(dlg) end } |
| 56 | + end |
| 57 | + |
| 58 | + local nextText |
| 59 | + if last then nextText = "&Finish" else nextText = "&Next" end |
| 60 | + dlg:button{ text=nextText, onclick=function() nextPage(dlg) end } |
| 61 | +end |
| 62 | + |
| 63 | +-- Create each dialog with its data fields |
| 64 | +dlg1:separator{ text="Page 1" }:entry{ label="Data 1", id="data1" } |
| 65 | +dlg2:separator{ text="Page 2" }:entry{ label="Data 2", id="data2" } |
| 66 | +dlg3:separator{ text="Page 3" }:entry{ label="Data 3", id="data3" } |
| 67 | + |
| 68 | +-- Create the common buttons on all pages (it's the Previous/Next buttons) |
| 69 | +for i = 1,#dlgs do |
| 70 | + addFooter(dlgs[i], (i == 1), (i == #dlgs)) |
| 71 | +end |
| 72 | + |
| 73 | +dlg1:show{ wait=false } |
0 commit comments