#include <iostream.h> // for C++ stream I/O
#include <hush/kit.h> // for kit (tk) class
#include <hush/session.h> // for session class
#include "fileselector.h" // for new fileselector widget
class application : public session {
public:
application(int argc, char* argv[]) : session(argc,argv, "example") {}
void prelude(); // do inits here
int main(); // main setup here
};
Note the use of _register() to register the new handler for deletion. See Garbage collection for more information on _register.
void application::prelude() {
fileselector* f = new fileselector; _register(f);
tk->bind(f->type(), f); // Create script command
}
Note: the main routine will not be called if a script is supplied on the command line. So the stuff below does not appear if we use this program as an interpreter.
int application::main() {
widget* root = tk->root();
fileselector* f = new fileselector(root, "just_an_example");
f->title("Select a file");
f->dirpath("~"); // cd ~ (
cout << "Wait until file selected." << endl;
const char* filename = f->get();
if (filename)
cout << "You selected file: " << filename << endl;
else
cout << "You canceled fileselection." <<endl;
return OK;
}
int main(int argc, char* argv[]) {
application* a = new application(argc,argv);
int result = a->run();
delete a;
session::statistics();
return result;
}