Skip to content

Commit

Permalink
fix #660
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Jul 4, 2024
1 parent 9d0ee97 commit f1f2a2b
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 26 deletions.
31 changes: 31 additions & 0 deletions core/Enum.vala
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,34 @@ public enum ReminderType {
}
}
}

public enum ItemType {
TASK,
NOTE;

public string to_string () {
switch (this) {
case TASK:
return "task";

case NOTE:
return "note";

default:
assert_not_reached ();
}
}

public static ItemType parse (string value) {
switch (value) {
case "task":
return ItemType.TASK;

case "note":
return ItemType.NOTE;

default:
assert_not_reached ();
}
}
}
1 change: 1 addition & 0 deletions core/Objects/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Objects.Item : Objects.BaseObject {
public string project_id { get; set; default = ""; }
public string parent_id { get; set; default = ""; }
public string extra_data { get; set; default = ""; }
public ItemType item_type { get; set; default = ItemType.TASK; }

public Objects.DueDate due { get; set; default = new Objects.DueDate (); }
public Gee.ArrayList<Objects.Label> labels { get; set; default = new Gee.ArrayList<Objects.Label> (); }
Expand Down
19 changes: 15 additions & 4 deletions core/Services/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ public class Services.Database : GLib.Object {
*/

add_text_column ("Projects", "sync_id", "");

/*
* Planify 4.8
* - Add sync_id column to Projects
*/

add_text_column ("Items", "item_type", ItemType.TASK.to_string ());
}

private void create_tables () {
Expand Down Expand Up @@ -318,7 +325,8 @@ public class Services.Database : GLib.Object {
collapsed INTEGER,
pinned INTEGER,
labels TEXT,
extra_data TEXT
extra_data TEXT,
item_type TEXT
);
""";

Expand Down Expand Up @@ -1265,10 +1273,10 @@ public class Services.Database : GLib.Object {
sql = """
INSERT OR IGNORE INTO Items (id, content, description, due, added_at, completed_at,
updated_at, section_id, project_id, parent_id, priority, child_order,
checked, is_deleted, day_order, collapsed, pinned, labels, extra_data)
checked, is_deleted, day_order, collapsed, pinned, labels, extra_data, item_type)
VALUES ($id, $content, $description, $due, $added_at, $completed_at,
$updated_at, $section_id, $project_id, $parent_id, $priority, $child_order,
$checked, $is_deleted, $day_order, $collapsed, $pinned, $labels, $extra_data);
$checked, $is_deleted, $day_order, $collapsed, $pinned, $labels, $extra_data, $item_type);
""";

db.prepare_v2 (sql, sql.length, out stmt);
Expand All @@ -1291,6 +1299,7 @@ public class Services.Database : GLib.Object {
set_parameter_bool (stmt, "$pinned", item.pinned);
set_parameter_str (stmt, "$labels", get_labels_ids (item.labels));
set_parameter_str (stmt, "$extra_data", item.extra_data);
set_parameter_str (stmt, "$item_type", item.item_type.to_string ());

if (stmt.step () == Sqlite.DONE) {
add_item (item, insert);
Expand Down Expand Up @@ -1480,6 +1489,7 @@ public class Services.Database : GLib.Object {
return_value.pinned = get_parameter_bool (stmt, 16);
return_value.labels = get_labels_by_item_labels (stmt.column_text (17));
return_value.extra_data = stmt.column_text (18);
return_value.item_type = ItemType.parse (stmt.column_text (19));

return return_value;
}
Expand Down Expand Up @@ -1737,7 +1747,7 @@ public class Services.Database : GLib.Object {
section_id=$section_id, project_id=$project_id, parent_id=$parent_id,
priority=$priority, child_order=$child_order, checked=$checked,
is_deleted=$is_deleted, day_order=$day_order, collapsed=$collapsed,
pinned=$pinned, labels=$labels, extra_data=$extra_data
pinned=$pinned, labels=$labels, extra_data=$extra_data, item_type=$item_type
WHERE id=$id;
""";

