I would like to propose a new addition to already wonderful functions of:
Go back one location
Go forward one location
General: Most Recently Viewed File
which would be: Jump to last saved file
Usually in my workflow I have dozens of files that are open for reference and copy-from jobs, practically making their usage read-only, while there is always one file where I’m working on, which gets saved every once in a while. So, a function like that would help me always jump back to the file I’m pasting to, since that one would always be the last one saved.
I was informed that this could be achieved with a macro, but I have no idea where to start.
Any help on building such a macro would be greatly appreciated.
You could also use the Switch to Tab #1 command. Open commando (ctrl + shift + o), hit the command scope then search Switch. ALL of those commands can be mapped to a keybinding in your preferences. So that’s probably the easiest route but it will require that said file stay in one spot. Easy enough if you just leave it in position 1.
This should be easy enough in a macro as well. You’ll want the Komodo Extension Developer for the Javascript shell.
Once you’ve got that you’ll want the require("ko/views") SDK. Soon you’ll be able to reference it online in the new Komodo docs but that won’t be updated until 9.3 release. For now you can tab through results in the JS shell. eg. require("ko/views").|//press tab twice at the bar. Note a view is the entire editor Mozilla UI element which wraps a the file object inside itself as koDoc.
Some functions you’ll be interested in.
To get all open file objects:
require(“ko/views”).all(); //returns an array
var view1 = require(“ko/views”).all()[0];
Get current view:
require("ko/views").current().get();
Once you have a view, get it’s path:
var view = require("ko/views").current().get();
view.getURI();
Get the views filename:
`view.koDoc.baseName`
// filename.py
That should get you started. There are MANY functions wrapped up in there so have a look and please do ask questions.
Guys, thank you very much for your quick help and macro ideas.
@nathanr, however I can’t make that code to work.
I don’t understand what is wrong with it and I get weird errors from Komodo that I don’t understand.
First time I put it in a macro and run it I got ‘type error extensions.goToLastSaved is undefined’.
Then I tried to remove the first IF part, and now I get “undefined: The command ‘undefined’ is already in use”
@AtmanActive, thanks for confirming. At line 27 goToLastSaved isn’t defined. This information was in the logs but not in the alert window which isn’t as helpful. I’m going to file a bug on that.
Just to clarify for someone reading this later:
The macro above should be set to autorun on Komodo start. That’s in macro’s properties->triggers.
So, this macro runs once on startup to initialize the functionality and that’s it.
Next, create another new macro to actually invoke this function. The one that can be included in the toolbar:
komodo.assertMacroVersion(3);
if (komodo.view) { komodo.view.setFocus(); }
ko.commands.doCommand('cmd_goto_lastsaved')
ko.commands.doCommand('cmd_focusEditor')