Purpose
Allow the user to save the selected table layout
In a
self-defined table control the user can change the column widths and
the order of the columns with the mouse. The adjustments are only
valid for the current session. This tip shows how you can give
the user the option of saving the current table layout and loading
it automatically when the table is displayed again. |
Solution We add tow buttons which allow the user to save the
table layout and to restore the standard layout. For storing the
settings we use a local text file.
Our starting point is the following table:
Table
(3,5)
(12,90)
title="My
table"
name="tabx1"
rows="10"
Column
"Column 1"
size=16
name="col1"
Column
"Column 2"
size=16
name="col2"
Column
"Column 3"
size=16
name="col3"
Column
"Column 4"
size=16
name="col4"
Column
"Column 5"
size=16
name="col5"
We add buttons to save
and restore the layout:
Pushbutton
(3,94)
"@44\QSave table layout@"
_ size=(1,2)
process="save_tablesettings.tabx1.txt"
Pushbutton
(3,98)
"@2W\QRestore standard table
layout@" _
size=(1,2)
process="restore_tablesettings.tabx1.txt"
We finally add an include
which loads the user settings when the table is displayed the first time:
// load
current lable louyout
include
"load_tablesettings.tabx1.txt"
|

InputScript "save_tablesettings.tabx1.txt"
Set
V[filename]
"&%[APPDATA]\guixt\tablesettings.tabx1.txt" OpenFile
"&V[filename]"
-output
if
q[ok]
AppendFile
"&V[filename]"
_
tabx1.stat.columnnumber.col1 _ tabx1.stat.columnnumber.col2 _
tabx1.stat.columnnumber.col3 _ tabx1.stat.columnnumber.col4 _
tabx1.stat.columnnumber.col5
AppendFile
"&V[filename]"
_
tabx1.stat.columnwidth.col1 _ tabx1.stat.columnwidth.col2 _
tabx1.stat.columnwidth.col3 _ tabx1.stat.columnwidth.col4 _
tabx1.stat.columnwidth.col5
CloseFile
"&V[filename]"
// Message
Message
"S: Table layout saved"
-statusline
else
// error message
Message
"E: Could not write settings file
&V[filename]"
-statusline endif
// no action
Enter
"?"
InputScript
"restore_tablesettings.tabx1.txt""
Set
V[filename]
"&%[APPDATA]\guixt\tablesettings.tabx1.txt"
RemoveFile
"&V[filename]"
// set
standard layout
Set
V[tabx1.stat.columnnumber.col1]
1 Set
V[tabx1.stat.columnnumber.col2]
2 Set
V[tabx1.stat.columnnumber.col3]
3 Set
V[tabx1.stat.columnnumber.col4]
4 Set
V[tabx1.stat.columnnumber.col5]
5
Set
V[tabx1.stat.columnwidth.col1]
16 Set
V[tabx1.stat.columnwidth.col2]
16 Set
V[tabx1.stat.columnwidth.col3]
16 Set
V[tabx1.stat.columnwidth.col4]
16 Set
V[tabx1.stat.columnwidth.col5]
16
//
Message Message
"S: Standard lable layout
restored"
-statusline
// no action
Enter
"?"
Include
file "load_tablesettings.tabx1.txt""
if
not
V[tabx1.stat.columnnumber.col1]
Set
V[filename]
"&%[APPDATA]\guixt\tablesettings.tabx1.txt
OpenFile
"&V[filename]"
if
q[ok]
// read
column order
ReadFile
"&V[filename]"
_
tabx1.stat.columnnumber.col1 _ tabx1.stat.columnnumber.col2 _
tabx1.stat.columnnumber.col3 _
tabx1.stat.columnnumber.col4 _ tabx1.stat.columnnumber.col5
//
read column width
ReadFile
"&V[filename]"
_
tabx1.stat.columnwidth.col1 _ tabx1.stat.columnwidth.col2 _
tabx1.stat.columnwidth.col3 _
tabx1.stat.columnwidth.col4 _ tabx1.stat.columnwidth.col5
CLoseFile
"&V[filename]"
endif
endif
Components
InputAssistant
|