Code

* don't strech buttons on lpe dialog when resizing the dialog
[inkscape.git] / src / ui / dialog / scriptdialog.cpp
index 8cc8f88aa9920cc546a60f299ddcf53cecc31093..a56e74df33a1905aa3a2d055d9d124f506887dd3 100644 (file)
@@ -1,7 +1,10 @@
-/*
- *   Other dudes from The Inkscape Organization
+/**
+ *  Dialog for executing and monitoring script execution
+ *  
+ * Author:  
+ *   Bob Jamison
  *
- * Copyright (C) 2004, 2005 Authors
+ * Copyright (C) 2004-2007 Authors
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -98,13 +101,29 @@ class ScriptDialogImpl : public ScriptDialog
 };
 
 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.getDesktop()\n"
-    "dialogmanager = inkscape.getDialogManager()\n"
-    "document = desktop.getDocument()\n"
-    "document.hello()\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
     "";
 
 
@@ -142,9 +161,12 @@ lang)
     Glib::ustring error;
     Inkscape::Extension::Script::InkscapeScript engine;
     bool ok = engine.interpretScript(script, output, error, lang);
-    if (!ok) return;
     outputText.get_buffer()->set_text(output);
     errorText.get_buffer()->set_text(error);
+    if (!ok)
+        {
+        //do we want something here?
+        }
 }
 
 /**
@@ -170,19 +192,24 @@ void ScriptDialogImpl::executePerl()
 /**
  * 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 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) ) );
-    mainVBox->pack_start(menuBar, Gtk::PACK_SHRINK);
+#endif
+    contents->pack_start(menuBar, Gtk::PACK_SHRINK);
 
     //### Set up the script field
     scriptText.set_editable(true);
@@ -192,7 +219,7 @@ ScriptDialogImpl::ScriptDialogImpl()
     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);
@@ -202,7 +229,7 @@ ScriptDialogImpl::ScriptDialogImpl()
     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);
@@ -212,7 +239,7 @@ ScriptDialogImpl::ScriptDialogImpl()
     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);
@@ -223,10 +250,10 @@ ScriptDialogImpl::ScriptDialogImpl()
 /**
  * Factory method.  Use this to create a new ScriptDialog
  */
-ScriptDialog *ScriptDialog::create()
+ScriptDialog &ScriptDialog::getInstance()
 {
     ScriptDialog *dialog = new ScriptDialogImpl();
-    return dialog;
+    return *dialog;
 }