Scripting
From makagiga
Contents |
Custom Tool Bar Actions
Creating a new action
- Right-click on an empty tool bar area
- Select New Action...
- Optionally select icon, enter a short name and description
- Select a script language you want to use (NOTE: currently only JavaScript is fully supported)
- Click Create - a built-in Script Editor will appear
- Right-click on the new action button again to change its properties
Using the Script Editor
- Type a JavaScript code (TIP: Use Snippets menu to paste useful code samples)
- Click Test (F9) to compile and test the code
- Click Save to save changes and close editor
Examples
Convert selected text to lower case (works with Notepad editor)
importClass(javax.swing.text.JTextComponent);
importClass(org.makagiga.commons.MMessage);
importClass(org.makagiga.commons.MStatusBar);
importClass(org.makagiga.editors.Editor);
var core = Editor.currentCore;
if (core instanceof JTextComponent) {
var text = core.selectedText;
if (text) {
core.replaceSelection(text.toLowerCase());
}
else {
MStatusBar.info("No text selection");
}
}
Insert text (works with Image editor/viewer)
importPackage(java.awt);
importClass(org.makagiga.editors.Editor);
importClass(org.makagiga.editors.image.ImageEditorCore);
importClass(org.makagiga.commons.MMessage);
var core = Editor.currentCore;
if (core instanceof ImageEditorCore && core.canDraw()) {
var text = MMessage.input(null, "Enter text", "Text:", "Insert Text");
if (text) {
core.beforeModification(); // save current image for Undo
var g = core.canvas.createGraphics();
g.color = Color.WHITE; // text color
var size = 32; // font size
g.font = new Font("Dialog", Font.BOLD, size);
var fm = g.fontMetrics;
g.drawString(
text,
core.canvas.width / 2 - fm.stringWidth(text) / 2, // x
(core.canvas.height / 2 - size / 2) + fm.ascent // y
);
g.dispose();
core.afterModification(); // update Undo data
}
}
Full screen vim-like view ;-) (works with Notepad editor)
importClass(java.awt.Color);
importClass(java.awt.Font);
importClass(org.makagiga.editors.Editor);
importClass(org.makagiga.editors.notepad.NotepadEditorCore);
var notepad = Editor.currentCore; // get active editor/tab
if (notepad instanceof NotepadEditorCore && notepad.editable) {
notepad.background = Color.BLACK;
var fg = new Color(0x66cc00);
notepad.caretColor = fg;
notepad.foreground = fg;
notepad.font = new Font(Font.MONOSPACED, Font.PLAIN, notepad.font.size);
// switch to full screen
org.makagiga.tools.presentation.Presentation.active = true;
}
User Script (user.js)
User Script is a simple JavaScript file executed on application startup.
The default file location is:
[Makagiga profile folder]/scripts/user.js
(e.g. /home/username/.makagiga/scripts/user.js)
See menu -> Help -> About -> System to get Makagiga profile folder.


