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

List:       kde-devel
Subject:    [PATCH] Partial fix to kmenuedit problems.
From:       Ajith Balachandran <abalacha () yahoo ! com>
Date:       2001-06-17 15:25:49
[Download RAW message or body]

Hi,

The cut/paste feature in kmenuedit was broken. The following patch
mostly fixes it.

Things to do are...

  o Entire menu hierarchies are deleted without asking if you press
    delete - Ask for confirmation.
  o New Item/Submenu doesn't check for existence of the same entry.
  o Clean up code - mainly whatever I added...

I won't get time to hack KDE until next weekend. So if this patch 
doesn't look ok, feel free to modify it...

-Ajith.

? kdebase/kmenuedit/treeview.cpp.1
Index: kdebase/kmenuedit/treeview.cpp
===================================================================
RCS file: /home/kde/kdebase/kmenuedit/treeview.cpp,v
retrieving revision 1.25
diff -u -3 -p -r1.25 treeview.cpp
--- kdebase/kmenuedit/treeview.cpp	2001/06/14 10:28:19	1.25
+++ kdebase/kmenuedit/treeview.cpp	2001/06/17 14:32:06
@@ -226,7 +226,7 @@ void TreeView::currentChanged()
 }
 
 // moving = src will be removed later
-void TreeView::copyFile(const QString& src, const QString& dest, bool
moving )
+void TreeView::copyFile(const QString& src, const QString& dest, bool
moving, const QString &name)
 {
     // We can't simply copy a .desktop file as several prefixes might
     // contain a version of that file. To make sure to copy all groups
@@ -270,6 +270,9 @@ void TreeView::copyFile(const QString& s
     d.setDesktopGroup();
     d.writeEntry("Hidden", false);
 
+    if ( !name.isEmpty() ) 
+        d.writeEntry("Name", name);
+
     d.sync();
 
     if( moving && KHotKeys::present()) // tell khotkeys this menu
entry has moved
@@ -277,7 +280,7 @@ void TreeView::copyFile(const QString& s
 }
 
 // moving = src will be removed later
-void TreeView::copyDir(const QString& s, const QString& d, bool moving
)
+void TreeView::copyDir(const QString& s, const QString& d, bool
moving, const QString& name)
 {
     // We create the destination directory in a writeable prefix
returned
     // by locateLocal(), copy the .directory and the .desktop files
over.
@@ -319,6 +322,10 @@ void TreeView::copyDir(const QString& s,
     KSimpleConfig c(locateLocal("apps", dest + "/.directory"));
     c.setDesktopGroup();
     c.writeEntry("Hidden", false);
+
+    if ( !name.isEmpty() ) 
+        c.writeEntry("Name", name);
+
     c.sync();
 }
 
@@ -793,20 +800,58 @@ void TreeView::paste()
         dest.truncate(pos);
     }
 
-    kdDebug() << "### clip: " << _clipboard.local8Bit() << " dest: "
<< dest.local8Bit() << " ###" << endl;
+    // Check if the destination file exists.
+    QString destFile = locateLocal("apps", dest + '/' + _clipboard);
+    QFile f(destFile);
+
+    QString newFileName = _clipboard;
+    QString newNameEntry = QString::null;
+
+    if (f.exists()) {
+
+       // The terget exists. Prompt the user for a new file name
+       // Loop until the user enter a non existent file name or ESC.
+        while ( true ) {
+
+	    _ndlg->setText(i18n("NewItem"));
+	    if (!_ndlg->exec()) return;
+
+	    newFileName = _ndlg->text();
+	    if (newFileName.isEmpty())
+	        newFileName = "NewFile";
+
+	    newNameEntry = newFileName;
+
+	    if ( _clipboard.find(".desktop") > 0 )
+	        newFileName += ".desktop";
+	    else if ( _clipboard.find(".directory") > 0 )
+	        newFileName += "/.directory";
+	    
+	    // Check if the new name entered by the user exists.
+	    QString destFile = locateLocal("apps", dest + '/' + newFileName);
+	    QFile f(destFile);
+
+	    if ( !f.exists() )
+	        break;
+	}
+    }
 
     // is _clipboard a .directory or a .desktop file
-    if(_clipboard.find(".directory") > 0)// if cut&paste is done,
assume it's moving too
-        copyDir(QString(clipboard_prefix) + _clipboard, dest + '/' +
_clipboard, true );
-    else if (_clipboard.find(".desktop"))
-        copyFile(QString(clipboard_prefix) + _clipboard, dest + '/' +
_clipboard, true );
+    // if cut&paste is done, assume it's moving too
 
+    if ( _clipboard.find(".directory") > 0 ) 
+        copyDir(QString(clipboard_prefix) + _clipboard, dest + '/' +
newFileName,
+		true, newNameEntry);
+    else if ( _clipboard.find(".desktop") > 0 )
+        copyFile(QString(clipboard_prefix) + _clipboard, dest + '/' +
newFileName,
+		 true, newNameEntry);
+
     // create the TreeItems:
 
     QListViewItem* parent = 0;
 
-    if(item){
-	if(item->isExpandable()) {
+    if (item) {
+	if (item->isExpandable()) {
 	    parent = item;
 	    item = 0;
 	}
@@ -814,24 +859,27 @@ void TreeView::paste()
 	    parent = item->parent();
     }
 
-    if(parent)
+    if (parent)
         parent->setOpen(true);
 
     TreeItem* newitem;
-    if (!parent)
+    if (!parent) {
 	newitem = new TreeItem(this, item, "");
+    }
     else
 	newitem = new TreeItem(parent, item, "");
 
-    KDesktopFile df(locateLocal("apps", dest + '/' + _clipboard));
+    KDesktopFile df(locateLocal("apps", dest + '/' + newFileName));
 
     newitem->setText(0, df.readName());
     if(!dest.isEmpty())
-	newitem->setFile(dest + '/' + _clipboard);
+	newitem->setFile(dest + '/' + newFileName);
     else
-	newitem->setFile(_clipboard);
+	newitem->setFile(newFileName);
     newitem->setPixmap(0,
KGlobal::iconLoader()->loadIcon(df.readIcon(),KIcon::Desktop,
KIcon::SizeSmall));
 
+    if ( _clipboard.find(".directory") > 0 ) 
+        newitem->setExpandable(true);
 
     fillBranch(newitem->file(), newitem);
 }
@@ -869,5 +917,5 @@ void TreeView::del()
 
 void TreeView::cleanupClipboard()
 {
-    // TODO
+    deleteDir(clipboard_prefix);
 }
Index: kdebase/kmenuedit/treeview.h
===================================================================
RCS file: /home/kde/kdebase/kmenuedit/treeview.h,v
retrieving revision 1.12
diff -u -3 -p -r1.12 treeview.h
--- kdebase/kmenuedit/treeview.h	2000/11/17 17:42:06	1.12
+++ kdebase/kmenuedit/treeview.h	2001/06/17 14:32:06
@@ -76,8 +76,10 @@ protected:
     // moving = src will be removed later
     void copy( bool moving );
 
-    void copyFile(const QString& src, const QString& dest, bool moving
);
-    void copyDir(const QString& src, const QString& dest, bool moving
);
+    void copyFile(const QString& src, const QString& dest, bool
moving,
+		  const QString &name = QString::null);
+    void copyDir(const QString& src, const QString& dest, bool moving,
+		 const QString &name = QString::null);
 
     void deleteFile(const QString& deskfile);
     void deleteDir(const QString& dir);





__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/
 
>> Visit http://master.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

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

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