[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [PATCH] kmenuedit enhancment
From:       Raffaele Sandrini <sandrini () kde ! org>
Date:       2002-02-11 10:28:40
[Download RAW message or body]

On Sunday 10 February 2002 14:41, David Faure wrote:
> Ok, but why should that be two menu items then ? Why not offer "Delete"
> only, which in fact hides the item (NoDisplay=true)?
> Having a Delete menuitem that tells the user "you can't delete it" sounds
> a bit useless to me. And if it's for local files only... isn't it enough
> to offer NoDisplay instead of real deletion - for the sake of a simpler
> UI?

Ok, i (re)added now the hidden (hide=true) feature but it will only be used 
when the item is moved.
I left the hide/unhide because if there is only a delete i have to do 
something like undelete... because its important to me that the user can 
reshow his items (NoDisplay=true/false).
Kmenuedit has a simple UI... i think there is no problem with there two new 
buttons.

Try the new patch (taken from CVS)

cheers,
Raffaele
-- 
Raffaele Sandrini <sandrini@kde.org>
["kmenuedit.diff" (text/x-diff)]

Index: kmenuedit.cpp
===================================================================
RCS file: /home/kde/kdebase/kmenuedit/kmenuedit.cpp,v
retrieving revision 1.42
diff -u -3 -p -r1.42 kmenuedit.cpp
--- kmenuedit.cpp	2001/12/29 17:23:01	1.42
+++ kmenuedit.cpp	2002/02/11 10:21:38
@@ -1,5 +1,6 @@
 /*
  *   Copyright (C) 2000 Matthias Elter <elter@kde.org>
+ *   Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org)
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -65,7 +66,9 @@ void KMenuEdit::setupActions()
 {
     (void)new KAction(i18n("&New Submenu"), "menu_new", 0, actionCollection(), \
                "newsubmenu");
     (void)new KAction(i18n("New &Item"), "filenew", 0, actionCollection(), \
                "newitem");
-    (void)new KAction(i18n("&Delete"), "editdelete", 0, actionCollection(), \
"delete"); +    (void)new KAction(i18n("&Delete"), "edittrash", 0, \
actionCollection(), "delete"); +    (void)new KAction(i18n("&Hide"), "editdelete", 0, \
actionCollection(), "hide"); +    (void)new KAction(i18n("&Unhide"), "redo", 0, \
actionCollection(), "unhide");  
     KStdAction::quit(this, SLOT( slotClose() ), actionCollection());
     KStdAction::cut(0, 0, actionCollection());
Index: kmenueditui.rc
===================================================================
RCS file: /home/kde/kdebase/kmenuedit/kmenueditui.rc,v
retrieving revision 1.3
diff -u -3 -p -r1.3 kmenueditui.rc
--- kmenueditui.rc	2000/09/25 21:32:15	1.3
+++ kmenueditui.rc	2002/02/11 10:21:38
@@ -16,6 +16,8 @@
  <Action name="edit_paste"/>
  <Separator/>
  <Action name="delete"/>
+ <Action name="hide"/>
+ <Action name="unhide"/>
 </Menu>
 </MenuBar>
 
@@ -28,6 +30,8 @@
  <Action name="edit_paste"/>
  <Separator/>
  <Action name="delete"/>
+ <Action name="hide"/>
+ <Action name="unhide"/>
 </ToolBar>
 
 </kpartgui>
Index: main.cpp
===================================================================
RCS file: /home/kde/kdebase/kmenuedit/main.cpp,v
retrieving revision 1.34
diff -u -3 -p -r1.34 main.cpp
--- main.cpp	2001/12/29 17:23:01	1.34
+++ main.cpp	2002/02/11 10:21:38
@@ -1,5 +1,6 @@
 /*
  *   Copyright (C) 2000 Matthias Elter <elter@kde.org>
+ *   Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org)
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -34,7 +35,7 @@ int main( int argc, char **argv )
 {
     KAboutData aboutData("kmenuedit", I18N_NOOP("KDE Menu Editor"),
 			 version, description, KAboutData::License_GPL,
-			 "(c) 2001, Raffaele Sandrini");
+			 "(C) 2002, Raffaele Sandrini");
     aboutData.addAuthor("Raffaele Sandrini", I18N_NOOP("Maintainer"), \
                "sandrini@kde.org");
     aboutData.addAuthor("Matthias Elter", I18N_NOOP("Original Author"), \
"elter@kde.org");  
Index: treeview.cpp
===================================================================
RCS file: /home/kde/kdebase/kmenuedit/treeview.cpp,v
retrieving revision 1.32
diff -u -3 -p -r1.32 treeview.cpp
--- treeview.cpp	2001/12/29 17:23:01	1.32
+++ treeview.cpp	2002/02/11 10:21:38
@@ -1,5 +1,6 @@
 /*
  *   Copyright (C) 2000 Matthias Elter <elter@kde.org>
+ *   Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org)
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -34,6 +35,7 @@
 #include <kiconloader.h>
 #include <kdesktopfile.h>
 #include <kaction.h>
+#include <kmessagebox.h>
 
 #include "namedlg.h"
 #include "treeview.h"
@@ -87,6 +89,8 @@ TreeView::TreeView( KActionCollection *a
     connect(_ac->action("edit_copy"), SIGNAL(activated()), SLOT(copy()));
     connect(_ac->action("edit_paste"), SIGNAL(activated()), SLOT(paste()));
     connect(_ac->action("delete"), SIGNAL(activated()), SLOT(del()));
+    connect(_ac->action("hide"), SIGNAL(activated()), SLOT(hide()));
+    connect(_ac->action("unhide"), SIGNAL(activated()), SLOT(unhide()));
 
     // setup rmb menu
     _rmb = new QPopupMenu(this);
@@ -105,6 +109,16 @@ TreeView::TreeView( KActionCollection *a
     }
 
     _rmb->insertSeparator();
+    
+    if(_ac->action("hide")) {
+        _ac->action("hide")->plug(_rmb);
+        _ac->action("hide")->setEnabled(false);
+    }
+    
+    if(_ac->action("unhide")) {
+        _ac->action("unhide")->plug(_rmb);
+        _ac->action("unhide")->setEnabled(false);
+    }
 
     if(_ac->action("delete")) {
         _ac->action("delete")->plug(_rmb);
@@ -124,7 +138,8 @@ TreeView::TreeView( KActionCollection *a
 }
 
 void TreeView::fill()
-{
+{    //QString name(item->text(0));
+    //if (!(name.find("[Hidden]") > 0))
     clear();
     fillBranch("", 0);
 }
@@ -154,13 +169,23 @@ void TreeView::fillBranch(const QString&
 	    if(df.readBoolEntry("Hidden") == true)
 		continue;
 
+	    if(df.readBoolEntry("NoDisplay") == true) {
+		    TreeItem* item;
+		    if (parent == 0) item = new TreeItem(this, *it);
+	    	else item = new TreeItem(parent, *it);
+
+		    item->setText(0, df.readName() + i18n(" [Hidden]"));
+		    //item->setPixmap(0, KGlobal::iconLoader()->loadIcon("no",KIcon::Desktop, \
KIcon::SizeSmall)); +	    	    item->setPixmap(0, \
KGlobal::iconLoader()->loadIcon(df.readIcon(),KIcon::Desktop, KIcon::SizeSmall)); +	  \
} +	    else {
 	    TreeItem* item;
 	    if (parent == 0) item = new TreeItem(this, *it);
 	    else item = new TreeItem(parent, *it);
 
 	    item->setText(0, df.readName());
-	    item->setPixmap(0, KGlobal::iconLoader()->
-			    loadIcon(df.readIcon(),KIcon::Desktop, KIcon::SizeSmall));
+	    item->setPixmap(0, \
KGlobal::iconLoader()->loadIcon(df.readIcon(),KIcon::Desktop, KIcon::SizeSmall)); +	  \
}  }
 	while (it != filelist.begin());
     }
@@ -168,7 +193,7 @@ void TreeView::fillBranch(const QString&
     // add directories and process sudirs
     if (!dirlist.isEmpty()) {
 	QStringList::ConstIterator it = dirlist.end();
-	do{
+	do {
 	    --it;
 
 	    QString dirFile = KGlobal::dirs()->findResource("apps", *it + "/.directory");
@@ -186,19 +211,31 @@ void TreeView::fillBranch(const QString&
             }
 	    else {
                 KDesktopFile df(dirFile);
-                if(df.readBoolEntry("Hidden") == true)
-                    continue;
-
+		if(df.readBoolEntry("Hidden") == true)
+		continue;
+		
+                if(df.readBoolEntry("Hidden") == true) {
+	                if (parent == 0)
+	                    item = new TreeItem(this,  *it + "/.directory");
+	                else
+	                    item = new TreeItem(parent, *it + "/.directory");
+
+	                item->setText(0, df.readName() + i18n(" [Hidden]"));
+	                //item->setPixmap(0, \
KGlobal::iconLoader()->loadIcon("no",KIcon::Desktop, KIcon::SizeSmall)); \
+			item->setPixmap(0, KGlobal::iconLoader()->loadIcon(df.readIcon(),KIcon::Desktop, \
KIcon::SizeSmall)); +	                item->setExpandable(true);
+		}
+		else {
                 if (parent == 0)
                     item = new TreeItem(this,  *it + "/.directory");
                 else
                     item = new TreeItem(parent, *it + "/.directory");
 
                 item->setText(0, df.readName());
-                item->setPixmap(0, KGlobal::iconLoader()
-                                ->loadIcon(df.readIcon(),KIcon::Desktop, \
KIcon::SizeSmall)); +                item->setPixmap(0, \
KGlobal::iconLoader()->loadIcon(df.readIcon(),KIcon::Desktop, KIcon::SizeSmall));  \
                item->setExpandable(true);
-            }
+		}
+	   }
 	    fillBranch(*it, item);
 	}
 	while (it != dirlist.begin());
@@ -207,9 +244,19 @@ void TreeView::fillBranch(const QString&
 
 void TreeView::itemSelected(QListViewItem *item)
 {
-    _ac->action("edit_cut")->setEnabled(selectedItem());
-    _ac->action("edit_copy")->setEnabled(selectedItem());
-    _ac->action("delete")->setEnabled(selectedItem());
+    bool selected = false, hselected = false;
+    if (item) {
+	selected = true;
+	QString name(item->text(0));
+	if (!(name.find("[Hidden]") > 0)) {
+		hselected = true;
+	}
+    _ac->action("edit_cut")->setEnabled(selected);
+    _ac->action("edit_copy")->setEnabled(selected);
+    _ac->action("delete")->setEnabled(selected);
+    _ac->action("hide")->setEnabled(hselected);
+    _ac->action("unhide")->setEnabled(!hselected);
+    }
 
     if(!item) return;
 
@@ -324,7 +371,7 @@ void TreeView::copyDir(const QString& s,
     c.sync();
 }
 
-void TreeView::deleteFile(const QString& deskfile)
+bool TreeView::deleteFile(const QString& deskfile, const bool move = false)
 {
     // We search for the file in all prefixes and remove all writeable
     // ones. If we were not able to remove all (because of lack of permissons)
@@ -345,21 +392,20 @@ void TreeView::deleteFile(const QString&
             allremoved = false;
     }
 
-    // if we did not have the permissions to remove all files we set a hidden flag
-    // in the local one.
-    if(!allremoved) {
-        KSimpleConfig c(locateLocal("apps", deskfile));
+    if( KHotKeys::present()) // tell khotkeys this menu entry has been removed
+        KHotKeys::menuEntryDeleted( deskfile );
+	
+    if(move) {
+	KSimpleConfig c(locateLocal("apps", deskfile));
         c.setDesktopGroup();
         c.writeEntry("Name", "empty");
         c.writeEntry("Hidden", true);
         c.sync();
-    }
-
-    if( KHotKeys::present()) // tell khotkeys this menu entry has been removed
-        KHotKeys::menuEntryDeleted( deskfile );
+    } else
+	return allremoved;
 }
 
-void TreeView::deleteDir(const QString& d)
+bool TreeView::deleteDir(const QString& d, const bool move = false)
 {
     // We delete all .desktop files and then process with the subdirs.
     // Afterwards the .directory file gets deleted from all prefixes
@@ -399,15 +445,37 @@ void TreeView::deleteDir(const QString& 
         if(!dir.rmdir(*it))
             allremoved = false;
     }
-
-    // set a local hidden flag if not all dirs could be deleted
-    if(!allremoved) {
+    
+    if(move) {
         KSimpleConfig c(locateLocal("apps", directory + "/.directory"));
         c.setDesktopGroup();
         c.writeEntry("Name", "empty");
         c.writeEntry("Hidden", true);
         c.sync();
-    }
+    } else
+	return allremoved;
+}
+
+void TreeView::hideFile(const QString& deskfile, bool hide) {
+
+        KSimpleConfig c(locateLocal("apps", deskfile));
+        c.setDesktopGroup();
+        c.writeEntry("NoDisplay", hide);
+        c.sync();
+
+
+    if( KHotKeys::present()) // tell khotkeys this menu entry has been removed
+        KHotKeys::menuEntryDeleted( deskfile );
+}
+
+void TreeView::hideDir(const QString& d, const QString name, bool hide, QString \
icon) { +	QString directory = d;
+	KSimpleConfig c(locateLocal("apps", directory + "/.directory"));
+	c.setDesktopGroup();
+	c.writeEntry("Name", name);
+	c.writeEntry("Hidden", hide);
+	c.writeEntry("Icon", icon);
+	c.sync();
 }
 
 QStringList TreeView::fileList(const QString& rPath)
@@ -544,11 +612,11 @@ void TreeView::slotDropped (QDropEvent *
 
     if(isDir) {
         copyDir(src, dest, true );
-        deleteDir(src);
+        deleteDir(src, true);
     }
     else {
         copyFile(src, dest, true );
-        deleteFile(src);
+        deleteFile(src, true);
     }
 }
 
@@ -858,18 +926,59 @@ void TreeView::del()
     // is file a .directory or a .desktop file
     if(file.find(".directory") > 0)
     {
-        deleteDir(file.mid(0, file.find("/.directory")));
-        delete item;
+        if (!(deleteDir(file.mid(0, file.find("/.directory")))))
+		KMessageBox::sorry(0, i18n("This is a root item. You don't have permission to \
delete it. Hide it instead please."), i18n("Permission denied")); +	else
+        	delete item;
+    }
+    else if (file.find(".desktop"))
+    {
+        if (!(deleteFile(file)))
+		KMessageBox::sorry(0, i18n("This is a root item. You don't have permission to \
delete it. Hide it instead please."), i18n("Permission denied")); +	else
+		delete item;
+    }
+
+    _ac->action("edit_cut")->setEnabled(false);
+    _ac->action("edit_copy")->setEnabled(false);
+    _ac->action("delete")->setEnabled(false);
+    _ac->action("hide")->setEnabled(false);
+
+    // Select new current item
+    setSelected( currentItem(), true );
+    // Switch the UI to show that item
+    itemSelected( selectedItem() );
+}
+
+void TreeView::dohide(bool _hide) {
+    TreeItem *item = (TreeItem*)selectedItem();
+
+    // nil selected? -> nil to hide
+    if (item == 0) return;
+
+    QString file = item->file();
+    KDesktopFile df(item->file());
+
+    // is file a .directory or a .desktop file
+    if(file.find(".directory") > 0)
+    {
+        hideDir(file.mid(0, file.find("/.directory")), df.readName(), _hide, \
df.readIcon());  }
     else if (file.find(".desktop"))
     {
-        deleteFile(file);
-        delete item;
+        hideFile(file, _hide);
     }
+    if (_hide)
+    	item->setText(0, item->text(0) + i18n(" [Hidden]"));
+    else
+    	item->setText(0, df.readName());
+
+    item->repaint();
 
     _ac->action("edit_cut")->setEnabled(false);
     _ac->action("edit_copy")->setEnabled(false);
     _ac->action("delete")->setEnabled(false);
+    _ac->action("hide")->setEnabled(false);
 
     // Select new current item
     setSelected( currentItem(), true );
@@ -881,3 +990,4 @@ void TreeView::cleanupClipboard()
 {
     // TODO
 }
+
Index: treeview.h
===================================================================
RCS file: /home/kde/kdebase/kmenuedit/treeview.h,v
retrieving revision 1.13
diff -u -3 -p -r1.13 treeview.h
--- treeview.h	2001/10/19 03:48:26	1.13
+++ treeview.h	2002/02/11 10:21:38
@@ -1,5 +1,6 @@
 /*
  *   Copyright (C) 2000 Matthias Elter <elter@kde.org>
+ *   Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org)
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -68,6 +69,8 @@ protected slots:
     void copy();
     void paste();
     void del();
+    void hide();
+    void unhide();
 
 protected:
     void fill();
@@ -79,9 +82,14 @@ protected:
     void copyFile(const QString& src, const QString& dest, bool moving );
     void copyDir(const QString& src, const QString& dest, bool moving );
 
-    void deleteFile(const QString& deskfile);
-    void deleteDir(const QString& dir);
+    bool deleteFile(const QString& deskfile, const bool move = false);
+    bool deleteDir(const QString& dir, const bool move = false);
+    void hideFile(const QString& deskfile, bool hide);
+    void hideDir(const QString& d, const QString name, bool hide, QString icon);
+    
+    void dohide(bool _hide);
 
+
     void cleanupClipboard();
 
     QStringList fileList(const QString& relativePath);
@@ -96,5 +104,13 @@ private:
     NameDialog        *_ndlg;
     QString            _clipboard;
 };
+
+inline void TreeView::hide() {
+	dohide(true);
+}
+
+inline void TreeView::unhide() {
+	dohide(false);
+}
 
 #endif



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic