Skip to content

Commit f29aa4e

Browse files
committed
fix #1252
1 parent cd5b53a commit f29aa4e

File tree

5 files changed

+83
-27
lines changed

5 files changed

+83
-27
lines changed

core/Services/Database.vala

+1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ public class Services.Database : GLib.Object {
694694
} else {
695695
warning ("Error: %d: %s", db.errcode (), db.errmsg ());
696696
}
697+
697698
stmt.reset ();
698699
}
699700

core/Services/EventBus.vala

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class Services.EventBus : Object {
4545
public signal void project_picker_changed (string id);
4646
public signal void section_picker_changed (string id);
4747
public signal void project_parent_changed (Objects.Project project, string old_parent_id, bool collapsed = false);
48+
public signal void update_inserted_project_map (Gtk.Widget row, string old_parent_id);
4849
public signal void checked_toggled (Objects.Item item, bool old_checked);
4950
public signal void favorite_toggled (Objects.Project project);
5051
public signal void item_moved (Objects.Item item, string old_project_id, string old_section_id, string old_parent_id = "");

src/Layouts/ProjectRow.vala

+25-11
Original file line numberDiff line numberDiff line change
@@ -309,23 +309,33 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
309309
add_subproject (subproject);
310310
});
311311

312-
Services.EventBus.get_default ().project_parent_changed.connect ((subproject, old_parent_id, collapsed) => {
312+
Services.EventBus.get_default ().project_parent_changed.connect ((_project, old_parent_id, collapsed) => {
313313
if (old_parent_id == project.id) {
314-
if (subprojects_hashmap.has_key (subproject.id_string)) {
315-
subprojects_hashmap [subproject.id_string].hide_destroy ();
316-
subprojects_hashmap.unset (subproject.id_string);
314+
if (subprojects_hashmap.has_key (_project.id)) {
315+
subprojects_hashmap [_project.id].hide_destroy ();
316+
subprojects_hashmap.unset (_project.id);
317317
}
318318
}
319319

320-
if (subproject.parent_id == project.id) {
321-
add_subproject (subproject);
320+
if (_project.parent_id == project.id) {
321+
add_subproject (_project);
322322

323323
if (collapsed) {
324324
project.collapsed = true;
325325
arrow_button.add_css_class ("opened");
326326
}
327327
}
328328
});
329+
330+
Services.EventBus.get_default ().update_inserted_project_map.connect ((_row, old_parent_id) => {
331+
var row = (Layouts.ProjectRow) _row;
332+
333+
if (old_parent_id == project.id) {
334+
if (subprojects_hashmap.has_key (row.project.id)) {
335+
subprojects_hashmap.unset (row.project.id);
336+
}
337+
}
338+
});
329339
}
330340

331341
private void update_count_label (int count) {
@@ -376,6 +386,8 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
376386

377387
var source_list = (Gtk.ListBox) picked_widget.parent;
378388
var target_list = (Gtk.ListBox) target_widget.parent;
389+
390+
string old_parent_id = picked_project.parent_id;
379391

380392
if (picked_project.parent_id != target_project.parent_id) {
381393
picked_project.parent_id = target_project.parent_id;
@@ -384,10 +396,12 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
384396
Services.Todoist.get_default ().move_project_section.begin (picked_project, target_project.parent_id, (obj, res) => {
385397
if (Services.Todoist.get_default ().move_project_section.end (res).status) {
386398
Services.Database.get_default ().update_project (picked_project);
399+
Services.EventBus.get_default ().update_inserted_project_map (picked_widget, old_parent_id);
387400
}
388401
});
389-
} else if (picked_project.backend_type == BackendType.LOCAL) {
402+
} else {
390403
Services.Database.get_default ().update_project (picked_project);
404+
Services.EventBus.get_default ().update_inserted_project_map (picked_widget, old_parent_id);
391405
}
392406
}
393407

@@ -493,7 +507,7 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
493507
Services.EventBus.get_default ().project_parent_changed (picked_project, old_parent_id, true);
494508
}
495509
});
496-
} else if (picked_project.backend_type == BackendType.LOCAL) {
510+
} else {
497511
Services.Database.get_default ().update_project (picked_project);
498512
Services.EventBus.get_default ().project_parent_changed (picked_project, old_parent_id, true);
499513
}
@@ -778,9 +792,9 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
778792
}
779793

780794
public void add_subproject (Objects.Project project) {
781-
if (!subprojects_hashmap.has_key (project.id_string) && show_subprojects) {
782-
subprojects_hashmap [project.id_string] = new Layouts.ProjectRow (project);
783-
listbox.append (subprojects_hashmap [project.id_string]);
795+
if (!subprojects_hashmap.has_key (project.id) && show_subprojects) {
796+
subprojects_hashmap [project.id] = new Layouts.ProjectRow (project);
797+
listbox.append (subprojects_hashmap [project.id]);
784798
}
785799
}
786800
}

src/Layouts/Sidebar.vala

