PDA

View Full Version : Jump to last saved file



MichaelOxley
10-02-2015,
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.
Thanks.

Mikelance
10-03-2015,
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 (http://komodoide.com/packages/addons/komodo-developer-extension/) 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 (http://beta.docs.komodoide.com/SDK/api/commonjs) 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.pyThat should get you started. There are MANY functions wrapped up in there so have a look and please do ask questions.
Oh one last function you'll want: view.focus() //http://forum.komodoide.com/images/emoji/apple/wink.png?v=0


Carey

micoul81
10-04-2015,
Here's a simple userscript (macro) I quickly threw together:
if (extensions.goToLastSaved)
{
window.removeEventListener("file_saved", extensions.goToLastSaved.onFileSave);
require("ko/commands").unregister("goto_lastsaved");
}

(function() {

var lastView = null;

this.onFileSave = function()
{
lastView = ko.views.manager.currentView;
}

this.onGoto = function()
{
var v = ko.views.manager.currentView;
if (lastView && v != lastView)
xtk.domutils.fireEvent(lastView.parentNode._tab, 'click');
}

require("ko/commands").register("goto_lastsaved", this.onGoto, {label: "Go to Last Saved"});
window.addEventListener("file_saved", extensions.goToLastSaved.onFileSave);

}).apply(extensions.goToLastSaved)

Mark C.Smith
10-05-2015,
They compliment each other! Excellent!


Carey