implementing deleting a partition via the context menu

This commit is contained in:
Michael Hudson-Doyle 2018-06-08 06:23:46 +12:00
parent e11e02f89d
commit 2459f585a8
2 changed files with 57 additions and 2 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
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()

View File

@ -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: