Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TaskListGrid: Gtk4 prep #385

Merged
merged 2 commits into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 34 additions & 44 deletions src/Widgets/TaskListGrid.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
}

construct {
E.SourceRegistry? registry = null;
try {
E.SourceRegistry? registry = null;
registry = Application.model.get_registry_sync ();
is_gtasks = Application.model.get_collection_backend_name (source, registry) == "google";
} catch (Error e) {
Expand All @@ -34,23 +34,18 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
var list_settings_popover = new Tasks.Widgets.ListSettingsPopover ();

var settings_button = new Gtk.MenuButton () {
halign = END,
image = new Gtk.Image.from_icon_name ("view-more-symbolic", Gtk.IconSize.MENU),
margin_end = 24,
valign = Gtk.Align.CENTER,
tooltip_text = _("Edit Name and Appearance"),
popover = list_settings_popover,
image = new Gtk.Image.from_icon_name ("view-more-symbolic", Gtk.IconSize.MENU)
tooltip_text = _("Edit Name and Appearance"),
valign = CENTER
};
settings_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
settings_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);

var placeholder = new Gtk.Label (_("No Tasks"));
placeholder.show ();
placeholder.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
placeholder.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

add_task_list = new Gtk.ListBox () {
margin_top = 24,
selection_mode = Gtk.SelectionMode.SINGLE,
selection_mode = SINGLE,
activate_on_single_click = true
};
add_task_list.get_style_context ().add_class (Gtk.STYLE_CLASS_BACKGROUND);
Expand All @@ -71,8 +66,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
Gtk.ButtonsType.CLOSE
);
error_dialog.show_error_details (e.message);
error_dialog.run ();
error_dialog.destroy ();
error_dialog.present ();
error_dialog.response.connect (error_dialog.destroy);
}

return GLib.Source.REMOVE;
Expand All @@ -81,20 +76,25 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
});
add_task_list.add (add_task_row);

var placeholder = new Gtk.Label (_("No Tasks"));
placeholder.show ();
placeholder.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL);
placeholder.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL);

task_list = new Gtk.ListBox () {
selection_mode = Gtk.SelectionMode.MULTIPLE,
selection_mode = MULTIPLE,
activate_on_single_click = true
};
task_list.set_placeholder (placeholder);
task_list.set_sort_func (sort_function);
task_list.get_style_context ().add_class (Gtk.STYLE_CLASS_BACKGROUND);

var scrolled_window = new Gtk.ScrolledWindow (null, null) {
child = task_list,
hexpand = true,
vexpand = true,
hscrollbar_policy = Gtk.PolicyType.NEVER
};
scrolled_window.add (task_list);

column_spacing = 12;
attach (editable_title, 0, 0);
Expand All @@ -107,17 +107,14 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
});
on_show_completed_changed (Application.settings.get_boolean ("show-completed"));

settings_button.toggled.connect (() => {
unowned GLib.ActionMap win_action_map = (GLib.ActionMap) get_action_group (MainWindow.ACTION_GROUP_PREFIX);
settings_button.activate.connect (() => {
unowned var main_window = (Gtk.ApplicationWindow) ((Gtk.Application) GLib.Application.get_default ()).active_window;

if (settings_button.active) {
list_settings_popover.source = source;

if (win_action_map != null) {
((SimpleAction) win_action_map.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (true);
}

} else if (win_action_map != null) {
((SimpleAction) main_window.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (true);
} else {
/*
* We can't immediate disable the action once the popover is closed,
* because this would lead to the action not beeing executed in case
Expand All @@ -126,7 +123,7 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
* be executed if needed.
*/
GLib.Idle.add (() => {
((SimpleAction) win_action_map.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (
((SimpleAction) main_window.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (
add_task_list.get_selected_rows ().length () == 0 &&
task_list.get_selected_rows ().length () == 0
);
Expand All @@ -139,10 +136,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
task_list.row_activated.connect (on_row_activated);

editable_title.notify["editing"].connect (() => {
unowned GLib.ActionMap win_action_map = (GLib.ActionMap) get_action_group (MainWindow.ACTION_GROUP_PREFIX);
if (win_action_map != null) {
((SimpleAction) win_action_map.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (!editable_title.editing);
}
unowned var main_window = (Gtk.ApplicationWindow) ((Gtk.Application) GLib.Application.get_default ()).active_window;
((SimpleAction) main_window.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (!editable_title.editing);
});

editable_title.changed.connect (() => {
Expand Down Expand Up @@ -181,9 +176,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
}

private void set_view_for_query (string query) {
var children = task_list.get_children ();
foreach (unowned var child in children) {
task_list.remove (child);
while (task_list.get_row_at_index (0) != null) {
task_list.remove (task_list.get_row_at_index (0));
}

if (view != null) {
Expand All @@ -206,10 +200,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
var task_row = (Tasks.Widgets.TaskRow) row;
task_row.reveal_child_request (true);

unowned GLib.ActionMap win_action_map = (GLib.ActionMap) get_action_group (MainWindow.ACTION_GROUP_PREFIX);
if (win_action_map != null) {
((SimpleAction) win_action_map.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (false);
}
unowned var main_window = (Gtk.ApplicationWindow) ((Gtk.Application) GLib.Application.get_default ()).active_window;
((SimpleAction) main_window.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (false);
}

private void on_row_unselect (Gtk.ListBoxRow row) {
Expand All @@ -218,10 +210,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
}

if (add_task_list.get_selected_rows ().length () == 0 && task_list.get_selected_rows ().length () == 0) {
unowned GLib.ActionMap win_action_map = (GLib.ActionMap) get_action_group (MainWindow.ACTION_GROUP_PREFIX);
if (win_action_map != null) {
((SimpleAction) win_action_map.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (true);
}
unowned var main_window = (Gtk.ApplicationWindow) get_toplevel ();
((SimpleAction) main_window.lookup_action (MainWindow.ACTION_DELETE_SELECTED_LIST)).set_enabled (true);
}
}

Expand Down Expand Up @@ -294,8 +284,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
Gtk.ButtonsType.CLOSE
);
error_dialog.show_error_details (e.message);
error_dialog.run ();
error_dialog.destroy ();
error_dialog.present ();
error_dialog.response.connect (error_dialog.destroy);
}

return GLib.Source.REMOVE;
Expand All @@ -316,8 +306,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
Gtk.ButtonsType.CLOSE
);
error_dialog.show_error_details (e.message);
error_dialog.run ();
error_dialog.destroy ();
error_dialog.present ();
error_dialog.response.connect (error_dialog.destroy);
}

return GLib.Source.REMOVE;
Expand All @@ -338,8 +328,8 @@ public class Tasks.Widgets.TaskListGrid : Gtk.Grid {
Gtk.ButtonsType.CLOSE
);
error_dialog.show_error_details (e.message);
error_dialog.run ();
error_dialog.destroy ();
error_dialog.present ();
error_dialog.response.connect (error_dialog.destroy);
}

return GLib.Source.REMOVE;
Expand Down