Auto sort tabs (real-time)
-
@Alan-Kilborn said in Auto sort tabs (real-time):
Didnât you, at one time, face a similar issue?
I think you did --> https://github.com/bruderstein/PythonScript/issues/153
But maybe doesnât apply in my case, as issue 153 seems to indicate that âNotepadâ object callbacks donât suffer this fate, just âEditorâ object callbacksâŚ
-
Your script is installing/uninstalling for me. Maybe this isnât
fixed in PS2?? Let me give it a try with 1.5.X -
Yep, the same script that works with PS3 does not uninstall the callback when you using PS2.
-
@Ekopalypse said in Auto sort tabs (real-time):
Yep, the same script that works with PS3 does not uninstall the callback when you using PS2.
Thanks for the confirmation.
I keep forgetting about PS3.
But, in truth, I have a few project where I need non-UTF8 encodings, so Iâm a bit afraid to make the jump anyway.
I will make a note in my copy of the script that it canât be uninstalled under PS2.
But, if it is something that someone will use, I donât think theyâll uninstall it, and will set up the install part in startup.py. -
@Alan-Kilborn said in Auto sort tabs (real-time):
The ideal way would be to tie it into the âbuffer activatedâ callback.
So I ended up doing this to the script.
To avoid the script âretriggeringâ itself, I added a new member variable in the init:self.is_installed = False
and then changed the callback function (its name, too!) a bit:
def buffer_activated_callback(self, args): if self.in_callback: return # the script moving tabs around will cause more callbacks to trigger; prevent this self.in_callback = True ... ...what it was doing before... ... self.in_callback = False
It seems to work okay.
If thereâs interest, I can republish the entire script with the mods. -
@Alan-Kilborn said in Auto sort tabs (real-time):
I added a new member variable in the init:\
self.is_installed = False ... if self.in_callback:
Was that a typo in the first line, or am I confused and those are two separate things?
Assuming that first line should have been
self.in_callback = False
, I was able to see that work for me.Itâs fun to try to âfightâ it: try to rearrange the tabs manually while the script is in effect. ;-) But I guess the kind of person who would want this running all the time would not be the kind who would try to fight it, so wouldnât accidentally trigger the fight.
Good work on that.
Given that it was multiple changes (adding a variable, changing method name, changing the notification itâs hooked to), it might be good to re-publish, so that future readers wonât make mistakes while piecing the script together, and then complain at you that it doesnât work.
Thanks for the fun diversion.
-
@PeterJones said in Auto sort tabs (real-time):
Was that a typo in the first line
Yep, dammit. Sorry.
it might be good to re-publish
OK, will do.
-
Itâs fun to try to âfightâ it: try to rearrange the tabs manually while the script is in effect. ;-)
I certainly did NOT do any type of testing like that!
If it fails during something of that nature, well, sorry, but the user is to blame in that case. :-)and then complain at you that it doesnât work.
Hey, how did you make that little complain-at-you popup text?
Okay, so hereâs an âaâ version of the script, with all the changes previously discussed:
# -*- coding: utf-8 -*- from Npp import editor, notepad, NOTIFICATION import os class SFTBFa(object): def __init__(self): self.installed = False self.in_callback = False def install(self): if not self.installed: notepad.callback(self.buffer_activated_callback, [NOTIFICATION.BUFFERACTIVATED]) self.installed = True def uninstall(self): if self.installed: notepad.clearCallbacks(self.buffer_activated_callback) # <---- may not work until PS 3.0.4+; see https://github.com/bruderstein/PythonScript/issues/153 self.installed = False def is_installed(self): return self.installed def buffer_activated_callback(self, args): if self.in_callback: return # the script moving tabs around will cause more callbacks to trigger; prevent this self.in_callback = True current_view = notepad.getCurrentView() other_view = 1 if current_view == 0 else 0 if notepad.getCurrentDocIndex(other_view) == 4294967295L: other_view = None curr_view_paths_list = []; curr_view_sorted_paths_list = [] other_view_paths_list = []; other_view_sorted_paths_list = [] for (filename, _, index_in_view, view) in notepad.getFiles(): if view == current_view: curr_view_paths_list.append(filename) curr_view_sorted_paths_list.append(filename) else: other_view_paths_list.append(filename) other_view_sorted_paths_list.append(filename) curr_view_sorted_paths_list.sort(key=lambda x: x.rsplit(os.sep, 1)[-1].upper()) curr_view_already_sorted = True if curr_view_paths_list == curr_view_sorted_paths_list else False other_view_sorted_paths_list.sort(key=lambda x: x.rsplit(os.sep, 1)[-1].upper()) other_view_already_sorted = True if other_view_paths_list == other_view_sorted_paths_list else False if not (curr_view_already_sorted and other_view_already_sorted): processed_other_view = False if other_view != None and not other_view_already_sorted: self.rearrange_tabs_in_view(other_view, other_view_sorted_paths_list) processed_other_view = True processed_current_view = False if not curr_view_already_sorted: self.rearrange_tabs_in_view(current_view, curr_view_sorted_paths_list) processed_current_view = True if processed_other_view and not processed_current_view: # leave the view we started in as the active one: notepad.activateIndex(current_view, notepad.getCurrentDocIndex(current_view)) self.in_callback = False def rearrange_tabs_in_view(self, view, sorted_name_list): notepad.activateIndex(view, notepad.getCurrentDocIndex(view)) # get switched into the correct view remembered_active_filename = notepad.getCurrentFilename() destination_index = 0 num_of_tabs = len(sorted_name_list) while destination_index < num_of_tabs: current_order_list = [] for (filename, _, index_in_view, v) in notepad.getFiles(): if v == view: current_order_list.append(filename) curr_location_index = current_order_list.index(sorted_name_list[destination_index]) move_left_count = curr_location_index - destination_index if move_left_count > 0: notepad.activateFile(current_order_list[curr_location_index]) for _ in range(move_left_count): notepad.menuCommand(MENUCOMMAND.VIEW_TAB_MOVEBACKWARD) destination_index += 1 notepad.activateFile(remembered_active_filename) if __name__ == '__main__': if 'sftbf_a' not in globals(): sftbf_a = SFTBFa() # each running of the script toggles install/uninstall: sftbf_a.uninstall() if sftbf_a.is_installed() else sftbf_a.install() notepad.messageBox('SortFileTabsByFilename {}INSTALLED!'.format('' if sftbf_a.is_installed() else 'UN'), '')
-
@Alan-Kilborn said in Auto sort tabs (real-time):
how did you make that little complain-at-you popup text?
I think that I may haveâŚ
Well, not quite, because when I click on mine it takes me somewhere (bad) whereas clicking on @PeterJones 's it doesnât go anywhere.
-
@Alan-Kilborn said in Auto sort tabs (real-time):
Hey, how did you make that little complain-at-you popup text?
See How to Markdown Code on this forum. đ
No, really, itâs there:
This is a simple [here](https://www.google.com âgo Google!â) link with custom hover pop-up text
The popup hover text is the âtitleâ text of the link. Itâs also described at the no-longer-officially-linked daringfireball markdown spec
And then, while Iâm typing, you said
I think that I may have [figured it out myself]âŚ
Congrats. Of course, if I werenât wanting the bragging rights, I wouldnât have been able to post this reply, since you went and figured it out.
Well, not quite,
Oh, sure, you realize you had a problem while I am still writing about your problem. Let me type this reply! đ
[text](# "hover")
will do what you want. The#
is the HTML shortcut for âgo to the unnamed anchor on the current pageâ, which has been HTML shorthand for âdo nothing with this linkâ forever (or, at least, from early forms of HTML in the 90s) -
looks like auto-sort is really a rocket scienceâŚ
-
@Maxitrol-Mat said in Auto sort tabs (real-time):
looks like auto-sort is really a rocket scienceâŚ
Why do you say that?
-
Regardless of otherâs sense of entitlement, I certainly appreciate the free software of notepad++ :D
@alan-kilborn, I have a couple of questions:
-
How could I modify this to work so I can get my tabs to sort by âcreation dateâ since I accidentally sorted by âNameâ when I hit that âSort Tabsâ button in the existing feature? ⌠Maybe there is a simpler method since Iâm not in need of automation?
-
Also, how does one run a script for notepad++?
Btw, there is another post for my particular request by @Ashil-Krishnan here, but no solution. However, @PeterJones referenced this post, which brought me here to inquire.
Thanks!
-
-
-
@daniel-tomberlin said in Auto sort tabs (real-time):
sort by âcreation dateâ
This may be problematic as tabs unsaved into the filesystem, with names such as
new 1
,new 3
, etc. make determining a âcreation date/timeâ difficult. -
@daniel-tomberlin said in Auto sort tabs (real-time):
how does one run a script for notepad++?
Well presuming you mean a PythonScript, and thus that you have that plugin installed, and a script file created and saved, the most basic way of running it is to pull down this menu structure and select your desired script:
You can also bind a script running to a keycombination for easier execution.
-
@alan-kilborn, I see. I presume it would be the same for âmodified dateâ too. Well, Iâll keep my eye out in case you feel like conducting another âmental exercise.â ;)
Btw, thanks for the script tip!
-
@daniel-tomberlin said in Auto sort tabs (real-time):
Well, Iâll keep my eye out in case you feel like conducting another âmental exercise.â
Unlikely because I never work with unsaved tabs (such as the mentioned
new 1
, etal). I did the original script because I thought it might be of some use to me. I donât tend to code âcomplicated thingsâ for others if I have no use for them. -
@alan-kilborn, ah, I understand.
Just an FYI, I did notice that the sessions.xml file in the Notepad++ folder under âŚ\AppData\Roaming\ path does have a date at the end of the âbackupFilePathâ parameter. So the end of the path reads ââŚ\new1@yyyy-mm-dd_123456,â however, saved file paths do not have anything populated in that parameter. There are also the parameters âoriginalFileLatModiTimestampâ and âoriginalFileLatModiTimestampHighâ that are â0â in the ânewâ tab, but have 8 numbers in the saved file, one negative and the other positive respectively. I may be able to figure out a way to manually sort my tabs by modifying the startPos=â2488â and endPos=â2488â in this file if I figure out what those numbers mean, including the number at the end of the aforementioned âbackupFilePathâ parameter too.
Btw, below is an example of what Iâm seeing in case anyone has any answers here, but maybe answer on the other post as it is more appropriate.
<File firstVisibleLine="0" xOffset="0" scrollWidth="9423" startPos="120" endPos="120" selMode="0" offset="0" wrapCount="1" lang="SQL" encoding="-1" userReadOnly="no" filename="\\mypath\myfilename.sql" backupFilePath="" originalFileLastModifTimestamp="-386892058" originalFileLastModifTimestampHigh="30736076" mapFirstVisibleDisplayLine="-1" mapFirstVisibleDocLine="-1" mapLastVisibleDocLine="-1" mapNbLine="-1" mapHigherPos="-1" mapWidth="-1" mapHeight="-1" mapKByteInDoc="1140719616" mapWrapIndentMode="-1" mapIsWrap="no" /> <File firstVisibleLine="6" xOffset="0" scrollWidth="3990" startPos="2488" endPos="2488" selMode="0" offset="0" wrapCount="18" lang="SQL" encoding="-1" userReadOnly="no" filename="new 1" backupFilePath="C:\Users\username\AppData\Roaming\Notepad++\backup\new 1@2020-09-01_101742" originalFileLastModifTimestamp="0" originalFileLastModifTimestampHigh="0" mapFirstVisibleDisplayLine="-1" mapFirstVisibleDocLine="-1" mapLastVisibleDocLine="-1" mapNbLine="-1" mapHigherPos="-1" mapWidth="-1" mapHeight="-1" mapKByteInDoc="0" mapWrapIndentMode="-1" mapIsWrap="no" />
Anyway, thanks for the reply.
-
Are you posting the exact same comment in TWO threads? If so Iâd say âWhy?â and also âThatâs not a great ideaâ.
-
@alan-kilborn, not exactly. One is speaking to you with reference to the other post. Iâm basically cross posting the code part since itâs related.