#include <xtd/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/message_box>
#include <xtd/forms/save_file_dialog>
#include <xtd/forms/text_box>
#include <xtd/io/stream_writer>
#include <xtd/timers/timer>
#include <xtd/date_time>
#include <xtd/startup>
#include <memory>
namespace timer_example {
class form1 :
public form {
public:
static void main() {
application::run(form1 {});
}
form1() {
initialize_component();
text("Quick Text Editor");
button1.text("Save");
text_box1.multiline(true);
save_file_dialog1.filter("txt files (*.txt)|*.txt|All files (*.*)|*.*");
save_file_dialog1.restore_directory(true);
timer.elapsed += {*
this, &form1::prompt_for_save};
timer.synchronizing_object(*
this);
}
private:
void initialize_component() {
form_closing += {*this, &form1::form1_form_closing};
controls().push_back_range({text_box1, button1});
button1.dock(dock_style::bottom);
button1.click += {*this, &form1::button1_click};
text_box1.dock(dock_style::fill);
text_box1.text_changed += {*this, &form1::text_box1__text_changed};
}
if (has_changed && !dialog_is_open) {
elapsed_minutes++;
dialog_is_open = true;
if (message_box::show(string::format("{0} minutes have elapsed since the text was saved. Save it now? ",
elapsed_minutes), "Save Text",
message_box_buttons::yes_no_cancel, message_box_icon::question) == dialog_result::yes)
button1_click(*this, event_args::empty);
}
dialog_is_open = false;
}
void button1_click(
object& sender,
const event_args& e) {
if (string::is_empty(save_file_dialog1.file_name())) {
if (save_file_dialog1.show_dialog() == dialog_result::ok)
sw = new_ptr<stream_writer>(save_file_dialog1.file_name(), false);
}
txt = text_box1.text();
has_changed = false;
}
if (sw != null) {
sw->write(txt);
sw->close();
}
}
void text_box1__text_changed(
object& sender,
const event_args& e) {
has_changed = true;
}
bool dialog_is_open = false;
int elapsed_minutes = 0;
bool has_changed = false;
string txt;
};
}
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.h:18
Represents a standard Windows text box.
Definition text_box.h:31
Provides data for the xtd::timers::timer::elapsed event.
Definition elapsed_event_args.h:18
Generates an event after a set interval, with an option to generate recurring events.
Definition timer.h:50
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.h:27
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.h:16
Provides the xtd::timers::timer component, which allows you to raise an event on a specified interval...
Definition elapsed_event_args.h:11
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10