Resa la Confapp resistente al firm_change
git-svn-id: svn://10.65.10.50/trunk@5513 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
9549063858
commit
75b9ec139f
@ -15,7 +15,7 @@ bool TConfig_application::create()
|
|||||||
{
|
{
|
||||||
arg = argv(i);
|
arg = argv(i);
|
||||||
if (arg == "-c")
|
if (arg == "-c")
|
||||||
_which_config = atoi(argv(++i));
|
set_config(atoi(argv(++i)));
|
||||||
else
|
else
|
||||||
if (arg[0] == '-')
|
if (arg[0] == '-')
|
||||||
continue;
|
continue;
|
||||||
@ -46,69 +46,101 @@ bool TConfig_application::menu(MENU_TAG m)
|
|||||||
return xvt_test_menu_tag(BAR_ITEM(2));
|
return xvt_test_menu_tag(BAR_ITEM(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TConfig_application::user_create()
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TConfig_application::user_destroy()
|
||||||
|
{
|
||||||
|
if (_m) delete _m;
|
||||||
|
if (_cnf) delete _cnf;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TConfig_application::save_mask(bool tosave)
|
||||||
|
{
|
||||||
|
if (_m==NULL) return;
|
||||||
|
const int max = _m->dirty() ? _m->fields() : 0;
|
||||||
|
for (int i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
TMask_field& f = _m->fld(i);
|
||||||
|
if (f.dirty() && f.field())
|
||||||
|
{
|
||||||
|
const char* fname = f.field()->name();
|
||||||
|
const char* value = f.get();
|
||||||
|
const int index = f.field()->to();
|
||||||
|
const char* oldvl = _cnf->get(fname);
|
||||||
|
|
||||||
|
if (!tosave)
|
||||||
|
tosave = yesno_box("Modifiche non registrate. Salvare?");
|
||||||
|
|
||||||
|
if (!tosave) break;
|
||||||
|
|
||||||
|
if (postprocess_config_changed(_parag, fname, oldvl, value))
|
||||||
|
_cnf->set(fname, value, NULL, TRUE, index > -1 ? index : -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TConfig_application::load_mask()
|
||||||
|
{
|
||||||
|
if (_m==NULL) return;
|
||||||
|
const int max = _m->fields();
|
||||||
|
for (int i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
TMask_field& f = _m->fld(i);
|
||||||
|
if (f.field() != NULL)
|
||||||
|
{
|
||||||
|
const TFieldref* fr = f.field();
|
||||||
|
const char* fname = fr->name();
|
||||||
|
const int index = fr->to();
|
||||||
|
TString& oldvl = _cnf->get(fname,NULL, index > -1 ? index : -1);
|
||||||
|
f.set(oldvl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TConfig_application::load_config()
|
||||||
|
{
|
||||||
|
if (_cnf) delete _cnf;
|
||||||
|
_cnf = new TConfig(_which_config, _parag);
|
||||||
|
}
|
||||||
|
|
||||||
void TConfig_application::do_config(int m)
|
void TConfig_application::do_config(int m)
|
||||||
{
|
{
|
||||||
TString par(name());
|
TString _parag(name());
|
||||||
if (m < _paragraphs.items())
|
if (m < _paragraphs.items())
|
||||||
par = (TString&)_paragraphs[m];
|
_parag = (TString&)_paragraphs[m];
|
||||||
else par.cut(2);
|
else _parag.cut(2);
|
||||||
|
|
||||||
|
load_config();
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
TConfig cnf(_which_config, par);
|
|
||||||
|
|
||||||
const TFilename maskname(cnf.get("EdMask"));
|
const TFilename maskname(_cnf->get("EdMask"));
|
||||||
if (!maskname.empty())
|
if (!maskname.empty())
|
||||||
{
|
{
|
||||||
TMask m(maskname);
|
if (_m) delete _m;
|
||||||
|
_m= new TMask(maskname);
|
||||||
|
|
||||||
// carica campi
|
// carica campi
|
||||||
const int max = m.fields();
|
load_mask();
|
||||||
for (int i = 0; i < max; i++)
|
|
||||||
{
|
|
||||||
TMask_field& f = m.fld(i);
|
|
||||||
if (f.field() != NULL)
|
|
||||||
{
|
|
||||||
const TFieldref* fr = f.field();
|
|
||||||
const char* fname = fr->name();
|
|
||||||
const int index = fr->to();
|
|
||||||
TString& oldvl = cnf.get(fname,NULL, index > -1 ? index : -1);
|
|
||||||
if (!oldvl.empty())
|
|
||||||
f.set(oldvl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run mask
|
// run mask
|
||||||
if (!preprocess_config(m,cnf))
|
if (!preprocess_config(*_m,*_cnf))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int k = m.run();
|
int k = _m->run();
|
||||||
if (postprocess_config(m,cnf))
|
if (postprocess_config(*_m,*_cnf))
|
||||||
{
|
{
|
||||||
bool tosave = k == K_ENTER || k == K_SAVE;
|
bool tosave = k == K_ENTER || k == K_SAVE;
|
||||||
|
|
||||||
if (k == K_ENTER || k == K_QUIT)
|
if (k == K_ENTER || k == K_QUIT)
|
||||||
{
|
{
|
||||||
// aggiusta campi
|
// aggiusta campi
|
||||||
for (i = 0; i < max; i++)
|
save_mask(tosave);
|
||||||
{
|
|
||||||
TMask_field& f = m.fld(i);
|
|
||||||
if (f.dirty() && f.field())
|
|
||||||
{
|
|
||||||
const char* fname = f.field()->name();
|
|
||||||
const char* value = f.get();
|
|
||||||
const int index = f.field()->to();
|
|
||||||
const char* oldvl = cnf.get(fname);
|
|
||||||
|
|
||||||
if (!tosave)
|
|
||||||
tosave = yesno_box("Modifiche non registrate. Salvare?");
|
|
||||||
|
|
||||||
if (!tosave) break;
|
|
||||||
|
|
||||||
if (postprocess_config_changed(par, fname, oldvl, value))
|
|
||||||
cnf.set(fname, value, NULL, TRUE, index > -1 ? index : -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
@ -123,6 +155,21 @@ void TConfig_application::do_config(int m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TConfig_application::on_firm_change()
|
||||||
|
{
|
||||||
|
((TConfig_application *)this)->save_mask(FALSE);
|
||||||
|
load_config();
|
||||||
|
load_mask();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TConfig_application::set_config(int which)
|
||||||
|
{
|
||||||
|
_which_config= which;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool TConfig_application::preprocess_config (TMask& mask, TConfig& config)
|
bool TConfig_application::preprocess_config (TMask& mask, TConfig& config)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -154,3 +201,13 @@ bool TConfig_application::postprocess_config_changed(
|
|||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TConfig_application::TConfig_application(int which_config)
|
||||||
|
: _cnf(NULL), _m(NULL)
|
||||||
|
{
|
||||||
|
set_config(which_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TConfig_application::~TConfig_application()
|
||||||
|
{
|
||||||
|
}
|
@ -50,6 +50,12 @@ class TConfig_application : public TApplication
|
|||||||
// @cmember:(INTERNAL) Ultima voce di menu' selezionata
|
// @cmember:(INTERNAL) Ultima voce di menu' selezionata
|
||||||
MENU_TAG _last_choice;
|
MENU_TAG _last_choice;
|
||||||
|
|
||||||
|
// @cmember:(INTERNAL) Config corrente
|
||||||
|
TConfig *_cnf ;
|
||||||
|
// @cmember:(INTERNAL) Paragrafo corrente
|
||||||
|
TString16 _parag;
|
||||||
|
// @cmember:(INTERNAL) Maschera di modifica
|
||||||
|
TMask *_m;
|
||||||
// @cmember:(INTERNAL) Crea la finestra principale (vedi <c TApplication>)
|
// @cmember:(INTERNAL) Crea la finestra principale (vedi <c TApplication>)
|
||||||
virtual bool create();
|
virtual bool create();
|
||||||
// @cmember:(INTERNAL) Rimuove l'applicazione (vedi <c TApplication>)
|
// @cmember:(INTERNAL) Rimuove l'applicazione (vedi <c TApplication>)
|
||||||
@ -57,17 +63,21 @@ class TConfig_application : public TApplication
|
|||||||
// @cmember:(INTERNAL) Controlla il menu' (vedi <c TApplication>)
|
// @cmember:(INTERNAL) Controlla il menu' (vedi <c TApplication>)
|
||||||
virtual bool menu(MENU_TAG);
|
virtual bool menu(MENU_TAG);
|
||||||
|
|
||||||
|
// @cmember:(INTERNAL) Carica i parametri su maschera
|
||||||
|
void load_mask();
|
||||||
|
// @cmember:(INTERNAL) Salva i parametri dalla maschera
|
||||||
|
void save_mask(bool tosave) ;
|
||||||
|
|
||||||
|
// @cmember:(INTERNAL) Carica il config
|
||||||
|
void load_config();
|
||||||
|
|
||||||
// @cmember:(INTERNAL) Permette di modificare la configurazione del paragrafo <p m>
|
// @cmember:(INTERNAL) Permette di modificare la configurazione del paragrafo <p m>
|
||||||
void do_config(int m);
|
void do_config(int m);
|
||||||
|
|
||||||
// @access Protected Member
|
// @access Protected Member
|
||||||
protected:
|
protected:
|
||||||
// @cmember Ritorna TRUE
|
virtual bool user_create() ;
|
||||||
virtual bool user_create()
|
virtual bool user_destroy() ;
|
||||||
{ return TRUE; }
|
|
||||||
// @cmember Ritorna TRUE
|
|
||||||
virtual bool user_destroy()
|
|
||||||
{ return TRUE; }
|
|
||||||
|
|
||||||
// @cmember Viene chiamata prima della <mf TApplication::run> e ferma tutto se ritorna FALSE
|
// @cmember Viene chiamata prima della <mf TApplication::run> e ferma tutto se ritorna FALSE
|
||||||
virtual bool preprocess_config (TMask& mask, TConfig& config);
|
virtual bool preprocess_config (TMask& mask, TConfig& config);
|
||||||
@ -78,16 +88,15 @@ protected:
|
|||||||
// dalla maschera principale.
|
// dalla maschera principale.
|
||||||
virtual bool postprocess_config_changed (const char* par, const char* var, const char* oldv, const char* newv);
|
virtual bool postprocess_config_changed (const char* par, const char* var, const char* oldv, const char* newv);
|
||||||
|
|
||||||
|
virtual void on_firm_change();
|
||||||
// @access Public Member
|
// @access Public Member
|
||||||
public:
|
public:
|
||||||
// @cmember Setta il tipo di file di configurazione al quale e' associata l'applicazione
|
// @cmember Setta il tipo di file di configurazione al quale e' associata l'applicazione
|
||||||
void set_config(int which) {_which_config = which;}
|
void set_config(int which);
|
||||||
// @cmember Costruttore
|
// @cmember Costruttore
|
||||||
TConfig_application(int which_config = CONFIG_GENERAL) : _which_config(which_config)
|
TConfig_application(int which_config = CONFIG_GENERAL) ;
|
||||||
{}
|
|
||||||
// @cmember Distruttore
|
// @cmember Distruttore
|
||||||
virtual ~TConfig_application()
|
virtual ~TConfig_application() ;
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user