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
include
@ -15,7 +15,7 @@ bool TConfig_application::create()
|
||||
{
|
||||
arg = argv(i);
|
||||
if (arg == "-c")
|
||||
_which_config = atoi(argv(++i));
|
||||
set_config(atoi(argv(++i)));
|
||||
else
|
||||
if (arg[0] == '-')
|
||||
continue;
|
||||
@ -46,69 +46,101 @@ bool TConfig_application::menu(MENU_TAG m)
|
||||
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)
|
||||
{
|
||||
TString par(name());
|
||||
TString _parag(name());
|
||||
if (m < _paragraphs.items())
|
||||
par = (TString&)_paragraphs[m];
|
||||
else par.cut(2);
|
||||
_parag = (TString&)_paragraphs[m];
|
||||
else _parag.cut(2);
|
||||
|
||||
load_config();
|
||||
for (;;)
|
||||
{
|
||||
TConfig cnf(_which_config, par);
|
||||
|
||||
const TFilename maskname(cnf.get("EdMask"));
|
||||
const TFilename maskname(_cnf->get("EdMask"));
|
||||
if (!maskname.empty())
|
||||
{
|
||||
TMask m(maskname);
|
||||
if (_m) delete _m;
|
||||
_m= new TMask(maskname);
|
||||
|
||||
// carica campi
|
||||
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);
|
||||
if (!oldvl.empty())
|
||||
f.set(oldvl);
|
||||
}
|
||||
}
|
||||
|
||||
load_mask();
|
||||
// run mask
|
||||
if (!preprocess_config(m,cnf))
|
||||
if (!preprocess_config(*_m,*_cnf))
|
||||
break;
|
||||
|
||||
int k = m.run();
|
||||
if (postprocess_config(m,cnf))
|
||||
int k = _m->run();
|
||||
if (postprocess_config(*_m,*_cnf))
|
||||
{
|
||||
bool tosave = k == K_ENTER || k == K_SAVE;
|
||||
|
||||
if (k == K_ENTER || k == K_QUIT)
|
||||
{
|
||||
// aggiusta campi
|
||||
for (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(par, fname, oldvl, value))
|
||||
cnf.set(fname, value, NULL, TRUE, index > -1 ? index : -1);
|
||||
}
|
||||
}
|
||||
save_mask(tosave);
|
||||
}
|
||||
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)
|
||||
{
|
||||
return TRUE;
|
||||
@ -154,3 +201,13 @@ bool TConfig_application::postprocess_config_changed(
|
||||
{
|
||||
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
|
||||
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>)
|
||||
virtual bool create();
|
||||
// @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>)
|
||||
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>
|
||||
void do_config(int m);
|
||||
|
||||
// @access Protected Member
|
||||
protected:
|
||||
// @cmember Ritorna TRUE
|
||||
virtual bool user_create()
|
||||
{ return TRUE; }
|
||||
// @cmember Ritorna TRUE
|
||||
virtual bool user_destroy()
|
||||
{ return TRUE; }
|
||||
virtual bool user_create() ;
|
||||
virtual bool user_destroy() ;
|
||||
|
||||
// @cmember Viene chiamata prima della <mf TApplication::run> e ferma tutto se ritorna FALSE
|
||||
virtual bool preprocess_config (TMask& mask, TConfig& config);
|
||||
@ -78,16 +88,15 @@ protected:
|
||||
// dalla maschera principale.
|
||||
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
|
||||
public:
|
||||
// @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
|
||||
TConfig_application(int which_config = CONFIG_GENERAL) : _which_config(which_config)
|
||||
{}
|
||||
TConfig_application(int which_config = CONFIG_GENERAL) ;
|
||||
// @cmember Distruttore
|
||||
virtual ~TConfig_application()
|
||||
{}
|
||||
virtual ~TConfig_application() ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user