#include <nana/gui.hpp>
#include <nana/gui/widgets/menubar.hpp>
#include <nana/gui/widgets/textbox.hpp>
#include <nana/gui/place.hpp>
#include <nana/gui/msgbox.hpp>
#include <nana/gui/filebox.hpp>
#include <thread>
#include <iostream>
using namespace nana;
class notepad_form :
public form
{
public:
notepad_form()
{
caption("Simple Notepad - Nana C++ Library");
textbox_.borderless(true);
textbox_.enable_dropfiles(true);
textbox_.events().mouse_dropfiles([
this](
const arg_dropfiles& arg)
{
});
_m_make_menus();
place_.div("vert<menubar weight=28><textbox>");
place_["menubar"] << menubar_;
place_["textbox"] << textbox_;
place_.collocate();
if (!_m_ask_save())
});
}
textbox& get_tb(){
return textbox_;}
private:
std::filesystem::path _m_pick_file(bool is_open) const
{
auto files = fbox.
show();
return (files.empty() ? std::filesystem::path{} : files.front());
}
bool _m_ask_save()
{
if (textbox_.edited())
{
auto fs = textbox_.filename();
msgbox box(*
this,
"Simple Notepad", msgbox::button_t::yes_no_cancel);
box << "Do you want to save these changes?";
{
if (fs.empty())
{
fs = _m_pick_file(false);
if (fs.empty())
break;
if (fs.extension().string() != ".txt")
fs = fs.extension().string() + ".txt";
}
textbox_.store(fs);
break;
break;
return false;
}
}
return true;
}
void _m_make_menus()
{
menubar_.push_back("&FILE");
{
if(_m_ask_save())
textbox_.reset();
});
{
if (_m_ask_save())
{
auto fs = _m_pick_file(true);
if (!fs.empty())
textbox_.load(fs);
}
});
{
auto fs = textbox_.filename();
if (fs.empty())
{
fs = _m_pick_file(false);
if (fs.empty())
return;
}
textbox_.store(fs);
});
menubar_.push_back("F&ORMAT");
{
textbox_.line_wrapped(ip.
checked());
});
}
};
void Wait(unsigned wait=0)
{
if (wait)
}
int main()
{
notepad_form npform;
npform.show();
#ifdef NANA_AUTOMATIC_GUI_TESTING
1,1, [&npform]()
{
}
#endif
);
}