From 08cdd6d36428f212b2538f03f335a74b6b1deb3a Mon Sep 17 00:00:00 2001 From: Iyaan Azeez Date: Sun, 14 Nov 2021 23:25:27 +0500 Subject: [PATCH 1/7] Added limit to editable characters --- src/Widgets/TaskView.vala | 13 ++++++++++++- src/Window.vala | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Widgets/TaskView.vala b/src/Widgets/TaskView.vala index c543fd1..67f89c8 100644 --- a/src/Widgets/TaskView.vala +++ b/src/Widgets/TaskView.vala @@ -21,6 +21,7 @@ namespace Agenda { + public class TaskView : Gtk.TreeView { private TaskList task_list; @@ -58,6 +59,8 @@ namespace Agenda { text.ypad = 6; text.editable = true; text.max_width_chars = 10; + text.wrap_width = 50; + text.wrap_mode = Pango.WrapMode.WORD_CHAR; text.ellipsize_set = true; text.ellipsize = Pango.EllipsizeMode.END; @@ -82,6 +85,7 @@ namespace Agenda { set_tooltip_column (TaskList.Columns.TEXT); text.editing_started.connect ( (editable, path) => { + debug ("Editing started"); is_editing = true; }); @@ -144,10 +148,17 @@ namespace Agenda { private void text_edited (string path, string edited_text) { /* If the user accidentally blanks a task, abort the edit */ + + debug ("String: %s length: %d", edited_text, edited_text.length); if (task_is_empty (edited_text)) { return; } - task_list.set_task_text (path, edited_text); + if (edited_text.length > EDITED_TEXT_MAX_LEN) { + string new_cut_text = edited_text.slice(0, EDITED_TEXT_MAX_LEN); + task_list.set_task_text (path, new_cut_text); + } else { + task_list.set_task_text (path, edited_text); + } is_editing = false; } } diff --git a/src/Window.vala b/src/Window.vala index 8dfcb0f..0afb084 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -23,6 +23,8 @@ namespace Agenda { const int MIN_WIDTH = 500; const int MIN_HEIGHT = 600; + // Limit for any edited text + const int EDITED_TEXT_MAX_LEN = 10; const string HINT_STRING = _("Add a new task…"); @@ -134,7 +136,7 @@ namespace Agenda { task_entry.name = "TaskEntry"; task_entry.get_style_context ().add_class ("task-entry"); task_entry.placeholder_text = HINT_STRING; - task_entry.max_length = 64; + task_entry.max_length = EDITED_TEXT_MAX_LEN; task_entry.hexpand = true; task_entry.valign = Gtk.Align.START; task_entry.set_icon_tooltip_text ( From 22d6fd81d5b7ef0375668c7456a68acc6d07e43d Mon Sep 17 00:00:00 2001 From: Iyaan Azeez Date: Sun, 14 Nov 2021 23:33:50 +0500 Subject: [PATCH 2/7] Changed EDITED_TEXT_MAX_LEN value --- src/Window.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Window.vala b/src/Window.vala index 0afb084..a7e5a34 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -24,7 +24,7 @@ namespace Agenda { const int MIN_WIDTH = 500; const int MIN_HEIGHT = 600; // Limit for any edited text - const int EDITED_TEXT_MAX_LEN = 10; + const int EDITED_TEXT_MAX_LEN = 64; const string HINT_STRING = _("Add a new task…"); From 103a29dfc770bed1ca5083599fd794d8d1717012 Mon Sep 17 00:00:00 2001 From: Iyaan Azeez Date: Mon, 15 Nov 2021 09:37:33 +0500 Subject: [PATCH 3/7] Added button to headerbar to remove completed tasks --- src/Window.vala | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Window.vala b/src/Window.vala index 8dfcb0f..f4f20b7 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -69,6 +69,16 @@ namespace Agenda { header.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); this.set_titlebar (header); + var button = new Gtk.Button.from_icon_name ("user-trash-symbolic", Gtk.IconSize.BUTTON); + button.clicked.connect (() => { + // Remove completed tasks + if (task_list != null) { + task_list.remove_completed_tasks(); + } + stdout.printf ("You deleted completed tasks\n"); + }); + header.pack_start(button); + // Set up geometry Gdk.Geometry geo = Gdk.Geometry (); geo.min_width = MIN_WIDTH; From 8c9b7d4475453007a8c7a656c92a8d99ca0e76db Mon Sep 17 00:00:00 2001 From: Iyaan Azeez Date: Mon, 15 Nov 2021 16:14:08 +0500 Subject: [PATCH 4/7] Added sorting to tasks to push completed tasks down the list --- src/Models/TaskList.vala | 24 ++++++++++++++++++++++++ src/Window.vala | 2 ++ 2 files changed, 26 insertions(+) diff --git a/src/Models/TaskList.vala b/src/Models/TaskList.vala index a5a4728..ec5bcaa 100644 --- a/src/Models/TaskList.vala +++ b/src/Models/TaskList.vala @@ -88,6 +88,30 @@ namespace Agenda { list_changed (); } + /* + * Sort the tasks so finished tasks are at bottom + */ + public void sort_tasks () { + Gtk.TreeIter iter; + bool valid = get_iter_first (out iter); + Task[] tasks = {}; + + while (valid) { + Task task = get_task (iter); + if (task.complete) { + tasks += task; + remove (ref iter); + continue; + } + valid = iter_next (ref iter); + } + + int i; + for (i = 0; i < tasks.length; i++) { + append_task (tasks[i]); + } + list_changed (); + } public void clear_undo () { undo_list = new TaskListHistory (); diff --git a/src/Window.vala b/src/Window.vala index 46e89d0..d79b679 100644 --- a/src/Window.vala +++ b/src/Window.vala @@ -241,6 +241,8 @@ namespace Agenda { task_list.append_task (task); history_list.add_item (task.text); + // When adding a new task rearrange the tasks + task_list.sort_tasks (); task_entry.text = ""; } From 0946e5edac02767781a4b2f9b8eab7cbf91fb786 Mon Sep 17 00:00:00 2001 From: Iyaan Azeez Date: Wed, 17 Nov 2021 11:13:05 +0500 Subject: [PATCH 5/7] To merge new changes from upstream --- app/TaskListBoxRow.vala | 6 ++---- app/Window.vala | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/TaskListBoxRow.vala b/app/TaskListBoxRow.vala index 86c03bb..73fc974 100644 --- a/app/TaskListBoxRow.vala +++ b/app/TaskListBoxRow.vala @@ -17,8 +17,7 @@ You should have received a copy of the GNU General Public License along with Agenda. If not, see . -***/ -namespace Agenda { +***/ namespace Agenda { public class TaskListBoxRow : Gtk.ListBoxRow { @@ -26,8 +25,8 @@ namespace Agenda { public TaskListBoxRow (Task task) { var label = new Gtk.Label.with_mnemonic (task.text); - var check_button = new Gtk.CheckButton (); + check_button.set_active (task.complete); check_button.toggled.connect (() => { @@ -49,7 +48,6 @@ namespace Agenda { grid.add (label); grid.show_all (); - this.add (grid); } } diff --git a/app/Window.vala b/app/Window.vala index 6b8594e..f08561a 100644 --- a/app/Window.vala +++ b/app/Window.vala @@ -59,6 +59,9 @@ namespace Agenda { this.get_style_context ().add_class ("rounded"); this.set_size_request (MIN_WIDTH, MIN_HEIGHT); + // Recive button events + set_events (Gdk.EventMask.BUTTON_PRESS_MASK); + var header = new Gtk.HeaderBar (); header.show_close_button = true; header.get_style_context ().add_class ("titlebar"); From fc326b5c71da9efd4a3985338264cd945cdf7c0d Mon Sep 17 00:00:00 2001 From: Iyaan Azeez Date: Wed, 17 Nov 2021 14:12:56 +0500 Subject: [PATCH 6/7] Can delete tasks from view and added button to delete them --- app/TaskListBox.vala | 5 +++++ app/TaskListBoxRow.vala | 14 +++++++++++--- app/Window.vala | 8 +++++++- lib/ITaskRepository.vala | 2 +- lib/TaskRepositoryFile.vala | 6 ++++-- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/TaskListBox.vala b/app/TaskListBox.vala index f7a776c..87eb6c9 100644 --- a/app/TaskListBox.vala +++ b/app/TaskListBox.vala @@ -24,6 +24,7 @@ namespace Agenda { public class TaskListBox : Gtk.ListBox { public signal void task_changed (int index, Task task); + public signal void task_deleted (int index, Task task); public TaskListBox (TaskRepositoryFile tasks) { this.bind_model (tasks, list_box_create_widget); @@ -38,6 +39,10 @@ namespace Agenda { task_changed (index, task); }); + row.task_deleted.connect ((index, task) => { + task_deleted (index, task); + }); + return row; } } diff --git a/app/TaskListBoxRow.vala b/app/TaskListBoxRow.vala index 3fc9170..1b4817b 100644 --- a/app/TaskListBoxRow.vala +++ b/app/TaskListBoxRow.vala @@ -22,10 +22,9 @@ public class TaskListBoxRow : Gtk.ListBoxRow { public signal void task_changed (int index, Task task); + public signal void task_deleted (int index, Task task); public TaskListBoxRow (Task task) { -<<<<<<< HEAD -======= var label = new Gtk.Label (task.text); var strike_attr = Pango.attr_strikethrough_new (task.complete); @@ -33,7 +32,6 @@ attr_list.insert ((owned) strike_attr); label.set_attributes (attr_list); ->>>>>>> 10ff6871a8769ef3e356b8b5e7a226626b8b9e93 var check_button = new Gtk.CheckButton (); check_button.set_active (task.complete); @@ -48,6 +46,15 @@ label.set_attributes (attr_list); }); + var delete_button = new Gtk.Button.from_icon_name ("edit-delete"); + delete_button.halign = Gtk.Align.END; + delete_button.hexpand = true; + + delete_button.clicked.connect (() => { + var index = this.get_index (); + task_deleted (index, task); + }); + var grid = new Gtk.Grid (); grid.set_margin_start (12); grid.set_margin_end (12); @@ -57,6 +64,7 @@ grid.add (check_button); grid.add (label); + grid.add (delete_button); grid.show_all (); this.add (grid); diff --git a/app/Window.vala b/app/Window.vala index f08561a..26844f0 100644 --- a/app/Window.vala +++ b/app/Window.vala @@ -105,6 +105,7 @@ namespace Agenda { task_list_box = new Agenda.TaskListBox (Application.tasks); task_list_box.task_changed.connect (update_task); + task_list_box.task_deleted.connect (delete_task); scrolled_window = new Gtk.ScrolledWindow (null, null); scrolled_window.expand = true; @@ -157,7 +158,7 @@ namespace Agenda { public void append_task () { Task task = new Task.with_attributes ( - "", + new DateTime.now_local ().hash ().to_string (), false, task_entry.text); @@ -170,6 +171,11 @@ namespace Agenda { Application.tasks.update (index, task); } + public void delete_task (int index, Task task) { + stdout.printf ("Delete task %s - %s\n", task.id, task.text); + bool yes = Application.tasks.remove (index, task); + } + public void restore_window_position () { var size = Application.settings.get_value ("window-size"); var position = Application.settings.get_value ("window-position"); diff --git a/lib/ITaskRepository.vala b/lib/ITaskRepository.vala index 6e9622a..3d26dfb 100644 --- a/lib/ITaskRepository.vala +++ b/lib/ITaskRepository.vala @@ -25,6 +25,6 @@ namespace Agenda { public abstract Task? get_by_id (int id); public abstract void add (Task task); public abstract void update (int index, Task task); - public abstract bool remove (Task task); + public abstract bool remove (int index, Task task); } } diff --git a/lib/TaskRepositoryFile.vala b/lib/TaskRepositoryFile.vala index 992c42b..1f7b029 100644 --- a/lib/TaskRepositoryFile.vala +++ b/lib/TaskRepositoryFile.vala @@ -44,6 +44,7 @@ namespace Agenda { } public Task? get_by_id (int index) { + if (index > this.task_list.size) { return null; } @@ -67,10 +68,11 @@ namespace Agenda { return (uint) this.task_list.size; } - public bool remove (Task task) { + public bool remove (int index, Task task) { + stdout.printf ("Contains: %s\n", this.task_list.contains (task).to_string ()); var removed = this.task_list.remove (task); if (removed) { - this.items_changed (0, 1, 0); + this.items_changed (index, 1, 0); this.save (); } From cbba243ca2df7a32bd544ec7177379ff2e27770d Mon Sep 17 00:00:00 2001 From: Iyaan Azeez Date: Wed, 17 Nov 2021 14:22:52 +0500 Subject: [PATCH 7/7] Removed debug printf --- app/Window.vala | 3 +-- lib/TaskRepositoryFile.vala | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Window.vala b/app/Window.vala index 26844f0..20b5973 100644 --- a/app/Window.vala +++ b/app/Window.vala @@ -172,8 +172,7 @@ namespace Agenda { } public void delete_task (int index, Task task) { - stdout.printf ("Delete task %s - %s\n", task.id, task.text); - bool yes = Application.tasks.remove (index, task); + Application.tasks.remove (index, task); } public void restore_window_position () { diff --git a/lib/TaskRepositoryFile.vala b/lib/TaskRepositoryFile.vala index 1f7b029..aece7ee 100644 --- a/lib/TaskRepositoryFile.vala +++ b/lib/TaskRepositoryFile.vala @@ -69,7 +69,6 @@ namespace Agenda { } public bool remove (int index, Task task) { - stdout.printf ("Contains: %s\n", this.task_list.contains (task).to_string ()); var removed = this.task_list.remove (task); if (removed) { this.items_changed (index, 1, 0);