KDev4: "New File" File Location

Casey Link unnamedrambler at gmail.com
Wed Sep 24 12:51:14 UTC 2008


Here is a patch that changes the behavior of the New File action to
create the temp file in the same directory as the currently open file.
One drawback to this approach is that it actually writes a blank file,
which means you have to clean it up later either by Saving As and
deleting the tmp file, or Saving and renaming the temp file to be what
you want.

It would be nice if New File created a blank buffer, or prompted for a
File Name (and possibly a location).

Ramblurr / Casey Link

Index: shell/documentcontroller.cpp
===================================================================
--- shell/documentcontroller.cpp        (revision 864013)
+++ shell/documentcontroller.cpp        (working copy)
@@ -256,8 +256,17 @@

 IDocument* DocumentController::openDocumentFromText( const QString& data )
 {
+    IDocument *activeDoc = activeDocument();
+    QString path;
+    if (activeDoc)
+    {
+        path = activeDoc->url().directory();
+    }
+
    KTemporaryFile *temp = new KTemporaryFile();
-    temp->setSuffix("kdevtmp");
+    temp->setSuffix(".kdevtmp");
+    if( !path.isEmpty() )
+        temp->setPrefix( path );
    temp->open();
    temp->write(data.toUtf8());
    temp->flush();




More information about the KDevelop-devel mailing list