New file (Shift+F4) behaviour
Closed, ResolvedPublic

Description

When the user presses F7, the window is filled with the current item's name

diff --git a/krusader/Panel/panelfunc.cpp b/krusader/Panel/panelfunc.cpp
index ba1b069..62ee3ab 100644
--- a/krusader/Panel/panelfunc.cpp
+++ b/krusader/Panel/panelfunc.cpp
@@ -712,7 +712,7 @@ void ListPanelFunc::rename(const QString &oldname, const QString &newname)
 void ListPanelFunc::mkdir()
 {
     // ask the new dir name..
-    QString dirName = QInputDialog::getText(krMainWindow, i18n("New directory"), i18n("Directory's name:"));
+    QString dirName = QInputDialog::getText(krMainWindow, i18n("New directory"), i18n("Directory's name:"), QLineEdit::Normal, panel->getCurrentName());
 
     // if the user canceled - quit
     if (dirName.isEmpty())

the text is already selected, so if the user doesn't want this hint, he can just start typing. The patch just uses panel->getCurrentName() but we could remove the extension for files (like in TC) - QFileInfo(panel->getCurrentName()).completeBaseName() - or totally disable it for directories.

gengisdave added a project: Krusader.

Good idea! I'm up for stripping the file extension if file is the focused item.

I'd also like to suggest that we do a similar thing then creating a new text file (Shift + F4). In this case I'd probably prefer the whole file name along with extension.

asensi added a comment.Apr 9 2016, 4:35 PM

Good idea! I'm up for stripping the file extension if file is the focused item.

I'd also like to suggest that we do a similar thing then creating a new text file (Shift + F4). In this case I'd probably prefer the whole file name along with extension.

Yes! :-) Other file managers do it that way and it saves people from copying, from pasting, and in the end it saves time!

If I create a new file using an existing name, the old file is asked to be overwritten with a zero length file; I think it should be opened for editing.

This means Shift+F4 plus Enter is an alternative to F4; if you change the name (and it doesn't exists) a new file is created.

gengisdave renamed this task from Use current item's name in New Directory window to New file (Shift+F4) behaviour.Apr 10 2016, 8:02 AM
gengisdave moved this task from TODO to In progress on the Krusader board.
void ListPanelFunc::edit()
{
    QString name = panel->getCurrentName();
    if (name.isNull())
        return ;

    /* cutted code */

    KrViewer::edit(files() ->vfs_getFile(name));
}

void ListPanelFunc::editNew()
{
    if(!fileToCreate.isEmpty())
        return;

    // ask the user for the filename to edit
    fileToCreate = KChooseDir::getFile(i18n("Enter the filename to edit:"), panel->virtualPath(), panel->virtualPath());
    if(fileToCreate.isEmpty())
        return ;   // the user canceled

    QTemporaryFile *tempFile = new QTemporaryFile;
    tempFile->open();

    KIO::CopyJob *job = KIO::copy(QUrl::fromLocalFile(tempFile->fileName()), fileToCreate);
    job->setUiDelegate(0);
    job->setDefaultPermissions(true);
    connect(job, SIGNAL(result(KJob*)), SLOT(slotFileCreated(KJob*)));
    connect(job, SIGNAL(result(KJob*)), tempFile, SLOT(deleteLater()));
}

These are the two methods involved; before creating the new file, we check if the same name exists in the given path, if positive, we pass the file name/path to edit(). Where edit() (F4) is limited to the current Panel, with Shift+F4 we can create/edit a file everywhere.

gengisdave closed this task as Resolved.Jun 19 2016, 7:44 PM
gengisdave moved this task from In progress to Done on the Krusader board.Oct 10 2016, 8:47 PM