Problem: I have a macro that works when run from a
custom keybinding but it does not work when run from
the Tool menu.
komodo.view.setFocus();
komodo.doCommand('cmd_focusEditor'); /// added in just to be extra sure
komodo.doCommand('cmd_selectWordLeft'); /// this NO_WORKYThe specific part that fails is cmd_selectWordLeft.
Question: Is there a way to ensure that macro commands
will *always* work regardless of what context the user
chooses to invoke them from?
There are currently some issues with komodo.docommand and some commands. To work around this, change this line:
komodo.doCommand("cmd_selectWordLeft");
to this instead:
komodo.editor.wordLeftExtend();
Posted by: jeffg | April 18, 2006 at 10:37 PM
(http://blogs.activestate.com/jeffg/2005/09/komodo_hacks_pa.html)
I've spent some time trying to fix this, and here's the problem:
Each of the Komodo "cmd_*" commands execute inside a particular
"controller". When you've created a macro, the controller is
associated with the editor view. But when you save the macro
in a toolbox, it executes in that project's controller, and
it can't figure out how to get to the editor.
I suppose we could fix this, but in general it's better
to try to move your macros from using the Komodo commands
to working with the Komodo API more directly. Which is
what you did above, after whatever googling finding the
fix required.
- Eric
//if (komodo.view) { komodo.view.setFocus() };
if (komodo.view.scintilla) { komodo.view.scintilla.focus(); }
... and some duplicates. Todd figured out the solution a while
ago, but his change didn't get released. Nice work.
Ref: http://bugs.activestate.com/show_bug.cgi?id=53647
If you want to patch it, you'll need to dig macros.js out of komodo.jar,
and apply this patch:
===================================================================
--- src/chrome/komodo/content/library/macros.js (revision 25990)
+++ src/chrome/komodo/content/library/macros.js (working copy)
@@ -35,7 +35,7 @@
this._currentMacro.push("// Macro recorded on " + Date() + '\n');
var macroVersionNumber = "2"; // must match the number in peMacro.js
this._currentMacro.push('komodo.assertMacroVersion(' + macroVersionNumber + ');\n');
- this._currentMacro.push("if (komodo.view) { komodo.view.setFocus() };\n");
+ this._currentMacro.push("if (komodo.view && komodo.view.scintilla) { komodo.view.scintilla.focus(); }\n");
this._currentMacroText = new Array();
}
this.mode = 'recording';
Index: src/chrome/komodo/content/library/macros.js =================================================================== --- src/chrome/komodo/content/library/macros.js (revision 25990) +++ src/chrome/komodo/content/library/macros.js (working copy) @@ -35,7 +35,7 @@ this._currentMacro.push("// Macro recorded on " + Date() + '\n'); var macroVersionNumber = "2"; // must match the number in peMacro.js this._currentMacro.push('komodo.assertMacroVersion(' + macroVersionNumber + ');\n'); - this._currentMacro.push("if (komodo.view) { komodo.view.setFocus() };\n"); + this._currentMacro.push("if (komodo.view && komodo.view.scintilla) { komodo.view.scintilla.focus(); }\n"); this._currentMacroText = new Array(); } this.mode = 'recording';