+54-15
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class Layouts.Sidebar : Adw.Bin {
3737

3838
public Gee.HashMap <string, Layouts.ProjectRow> local_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
3939
public Gee.HashMap <string, Layouts.ProjectRow> todoist_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
40-
public Gee.HashMap <string, Layouts.ProjectRow> google_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
4140
public Gee.HashMap <string, Layouts.ProjectRow> caldav_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
4241
public Gee.HashMap <string, Layouts.ProjectRow> favorites_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
4342

@@ -387,15 +386,26 @@ public class Layouts.Sidebar : Adw.Bin {
387386
Services.Database.get_default ().project_updated.connect (update_projects_sort);
388387

389388
Services.EventBus.get_default ().project_parent_changed.connect ((project, old_parent_id) => {
389+
print ("project: %s\n".printf (project.name));
390+
print ("project parent id: %s\n".printf (project.parent.name));
391+
print ("old_parent_id: %s\n".printf (old_parent_id));
392+
390393
if (old_parent_id == "") {
391-
if (local_hashmap.has_key (project.id_string)) {
392-
local_hashmap [project.id_string].hide_destroy ();
393-
local_hashmap.unset (project.id_string);
394+
if (local_hashmap.has_key (project.id)) {
395+
local_hashmap [project.id].hide_destroy ();
396+
local_hashmap.unset (project.id);
397+
398+
print ("Elimina sub project\n");
394399
}
395400

396-
if (todoist_hashmap.has_key (project.id_string)) {
397-
todoist_hashmap [project.id_string].hide_destroy ();
398-
todoist_hashmap.unset (project.id_string);
401+
if (todoist_hashmap.has_key (project.id)) {
402+
todoist_hashmap [project.id].hide_destroy ();
403+
todoist_hashmap.unset (project.id);
404+
}
405+
406+
if (caldav_hashmap.has_key (project.id)) {
407+
caldav_hashmap [project.id].hide_destroy ();
408+
caldav_hashmap.unset (project.id);
399409
}
400410
}
401411

@@ -404,10 +414,44 @@ public class Layouts.Sidebar : Adw.Bin {
404414
}
405415
});
406416

417+
Services.EventBus.get_default ().update_inserted_project_map.connect ((_row, old_parent_id) => {
418+
var row = (Layouts.ProjectRow) _row;
419+
420+
if (old_parent_id == "") {
421+
if (local_hashmap.has_key (row.project.id)) {
422+
local_hashmap.unset (row.project.id);
423+
}
424+
425+
if (todoist_hashmap.has_key (row.project.id)) {
426+
todoist_hashmap.unset (row.project.id);
427+
}
428+
429+
if (caldav_hashmap.has_key (row.project.id)) {
430+
caldav_hashmap.unset (row.project.id);
431+
}
432+
}
433+
434+
if (!row.project.is_inbox_project && row.project.parent_id == "") {
435+
if (row.project.backend_type == BackendType.TODOIST) {
436+
if (!todoist_hashmap.has_key (row.project.id)) {
437+
todoist_hashmap[row.project.id] = row;
438+
}
439+
} else if (row.project.backend_type == BackendType.LOCAL) {
440+
if (!local_hashmap.has_key (row.project.id)) {
441+
local_hashmap[row.project.id] = row;
442+
}
443+
} else if (row.project.backend_type == BackendType.CALDAV) {
444+
if (!caldav_hashmap.has_key (row.project.id)) {
445+
caldav_hashmap[row.project.id] = row;
446+
}
447+
}
448+
}
449+
});
450+
407451
Services.EventBus.get_default ().favorite_toggled.connect ((project) => {
408-
if (favorites_hashmap.has_key (project.id_string)) {
409-
favorites_hashmap [project.id_string].hide_destroy ();
410-
favorites_hashmap.unset (project.id_string);
452+
if (favorites_hashmap.has_key (project.id)) {
453+
favorites_hashmap [project.id].hide_destroy ();
454+
favorites_hashmap.unset (project.id);
411455
} else {
412456
add_row_favorite (project);
413457
}
@@ -462,11 +506,6 @@ public class Layouts.Sidebar : Adw.Bin {
462506
todoist_hashmap [project.id_string] = new Layouts.ProjectRow (project);
463507
todoist_projects_header.add_child (todoist_hashmap [project.id_string]);
464508
}
465-
} else if (project.backend_type == BackendType.GOOGLE_TASKS) {
466-
if (!google_hashmap.has_key (project.id_string)) {
467-
google_hashmap [project.id_string] = new Layouts.ProjectRow (project);
468-
google_projects_header.add_child (google_hashmap [project.id_string]);
469-
}
470509
} else if (project.backend_type == BackendType.LOCAL) {
471510
if (!local_hashmap.has_key (project.id_string)) {
472511
local_hashmap [project.id_string] = new Layouts.ProjectRow (project);

src/Widgets/SubItems.vala

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public class Widgets.SubItems : Adw.Bin {
8686
};
8787

8888
var sub_tasks_header = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
89-
margin_start = 9
89+
margin_start = 9,
90+
margin_end = 9
9091
};
9192
sub_tasks_header.append (sub_tasks_title);
9293
sub_tasks_header.append (add_button);

0 commit comments

Comments
 (0)