Code

Extensions. Check element now search in the extension directory (see Bug #668895...
[inkscape.git] / src / extension / implementation / script.cpp
index e075feb913bb3b4a7820250dfd4fd99651f36491..0f234c7d44f60d6c5d3dbe440ca77cd3a1c66154 100644 (file)
@@ -6,6 +6,7 @@
  *   Bryce Harrington <bryce@osdl.org>
  *   Ted Gould <ted@gould.cx>
  *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2002-2005,2007 Authors
  *
 #include "extension/db.h"
 #include "script.h"
 #include "dialogs/dialog-events.h"
-#include "application/application.h"
+#include "inkscape.h"
 #include "xml/node.h"
 #include "xml/attribute-record.h"
 
 #include "util/glib-list-iterators.h"
-
+#include "path-prefix.h"
 
 
 #ifdef WIN32
@@ -228,27 +229,27 @@ Script::solve_reldir(Inkscape::XML::Node *reprin) {
 */
 bool Script::check_existence(const std::string &command)
 {
-
     // Check the simple case first
     if (command.empty()) {
         return false;
     }
 
     //Don't search when it is an absolute path. */
-    if (!Glib::path_is_absolute(command)) {
+    if (Glib::path_is_absolute(command)) {
         if (Glib::file_test(command, Glib::FILE_TEST_EXISTS)) {
             return true;
         } else {
             return false;
         }
     }
-
-    std::string path = Glib::getenv("PATH");
-    if (path.empty()) {
-       /* There is no `PATH' in the environment.
-           The default search path is the current directory */
-        path = G_SEARCHPATH_SEPARATOR_S;
-    }
+    
+    // First search in the extension path and the current directory
+    std::string path = INKSCAPE_EXTENSIONDIR;
+    path.append(";");
+    path.append(G_SEARCHPATH_SEPARATOR_S);
+    path.append(";");
+    // And then the PATH environment variable.
+    path.append(Glib::getenv("PATH"));
 
     std::string::size_type pos  = 0;
     std::string::size_type pos2 = 0;
@@ -532,9 +533,8 @@ SPDocument *Script::open(Inkscape::Extension::Input *module,
     } // data_read
 
     if (mydoc != NULL) {
-        g_free(mydoc->base);
-        mydoc->base = NULL;
-        sp_document_change_uri_and_hrefs(mydoc, filenameArg);
+        mydoc->setBase(0);
+        mydoc->changeUriAndHrefs(filenameArg);
     }
 
     // make sure we don't leak file descriptors from g_file_open_tmp
@@ -602,10 +602,14 @@ void Script::save(Inkscape::Extension::Output *module,
 
 
     file_listener fileout;
-    execute(command, params, tempfilename_in, fileout);
+    int data_read = execute(command, params, tempfilename_in, fileout);
+    
+    bool success = false;
 
-    std::string lfilename = Glib::filename_from_utf8(filenameArg);
-    bool success = fileout.toFile(lfilename);
+    if (data_read > 0) {
+        std::string lfilename = Glib::filename_from_utf8(filenameArg);
+        success = fileout.toFile(lfilename);
+    }
 
     // make sure we don't leak file descriptors from g_file_open_tmp
     close(tempfd_in);
@@ -979,7 +983,7 @@ int Script::execute (const std::list<std::string> &in_command,
 
     Glib::ustring stderr_data = fileerr.string();
     if (stderr_data.length() != 0 &&
-        Inkscape::NSApplication::Application::getUseGui()
+        inkscape_use_gui()
        ) {
         checkStderr(stderr_data, Gtk::MESSAGE_INFO,
                                  _("Inkscape has received additional data from the script executed.  "
@@ -1011,4 +1015,4 @@ int Script::execute (const std::list<std::string> &in_command,
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :