Community
    • Login

    Showing File-Path in Tab or above editor window

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    17 Posts 5 Posters 3.0k 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.
    • Alan KilbornA
      Alan Kilborn @Stimmenhotel
      last edited by

      @Stimmenhotel

      The titlebar approach works if the tab you are interested in is the active one. Hovering the mouse over an inactive tab will cause a little popup to appear with the full path of the tab in it.

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

        @Stimmenhotel

        What’s your end goal?
        I presume it is to switch to the tab at a definite path (that you have in mind but can’t immediately see), but I wanted to make sure this would be your next step…

        1 Reply Last reply Reply Quote 0
        • mkupperM
          mkupper @Stimmenhotel
          last edited by

          @Stimmenhotel Please see https://community.notepad-plus-plus.org/topic/24627/rename-the-tab-not-the-file which is similar to what you are asking about.

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

            @mkupper said in Showing File-Path in Tab or above editor window:

            which is similar to what you are asking about

            I don’t think the OP here wants to rename tabs…

            1 Reply Last reply Reply Quote 0
            • Mark OlsonM
              Mark Olson
              last edited by

              Sadly, this is yet another person who would have benefited from my recent PR that enabled showing the directory or the path in the tab bar.

              I’m not even going to suggest that the OP raise an issue, because it will just get rejected as a duplicate. ☹️

              Alan KilbornA Mark OlsonM 2 Replies Last reply Reply Quote 4
              • StimmenhotelS
                Stimmenhotel
                last edited by

                To add further information:

                I am working with a few configuration files, one of them is on a test system inside a TEMP folder managed by WinSCP.
                The files have the same name, as I often compare them and check for errors and/or similarities.

                I think renaming tabs would not be possible, as the temp folder sometimes changes. Same for colorcoding.
                Also I am not exclusively use NP++ for this case, so closing and opening tabs, workfolders, searching, etc. happens a lot.

                @Mark-Olson That would have nailed the problem, yes. Sadly it was rejected.
                Does it still make sense to add a comment to the PR?
                Maybe this can be added as a plugin?

                I think I will stay with temporary coloring for now or change the read-only status.

                Thanks for your suggestions.

                Mark OlsonM 1 Reply Last reply Reply Quote 1
                • Alan KilbornA
                  Alan Kilborn @Mark Olson
                  last edited by

                  @Mark-Olson said in Showing File-Path in Tab or above editor window:

                  Sadly, this is yet another person who would have benefited from my recent PR that enabled showing the directory or the path in the tab bar.

                  I’m not even going to suggest that the OP raise an issue, because it will just get rejected as a duplicate.

                  Yes, but OP could add a comment in the rejected issue; this would help show the author that the functionality is important to yet another person.

                  1 Reply Last reply Reply Quote 3
                  • Alan KilbornA
                    Alan Kilborn
                    last edited by PeterJones

                    Perhaps a script helps here…

                    Maybe when you need to go to a specific file that you see over and over in your tabs (“So which tab do I want??”), you run a script and it shows you all of the paths to these same-named tabs, and from there you could double-click the one you need to navigate to, and it would take you there; example:

                    6987046c-419c-42e4-9933-ae90181f38bf-image.png

                    I call the script ListDuplicatelyNamedTabsShowingFullPaths.py :

                    # -*- coding: utf-8 -*-
                    from __future__ import print_function
                    
                    #########################################
                    #
                    #  ListDuplicatelyNamedTabsShowingFullPaths (LDNTSFP)
                    #
                    #########################################
                    
                    # references:
                    #  https://community.notepad-plus-plus.org/topic/24685
                    
                    #-------------------------------------------------------------------------------
                    
                    from Npp import *
                    import inspect
                    import os
                    
                    #-------------------------------------------------------------------------------
                    
                    class LDNTSFP(object):
                    
                        def __init__(self):
                    
                            self.this_script_name = inspect.getframeinfo(inspect.currentframe()).filename.split(os.sep)[-1].rsplit('.', 1)[0]
                    
                            self.this_script_path_without_ext = inspect.getframeinfo(inspect.currentframe()).filename.rsplit('.', 1)[0]
                            self.results_file = self.this_script_path_without_ext + '.txt'
                    
                            self.original_file = None
                    
                            editor.callback(self.doubleclick_callback, [SCINTILLANOTIFICATION.DOUBLECLICK])
                    
                        def run(self):
                    
                            pathlist_by_tabtext_dict = {}
                    
                            view_0_tabtext_list = []  # for detecting cloned-files
                    
                            for (pathname, buffer_id, index, view) in notepad.getFiles():
                                if not os.path.isfile(pathname): continue  # skip any soft-named tabs
                                tab_text = pathname.rsplit(os.sep, 1)[-1]
                                if view == 0:
                                    view_0_tabtext_list.append(tab_text)
                                elif tab_text in view_0_tabtext_list:
                                    continue  # don't consider a cloned file as a duplicate tab for purposes of this script
                                if tab_text not in pathlist_by_tabtext_dict:
                                    pathlist_by_tabtext_dict[tab_text] = [ pathname ]
                                else:
                                    pathlist_by_tabtext_dict[tab_text].append(pathname)
                    
                            results_file_line_list = [
                                'DOUBLE-CLICK A PATHNAME LINE TO CLOSE THIS FILE AND OPEN THAT PATHNAME',
                                'DOUBLE-CLICK SOMEWHERE IN WHITESPACE TO CLOSE THIS FILE AND RETURN TO ORIGINAL FILE',
                                '',
                            ]
                    
                            have_at_least_one_duplicate_tab_name = False
                    
                            for tab_text in pathlist_by_tabtext_dict:
                                if len(pathlist_by_tabtext_dict[tab_text]) > 1:
                                    have_at_least_one_duplicate_tab_name = True
                                    results_file_line_list.append(tab_text + ' :')
                                    for path in pathlist_by_tabtext_dict[tab_text]:
                                        results_file_line_list.append('\t' + path)
                    
                            if have_at_least_one_duplicate_tab_name:
                    
                                self.original_file = notepad.getCurrentFilename()
                    
                                notepad.activateFile(self.results_file)  # in case it is already open
                                if notepad.getCurrentFilename() != self.results_file:
                                    open(self.results_file, 'w').close()  # so notepad.open() won't prompt or fail on non-existent file
                                    notepad.open(self.results_file)
                                    assert notepad.getCurrentFilename() == self.results_file
                    
                                eol = ['\r\n', '\r', '\n'][editor.getEOLMode()]
                                editor.setText(eol.join(results_file_line_list))
                                notepad.save()
                                editor.setReadOnly(True)
                    
                            else:
                    
                                self.mb('Currently there are no duplicately named tabs.')
                    
                        def doubleclick_callback(self, args):
                    
                            if notepad.getCurrentFilename() == self.results_file:
                    
                                double_click_pos = args['position']
                    
                                if double_click_pos == -1:
                    
                                    # not close to any text; simply return to original document
                                    notepad.close()  # close the file double-clicked in
                                    if self.original_file is not None:
                                        notepad.activateFile(self.original_file)
                                        self.original_file = None
                    
                                else:
                    
                                    double_click_line = editor.lineFromPosition(double_click_pos)
                                    dclick_line_content = editor.getLine(double_click_line)
                                    pathname_to_open = dclick_line_content.strip()
                                    if os.path.isfile(pathname_to_open):
                                        notepad.close()  # close the file double-clicked in
                                        notepad.activateFile(pathname_to_open)
                                        self.original_file = None
                    
                        def mb(self, msg, flags=0, title=''):  # a message-box function
                            return notepad.messageBox(msg, title if title else self.this_script_name, flags)
                    
                    #-------------------------------------------------------------------------------
                    
                    if __name__ == '__main__':
                        try:
                            ldntsfp
                        except NameError:
                            ldntsfp = LDNTSFP()
                        ldntsfp.run()
                    

                    The script opens a new file and then waits for you to do something (i.e., double-click) in that file. When that happens, this special file closes and you are back on your way with what you need to work on next.

                    –
                    Moderator EDIT (2024-Jan-14): The author of the script has found a fairly serious bug with the code published here for those that use Mac-style or Linux-style line-endings in their files. The logic for Mac and Linux was reversed, and thus if the script was used on one type of file, the line-endings for the opposite type of file could end up in the file after the script is run. This is insidious, because unless one works with visible line-endings turned on, this is likely not noticed. Some detail on the problem is HERE. The script above has been corrected per that instruction.

                    1 Reply Last reply Reply Quote 3
                    • Alan KilbornA Alan Kilborn referenced this topic on
                    • Mark OlsonM
                      Mark Olson @Stimmenhotel
                      last edited by

                      @Stimmenhotel said in Showing File-Path in Tab or above editor window:
                      I’m glad that you think my PR would have been useful!

                      Maybe this can be added as a plugin?

                      In any case, the NavigateTo plugin is good for working with large numbers of files in general, and it’s also pretty good for dealing with files that have duplicate filenames.

                      6aeadafa-eaa9-4a1d-b66d-b6c74c0043dd-image.png

                      As shown in the above example, NavigateTo is really useful for sifting through files that may have the same name or similar names. If you do decide to use NavigateTo, I highly recommend downloading a recent release.

                      StimmenhotelS 1 Reply Last reply Reply Quote 3
                      • Alan KilbornA
                        Alan Kilborn
                        last edited by

                        Here’s NavigateTo showing my fileset…not bad:

                        b0daa1ec-817f-4a3e-ade2-f47588b26c0b-image.png

                        1 Reply Last reply Reply Quote 1
                        • StimmenhotelS
                          Stimmenhotel @Mark Olson
                          last edited by

                          @Mark-Olson Quite clunky, but perfect for now. Thanks for the recommendation.
                          @Alan-Kilborn Thanks for the script, I will try it anyway. Especially as it shows me the way of using scripts, I will definitely try it anyway.

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

                            @Stimmenhotel said in Showing File-Path in Tab or above editor window:

                            Quite clunky

                            I think you mean the NavigateTo approach?

                            I find invoking that plugin clunky (in the sense of keyboard usage) and have made a suggestion that it should be made better; see HERE.

                            1 Reply Last reply Reply Quote 0
                            • Mark OlsonM
                              Mark Olson @Mark Olson
                              last edited by

                              @Mark-Olson said in Showing File-Path in Tab or above editor window:

                              Sadly, this is yet another person who would have benefited from my recent PR that enabled showing the directory or the path in the tab bar.

                              After a little more discussion, the PR that I mentioned above is firmly rejected, so there is definitely no point in trying to comment there.

                              Maybe there is some other way that might get accepted to change Notepad++ directly to make duplicate files easier to work with, but it seems doubtful to me.

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

                                If you’ve used a script in this thread, you might want to double check your copy of it for a bug I’ve discovered.
                                Look to previous postings in this topic thread where the script has been changed – find the text moderator edit (2024-Jan-14).
                                There’s a link there that describes the bug in more detail, and shows what needs to be changed in an old copy (or you can simply grab a copy of the current version).

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