Community
    • Login

    Set current directory to default if no real file is open

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 4 Posters 287 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • fml2F
      fml2
      last edited by fml2

      I’d like to explain the rationale behind the question.

      When I start NP++, the current folder is set to “Desktop”. This is the basic setup. The files I’m usually editing are not far from there.

      Sometimes, however, I edit files from other directories, maybe network ones. When I close the last such file I want the situation to return back to the basic setup. So that e.g. when I bring up the Open File dialog (Ctrl+O) it shows me the Desktop.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @fml2
        last edited by PeterJones

        @fml2 ,

        There isn’t a hybrid mode. The Default Directory settings are described in the User Manual. Either it always follows the current document (or most recent real document), or it always uses the directory of the last Open or Save action, or it always goes to the static default directory.

        As a workaround, you could use the Run menu:

        • Run > Run cmd /c "echo "%USERPROFILE%\Desktop" | clip"
        • Save…, assign a name (DesktopToClipboard or whatever) and a keyboard shortcut

        This would put DesktopToClipboard in the Run menu (and that shortcut), so anytime you’re about to go from a “new” file, you could use that menu action or shortcut, then when you Save your new file, you can paste in that value. It’s not exactly what you want, but it saves you having to navigate there yourself. (And, obviously, if your Desktop folder weren’t where you wanted the destination, put that directory in rather than Desktop before you initially Save… the Run action)


        update: switched to Desktop instead of Documents, since that’s what you said in your second post.

        1 Reply Last reply Reply Quote 1
        • fml2F
          fml2
          last edited by

          Thank you @PeterJones for the quick and detailed reply!

          What do you think, would the following proposal have a chance to be implemented?

          There is already a field for the custom directory in the settings. There could be a checkbox next to it saying “use it if there are no real files open”. If checkmarked (but as the radio button, the “follow current file” would be selected), the behaviour would be exactly like I want it to be.

          If there is a chance, I’d create an issue in the project on GitHub.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @fml2
            last edited by

            @fml2,

            What do you think, would the following proposal have a chance to be implemented?

            I don’t personally think it’s a bad idea, so I doubt it would be rejected out-of-hand. My guess is there might be a delay before someone volunteers to implement it, but I don’t think it’s out of the realm of possibility.

            But that’s just my opinion, and my guesses on such things have been wrong before.

            1 Reply Last reply Reply Quote 0
            • fml2F
              fml2
              last edited by

              I’ve thought about it a little bit more and see that what I wrote above is not an intuitive behaviour at all and is actually not what I want.

              What I probably really want is to be able to set the current working directory (which, to my understanding, is being tracked internally by Notepad++) to some standard value. So that when I bring up the Open File dialog next time, it shows that directory.

              Is there a command in NP++ to set the current directory to a desired value?

              1 Reply Last reply Reply Quote 0
              • fml2F
                fml2
                last edited by

                I’ve looked into the python script documentation but found nothing. The only method I found that somehow deals with directories (notepad.getNppDir()) does not what I need. I’ll create a feature request in the plugin.

                Alan KilbornA 1 Reply Last reply Reply Quote 1
                • Alan KilbornA
                  Alan Kilborn @fml2
                  last edited by Alan Kilborn

                  @fml2

                  If you’re open to a scripted solution, I think it could be achieved, if I’m understanding what you want well enough.

                  Write a script, assign it to be invoked when the keycombo for the normal save is pressed (Ctrl+s).

                  Within the script, check to see if the active tab is a file on disk. If it is, invoke normal Notepad++ save and exit the script.

                  Since it has been established that only unsaved tabs are now present, If not, check to see if all other open tabs are files on disk. If they are, invoke normal Notepad++ save and exit the script.

                  Since it has been established that only unsaved tabs are now present, save the file with more script code with the default directory of that save being the desktop folder.

                  EDIT: Oh, just noticed your posting about “current directory”. I’m not entirely sure, but I don’t believe that Notepad++ does anything valuable with that.

                  1 Reply Last reply Reply Quote 1
                  • fml2F
                    fml2
                    last edited by fml2

                    I’ve created two feature requests: one in Notepad++ and another in the Python Script plugin (and cross referenced them), since I don’t know where this feature would be better impemented.

                    • https://github.com/notepad-plus-plus/notepad-plus-plus/issues/17246
                    • https://github.com/bruderstein/PythonScript/issues/401
                    CoisesC 1 Reply Last reply Reply Quote 0
                    • Alan KilbornA
                      Alan Kilborn
                      last edited by

                      This thread seems related: https://community.notepad-plus-plus.org/topic/26900

                      1 Reply Last reply Reply Quote 0
                      • CoisesC
                        Coises @fml2
                        last edited by

                        @fml2 said in Set current directory to default if no real file is open:

                        I’ve created two feature requests: one in Notepad++ and another in the Python Script plugin (and cross referenced them), since I don’t know where this feature would be better impemented.

                        • https://github.com/notepad-plus-plus/notepad-plus-plus/issues/17246
                        • https://github.com/bruderstein/PythonScript/issues/401

                        I commented to your Notepad++ issue with a UI/design suggestion; hopefully no one will mind me repeating it here.

                        What would you and others think of this idea?

                        At Settings | Preferences… | Default Directory, indented beneath the bottom radio button (where you can specify a default directory), add a checkbox labeled Apply only to Open/Save on new tabs; otherwise follow current document.

                        The behavior when that box is checked would be as follows:

                        When the active tab already has a file on disk associated with it, behavior is the same as Follow current document: Open…, Save As… and Save a Copy As… open a file dialog in the directory that contains the file, and Save just saves the file in place.

                        When the active tab is new — does not have a file on disk associated with it — Open… and Save open a file dialog in the designated default directory. Save As… and Save a Copy As… behave as Follow current document does now: they open a file dialog in the directory corresponding to the most recently active tab that was associated with a file on disk.

                        That way you can still save new files in the directory in which you are already working by using Save As…, or in the default directory by using Save. Opening a file when the active tab has a file on disk would start the open dialog in the same directory, while opening the first file in a session would go to the default directory without the need to modify the Start In property of the Notepad++ shortcut.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors