2000-10-03 13:45:12 +00:00
|
|
|
#include <automask.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <prefix.h>
|
|
|
|
#include <tree.h>
|
2008-02-01 16:39:41 +00:00
|
|
|
#include <treectrl.h>
|
2000-10-03 13:45:12 +00:00
|
|
|
#include <urldefid.h>
|
1994-12-27 14:56:42 +00:00
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
#include "ba2201.h"
|
1995-04-03 15:05:04 +00:00
|
|
|
#include "ba2300.h"
|
1994-08-12 10:52:49 +00:00
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Autoform tree
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TAutoform_tree : public TString_tree
|
|
|
|
{
|
|
|
|
TConfig *_ini;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual TImage* image(bool selected) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TConfig& ini();
|
|
|
|
void study(const char* module);
|
|
|
|
bool studied(const char* module) const;
|
|
|
|
bool forget(const char* module);
|
|
|
|
|
|
|
|
TAutoform_tree();
|
|
|
|
virtual ~TAutoform_tree();
|
|
|
|
};
|
1994-08-12 10:52:49 +00:00
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
TConfig& TAutoform_tree::ini()
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
if (_ini == NULL)
|
|
|
|
_ini = new TConfig(CONFIG_USER, "Autoform");
|
|
|
|
return *_ini;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
void TAutoform_tree::study(const char* module)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
CHECK(module && *module, "Invalid module");
|
|
|
|
TString4 varname;
|
|
|
|
varname.strncpy(module, 2);
|
|
|
|
varname.lower();
|
|
|
|
TToken_string str(ini().get(varname), ',');
|
|
|
|
TString16 val = module; val.ltrim(2);
|
|
|
|
if (str.get_pos(val) < 0)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
str.add(val);
|
|
|
|
ini().set(varname, str);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
bool TAutoform_tree::studied(const char* module) const
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
if (module && *module)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
TString4 varname;
|
|
|
|
varname.strncpy(module, 2);
|
|
|
|
varname.lower();
|
|
|
|
TToken_string str(((TAutoform_tree*)this)->ini().get(varname), ',');
|
|
|
|
TString16 val = module; val.ltrim(2);
|
|
|
|
return str.get_pos(val) >= 0;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
return FALSE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
bool TAutoform_tree::forget(const char* module)
|
|
|
|
{
|
|
|
|
bool killed = FALSE;
|
|
|
|
if (module && *module)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
TString4 varname;
|
|
|
|
varname.strncpy(module, 2);
|
|
|
|
varname.lower();
|
|
|
|
TToken_string str(ini().get(varname), ',');
|
|
|
|
TString16 val = module; val.ltrim(2);
|
|
|
|
int pos = str.get_pos(val);
|
|
|
|
if (pos >= 0)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
str.destroy(pos);
|
|
|
|
ini().set(varname, str);
|
|
|
|
killed = TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
return killed;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
TImage* TAutoform_tree::image(bool selected) const
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
if (!has_son())
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
TString str; get_description(str);
|
|
|
|
str.cut(5);
|
|
|
|
if (studied(str))
|
|
|
|
return get_res_image(BMP_FILECHK);
|
|
|
|
}
|
|
|
|
return TString_tree::image(selected);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
TAutoform_tree::TAutoform_tree() : _ini(NULL)
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
TAutoform_tree::~TAutoform_tree()
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
if (_ini) delete _ini;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Autoform mask
|
|
|
|
///////////////////////////////////////////////////////////
|
1994-12-27 14:56:42 +00:00
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
class TAutoform_mask : public TAutomask
|
|
|
|
{
|
|
|
|
TAutoform_tree _tree;
|
1994-08-12 10:52:49 +00:00
|
|
|
|
|
|
|
protected:
|
2000-10-03 13:45:12 +00:00
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
static bool forget_lesson(TTree& tree, void* jolly, word flags);
|
|
|
|
void reset_lesson();
|
|
|
|
|
|
|
|
public:
|
|
|
|
int list_dirs(const char* filelist, TString_array& result) const;
|
|
|
|
void fill_tree();
|
|
|
|
|
|
|
|
TAutoform_tree& tree() { return _tree; }
|
|
|
|
|
|
|
|
TAutoform_mask();
|
|
|
|
virtual ~TAutoform_mask();
|
1994-08-12 10:52:49 +00:00
|
|
|
};
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
int TAutoform_mask::list_dirs(const char* filelist, TString_array& result) const
|
|
|
|
{
|
|
|
|
TWait_cursor hourglass;
|
|
|
|
result.destroy();
|
|
|
|
|
2008-10-07 09:06:37 +00:00
|
|
|
TFilename dirname(filelist);
|
2004-03-13 00:29:26 +00:00
|
|
|
int i;
|
|
|
|
|
2008-10-07 09:06:37 +00:00
|
|
|
for (i = dirname.len()-1; i >= 0; i--)
|
|
|
|
if (dirname[i] == '/' || dirname[i] == '\\' || dirname[i] == ':') break;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
2008-10-07 09:06:37 +00:00
|
|
|
TFilename mask(dirname.mid(i+1));
|
|
|
|
dirname.cut(i > 0 ? i+1 : 0);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
|
|
xvt_fsys_save_dir();
|
|
|
|
|
2008-10-07 09:06:37 +00:00
|
|
|
if (dirname.full())
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2008-10-07 09:06:37 +00:00
|
|
|
DIRECTORY d; xvt_fsys_convert_str_to_dir(dirname, &d);
|
|
|
|
BOOLEAN ok = xvt_fsys_set_dir(&d);
|
2000-10-03 13:45:12 +00:00
|
|
|
if (!ok)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SLIST files = xvt_fsys_list_files(DIR_TYPE, mask.get_buffer(), TRUE);
|
|
|
|
const int count = xvt_slist_count(files);
|
|
|
|
|
|
|
|
for (SLIST_ELT e = xvt_slist_get_first(files); e; e = xvt_slist_get_next(files, e))
|
|
|
|
{
|
|
|
|
char* f = xvt_slist_get(files, e, NULL);
|
|
|
|
if (*f != '.' && f[1] != ':')
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2008-10-07 09:06:37 +00:00
|
|
|
if (dirname.not_empty())
|
2000-10-03 13:45:12 +00:00
|
|
|
{
|
2008-10-07 09:06:37 +00:00
|
|
|
mask = dirname;
|
2000-10-03 13:45:12 +00:00
|
|
|
mask.add(f);
|
|
|
|
result.add(mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
result.add(f);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
1994-12-14 15:47:07 +00:00
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
|
|
xvt_slist_destroy(files);
|
|
|
|
xvt_fsys_restore_dir();
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_lessons(const TObject** o1, const TObject** o2)
|
|
|
|
{
|
|
|
|
const TFilename f1 = *(const TString*)*o1;
|
|
|
|
const TFilename f2 = *(const TString*)*o2;
|
2001-05-07 13:28:51 +00:00
|
|
|
const TString80 s1 = f1.name();
|
|
|
|
const TString80 s2 = f2.name();
|
2000-10-03 13:45:12 +00:00
|
|
|
int cmp = s1.compare(s2, 4, TRUE);
|
|
|
|
if (cmp == 0)
|
|
|
|
cmp = s2[4] - s1[4];
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAutoform_mask::fill_tree()
|
|
|
|
{
|
|
|
|
TTree_field& tf = tfield(F_TREE);
|
|
|
|
TFilename path = get(F_PATH);
|
|
|
|
TString desc;
|
|
|
|
if (path.exist())
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
if (_tree.goto_root())
|
|
|
|
_tree.kill_node();
|
|
|
|
_tree.add_son(path);
|
|
|
|
|
|
|
|
path.add("*");
|
|
|
|
TString_array a, b;
|
|
|
|
list_dirs(path, a);
|
|
|
|
for (int i = a.items()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
path = a.row(i);
|
|
|
|
_tree.goto_root();
|
|
|
|
_tree.add_son(path.name());
|
|
|
|
|
|
|
|
path.add("*");
|
|
|
|
list_dirs(path, b);
|
|
|
|
b.TArray::sort(compare_lessons);
|
|
|
|
for (int j = b.items()-1; j >= 0; j--)
|
|
|
|
{
|
|
|
|
path = b.row(j);
|
|
|
|
desc = path.name();
|
|
|
|
|
|
|
|
path.add("backup.ini");
|
|
|
|
TConfig ini(path, "Main");
|
|
|
|
desc << " - " << ini.get("Description");
|
|
|
|
if (desc.not_empty())
|
|
|
|
{
|
|
|
|
_tree.add_son(desc);
|
|
|
|
_tree.goto_father();
|
|
|
|
}
|
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
tf.set_tree(&_tree);
|
|
|
|
_tree.goto_root();
|
|
|
|
_tree.expand_all();
|
|
|
|
tf.win().force_update();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
bool TAutoform_mask::forget_lesson(TTree& tree, void* jolly, word flags)
|
|
|
|
{
|
|
|
|
if (!tree.has_son())
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
TAutoform_tree& at = (TAutoform_tree&)tree;
|
|
|
|
TString desc; at.get_description(desc);
|
|
|
|
desc.cut(5);
|
|
|
|
at.forget(desc);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
return FALSE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
void TAutoform_mask::reset_lesson()
|
|
|
|
{
|
|
|
|
TTree_field& tf = tfield(F_TREE);
|
|
|
|
if (tf.goto_selected())
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
if (_tree.goto_firstson())
|
|
|
|
_tree.scan_depth_first(forget_lesson, NULL);
|
|
|
|
else
|
|
|
|
forget_lesson(_tree, NULL, 0);
|
|
|
|
tf.win().force_update();
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
bool TAutoform_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
switch (o.dlg())
|
|
|
|
{
|
|
|
|
case F_PATH:
|
|
|
|
if (e == fe_init || e == fe_modify)
|
|
|
|
fill_tree();
|
|
|
|
break;
|
|
|
|
case DLG_RESET:
|
|
|
|
if (e == fe_button)
|
|
|
|
reset_lesson();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1994-12-14 15:47:07 +00:00
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
return TRUE;
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
TAutoform_mask::TAutoform_mask() : TAutomask("ba2300")
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
TConfig& ini = _tree.ini();
|
|
|
|
set(F_PATH, ini.get("Path"));
|
|
|
|
set(F_STUDENT, ini.get("Student"));
|
|
|
|
set(F_SOLUTION, ini.get("Solution"));
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
TAutoform_mask::~TAutoform_mask()
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
TConfig& ini = _tree.ini();
|
|
|
|
ini.set("Path", get(F_PATH));
|
|
|
|
ini.set("Student", get(F_STUDENT));
|
|
|
|
ini.set("Solution", get(F_SOLUTION));
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Autoform app
|
|
|
|
///////////////////////////////////////////////////////////
|
1994-08-12 10:52:49 +00:00
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
class TAutoform_app : public TArchive_app
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
protected:
|
|
|
|
virtual void main_loop();
|
|
|
|
};
|
1994-12-14 15:47:07 +00:00
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
void TAutoform_app::main_loop()
|
|
|
|
{
|
|
|
|
TAutoform_mask msk;
|
|
|
|
if (msk.run() == K_ENTER)
|
|
|
|
{
|
|
|
|
TTree_field& tf = msk.tfield(F_TREE);
|
|
|
|
TAutoform_tree& tree = msk.tree();
|
|
|
|
if (tf.goto_selected() && !tree.has_son())
|
|
|
|
{
|
|
|
|
TString desc; tree.get_description(desc);
|
2002-10-24 10:47:49 +00:00
|
|
|
if (yesno_box(FR("Si desidera caricare i dati\n%s?"), (const char*)desc))
|
2000-10-03 13:45:12 +00:00
|
|
|
{
|
|
|
|
desc.cut(5);
|
|
|
|
const short dlg = desc.right(1) == "I" ? F_STUDENT : F_SOLUTION;
|
|
|
|
const TFilename old_study = prefix().get_studio();
|
|
|
|
TFilename study = msk.get(dlg);
|
|
|
|
if (study.empty())
|
|
|
|
msk.set(dlg, study = old_study);
|
|
|
|
if (study != old_study)
|
|
|
|
prefix().set_studio(study);
|
|
|
|
restore(0x3, 0, msk.get(F_PATH));
|
|
|
|
tree.study(desc);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
}
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-12-27 14:56:42 +00:00
|
|
|
int ba2300(int argc, char* argv[])
|
1994-08-12 10:52:49 +00:00
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
TAutoform_app app;
|
2002-10-24 10:47:49 +00:00
|
|
|
app.run(argc, argv, TR("Autoformazione"));
|
1994-08-12 10:52:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|