Skip to content

Commit

Permalink
fix #1252
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Apr 16, 2024
1 parent cd5b53a commit f29aa4e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 27 deletions.
1 change: 1 addition & 0 deletions core/Services/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ public class Services.Database : GLib.Object {
} else {
warning ("Error: %d: %s", db.errcode (), db.errmsg ());
}

stmt.reset ();
}

Expand Down
1 change: 1 addition & 0 deletions core/Services/EventBus.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Services.EventBus : Object {
public signal void project_picker_changed (string id);
public signal void section_picker_changed (string id);
public signal void project_parent_changed (Objects.Project project, string old_parent_id, bool collapsed = false);
public signal void update_inserted_project_map (Gtk.Widget row, string old_parent_id);
public signal void checked_toggled (Objects.Item item, bool old_checked);
public signal void favorite_toggled (Objects.Project project);
public signal void item_moved (Objects.Item item, string old_project_id, string old_section_id, string old_parent_id = "");
Expand Down
36 changes: 25 additions & 11 deletions src/Layouts/ProjectRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,33 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
add_subproject (subproject);
});

Services.EventBus.get_default ().project_parent_changed.connect ((subproject, old_parent_id, collapsed) => {
Services.EventBus.get_default ().project_parent_changed.connect ((_project, old_parent_id, collapsed) => {
if (old_parent_id == project.id) {
if (subprojects_hashmap.has_key (subproject.id_string)) {
subprojects_hashmap [subproject.id_string].hide_destroy ();
subprojects_hashmap.unset (subproject.id_string);
if (subprojects_hashmap.has_key (_project.id)) {
subprojects_hashmap [_project.id].hide_destroy ();
subprojects_hashmap.unset (_project.id);
}
}

if (subproject.parent_id == project.id) {
add_subproject (subproject);
if (_project.parent_id == project.id) {
add_subproject (_project);

if (collapsed) {
project.collapsed = true;
arrow_button.add_css_class ("opened");
}
}
});

Services.EventBus.get_default ().update_inserted_project_map.connect ((_row, old_parent_id) => {
var row = (Layouts.ProjectRow) _row;

if (old_parent_id == project.id) {
if (subprojects_hashmap.has_key (row.project.id)) {
subprojects_hashmap.unset (row.project.id);
}
}
});
}

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

var source_list = (Gtk.ListBox) picked_widget.parent;
var target_list = (Gtk.ListBox) target_widget.parent;

string old_parent_id = picked_project.parent_id;

if (picked_project.parent_id != target_project.parent_id) {
picked_project.parent_id = target_project.parent_id;
Expand All @@ -384,10 +396,12 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
Services.Todoist.get_default ().move_project_section.begin (picked_project, target_project.parent_id, (obj, res) => {
if (Services.Todoist.get_default ().move_project_section.end (res).status) {
Services.Database.get_default ().update_project (picked_project);
Services.EventBus.get_default ().update_inserted_project_map (picked_widget, old_parent_id);
}
});
} else if (picked_project.backend_type == BackendType.LOCAL) {
} else {
Services.Database.get_default ().update_project (picked_project);
Services.EventBus.get_default ().update_inserted_project_map (picked_widget, old_parent_id);
}
}

Expand Down Expand Up @@ -493,7 +507,7 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
Services.EventBus.get_default ().project_parent_changed (picked_project, old_parent_id, true);
}
});
} else if (picked_project.backend_type == BackendType.LOCAL) {
} else {
Services.Database.get_default ().update_project (picked_project);
Services.EventBus.get_default ().project_parent_changed (picked_project, old_parent_id, true);
}
Expand Down Expand Up @@ -778,9 +792,9 @@ public class Layouts.ProjectRow : Gtk.ListBoxRow {
}

