Application global object.
An Application global object is created for you and only this object can exist in the application. It is named Application and is globally accessible, you can also access its properties directly.
none.
global name space.
ECMerge 2.1
The Application object let you access global information about the running application.
Property | Description |
current_frame | DocumentFrame object. Read-Only. Active frame in the graphical user interface, null if there is no active frame |
executable_path | String. Read-Only. Path to the running executable. |
initial_document | Document object. Read-Only / Available only during initial scripts (undefined else). This document is the document built from the command line arguments. |
script_url | URL object. Read-Only / Available only during initial scripts (undefined else). This URL points to the currently run script. |
scripts_generation | Number. Read-Only. This number gets incremented each time 'Reload macro scripts' is executed, it allows several scripts to cooperate as they know if they are run during a same reload or during successive reloads. |
scripts_settings | Object. This object is serialized with toSource() and saved to ECMerge settings file. It is reloaded at application startup with eval() thus restoring this object. This object is to be used to store MRUs and settings for the macro-commands. |
ui_language | Locale String. Read-Only. Language used for the User Interface as a locale code (such as: en_US, fr or de) |
version | String. Version number of ECMerge, as MAJOR.MINOR.BUILD (e.g. "2.1.65") |
add_frame
alert
choose
clone_options_set
clone_shared_options
confirm
execute_macro
exit
gc
get_options_sets_names
log
popup_menu
prompt
prompt_with_choices
set_shared_options
see functions samples.
Document object, DocumentFrame object.
function add_frame (document, focus)
returns a DocumentFrame
document. Document
object. Document to be viewed
focus. Boolean. True to give the focus immediately to this
frame
Application.
ECMerge 2.1
Adds a frame to view a document.
Loads a document from an ECMT file then add a view for it:
var doc = Document.load
("/home/user/myecmt.ecmt");
add_frame (doc, true);
DocumentFrame object
function alert (text)
text. String. Text to display
Application
ECMerge 2.1
Displays a text in a message box
Displays the famous "hello world!" message:
alert ("hello world!");
function choose (prompt, text1, text2, text3...)
function choose (prompt, texts_array)
returns chosen index or -1 if cancelled
function prompt_with_choices (prompt, text1, text2,
text3...)
function prompt_with_choices (prompt, texts_array)
returns chosen text or undefined if cancelled
prompt. String. Prompt to display to the user.
text1, text2, text3... String. Text to display in order.
texts_array. Array of String. Each element is displayed from 0
to length-1 in order.
Application
ECMerge 2.1
prompt_with_choices was introduced in ECMerge 2.2
Let the user choose from a list of text strings, with a prompt.
Prompt the user for a color then displays the index.
var chosen_color = choose ("Please choose a color:",
"blue", "red");
if (chosen_color != -1)
alert ("index " + chosen_color + "was
chosen");
Prompt the user for a color from an Array then displays the chosen color.
var colors = ["blue", "red", "yellow", "white"];
var chosen_color = choose ("Please choose a color:",
colors);
if (chosen_color != -1)
alert ("color:" +
colors[chosen_colors]);
Prompt the user for a color from an Array then displays the chosen color, letting the user type in another color.
var colors = ["blue", "red", "yellow", "white"];
var chosen_color = prompt_with_choices ("Please choose a
color:", colors);
if (chosen_color)
alert ("color:" + chosen_colors);
function clone_options_set ( name )
returns an OptionsSet
object
name. String. Name of the OptionsSet to retrieve
Application.
ECMerge 2.1
Returns a clone of the named OptionsSet.
Applies an OptionsSet to an existing document:
var params = mydoc.parameters.clone ( );
params.settings = Application.clone_options_set
(Application.get_options_sets_names( ) [0]);
mydoc.parameters = params;
OptionsSet object
function clone_share_options ( )
returns a limited OptionsSet object with only "file_types" and
"filters" sections.
none.
Application.
ECMerge 2.2
Returns a clone of the shared options of the application, that is, file types and converters (respectively "file_types" and "filters" sections).
OptionsSet object, set_shared_options method
function confirm (prompt)
returns true if OK is pressed, false if cancel is
pressed
prompt. String. Prompt displayed to the user
Application.
ECMerge 2.1
Displays a prompt to the user and makes him/her to press OK or cancel.
Ask if a file should be deleted.
var i_should = confirm ("Should I deleted this file?");
function execute_macro (macro_name)
macro_name. String. Name of the macro to execute
Application
ECMerge 2.1
Executes a macro-command in the current application context. Macro commands are listed in the user interface in the Key Binding options panel.
Closes the current frame (potentially asking if the document should be saved or discarded)
execute_macro ("file_close");
function exit (exit_code)
exit_code. Integer. Code to return as the application exit code. Usually 0 means success, any other value indicate an error.
Application.
ECMerge 2.1
Terminates the execution of the script, then the execution of the application.
Returns an exite code depending on a success variable.
var success = true;
exit (success ? 0 : 1);
function gc( )
none.
global name space.
ECMerge 2.1
Forces a garbage collection. Garbage collection is sometime necessary, in particular when resources are locked by objects which were already released, such as Document objects.
function get_options_sets_names ( )
returns an Array of String
none
Application.
ECMerge 2.2
Returns the list of options sets names.
OptionsSet object
function log (text)
text. String. Text to be logged.
global name space
ECMerge 2.1
Logs a text to the log view or the standard message output in command line mode.
Logs a text.
log ("this was logged");
function popup_menu (menu)
menu. A menu items Array. Menu to be displayed
Application.
ECMerge 2.2
Displays a contextual menu where the mouse cursor is currently placed. The menu is made of menu items defined as below.
Property | Description |
checked | Boolean. For 'check' or 'radio', item indicates if the item has the check or bullet in front of it |
event | Function object. Function to call if the menu item is clicked |
help_string | String. Text to display as the menu item help string |
icon_url | URL object. URL to the icon to be displayed. Only native filesystem URL are supported here. |
label | String. Label to display for that menu item. If empty, the item is a separator |
sub_menu | Menu items Array. If defined, this item defined a sub-menu and items in sub_menu are displayed inside that sub-menu |
type | String. One of 'check' for checkable menu items, 'radio' for radio menu items or empty/undefined for normal menu items |
This sample displays a menu with two dummy items:
var menu = [ { label: "menu item", event:
function() { alert("hi hoo") } },
{
label: "menu item 2", event: function() { alert("hi hoo 2") }
} ];
Application.popup_menu (menu);
none.
function prompt (prompt)
returns a string
prompt. String. Prompt for the text.
Application
ECMerge 2.1
Prompts for a text.
Logs the text that the user types.
log (prompt ("Please enter a text to log:"));
function set_share_options ( sdo )
sdo. OptionsSet object limited to shared options. Shared options to set
Application.
ECMerge 2.2
Sets the shared options of the Application, those options are immediately propagated to all the master copies of the options sets (those actually sharing file types and converters). In addition, if the master copy of the options set of current view actually evolved, the view gets the changes as if validated by the options set box.
OptionsSet object, clone_shared_options method