[gnome-boxes] app: Make delete_machines_undoable.message, optional
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] app: Make delete_machines_undoable.message, optional
- Date: Fri, 14 Nov 2014 17:42:14 +0000 (UTC)
commit adf7a15f09c1fd8bbc7a2086abf0636a4f71a0a0
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Fri Nov 14 14:01:03 2014 +0000
app: Make delete_machines_undoable.message, optional
Make message arg of delete_machines_undoable method, nullable and
optional.
https://bugzilla.gnome.org/show_bug.cgi?id=738761
src/app.vala | 36 ++++++++++++++++++++----------------
1 files changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 079ca27..74c6e45 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -462,14 +462,25 @@ private class Boxes.App: Gtk.Application {
* Deletes specified items, while allowing user to undo it.
*
* @param items the list of machines
- * @param message The message to be shown together with the undo button
+ * @param message optional message to be shown together with the undo button. If not provided, an
appropriate messsage
+ * is created.
* @param callback optional function that, if provided, is called after the undo operation
*
* @attention the ownership for items is required since GLib.List is a compact class.
*/
public void delete_machines_undoable (owned List<CollectionItem> items,
- string message,
+ string? message = null,
owned UndoNotifyCallback? undo_notify_callback = null) {
+ var num_items = items.length ();
+ if (num_items == 0)
+ return;
+
+ var msg = message;
+ if (msg == null)
+ msg = (num_items == 1) ? _("Box '%s' has been deleted").printf (items.data.name) :
+ ngettext ("%u box has been deleted",
+ "%u boxes have been deleted",
+ num_items).printf (num_items);
foreach (var item in items)
collection.remove_item (item);
@@ -486,30 +497,23 @@ private class Boxes.App: Gtk.Application {
Notification.CancelFunc really_remove = () => {
debug ("User did not cancel deletion. Deleting now...");
foreach (var item in items) {
- var machine = item as Machine;
- if (machine != null)
- // Will also delete associated storage volume if by_user is 'true'
- machine.delete (true);
+ if (!(item is Machine))
+ continue;
+
+ // Will also delete associated storage volume if by_user is 'true'
+ (item as Machine).delete (true);
}
};
- main_window.notificationbar.display_for_action (message, _("_Undo"), (owned) undo, (owned)
really_remove);
+ main_window.notificationbar.display_for_action (msg, _("_Undo"), (owned) undo, (owned)
really_remove);
}
public void remove_selected_items () {
var selected_items = main_window.view.get_selected_items ();
- var num_selected = selected_items.length ();
- if (num_selected == 0)
- return;
main_window.selection_mode = false;
- var message = (num_selected == 1) ? _("Box '%s' has been deleted").printf (selected_items.data.name)
:
- ngettext ("%u box has been deleted",
- "%u boxes have been deleted",
- num_selected).printf (num_selected);
-
- delete_machines_undoable ((owned) selected_items, message);
+ delete_machines_undoable ((owned) selected_items);
}
public AppWindow add_new_window () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]