From 2459f585a8daa4f5afdcb47fffe02ab95b8a45f5 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 8 Jun 2018 06:23:46 +1200 Subject: [PATCH] implementing deleting a partition via the context menu --- subiquity/ui/views/filesystem/delete.py | 52 +++++++++++++++++++++ subiquity/ui/views/filesystem/filesystem.py | 7 ++- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 subiquity/ui/views/filesystem/delete.py diff --git a/subiquity/ui/views/filesystem/delete.py b/subiquity/ui/views/filesystem/delete.py new file mode 100644 index 00000000..c7987c7c --- /dev/null +++ b/subiquity/ui/views/filesystem/delete.py @@ -0,0 +1,52 @@ +# Copyright 2018 Canonical, Ltd. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import logging +from urwid import Text + +from subiquitycore.ui.buttons import danger_btn, other_btn +from subiquitycore.ui.utils import button_pile +from subiquitycore.ui.stretchy import Stretchy + + +log = logging.getLogger('subiquity.ui.filesystem.disk_info') + + +class ConfirmDeleteStretchy(Stretchy): + + def __init__(self, parent, thing, delete_func): + self.parent = parent + self.thing = thing + self.delete_func = delete_func + + title = _("Confirm deletion of {}").format(thing.desc()) + + widgets = [ + Text(_("Do you really want to delete {}?").format(thing.label)), + Text(""), + button_pile([ + danger_btn(label=_("Delete"), on_press=self.confirm), + other_btn(label=_("Cancel"), on_press=self.cancel), + ]), + ] + super().__init__(title, widgets, 0, 2) + + def confirm(self, sender=None): + self.delete_func(self.thing) + self.parent.refresh_model_inputs() + self.parent.remove_overlay() + + def cancel(self, sender=None): + self.parent.remove_overlay() diff --git a/subiquity/ui/views/filesystem/filesystem.py b/subiquity/ui/views/filesystem/filesystem.py index 16dae50e..ff482fcf 100644 --- a/subiquity/ui/views/filesystem/filesystem.py +++ b/subiquity/ui/views/filesystem/filesystem.py @@ -54,6 +54,7 @@ from subiquitycore.view import BaseView from subiquity.models.filesystem import DeviceAction, Disk, humanize_size +from .delete import ConfirmDeleteStretchy from .disk_info import DiskInfoStretchy from .partition import PartitionStretchy, FormatEntireStretchy @@ -288,8 +289,10 @@ class DeviceList(WidgetWrap): if action == DeviceAction.EDIT: overlay = PartitionStretchy(self.parent, part.device, part) if action == DeviceAction.DELETE: - # TODO - return + overlay = ConfirmDeleteStretchy( + self.parent, + part, + self.parent.controller.delete_partition) if action == DeviceAction.FORMAT: overlay = FormatEntireStretchy(self.parent, part) if overlay is not None: