Tabbed File Editing
I would love to see tabbed editing implemented in the native pythonista editor, but in the meantime I've come up with a work-around. Tabs is a sidebar that allows you to add the current file as a tab (it will ask you to name the tab). There are probably better ways to do some of these things (I'm still learning a lot about programming), but it works. There are still some things that could be improved, so I welcome advise and tips for improvment. Feel free to improve it yourself (and share it back).
Just to note: this app will create a database file to store your tabs in. This allows you to close it and resume your session later without losing your tabs. It's meant to be in your actions list, so you can quickly reload your tabs. If you move or delete a file one of the tabs is referencing, it will throw it off. Just delete the database file and rerun it. I may try to fix this in the future.
I'm fairly certain thath there are methods like
editormodule, those should be easy to integrate.
get/set_selection() would be good. How would you easily force the displayed screen to put the selection mid screen. Setting the selection does not "scroll" the window.
The key line is the last.... If you call replace_text, the editor will scroll. Calling setting the start and end offset the same, and using an empty string ensures you don't actually change anything, but the editor scrolls just the same. The part that is hard to control is where the offset ends up on the screen. I believe there is a way by scrolling twice to have a little more control, (I.e overshooting, then backing up, as it does depend on the direction you are moving)... But this code just tries to keep a little context on screen.
By the way, not sure if smath ever publicized it, but this repo is an integration with his awesome Tabs with [editmenu] (https://github.com/jsbain/editmenu) one button block comment/uncomment, block indenting, cut,copy,paste, and execute the selected block in current interpreter session). Smath also added find and replace functionality, which makes this a sweet little package.
By the way, I had considered this in the past.... While it would be easy to save/resume the position when switching from the tab itself, we don't have any way to trigger an action when opening a file from the usual pythonista browser.. I guess the main use case would be switching back and forth between two files, so maybe that's ok. An alternative would be to poll the editor's file name and line number periodically, and update the database. I'm not sure if the editor sidebar and main ui run in different threads, if not there would be some risk of freezing.
editmenu with Tabs has now been updated to include saving of last selection/cursor location, and restoring it when switching tabs!
Also, I converted Tabs over to a class to fix problems with namespace collisions in some cases.
Also, the previous editmenu/Tabs mashup didn't keep the tabs database in a fixed location, resulting in lost tabs when running from action menu.
Now it does.
As an aside, I switched over from sqllite3 to shelve, because well it is easier for me to understand! This makes future enhancements easier, also, otherwise there has to be a lot of logic to add new columns, etc.
Where should this get installed. I getting a lot of file not found errors for the components (pyui and py files)
You should download all files into one folder, but the specific location shouldn't matter... Mine sits in an editmenu folder off of the ~/Documents folder. Use GitHubGet, gitview, or your favorite git manager to download. You should run editmenu.py first, that's probably the most tested, everything else is accessible from the buttons
JonB - I just downloaded the current version from github and am getting an error:
Traceback (most recent call last): File "./Tabs.py", line 78, in move self.sv.subviews[i].y -= self.tab_width*1.05 NameError: global name 'tab_width' is not defined
I've even changed the reference to self.tab_width to be self.width, and get the exact same error.
Whoops, my bad. Apparently when I tested this, I had the global tab_width still in the namespace, so the code appeared to work. I just checked in an update...
Actually, I'm a little confused by the traceback, since it implies tab width was a global, instead of an attribute of self (the fix I checked in added a self to that line where there was none before)
I checked with a fresh pull, so try again?