index 07f26b71f92618bb625f6dc3a1f7253b4e65f1b8..7b299b700cdb9231e10eb8a1c9d4142c92fdb5e2 100644 (file)
* Author:
* Bob Jamison
*
- * Copyright (C) 2004-2007 Authors
+ * Copyright (C) 2004-2008 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <extension/script/InkscapeScript.h>
-namespace Inkscape {
-namespace UI {
-namespace Dialog {
+
+namespace Inkscape
+{
+namespace UI
+{
+namespace Dialog
+{
+
//#########################################################################
*/
void execute(Inkscape::Extension::Script::InkscapeScript::ScriptLanguage lang);
+ /**
+ * Execute a Javascript script
+ */
+ void executeJavascript();
+
/**
* Execute a Python script
*/
void executePython();
/**
- * Execute a Perl script
+ * Execute a Ruby script
*/
- void executePerl();
+ void executeRuby();
};
-static char *defaultPythonCodeStr =
-#if defined(WITH_PYTHON)
- "# This is a sample Python script.\n"
- "# To run it, select 'Execute Python' from the File menu above.\n"
- "desktop = inkscape.activeDesktop\n"
- "dialogmanager = desktop.dialogManager\n"
- "document = inkscape.activeDocument\n"
- "inkscape.hello()\n"
- "dialogmanager.showAbout()\n"
-#elif defined(WITH_PERL)
- "# This is a sample Perl script.\n"
- "# To run it, select 'Execute Perl' from the File menu above.\n"
- "my $desktop = $inkscape->getDesktop();\n"
- "my $dialogmanager = $inkscape->getDialogManager();\n"
- "my $document = $desktop->getDocument();\n"
- "$document->hello();\n"
- "$dialogmanager->showAbout();\n"
-#else
- "# This is where you could type a script.\n"
- "# However, no scripting languages have been compiled\n"
- "# into Inkscape, so this window has no functionality.\n"
- "# When compiling Inkscape, run \"configure\" with\n"
- "# \"--with-python\" and/or \"--with-perl\".\n"
-#endif
- "";
+static const char *defaultCodeStr =
+ "/**\n"
+ " * This is some example Javascript.\n"
+ " * Try 'Execute Javascript'\n"
+ " */\n"
+ "importPackage(javax.swing);\n"
+ "function sayHello() {\n"
+ " JOptionPane.showMessageDialog(null, 'Hello, world!',\n"
+ " 'Welcome to Inkscape', JOptionPane.WARNING_MESSAGE);\n"
+ "}\n"
+ "\n"
+ "sayHello();\n"
+ "\n";
+
}
}
+/**
+ * Execute the script in the dialog
+ */
+void ScriptDialogImpl::executeJavascript()
+{
+ execute(Inkscape::Extension::Script::InkscapeScript::JAVASCRIPT);
+}
+
/**
* Execute the script in the dialog
*/
/**
* Execute the script in the dialog
*/
-void ScriptDialogImpl::executePerl()
+void ScriptDialogImpl::executeRuby()
{
- execute(Inkscape::Extension::Script::InkscapeScript::PERL);
+ execute(Inkscape::Extension::Script::InkscapeScript::RUBY);
}
/**
* Constructor
*/
-ScriptDialogImpl::ScriptDialogImpl()
+ScriptDialogImpl::ScriptDialogImpl() :
+ ScriptDialog()
{
- Gtk::VBox *mainVBox = get_vbox();
+ Gtk::Box *contents = _getContents();
//## Add a menu for clear()
menuBar.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_File"), fileMenu) );
fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_Clear"),
sigc::mem_fun(*this, &ScriptDialogImpl::clear) ) );
-#ifdef WITH_PYTHON
+ fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_Execute Javascript"),
+ sigc::mem_fun(*this, &ScriptDialogImpl::executeJavascript) ) );
fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_Execute Python"),
sigc::mem_fun(*this, &ScriptDialogImpl::executePython) ) );
-#endif
-#ifdef WITH_PERL
- fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_Execute Perl"),
- sigc::mem_fun(*this, &ScriptDialogImpl::executePerl) ) );
-#endif
- mainVBox->pack_start(menuBar, Gtk::PACK_SHRINK);
+ fileMenu.items().push_back( Gtk::Menu_Helpers::MenuElem(_("_Execute Ruby"),
+ sigc::mem_fun(*this, &ScriptDialogImpl::executeRuby) ) );
+ contents->pack_start(menuBar, Gtk::PACK_SHRINK);
//### Set up the script field
scriptText.set_editable(true);
- scriptText.get_buffer()->set_text(defaultPythonCodeStr);
+ scriptText.get_buffer()->set_text(defaultCodeStr);
scriptTextScroll.add(scriptText);
scriptTextScroll.set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_ALWAYS);
scriptTextFrame.set_label(_("Script"));
scriptTextFrame.set_shadow_type(Gtk::SHADOW_NONE);
scriptTextFrame.add(scriptTextScroll);
- mainVBox->pack_start(scriptTextFrame);
+ contents->pack_start(scriptTextFrame);
//### Set up the output field
outputText.set_editable(true);
outputTextFrame.set_label(_("Output"));
outputTextFrame.set_shadow_type(Gtk::SHADOW_NONE);
outputTextFrame.add(outputTextScroll);
- mainVBox->pack_start(outputTextFrame);
+ contents->pack_start(outputTextFrame);
//### Set up the error field
errorText.set_editable(true);
errorTextFrame.set_label(_("Errors"));
errorTextFrame.set_shadow_type(Gtk::SHADOW_NONE);
errorTextFrame.add(errorTextScroll);
- mainVBox->pack_start(errorTextFrame);
+ contents->pack_start(errorTextFrame);
// sick of this thing shrinking too much
set_size_request(350, 400);
/**
* Factory method. Use this to create a new ScriptDialog
*/
-ScriptDialog *ScriptDialog::create()
+ScriptDialog &ScriptDialog::getInstance()
{
ScriptDialog *dialog = new ScriptDialogImpl();
- return dialog;
+ return *dialog;
}