Added autosave

This commit is contained in:
Patrick Lipka 2021-12-15 13:03:27 +01:00
parent 85fd6e563f
commit 49d3d2f1e1
2 changed files with 8 additions and 3 deletions

View File

@ -87,7 +87,6 @@ void ProjectList::save(std::string file_name){
// exit(1); // exit(1);
} }
of.write((char*) &num_projects, sizeof(int)); of.write((char*) &num_projects, sizeof(int));
std::cout << "Saving: num_projects=" << num_projects << std::endl;
of.write((char*) &active_project_id, sizeof(int)); of.write((char*) &active_project_id, sizeof(int));
for (int i=0; i<num_projects; i++){ for (int i=0; i<num_projects; i++){
size_t len = projects[i].name.length(); size_t len = projects[i].name.length();

View File

@ -210,6 +210,7 @@ void command_start(std::string input, ProjectList *proj_list){
if (str.length() == 0){ if (str.length() == 0){
// start tracking for active task // start tracking for active task
track(proj_list->active_project); track(proj_list->active_project);
command_save(proj_list);
}else{ }else{
// change active task and start tracking // change active task and start tracking
int place_of_slash = str.find("/"); int place_of_slash = str.find("/");
@ -222,10 +223,9 @@ void command_start(std::string input, ProjectList *proj_list){
} }
int id=proj->find_task_id_by_name(trim(underscore_to_space(task_name))); int id=proj->find_task_id_by_name(trim(underscore_to_space(task_name)));
if(id >= 0){ if(id >= 0){
std::cout << "id=" << id << std::endl;
proj->set_active_task(id); proj->set_active_task(id);
std::cout << "now active: "<< proj->active_task->name << std::endl;
track(proj); track(proj);
command_save(proj_list);
}else{ }else{
std::cout << "Task " << underscore_to_space(str) << " does not exist." << std::endl; std::cout << "Task " << underscore_to_space(str) << " does not exist." << std::endl;
} }
@ -287,6 +287,7 @@ void command_rm(std::string input, ProjectList *proj_list){
} }
proj_list->remove_project(id); proj_list->remove_project(id);
std::cout << "Removed project " << underscore_to_space(proj_name) << "." << std::endl; std::cout << "Removed project " << underscore_to_space(proj_name) << "." << std::endl;
command_save(proj_list);
if (proj_list->num_projects > 0) { if (proj_list->num_projects > 0) {
std::cout << "Switched to project " << proj_list->active_project->name << std::endl; std::cout << "Switched to project " << proj_list->active_project->name << std::endl;
@ -321,6 +322,7 @@ void command_rm(std::string input, ProjectList *proj_list){
} }
std::cout << "Removed task " << underscore_to_space(proj->name) << "/" << underscore_to_space(task_name) << std::endl; std::cout << "Removed task " << underscore_to_space(proj->name) << "/" << underscore_to_space(task_name) << std::endl;
command_save(proj_list);
if (proj->num_tasks > 0) { if (proj->num_tasks > 0) {
std::cout << "Switched to task " << underscore_to_space(proj->name) << "/" << underscore_to_space(proj->active_task->name) << std::endl; std::cout << "Switched to task " << underscore_to_space(proj->name) << "/" << underscore_to_space(proj->active_task->name) << std::endl;
} }
@ -455,6 +457,7 @@ void command_at(std::string input, int wtime, ProjectList *proj_list){
// add time to active task // add time to active task
proj_list->active_project->active_task->add_time(wtime); proj_list->active_project->active_task->add_time(wtime);
std::cout << wtime << "s added to task " << proj_list->active_project->name << "/" << proj_list->active_project->active_task->name << std::endl; std::cout << wtime << "s added to task " << proj_list->active_project->name << "/" << proj_list->active_project->active_task->name << std::endl;
command_save(proj_list);
return; return;
}else{ }else{
// add time to task in same project // add time to task in same project
@ -462,6 +465,7 @@ void command_at(std::string input, int wtime, ProjectList *proj_list){
if (id >= 0){ if (id >= 0){
proj_list->active_project->tasks[id].add_time(wtime); proj_list->active_project->tasks[id].add_time(wtime);
std::cout << wtime << "s added to task " << proj_list->active_project->name << "/" << proj_list->active_project->tasks[id].name << std::endl; std::cout << wtime << "s added to task " << proj_list->active_project->name << "/" << proj_list->active_project->tasks[id].name << std::endl;
command_save(proj_list);
return; return;
}else{ }else{
std::cout << "Task " << proj_list->active_project->name << "/" << proj_name << " does not exist." << std::endl; std::cout << "Task " << proj_list->active_project->name << "/" << proj_name << " does not exist." << std::endl;
@ -500,6 +504,7 @@ void command_rt(std::string input, int wtime, ProjectList *proj_list){
if (id >= 0){ if (id >= 0){
proj_list->active_project->tasks[id].add_time(-wtime); proj_list->active_project->tasks[id].add_time(-wtime);
std::cout << wtime << "s removed from task " << proj_list->active_project->name << "/" << proj_list->active_project->tasks[id].name << std::endl; std::cout << wtime << "s removed from task " << proj_list->active_project->name << "/" << proj_list->active_project->tasks[id].name << std::endl;
command_save(proj_list);
return; return;
}else{ }else{
std::cout << "Task " << proj_list->active_project->name << "/" << proj_name << " does not exist." << std::endl; std::cout << "Task " << proj_list->active_project->name << "/" << proj_name << " does not exist." << std::endl;
@ -516,6 +521,7 @@ void command_rt(std::string input, int wtime, ProjectList *proj_list){
if(id >= 0){ if(id >= 0){
proj->tasks[id].add_time(wtime); proj->tasks[id].add_time(wtime);
std::cout << wtime << "s removed from task " << proj->name << "/" << proj->tasks[id].name << std::endl; std::cout << wtime << "s removed from task " << proj->name << "/" << proj->tasks[id].name << std::endl;
command_save(proj_list);
}else{ }else{
std::cout << "Task " << underscore_to_space(input) << " does not exist." << std::endl; std::cout << "Task " << underscore_to_space(input) << " does not exist." << std::endl;
} }