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) { if (c & Plasma::StartupCompletedConstraint) {
//common actions //common actions
bool unlocked = immutability() == Mutable; bool unlocked = immutability() == Mutable;
//FIXME make it work for containments //FIXME desktop containments can't be removed while in use.
//also, don't allow to delete the last desktop containment //it's kinda silly to have a keyboard shortcut for something that can only be used when the
//heck, can desktop ctmts even handle being deleted yet? //shortcut isn't active.
//so panel has a remove() that tears it down nicely. what does desktop have?
QAction* closeApplet = new QAction(i18n("Remove this %1", name()), this); QAction* closeApplet = new QAction(i18n("Remove this %1", name()), this);
closeApplet->setIcon(KIcon("edit-delete")); closeApplet->setIcon(KIcon("edit-delete"));
closeApplet->setEnabled(unlocked); closeApplet->setEnabled(unlocked);
@ -666,8 +665,10 @@ void Applet::flushPendingConstraintsEvents()
closeApplet->setShortcutContext(Qt::WidgetWithChildrenShortcut); //don't clash with other views closeApplet->setShortcutContext(Qt::WidgetWithChildrenShortcut); //don't clash with other views
if (! isContainment()) { if (! isContainment()) {
closeApplet->setShortcut(QKeySequence("ctrl+r")); 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); 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. * Destroys the applet; it will be removed nicely and deleted.
* Its configuration will also be deleted. * Its configuration will also be deleted.
*/ */
void destroy(); virtual void destroy();
/** /**
* Lets the user interact with the plasmoid options. * Lets the user interact with the plasmoid options.

View File

@ -36,6 +36,7 @@
#include <KAuthorized> #include <KAuthorized>
#include <KIcon> #include <KIcon>
#include <KMenu> #include <KMenu>
#include <KMessageBox>
#include <KMimeType> #include <KMimeType>
#include <KRun> #include <KRun>
#include <KServiceTypeTrader> #include <KServiceTypeTrader>
@ -927,6 +928,19 @@ void Containment::focusPreviousApplet()
d->focusApplet(d->applets.at(index)); 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 // Private class implementation

View File

@ -350,6 +350,13 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
void focusPreviousApplet(); 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: protected:
/** /**
* Sets the type of this containment. * Sets the type of this containment.

View File

@ -351,6 +351,11 @@ void Corona::destroyContainment(Containment *c)
if (!d->containments.contains(c)) { if (!d->containments.contains(c)) {
return; 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); d->containments.removeAll(c);
c->config().deleteGroup(); c->config().deleteGroup();