diff --git a/applet.cpp b/applet.cpp index e489c1e58..1e04679bf 100644 --- a/applet.cpp +++ b/applet.cpp @@ -655,10 +655,9 @@ void Applet::flushPendingConstraintsEvents() if (c & Plasma::StartupCompletedConstraint) { //common actions bool unlocked = immutability() == Mutable; - //FIXME make it work for containments - //also, don't allow to delete the last desktop containment - //heck, can desktop ctmts even handle being deleted yet? - //so panel has a remove() that tears it down nicely. what does desktop have? + //FIXME desktop containments can't be removed while in use. + //it's kinda silly to have a keyboard shortcut for something that can only be used when the + //shortcut isn't active. QAction* closeApplet = new QAction(i18n("Remove this %1", name()), this); closeApplet->setIcon(KIcon("edit-delete")); closeApplet->setEnabled(unlocked); @@ -666,8 +665,10 @@ void Applet::flushPendingConstraintsEvents() closeApplet->setShortcutContext(Qt::WidgetWithChildrenShortcut); //don't clash with other views if (! isContainment()) { closeApplet->setShortcut(QKeySequence("ctrl+r")); - connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(destroy())); + } else { + closeApplet->setShortcut(QKeySequence("ctrl+shift+r")); } + connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(destroy())); d->actions.addAction("remove", closeApplet); } diff --git a/applet.h b/applet.h index 0d686025f..a38441dfc 100644 --- a/applet.h +++ b/applet.h @@ -518,7 +518,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget * Destroys the applet; it will be removed nicely and deleted. * Its configuration will also be deleted. */ - void destroy(); + virtual void destroy(); /** * Lets the user interact with the plasmoid options. diff --git a/containment.cpp b/containment.cpp index 6a98f657d..4c17edec3 100644 --- a/containment.cpp +++ b/containment.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -927,6 +928,19 @@ void Containment::focusPreviousApplet() d->focusApplet(d->applets.at(index)); } +void Containment::destroy() +{ + if (immutability() != Mutable) { + return; + } + //FIXME maybe that %1 should be the containment type not the name + if (KMessageBox::warningContinueCancel(0, i18n("Do you really want to remove this %1?", name()), + i18n("Remove %1", name()), KStandardGuiItem::remove()) == KMessageBox::Continue ) { + clearApplets(); + corona()->destroyContainment(this); + } +} + // Private class implementation diff --git a/containment.h b/containment.h index 9ffd3b97f..939810817 100644 --- a/containment.h +++ b/containment.h @@ -350,6 +350,13 @@ class PLASMA_EXPORT Containment : public Applet */ void focusPreviousApplet(); + /** + * Destroys this containment and all its applets (after a confirmation dialog); + * it will be removed nicely and deleted. + * Its configuration will also be deleted. + */ + void destroy(); + protected: /** * Sets the type of this containment. diff --git a/corona.cpp b/corona.cpp index df0a91bbb..892fc2723 100644 --- a/corona.cpp +++ b/corona.cpp @@ -351,6 +351,11 @@ void Corona::destroyContainment(Containment *c) if (!d->containments.contains(c)) { return; } + //don't remove a desktop that's in use + //FIXME allow removal of containments for screens that don't currently exist + if (c->containmentType() != Containment::PanelContainment && c->screen() != -1) { + return; + } d->containments.removeAll(c); c->config().deleteGroup();