add tick and on_tick event, fix unsaved document prompt, implement TextInput blinking cursor
This commit is contained in:
@@ -1497,39 +1497,39 @@ void ui::Canvas::export_cubes()
|
||||
#endif
|
||||
}
|
||||
|
||||
void ui::Canvas::project_save(std::function<void()> on_complete)
|
||||
void ui::Canvas::project_save(std::function<void(bool)> on_complete)
|
||||
{
|
||||
if (App::I.check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
project_save_thread(App::I.doc_path);
|
||||
bool ret = project_save_thread(App::I.doc_path);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
on_complete(ret);
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void ui::Canvas::project_save(std::string file_path, std::function<void()> on_complete)
|
||||
void ui::Canvas::project_save(std::string file_path, std::function<void(bool)> on_complete)
|
||||
{
|
||||
if (App::I.check_license())
|
||||
{
|
||||
std::thread t([=] {
|
||||
project_save_thread(file_path);
|
||||
bool ret = project_save_thread(file_path);
|
||||
if (on_complete)
|
||||
on_complete();
|
||||
on_complete(ret);
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void ui::Canvas::project_save_thread(std::string file_path)
|
||||
bool ui::Canvas::project_save_thread(std::string file_path)
|
||||
{
|
||||
gl_state gl;
|
||||
|
||||
// already saved, nothing to do
|
||||
if (!m_unsaved)
|
||||
return;
|
||||
if (!m_unsaved && file_path == App::I.doc_path)
|
||||
return true;
|
||||
|
||||
// static char name[128];
|
||||
// sprintf(name, "%s/latlong.ppi", data_path.c_str());
|
||||
@@ -1549,7 +1549,6 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
if (!(fp = fopen(tmp_path.c_str(), "wb")))
|
||||
{
|
||||
LOG("cannot write tmp project to %s", tmp_path.c_str());
|
||||
//return;
|
||||
use_tmp = false;
|
||||
}
|
||||
}
|
||||
@@ -1560,7 +1559,7 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
if (!(fp = fopen(file_path.c_str(), "wb")))
|
||||
{
|
||||
LOG("cannot write project to %s", file_path.c_str());
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
LOG("unsafe mode saving directly to %s", file_path.c_str());
|
||||
}
|
||||
@@ -1644,6 +1643,7 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
bool success = false;
|
||||
if (use_tmp)
|
||||
{
|
||||
LOG("project saved tmp to %s", tmp_path.c_str());
|
||||
@@ -1652,31 +1652,40 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
{
|
||||
if (std::rename(tmp_path.c_str(), file_path.c_str()) == 0)
|
||||
{
|
||||
success = true;
|
||||
LOG("tmp file swapped succesfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
LOG("tmp file NOT swapped, original removed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
LOG("could not remove %s", file_path.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = true;
|
||||
LOG("project saved to %s", file_path.c_str());
|
||||
}
|
||||
|
||||
m_unsaved = false;
|
||||
m_newdoc = false;
|
||||
if (success)
|
||||
{
|
||||
m_unsaved = false;
|
||||
m_newdoc = false;
|
||||
}
|
||||
|
||||
App::I.async_start();
|
||||
pb->destroy();
|
||||
App::I.title_update();
|
||||
App::I.async_update();
|
||||
App::I.async_end();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void ui::Canvas::project_open(std::string file_path, std::function<void(bool)> on_complete)
|
||||
|
||||
Reference in New Issue
Block a user