Expand All @@ -1760,6 +1770,7 @@ public class Services.Database : GLib.Object {
set_parameter_bool (stmt, "$pinned", item.pinned);
set_parameter_str (stmt, "$labels", get_labels_ids (item.labels));
set_parameter_str (stmt, "$extra_data", item.extra_data);
set_parameter_str (stmt, "$item_type", item.item_type.to_string ());
set_parameter_str (stmt, "$id", item.id);

if (stmt.step () == Sqlite.DONE) {
Expand Down
23 changes: 12 additions & 11 deletions src/Layouts/ItemBoard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class Layouts.ItemBoard : Layouts.ItemBase {
private Gtk.Revealer motion_top_revealer;

private Gtk.CheckButton checked_button;
private Gtk.Revealer checked_button_revealer;
private Gtk.Label content_label;

private Widgets.LoadingButton hide_loading_button;
Expand Down Expand Up @@ -103,13 +102,6 @@ public class Layouts.ItemBoard : Layouts.ItemBase {
css_classes = { "priority-color" }
};

checked_button_revealer = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.CROSSFADE,
child = checked_button,
valign = Gtk.Align.START,
reveal_child = true
};

content_label = new Gtk.Label (item.content) {
wrap = true,
hexpand = true,
Expand Down Expand Up @@ -152,7 +144,7 @@ public class Layouts.ItemBoard : Layouts.ItemBase {
margin_end = 6
};

content_box.append (checked_button_revealer);
content_box.append (checked_button);
content_box.append (content_label);
content_box.append (select_revealer);

Expand Down Expand Up @@ -400,10 +392,10 @@ public class Layouts.ItemBoard : Layouts.ItemBase {
Services.EventBus.get_default ().show_multi_select.connect ((active) => {
if (active) {
select_revealer.reveal_child = true;
checked_button_revealer.reveal_child = false;
checked_button.sensitive = false;
} else {
select_revealer.reveal_child = false;
checked_button_revealer.reveal_child = true;
checked_button.sensitive = true;
select_checkbutton.active = false;
}
});
Expand Down Expand Up @@ -537,6 +529,15 @@ public class Layouts.ItemBoard : Layouts.ItemBase {
content_label.label = item.content;
content_label.tooltip_text = item.content.strip ();

// ItemType
if (item.item_type == ItemType.TASK) {
checked_button.sensitive = true;
checked_button.opacity = 1;
} else {
checked_button.sensitive = false;
checked_button.opacity = 0;
}

description_label.label = Util.get_default ().line_break_to_space (item.description);
description_label.tooltip_text = item.description.strip ();
description_revealer.reveal_child = description_label.label.length > 0;
Expand Down
33 changes: 22 additions & 11 deletions src/Layouts/ItemRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class Layouts.ItemRow : Layouts.ItemBase {
private Gtk.Revealer motion_top_revealer;

private Gtk.CheckButton checked_button;
private Gtk.Revealer checked_button_revealer;
private Widgets.TextView content_textview;
private Gtk.Revealer hide_loading_revealer;
private Gtk.Revealer project_label_revealer;
Expand Down Expand Up @@ -227,13 +226,6 @@ public class Layouts.ItemRow : Layouts.ItemBase {
sensitive = !item.project.is_deck
};

checked_button_revealer = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.SWING_RIGHT,
child = checked_button,
valign = Gtk.Align.CENTER,
reveal_child = true
};

content_label = new Gtk.Label (null) {
hexpand = true,
xalign = 0,
Expand Down Expand Up @@ -388,7 +380,7 @@ public class Layouts.ItemRow : Layouts.ItemBase {
};

var content_main_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
content_main_box.append (checked_button_revealer);
content_main_box.append (checked_button);
content_main_box.append (due_box_revealer);
content_main_box.append (content_box);
content_main_box.append (hide_loading_revealer);
Expand Down Expand Up @@ -704,12 +696,12 @@ public class Layouts.ItemRow : Layouts.ItemBase {
Services.EventBus.get_default ().show_multi_select.connect ((active) => {
if (active) {
select_revealer.reveal_child = true;
checked_button_revealer.reveal_child = false;
checked_button.sensitive = false;
labels_summary.reveal_child = false;
disable_drag_and_drop ();
} else {
select_revealer.reveal_child = false;
checked_button_revealer.reveal_child = true;
checked_button.sensitive = true;

if (!edit) {
labels_summary.check_revealer ();
Expand Down Expand Up @@ -831,6 +823,15 @@ public class Layouts.ItemRow : Layouts.ItemBase {
content_label.tooltip_text = item.content;
content_textview.buffer.text = item.content;

// ItemType
if (item.item_type == ItemType.TASK) {
checked_button.sensitive = true;
checked_button.opacity = 1;
} else {
checked_button.sensitive = false;
checked_button.opacity = 0;
}

// Update Description
if (description_handler_change_id != 0) {
current_buffer.disconnect (description_handler_change_id);
Expand Down Expand Up @@ -1123,6 +1124,9 @@ public class Layouts.ItemRow : Layouts.ItemBase {
private Gtk.Popover build_button_context_menu () {
var back_item = new Widgets.ContextMenu.MenuItem (_("Back"), "go-previous-symbolic");

var use_note_item = new Widgets.ContextMenu.MenuSwitch (_("Use as a Note"), "paper-symbolic");
use_note_item.active = item.item_type == ItemType.NOTE;

var copy_clipboard_item = new Widgets.ContextMenu.MenuItem (_("Copy to Clipboard"), "clipboard-symbolic");
var duplicate_item = new Widgets.ContextMenu.MenuItem (_("Duplicate"), "tabs-stack-symbolic");
var move_item = new Widgets.ContextMenu.MenuItem (_("Move"), "arrow3-right-symbolic");
Expand All @@ -1145,6 +1149,8 @@ public class Layouts.ItemRow : Layouts.ItemBase {
menu_box.margin_top = menu_box.margin_bottom = 3;

if (!item.completed) {
menu_box.append (use_note_item);
menu_box.append (new Widgets.ContextMenu.MenuSeparator ());
menu_box.append (copy_clipboard_item);
menu_box.append (duplicate_item);
menu_box.append (move_item);
Expand All @@ -1167,6 +1173,11 @@ public class Layouts.ItemRow : Layouts.ItemBase {

popover.child = menu_stack;

use_note_item.activate_item.connect (() => {
item.item_type = use_note_item.active ? ItemType.NOTE : ItemType.TASK;
item.update_local ();
});

copy_clipboard_item.clicked.connect (() => {
popover.popdown ();
item.copy_clipboard ();
Expand Down
10 changes: 10 additions & 0 deletions src/Layouts/ItemSidebarView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ public class Layouts.ItemSidebarView : Adw.Bin {
private Gtk.Popover build_context_menu () {
var back_item = new Widgets.ContextMenu.MenuItem (_("Back"), "go-previous-symbolic");

var use_note_item = new Widgets.ContextMenu.MenuSwitch (_("Use as a Note"), "paper-symbolic");
use_note_item.active = item.item_type == ItemType.NOTE;

copy_clipboard_item = new Widgets.ContextMenu.MenuItem (_("Copy to Clipboard"), "clipboard-symbolic");
duplicate_item = new Widgets.ContextMenu.MenuItem (_("Duplicate"), "tabs-stack-symbolic");
move_item = new Widgets.ContextMenu.MenuItem (_("Move"), "arrow3-right-symbolic");
Expand All @@ -473,6 +476,8 @@ public class Layouts.ItemSidebarView : Adw.Bin {
menu_box.margin_top = menu_box.margin_bottom = 3;

if (!item.completed) {
menu_box.append (use_note_item);
menu_box.append (new Widgets.ContextMenu.MenuSeparator ());
menu_box.append (copy_clipboard_item);
menu_box.append (duplicate_item);
menu_box.append (move_item);
Expand All @@ -495,6 +500,11 @@ public class Layouts.ItemSidebarView : Adw.Bin {

popover.child = menu_stack;

use_note_item.activate_item.connect (() => {
item.item_type = use_note_item.active ? ItemType.NOTE : ItemType.TASK;
item.update_local ();
});

copy_clipboard_item.clicked.connect (() => {
popover.popdown ();
item.copy_clipboard ();
Expand Down

0 comments on commit f1f2a2b

Please sign in to comment.