public void add_subproject (Objects.Project project) {
if (!subprojects_hashmap.has_key (project.id_string) && show_subprojects) {
subprojects_hashmap [project.id_string] = new Layouts.ProjectRow (project);
listbox.append (subprojects_hashmap [project.id_string]);
if (!subprojects_hashmap.has_key (project.id) && show_subprojects) {
subprojects_hashmap [project.id] = new Layouts.ProjectRow (project);
listbox.append (subprojects_hashmap [project.id]);
}
}
}
69 changes: 54 additions & 15 deletions src/Layouts/Sidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class Layouts.Sidebar : Adw.Bin {

public Gee.HashMap <string, Layouts.ProjectRow> local_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
public Gee.HashMap <string, Layouts.ProjectRow> todoist_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
public Gee.HashMap <string, Layouts.ProjectRow> google_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
public Gee.HashMap <string, Layouts.ProjectRow> caldav_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();
public Gee.HashMap <string, Layouts.ProjectRow> favorites_hashmap = new Gee.HashMap <string, Layouts.ProjectRow> ();

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

Services.EventBus.get_default ().project_parent_changed.connect ((project, old_parent_id) => {
print ("project: %s\n".printf (project.name));
print ("project parent id: %s\n".printf (project.parent.name));
print ("old_parent_id: %s\n".printf (old_parent_id));

if (old_parent_id == "") {
if (local_hashmap.has_key (project.id_string)) {
local_hashmap [project.id_string].hide_destroy ();
local_hashmap.unset (project.id_string);
if (local_hashmap.has_key (project.id)) {
local_hashmap [project.id].hide_destroy ();
local_hashmap.unset (project.id);

print ("Elimina sub project\n");
}

if (todoist_hashmap.has_key (project.id_string)) {
todoist_hashmap [project.id_string].hide_destroy ();
todoist_hashmap.unset (project.id_string);
if (todoist_hashmap.has_key (project.id)) {
todoist_hashmap [project.id].hide_destroy ();
todoist_hashmap.unset (project.id);
}

if (caldav_hashmap.has_key (project.id)) {
caldav_hashmap [project.id].hide_destroy ();
caldav_hashmap.unset (project.id);
}
}

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

Services.EventBus.get_default ().update_inserted_project_map.connect ((_row, old_parent_id) => {
var row = (Layouts.ProjectRow) _row;

if (old_parent_id == "") {
if (local_hashmap.has_key (row.project.id)) {
local_hashmap.unset (row.project.id);
}

if (todoist_hashmap.has_key (row.project.id)) {
todoist_hashmap.unset (row.project.id);
}

if (caldav_hashmap.has_key (row.project.id)) {
caldav_hashmap.unset (row.project.id);
}
}

if (!row.project.is_inbox_project && row.project.parent_id == "") {
if (row.project.backend_type == BackendType.TODOIST) {
if (!todoist_hashmap.has_key (row.project.id)) {
todoist_hashmap[row.project.id] = row;
}
} else if (row.project.backend_type == BackendType.LOCAL) {
if (!local_hashmap.has_key (row.project.id)) {
local_hashmap[row.project.id] = row;
}
} else if (row.project.backend_type == BackendType.CALDAV) {
if (!caldav_hashmap.has_key (row.project.id)) {
caldav_hashmap[row.project.id] = row;
}
}
}
});

Services.EventBus.get_default ().favorite_toggled.connect ((project) => {
if (favorites_hashmap.has_key (project.id_string)) {
favorites_hashmap [project.id_string].hide_destroy ();
favorites_hashmap.unset (project.id_string);
if (favorites_hashmap.has_key (project.id)) {
favorites_hashmap [project.id].hide_destroy ();
favorites_hashmap.unset (project.id);
} else {
add_row_favorite (project);
}
Expand Down Expand Up @@ -462,11 +506,6 @@ public class Layouts.Sidebar : Adw.Bin {
todoist_hashmap [project.id_string] = new Layouts.ProjectRow (project);
todoist_projects_header.add_child (todoist_hashmap [project.id_string]);
}
} else if (project.backend_type == BackendType.GOOGLE_TASKS) {
if (!google_hashmap.has_key (project.id_string)) {
google_hashmap [project.id_string] = new Layouts.ProjectRow (project);
google_projects_header.add_child (google_hashmap [project.id_string]);
}
} else if (project.backend_type == BackendType.LOCAL) {
if (!local_hashmap.has_key (project.id_string)) {
local_hashmap [project.id_string] = new Layouts.ProjectRow (project);
Expand Down
3 changes: 2 additions & 1 deletion src/Widgets/SubItems.vala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public class Widgets.SubItems : Adw.Bin {
};

var sub_tasks_header = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
margin_start = 9
margin_start = 9,
margin_end = 9
};
sub_tasks_header.append (sub_tasks_title);
sub_tasks_header.append (add_button);
Expand Down

0 comments on commit f29aa4e

Please sign in to comment.