summaryrefslogtreecommitdiff
path: root/app/bin/dprmfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/bin/dprmfile.c')
-rw-r--r--app/bin/dprmfile.c239
1 files changed, 168 insertions, 71 deletions
diff --git a/app/bin/dprmfile.c b/app/bin/dprmfile.c
index 5b22a01..18b0cbe 100644
--- a/app/bin/dprmfile.c
+++ b/app/bin/dprmfile.c
@@ -1,5 +1,5 @@
-/*
- * $Header: /home/dmarkle/xtrkcad-fork-cvs/xtrkcad/app/bin/dprmfile.c,v 1.3 2008-03-10 18:59:53 m_fischer Exp $
+/** \file dprmfile.c
+ * Param File Management
*/
/* XTrkCad - Model Railroad CAD
@@ -26,6 +26,8 @@
#include <stdint.h>
+#define PARAM_SUBDIR ("\\params")
+
/****************************************************************************
*
* Param File Management
@@ -208,24 +210,26 @@ EXPORT void RememberParamFiles( void )
static wWin_p paramFileW;
-static long paramFileSel = 1;
+static long paramFileSel = 0;
static wIcon_p mtbox_bm;
static wIcon_p chkbox_bm;
static void ParamFileAction( void * );
static void ParamFileBrowse( void * );
+static void ParamFileSelectAll( void * );
static paramListData_t paramFileListData = { 10, 370 };
static char * paramFileLabels[] = { N_("Show File Names"), NULL };
static paramData_t paramFilePLs[] = {
#define I_PRMFILLIST (0)
#define paramFileL ((wList_p)paramFilePLs[I_PRMFILLIST].control)
- { PD_LIST, NULL, "inx", 0, &paramFileListData, NULL, BL_DUP|BL_SETSTAY },
+ { PD_LIST, NULL, "inx", 0, &paramFileListData, NULL, BL_DUP|BL_SETSTAY|BL_MANY },
#define I_PRMFILTOGGLE (1)
{ PD_TOGGLE, &paramFileSel, "mode", 0, paramFileLabels, NULL, BC_HORZ|BC_NOBORDER },
-#define I_PRMFILACTION (2)
+ { PD_BUTTON, (void *)ParamFileSelectAll, "selectall", PDO_DLGCMDBUTTON, NULL, N_("Select all") },
+#define I_PRMFILACTION (3)
#define paramFileActionB ((wButton_p)paramFilePLs[I_PRMFILACTION].control)
- { PD_BUTTON, (void*)ParamFileAction, "action", PDO_DLGCMDBUTTON, NULL, N_("Unload") },
+ { PD_BUTTON, (void*)ParamFileAction, "action", PDO_DLGCMDBUTTON, NULL, N_("Unload"), 0L, FALSE },
{ PD_BUTTON, (void*)ParamFileBrowse, "browse", 0, NULL, N_("Browse ...") } };
static paramGroup_t paramFilePG = { "prmfile", 0, paramFilePLs, sizeof paramFilePLs/sizeof paramFilePLs[0] };
@@ -250,66 +254,80 @@ static void ParamFileLoadList( void )
wControlShow( (wControl_p)paramFileL, TRUE );
}
+/**
+ * Load the selected parameter files. This is a callback executed when the file selection dialog
+ * is closed.
+ * Steps:
+ * - the parameters are read from file
+ * - check is performed to see whether the content is already present, if yes the previously
+ * loaded content is invalidated
+ * - loaded parameter file is added to list of parameter files
+ * - if a parameter file dialog exists the list is updated. It is either rewritten in
+ * in case of an invalidated file or the new file is appended
+ * - the settings are updated
+ * These steps are repeated for every file in list
+ *
+ * \param files IN the number of filenames in the fileName array
+ * \param fileName IN an array of fully qualified filenames
+ * \param data IN ignored
+ * \return TRUE on success, FALSE on error
+ */
EXPORT int LoadParamFile(
- const char * pathName,
- const char * fileName,
+ int files,
+ char ** fileName,
void * data )
{
char * cp;
+ char *name;
wIndex_t inx;
- wBool_t redrawList;
+ int i = 0;
- if (pathName == NULL)
- return TRUE;
- memcpy( curParamDir, pathName, fileName-pathName );
- curParamDir[fileName-pathName] = '\0';
- wPrefSetString( "file", "paramdir", curParamDir );
-
- redrawList = FALSE;
- curContents = curSubContents = NULL;
- curParamFileIndex = paramFileInfo_da.cnt;
- if ( !ReadParams( 0, NULL, pathName ) )
- return FALSE;
- if (curContents == NULL) {
- curContents = curSubContents = MyStrdup( fileName );
- for ( cp=curContents; *cp; cp++ ) {
- if ( *cp == '=' || *cp == '\'' || *cp == '"' || *cp == ':' || *cp == '.' )
- *cp = ' ';
- }
- }
+ wBool_t redrawList = FALSE;
- for ( inx=0; inx<paramFileInfo_da.cnt; inx++ ) {
- if ( paramFileInfo(inx).valid &&
- strcmp( paramFileInfo(inx).contents, curContents ) == 0 ) {
- paramFileInfo(inx).valid = FALSE;
- redrawList = TRUE;
- break;
- }
- }
+ assert( fileName != NULL );
+ assert( files > 0);
- DYNARR_APPEND( paramFileInfo_t, paramFileInfo_da, 10 );
- paramFileInfo(curParamFileIndex).name = MyStrdup( pathName );
- paramFileInfo(curParamFileIndex).valid = TRUE;
- paramFileInfo(curParamFileIndex).deleted = FALSE;
- paramFileInfo(curParamFileIndex).deletedShadow =
- paramFileInfo(curParamFileIndex).deleted = FALSE;
- paramFileInfo(curParamFileIndex).contents = curContents;
-
- if ( paramFilePG.win ) {
- if ( redrawList ) {
- ParamFileLoadList();
- } else {
- strcpy( message, ((!paramFileSel) && paramFileInfo(curParamFileIndex).contents)?
- paramFileInfo(curParamFileIndex).contents:
- paramFileInfo(curParamFileIndex).name );
- wListAddValue( paramFileL, message, chkbox_bm, (void*)(intptr_t)curParamFileIndex );
- wListSetIndex( paramFileL, wListGetCount(paramFileL)-1 );
+ for( i=0; i < files; i++ )
+ {
+ curContents = curSubContents = NULL;
+ curParamFileIndex = paramFileInfo_da.cnt;
+ if ( !ReadParams( 0, NULL, fileName[ i ] ) )
+ return FALSE;
+
+ assert( curContents != NULL );
+ // in case the contents is already presented, make invalid
+ for ( inx=0; inx<paramFileInfo_da.cnt; inx++ ) {
+ if ( paramFileInfo(inx).valid &&
+ strcmp( paramFileInfo(inx).contents, curContents ) == 0 ) {
+ paramFileInfo(inx).valid = FALSE;
+ redrawList = TRUE;
+ break;
+ }
}
- }
- wPrefSetString( "Parameter File Map", curContents,
+ DYNARR_APPEND( paramFileInfo_t, paramFileInfo_da, 10 );
+ paramFileInfo(curParamFileIndex).name = MyStrdup( fileName[ i ] );
+ paramFileInfo(curParamFileIndex).valid = TRUE;
+ paramFileInfo(curParamFileIndex).deletedShadow =
+ paramFileInfo(curParamFileIndex).deleted = FALSE;
+ paramFileInfo(curParamFileIndex).contents = curContents;
+
+ if ( paramFilePG.win ) {
+ if ( redrawList ) {
+ ParamFileLoadList();
+ } else {
+ strcpy( message, ((!paramFileSel) && paramFileInfo(curParamFileIndex).contents)?
+ paramFileInfo(curParamFileIndex).contents:
paramFileInfo(curParamFileIndex).name );
+ wListAddValue( paramFileL, message, chkbox_bm, (void*)(intptr_t)curParamFileIndex );
+ wListSetIndex( paramFileL, wListGetCount(paramFileL)-1 );
+ }
+ }
+
+ wPrefSetString( "Parameter File Map", curContents,
+ paramFileInfo(curParamFileIndex).name );
+ }
curParamFileIndex = PARAM_CUSTOM;
DoChangeNotification( CHANGE_PARAMS );
return TRUE;
@@ -322,37 +340,113 @@ static void ParamFileBrowse( void * junk )
return;
}
+/**
+ * Update the action button. If at least one selected file is unloaded, the action button
+ * is set to 'Reload'. If all selected files are loaded, the button will be set to 'Unload'.
+ *
+ * \param varname1 IN this is a variable
+ * \return
+ */
static void UpdateParamFileButton(
wIndex_t fileInx )
{
- if (fileInx < 0 || fileInx >= paramFileInfo_da.cnt)
+ wIndex_t selcnt = wListGetSelectedCount( paramFileL );
+ wIndex_t inx, cnt;
+
+ void * data;
+
+ // set the default
+ wButtonSetLabel( paramFileActionB, _("Unload"));
+ paramFilePLs[ I_PRMFILACTION ].context = FALSE;
+
+ //nothing selected -> leave
+ if( selcnt <= 0 )
return;
- wButtonSetLabel( paramFileActionB,
- paramFileInfo(fileInx).deleted?_("Reload"):_("Unload") );
+
+ // get the number of items in list
+ cnt = wListGetCount( paramFileL );
+
+ // walk through the whole list box
+ for ( inx=0; inx<cnt; inx++ )
+ {
+ if ( wListGetItemSelected( (wList_p)paramFileL, inx ))
+ {
+ // if item is selected, get status
+ fileInx = (intptr_t)wListGetItemContext( paramFileL, inx );
+
+ if (fileInx < 0 || fileInx >= paramFileInfo_da.cnt)
+ return;
+ if( paramFileInfo(fileInx).deleted ) {
+ // if selected file was unloaded, set button to reload and finish loop
+ wButtonSetLabel( paramFileActionB, _("Reload"));
+ paramFilePLs[ I_PRMFILACTION ].context = (void *)TRUE;
+ break;
+ }
+ }
+ }
}
-static void ParamFileAction( void * junk )
+/**
+ * Unload selected files.
+ *
+ * \param action IN FALSE = unload, TRUE = reload parameter files
+ * \return
+ */
+
+static void ParamFileAction( void * action )
{
- wIndex_t listInx;
+ wIndex_t selcnt = wListGetSelectedCount( paramFileL );
+ wIndex_t inx, cnt;
wIndex_t fileInx;
void * data;
- listInx = wListGetValues( paramFileL, NULL, 0, NULL, &data );
- if (listInx<0)
+ unsigned newDeletedState;
+
+ if( action )
+ newDeletedState = FALSE;
+ else
+ newDeletedState = TRUE;
+
+ //nothing selected -> leave
+ if( selcnt <= 0 )
return;
- fileInx = (wIndex_t)(long)data;
- paramFileInfo(fileInx).deleted = ! paramFileInfo(fileInx).deleted;
-#ifndef LATER
- strcpy( message, ((!paramFileSel) && paramFileInfo(fileInx).contents)?
- paramFileInfo(fileInx).contents:
- paramFileInfo(fileInx).name );
- wListSetValues( paramFileL, listInx, message, (paramFileInfo(fileInx).deleted)?mtbox_bm:chkbox_bm, (void*)(intptr_t)fileInx );
-#endif
+
+ // get the number of items in list
+ cnt = wListGetCount( paramFileL );
+
+ // walk through the whole list box
+ for ( inx=0; inx<cnt; inx++ )
+ {
+ if ( wListGetItemSelected( (wList_p)paramFileL, inx ) )
+ {
+ fileInx = (intptr_t)wListGetItemContext( paramFileL, inx );
+
+ // set the desired state
+ paramFileInfo(fileInx).deleted = newDeletedState;
+
+ strcpy( message, ((!paramFileSel) && paramFileInfo(fileInx).contents)?
+ paramFileInfo(fileInx).contents:
+ paramFileInfo(fileInx).name );
+ wListSetValues( paramFileL, inx, message, (paramFileInfo(fileInx).deleted)?mtbox_bm:chkbox_bm, (void*)(intptr_t)fileInx );
+ }
+ }
DoChangeNotification( CHANGE_PARAMS );
UpdateParamFileButton( fileInx );
}
+/**
+ * Select all files in the list and set action button
+ *
+ * \param junk IN ignored
+ * \return
+ */
+
+static void ParamFileSelectAll( void *junk )
+{
+ wListSelectAll( paramFileL );
+ UpdateParamFileButton( 0 );
+}
static void ParamFileOk( void * junk )
{
@@ -426,12 +520,15 @@ static void DoParamFiles( void * junk )
dir = wPrefGetString( "file", "paramdir" );
if (dir != NULL)
strcpy( curParamDir, dir );
- else
+ else {
+ // in case there is no preference setting, use the installation's param directory as default
strcpy( curParamDir, libDir );
+ strcat( curParamDir, PARAM_SUBDIR );
+ }
mtbox_bm = wIconCreateBitMap( mtbox_width, mtbox_height, mtbox_bits, drawColorBlack );
chkbox_bm = wIconCreateBitMap( chkbox_width, chkbox_height, chkbox_bits, drawColorBlack );
paramFileW = ParamCreateDialog( &paramFilePG, MakeWindowTitle(_("Parameter Files")), _("Ok"), ParamFileOk, ParamFileCancel, TRUE, NULL, 0, ParamFileDlgUpdate );
- paramFile_fs = wFilSelCreate( mainW, FS_LOAD, 0, _("Load Parameters"), _("Parameter files|*.xtp"), LoadParamFile, NULL );
+ paramFile_fs = wFilSelCreate( mainW, FS_LOAD, FS_MULTIPLEFILES, _("Load Parameters"), _("Parameter files|*.xtp"), LoadParamFile, NULL );
ParamFileLoadList();
}
ParamLoadControls( &paramFilePG );