Bug 61591 - "new file" relocation outside project tree fails
Summary: "new file" relocation outside project tree fails
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: file create (show other bugs)
Version: git master
Platform: Compiled Sources Solaris
: NOR normal
Target Milestone: ---
Assignee: KDevelop Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-23 21:42 UTC by Daniel Franke
Modified: 2003-07-25 23:22 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Franke 2003-07-23 21:42:02 UTC
Version:           alpha5 / CVS 030723 (using KDE KDE 3.1.2)
Installed from:    Compiled From Sources
Compiler:          gcc-3.2.2 
OS:          Solaris

Select File->New from menu, change directory in "File creation dialog" to somewhere outside the project (one may argue about the sense of an action like this ;), say change it to '/tmp/'. give a filename, say 'foo.cpp', (select or deselect "Add to project", that doesn't matter) and press 'Ok'.

The debug output will somewhat look like
--snip--
gideon: Looking for filetype pointer for /
gideon: could not find filetype
gideon: relative to proj dir = .cpp
gideon: filename = .cpp
kdevelop (core): [virtual void PartController::editDocument(const KURL&, int, int)] file:/home/franke/devel/sibsim/.cpp linenum -1
--snip--

No file will be created, and no error is reported.
Comment 1 Alexander Dymo 2003-07-25 23:22:51 UTC
Subject: kdevelop/parts/filecreate

CVS commit by dymo: 

allow to create and open files not only in the project directory (if "Add to project" box is unchecked)
CCMAIL: 61591-done@bugs.kde.org


  M +61 -31    filecreate_part.cpp   1.34


--- kdevelop/parts/filecreate/filecreate_part.cpp  #1.33:1.34
@@ -437,5 +437,6 @@ KDevCreateFile::CreatedFile FileCreatePa
   }
 
-
+  if (dialog.addToProject())
+  {
   // work out the path relative to the project directory
   QString relToProj = URLUtil::relativePath(projectURL, selectedURL, URLUtil::SLASH_PREFIX );
@@ -462,14 +463,43 @@ KDevCreateFile::CreatedFile FileCreatePa
   }
 
-  if (result.addToProject)
     project()->addFile(relToProj.mid(1));
 
+    // tell the caller what we did
+    result.filename = filename;
+    result.dir = URLUtil::directory(relToProj);
+    result.status = KDevCreateFile::CreatedFile::STATUS_OK;
+  }
+  else //this is for non-project files
+  {
+    QString fullPath = selectedURL.path();
+    // add appropriate extension, if not already there
+    if (!ext.isNull() & ext!="" & !fullPath.endsWith("." + ext)) fullPath+="." + ext;
 
+    QString filename = URLUtil::filename(fullPath);
 
+    kdDebug(9034) << "full path = " << fullPath << endl;
+    kdDebug(9034) << "filename = " << filename << endl;
 
-  // tell the caller what we did
+    // add in subtype, if specified
+    if (!subtype.isEmpty())
+        ext += "-" + subtype;
+
+    // create file from template, and add it to the project
+    if (!FileTemplate::exists(this, ext) ||
+        !FileTemplate::copy(this, ext, fullPath) ) {
+        // no template, create a blank file instead
+        QFile f(fullPath);
+        f.open( IO_WriteOnly );
+        f.close();
+    }
+    KURL url;
+    url.setPath(fullPath);
+    qWarning("url: %s", url.url().latin1());
+    partController()->editDocument(url);
   result.filename = filename;
-  result.dir = URLUtil::directory(relToProj);
+    result.dir = URLUtil::directory(fullPath);
   result.status = KDevCreateFile::CreatedFile::STATUS_OK;
+  }
+
   return result;
 }