replace Panel::remove() with Containment::destroy()

now I can remove some of the ten desktop containments I accumulated :)
oh, and the code is cleaner too, yay!

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=810129
This commit is contained in:
Chani Armitage 2008-05-20 04:02:36 +00:00
parent fdef4627ab
commit ccde7ded20
5 changed files with 33 additions and 6 deletions

View File

@ -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);
}

View File

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

View File

@ -36,6 +36,7 @@
#include <KAuthorized>
#include <KIcon>
#include <KMenu>
#include <KMessageBox>
#include <KMimeType>
#include <KRun>
#include <KServiceTypeTrader>
@ -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

View File

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

View File

@ -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();