diff options
31 files changed, 536 insertions, 549 deletions
diff --git a/share/extensions/color_custom.inx b/share/extensions/color_custom.inx index 647caade7..211ecb315 100644 --- a/share/extensions/color_custom.inx +++ b/share/extensions/color_custom.inx @@ -1,5 +1,5 @@ <inkscape-extension>
- <_name>Custom...</_name>
+ <_name>Custom</_name>
<id>org.inkscape.color.custom</id>
<dependency type="executable" location="extensions">coloreffect.py</dependency>
<dependency type="executable" location="extensions">color_custom.py</dependency>
@@ -16,4 +16,4 @@ <script>
<command reldir="extensions" interpreter="python">color_custom.py</command>
</script>
-</inkscape-extension>
\ No newline at end of file +</inkscape-extension>
diff --git a/share/extensions/color_replace.inx b/share/extensions/color_replace.inx index fe2fc612b..21816f015 100644 --- a/share/extensions/color_replace.inx +++ b/share/extensions/color_replace.inx @@ -1,5 +1,5 @@ <inkscape-extension>
- <_name>Replace color...</_name>
+ <_name>Replace color</_name>
<id>org.inkscape.color.replacecolor</id>
<dependency type="executable" location="extensions">coloreffect.py</dependency>
<dependency type="executable" location="extensions">color_replace.py</dependency>
diff --git a/share/extensions/text_replace.inx b/share/extensions/text_replace.inx index 547e85c89..a63c55512 100644 --- a/share/extensions/text_replace.inx +++ b/share/extensions/text_replace.inx @@ -1,5 +1,5 @@ <inkscape-extension>
- <_name>Replace text...</_name>
+ <_name>Replace text</_name>
<id>org.inkscape.text.replacetext</id>
<dependency type="executable" location="extensions">chardataeffect.py</dependency>
<dependency type="executable" location="extensions">text_replace.py</dependency>
@@ -14,4 +14,4 @@ <script>
<command reldir="extensions" interpreter="python">text_replace.py</command>
</script>
-</inkscape-extension>
\ No newline at end of file +</inkscape-extension> diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 76af73ed3..a45ef0199 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -212,21 +212,17 @@ Effect::prefs (Inkscape::UI::View::View * doc) return true; } + if (param_visible_count() == 0) { + effect(doc); + return true; + } + if (!loaded()) set_state(Extension::STATE_LOADED); if (!loaded()) return false; - sigc::signal<void> * changeSignal = new sigc::signal<void>; - - Gtk::Widget * controls; - Implementation::ImplementationDocumentCache * docCache = imp->newDocCache(this, doc); - controls = imp->prefs_effect(this, doc, changeSignal, docCache); - - ExecutionEnv executionEnv(this, doc, controls, changeSignal, NULL, docCache); - - timer->lock(); - executionEnv.run(); - timer->unlock(); + _prefDialog = new PrefDialog(this->get_name(), this->get_help(), NULL, this); + _prefDialog->show(); return true; } @@ -250,9 +246,14 @@ Effect::effect (Inkscape::UI::View::View * doc) if (!loaded()) return; - ExecutionEnv executionEnv(this, doc, NULL); + ExecutionEnv executionEnv(this, doc); timer->lock(); executionEnv.run(); + if (executionEnv.wait()) { + executionEnv.commit(); + } else { + executionEnv.cancel(); + } timer->unlock(); return; @@ -313,11 +314,6 @@ void Effect::set_pref_dialog (PrefDialog * prefdialog) { _prefDialog = prefdialog; - if (_prefDialog == NULL) { - timer->unlock(); - } else { - timer->lock(); - } return; } diff --git a/src/extension/effect.h b/src/extension/effect.h index 44d18146a..58e39c63d 100644 --- a/src/extension/effect.h +++ b/src/extension/effect.h @@ -60,6 +60,8 @@ class Effect : public Extension { Effect * _effect; /** \brief Whether or not to show preferences on display */ bool _showPrefs; + /** \brief Name with elipses if that makes sense */ + gchar * _elip_name; protected: virtual SPAction * make_action (Inkscape::UI::View::View * view); public: @@ -70,9 +72,23 @@ class Effect : public Extension { gchar const * image, Effect * effect, bool showPrefs) : - Verb(id, _(name), _(tip), image), _effect(effect), _showPrefs(showPrefs) { + Verb(id, _(name), _(tip), image), + _effect(effect), + _showPrefs(showPrefs), + _elip_name(NULL) { /* No clue why, but this is required */ this->set_default_sensitive(true); + if (_showPrefs && effect != NULL && effect->param_visible_count() != 0) { + _elip_name = g_strdup_printf("%s...", _(name)); + set_name(_elip_name); + } + } + + /** \brief Destructor */ + ~EffectVerb() { + if (_elip_name != NULL) { + g_free(_elip_name); + } } }; diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index a978ec7cb..fae764a9d 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -2,7 +2,7 @@ * Authors: * Ted Gould <ted@gould.cx> * - * Copyright (C) 2007 Authors + * Copyright (C) 2007-2008 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -28,21 +28,26 @@ namespace Inkscape { namespace Extension { +/** \brief Create an execution environment that will allow the effect + to execute independently. + \param effect The effect that we should execute + \param doc The Document to execute on + \param docCache The cache created for that document + \param show_working Show the working dialog + \param show_error Show the error dialog (not working) -ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Gtk::Widget * controls, sigc::signal<void> * changeSignal, Gtk::Dialog * prefDialog, Implementation::ImplementationDocumentCache * docCache) : + Grabs the selection of the current document so that it can get + restored. Will generate a document cache if one isn't provided. +*/ +ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Implementation::ImplementationDocumentCache * docCache, bool show_working, bool show_errors) : + _state(ExecutionEnv::INIT), _visibleDialog(NULL), - _prefsVisible(false), - _finished(false), - _humanWait(false), - _canceled(false), - _prefsChanged(false), - _livePreview(true), - _shutdown(false), - _selfdelete(false), - _changeSignal(changeSignal), + _mainloop(NULL), _doc(doc), _docCache(docCache), - _effect(effect) + _effect(effect), + _show_working(show_working), + _show_errors(show_errors) { SPDesktop *desktop = (SPDesktop *)_doc; sp_namedview_document_from_window(desktop); @@ -59,107 +64,64 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Gtk } } - _mainloop = Glib::MainLoop::create(false); - - if (prefDialog == NULL) { - if (controls != NULL) { - createPrefsDialog(controls); - } else { - createWorkingDialog(); - } - } else { - _visibleDialog = prefDialog; - _prefsVisible = true; - _dialogsig = _visibleDialog->signal_response().connect(sigc::mem_fun(this, &ExecutionEnv::preferencesResponse)); - - // We came from a dialog, we'll need to die by ourselves. - _selfdelete = true; - } - - if (_changeSignal != NULL) { - _changesig = _changeSignal->connect(sigc::mem_fun(this, &ExecutionEnv::preferencesChange)); - } + genDocCache(); return; } +/** \brief Destroy an execution environment + + Destroys the dialog if created and the document cache. +*/ ExecutionEnv::~ExecutionEnv (void) { - _dialogsig.disconnect(); - _timersig.disconnect(); - if (_prefsVisible) { - _changesig.disconnect(); - } - if (_visibleDialog != NULL && !_shutdown && !_prefsVisible) { + if (_visibleDialog != NULL) { + _visibleDialog->hide(); delete _visibleDialog; + _visibleDialog = NULL; } - if (_changeSignal != NULL && !_shutdown) { - delete _changeSignal; - } - killDocCache(); + killDocCache(); return; } -void -ExecutionEnv::genDocCache (void) { -if (_docCache == NULL) { - // printf("Gen Doc Cache\n"); - _docCache = _effect->get_imp()->newDocCache(_effect, _doc); - } - return; -} - -void -ExecutionEnv::killDocCache (void) { - if (_docCache != NULL) { - // printf("Killed Doc Cache\n"); - delete _docCache; - _docCache = NULL; - } - return; -} +/** \brief Generate a document cache if needed + If there isn't one we create a new one from the implementation + from the effect's implementation. +*/ void -ExecutionEnv::preferencesChange (void) { - _timersig.disconnect(); - if (_livePreview) { - _timersig = Glib::signal_timeout().connect(sigc::mem_fun(this, &ExecutionEnv::preferencesTimer), 100, Glib::PRIORITY_DEFAULT_IDLE); - } +ExecutionEnv::genDocCache (void) { + if (_docCache == NULL) { + // printf("Gen Doc Cache\n"); + _docCache = _effect->get_imp()->newDocCache(_effect, _doc); + } return; } -bool -ExecutionEnv::preferencesTimer (void) { - //std::cout << "Preferences are a changin'" << std::endl; - _prefsChanged = true; - if (_humanWait) { - _mainloop->quit(); - documentCancel(); - _humanWait = false; - } else { - processingCancel(); - documentCancel(); - } - return false; -} +/** \brief Destory a document cache + Just delete it. +*/ void -ExecutionEnv::createPrefsDialog (Gtk::Widget * controls) { - _visibleDialog = new PrefDialog(_effect->get_name(), _effect->get_help(), controls, this, _effect, _changeSignal); - _visibleDialog->show(); - _dialogsig = _visibleDialog->signal_response().connect(sigc::mem_fun(this, &ExecutionEnv::preferencesResponse)); - - _prefsVisible = true; +ExecutionEnv::killDocCache (void) { + if (_docCache != NULL) { + // printf("Killed Doc Cache\n"); + delete _docCache; + _docCache = NULL; + } return; } +/** \brief Create the working dialog + + Builds the dialog with a message saying that the effect is working. + And make sure to connect to the cancel. +*/ void ExecutionEnv::createWorkingDialog (void) { if (_visibleDialog != NULL) { + _visibleDialog->hide(); delete _visibleDialog; - } - if (_changeSignal != NULL) { - delete _changeSignal; - _changeSignal = NULL; + _visibleDialog = NULL; } gchar * dlgmessage = g_strdup_printf(_("'%s' working, please wait..."), _effect->get_name()); @@ -168,79 +130,39 @@ ExecutionEnv::createWorkingDialog (void) { Gtk::MESSAGE_INFO, Gtk::BUTTONS_CANCEL, true); // modal - _dialogsig = _visibleDialog->signal_response().connect(sigc::mem_fun(this, &ExecutionEnv::workingCanceled)); + _visibleDialog->signal_response().connect(sigc::mem_fun(this, &ExecutionEnv::workingCanceled)); g_free(dlgmessage); _visibleDialog->show(); - _prefsVisible = false; return; } void -ExecutionEnv::workingCanceled( const int /*resp*/ ) { - printf("Working Canceled\n"); - processingCancel(); - documentCancel(); - _finished = true; +ExecutionEnv::workingCanceled( const int resp) { + cancel(); + undo(); return; } void -ExecutionEnv::preferencesResponse (const int resp) { - if (resp == Gtk::RESPONSE_OK) { - if (_humanWait && _livePreview) { - documentCommit(); - _mainloop->quit(); - _finished = true; - } else { - createWorkingDialog(); - if (!_livePreview) { - _mainloop->quit(); - _humanWait = false; - } - } - } else { - if (_humanWait) { - _mainloop->quit(); - } else { - processingCancel(); - } - documentCancel(); - _finished = true; - } - return; -} - -void -ExecutionEnv::processingComplete(void) { - //std::cout << "Processing Complete" << std::endl; - if (_prefsChanged) { return; } // do it all again - if (_prefsVisible) { - _humanWait = true; - } else { - documentCommit(); - _finished = true; - } - return; -} - -void -ExecutionEnv::processingCancel (void) { +ExecutionEnv::cancel (void) { _effect->get_imp()->cancelProcessing(); return; } void -ExecutionEnv::documentCancel (void) { - _canceled = true; +ExecutionEnv::undo (void) { + sp_document_cancel(_doc->doc()); + reselect(); return; } void -ExecutionEnv::documentCommit (void) { +ExecutionEnv::commit (void) { sp_document_done(_doc->doc(), SP_VERB_NONE, _(_effect->get_name())); Effect::set_last_effect(_effect); _effect->get_imp()->commitDocument(); + killDocCache(); return; } @@ -269,67 +191,39 @@ ExecutionEnv::reselect (void) { void ExecutionEnv::run (void) { - while (!_finished) { - _canceled = false; - if (_humanWait) { - _mainloop->run(); - } else { - _prefsChanged = false; - genDocCache(); - _effect->get_imp()->effect(_effect, _doc, _docCache); - processingComplete(); - } - if (_canceled) { - sp_document_cancel(_doc->doc()); - reselect(); - } - } - if (_selfdelete) { - delete this; + _state = ExecutionEnv::RUNNING; + if (_show_working) { + createWorkingDialog(); } + _effect->get_imp()->effect(_effect, _doc, _docCache); + _state = ExecutionEnv::COMPLETE; + // _runComplete.signal(); return; } -/** \brief Set the state of live preview - \param state The current state - - This will cancel the document preview and and configure - whether we should be waiting on the human. It will also - clear the document cache. -*/ void -ExecutionEnv::livePreview (bool state) { +ExecutionEnv::runComplete (void) { _mainloop->quit(); - if (_livePreview && !state) { - documentCancel(); - _humanWait = true; - } - if (!_livePreview && state) { - _humanWait = false; - } - _livePreview = state; - if (!_livePreview) { - killDocCache(); - } - return; } -void -ExecutionEnv::shutdown (bool del) { - if (_humanWait) { - _mainloop->quit(); - } else { - processingCancel(); - } - documentCancel(); +bool +ExecutionEnv::wait (void) { + if (_state != ExecutionEnv::COMPLETE) { + if (_mainloop) { + _mainloop = Glib::MainLoop::create(false); + } - _finished = true; - _shutdown = true; - _selfdelete = del; + sigc::connection conn = _runComplete.connect(sigc::mem_fun(this, &ExecutionEnv::runComplete)); + _mainloop->run(); - return; + conn.disconnect(); + } + + return true; } + + } } /* namespace Inkscape, Extension */ diff --git a/src/extension/execution-env.h b/src/extension/execution-env.h index 949d09db6..c2d4e7e4a 100644 --- a/src/extension/execution-env.h +++ b/src/extension/execution-env.h @@ -26,53 +26,80 @@ namespace Extension { class ExecutionEnv { private: + enum state_t { + INIT, //< The context has been initialized + COMPLETE, //< We've completed atleast once + RUNNING //< The effect is currently running + }; + /** \brief What state the execution engine is in. */ + state_t _state; + + /** \brief If there is a working dialog it'll be referenced + right here. */ Gtk::Dialog * _visibleDialog; - bool _prefsVisible; - bool _finished; - bool _humanWait; - bool _canceled; - bool _prefsChanged; - bool _livePreview; - bool _shutdown; - bool _selfdelete; - sigc::signal<void> * _changeSignal; + /** \brief Signal that the run is complete. */ + sigc::signal<void> _runComplete; + /** \brief In some cases we need a mainLoop, when we do, this is + a pointer to it. */ Glib::RefPtr<Glib::MainLoop> _mainloop; + /** \brief The document that we're working on. */ Inkscape::UI::View::View * _doc; + /** \brief A list of the IDs of all the selected objects before + we started to work on this document. */ std::list<Glib::ustring> _selected; - sigc::connection _dialogsig; - sigc::connection _changesig; - sigc::connection _timersig; - Implementation::ImplementationDocumentCache * _docCache; + /** \brief A document cache if we were passed one. */ + Implementation::ImplementationDocumentCache * _docCache; -public: + /** \brief The effect that we're executing in this context. */ Effect * _effect; + /** \brief Show the working dialog when the effect is executing. */ + bool _show_working; + /** \brief Display errors if they occur. */ + bool _show_errors; +public: + + /** \brief Create a new context for exection of an effect + \param effect The effect to execute + \param doc The document to execute the effect on + \param docCache The implementation cache of the document. May be + NULL in which case it'll be created by the execution + environment. + \prarm show_working Show a small dialog signaling the effect + is working. Allows for user canceling. + \param show_errors If the effect has an error, show it or not. + */ ExecutionEnv (Effect * effect, - Inkscape::UI::View::View * doc, - Gtk::Widget * controls = NULL, - sigc::signal<void> * changeSignal = NULL, - Gtk::Dialog * prefDialog = NULL, - Implementation::ImplementationDocumentCache * docCache = NULL); + Inkscape::UI::View::View * doc, + Implementation::ImplementationDocumentCache * docCache = NULL, + bool show_working = true, + bool show_errors = true); virtual ~ExecutionEnv (void); + /** \brief Starts the execution of the effect + \return Returns whether the effect was executed to completion */ void run (void); - void livePreview (bool state = true); - void shutdown (bool del = false); + /** \brief Cancel the execution of the effect */ + void cancel (void); + /** \brief Commit the changes to the document */ + void commit (void); + /** \brief Undoes what the effect completed. */ + void undo (void); + /** \brief Wait for the effect to complete if it hasn't. */ + bool wait (void); private: + void runComplete (void); void createPrefsDialog (Gtk::Widget * controls); void createWorkingDialog (void); void workingCanceled (const int resp); - void preferencesResponse (const int resp); - void preferencesChange (void); - bool preferencesTimer (void); void processingCancel (void); void processingComplete(void); void documentCancel (void); void documentCommit (void); void reselect (void); - void genDocCache (void); - void killDocCache (void); + void genDocCache (void); + void killDocCache (void); }; } } /* namespace Inkscape, Extension */ diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 84f09aedb..07803c187 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -288,10 +288,10 @@ Extension::check (void) void Extension::printFailure (Glib::ustring reason) { - error_file << _("Extension \"") << name << _("\" failed to load because "); - error_file << reason.raw(); - error_file << std::endl; - return; + error_file << _("Extension \"") << name << _("\" failed to load because "); + error_file << reason.raw(); + error_file << std::endl; + return; } /** @@ -692,23 +692,9 @@ Extension::autogui (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<v void Extension::paramListString (std::list <std::string> &retlist) { - //std::list <std::string> retarray; - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = reinterpret_cast<Parameter *>(list->data); - - std::string param_string; - param_string += "--"; - param_string += param->name(); - param_string += "="; - Glib::ustring * out = param->string(); - param_string += *out; - delete out; - - retlist.insert(retlist.end(), param_string); - - // insert parameters subparameters if any (for example notebook parameter has subparams) - param->insert_subparam_strings(retlist); + param->string(retlist); } return; diff --git a/src/extension/extension.h b/src/extension/extension.h index e4f2dc88e..4af65dc92 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -94,7 +94,7 @@ private: static std::ofstream error_file; /**< This is the place where errors get reported */ protected: - Inkscape::XML::Node *repr; /**< The XML description of the Extension */ + Inkscape::XML::Node *repr; /**< The XML description of the Extension */ Implementation::Implementation * imp; /**< An object that holds all the functions for making this work */ ExpirationTimer * timer; /**< Timeout to unload after a given time */ @@ -124,6 +124,23 @@ private: extension */ public: + /** \brief A function to get the the number of parameters that + the extension has. + \return The number of parameters. */ + unsigned int param_count ( ) { return parameters == NULL ? 0 : + g_slist_length(parameters); }; + /** \brief A function to get the the number of parameters that + are visible to the user that the extension has. + \return The number of visible parameters. + + \note Currently this just calls param_count as visible isn't implemented + but in the future it'll do something different. Please call + the appropriate function in code so that it'll work in the + future. + */ + unsigned int param_visible_count ( ) { return param_count(); }; + +public: /** An error class for when a parameter is called on a type it is not */ class param_wrong_type {}; class param_not_color_param {}; diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 09dc9eb30..37e4e15b8 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -98,7 +98,11 @@ struct interpreter_t { */ static interpreter_t const interpreterTab[] = { {"perl", "perl-interpreter", "perl" }, +#ifdef _WIN32 + {"python", "python-interpreter", "pythonw" }, +#else {"python", "python-interpreter", "python" }, +#endif {"ruby", "ruby-interpreter", "ruby" }, {"shell", "shell-interpreter", "sh" }, { NULL, NULL, NULL } @@ -453,19 +457,19 @@ Script::check(Inkscape::Extension::Extension *module) } class ScriptDocCache : public ImplementationDocumentCache { - friend class Script; + friend class Script; protected: - std::string _filename; + std::string _filename; int _tempfd; public: - ScriptDocCache (Inkscape::UI::View::View * view); - ~ScriptDocCache ( ); + ScriptDocCache (Inkscape::UI::View::View * view); + ~ScriptDocCache ( ); }; ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) : - ImplementationDocumentCache(view), - _filename(""), - _tempfd(0) + ImplementationDocumentCache(view), + _filename(""), + _tempfd(0) { try { _tempfd = Glib::file_open_tmp(_filename, "ink_ext_XXXXXX.svg"); @@ -481,7 +485,7 @@ ScriptDocCache::ScriptDocCache (Inkscape::UI::View::View * view) : Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE), view->doc(), _filename.c_str(), FALSE, FALSE, FALSE); - return; + return; } ScriptDocCache::~ScriptDocCache ( ) @@ -727,21 +731,21 @@ Script::save(Inkscape::Extension::Output *module, void Script::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *doc, - ImplementationDocumentCache * docCache) + ImplementationDocumentCache * docCache) { - if (docCache == NULL) { - docCache = newDocCache(module, doc); - } - ScriptDocCache * dc = dynamic_cast<ScriptDocCache *>(docCache); - if (dc == NULL) { - printf("TOO BAD TO LIVE!!!"); - exit(1); - } + if (docCache == NULL) { + docCache = newDocCache(module, doc); + } + ScriptDocCache * dc = dynamic_cast<ScriptDocCache *>(docCache); + if (dc == NULL) { + printf("TOO BAD TO LIVE!!!"); + exit(1); + } SPDesktop *desktop = (SPDesktop *)doc; sp_namedview_document_from_window(desktop); - gchar * orig_output_extension = g_strdup(sp_document_repr_root(desktop->doc())->attribute("inkscape:output_extension")); + gchar * orig_output_extension = g_strdup(sp_document_repr_root(desktop->doc())->attribute("inkscape:output_extension")); std::list<std::string> params; module->paramListString(params); @@ -807,9 +811,9 @@ Script::effect(Inkscape::Extension::Effect *module, mydoc->release(); sp_namedview_update_layers_from_document(desktop); - sp_document_repr_root(desktop->doc())->setAttribute("inkscape:output_extension", orig_output_extension); + sp_document_repr_root(desktop->doc())->setAttribute("inkscape:output_extension", orig_output_extension); } - g_free(orig_output_extension); + g_free(orig_output_extension); return; } diff --git a/src/extension/input.cpp b/src/extension/input.cpp index 7ac97b9ed..cdc4f32f4 100644 --- a/src/extension/input.cpp +++ b/src/extension/input.cpp @@ -94,8 +94,8 @@ Input::Input (Inkscape::XML::Node * in_repr, Implementation::Implementation * in } /** - \return None - \brief Destroys an Input extension + \return None + \brief Destroys an Input extension */ Input::~Input (void) { @@ -103,44 +103,44 @@ Input::~Input (void) g_free(extension); g_free(filetypename); g_free(filetypetooltip); - g_free(output_extension); + g_free(output_extension); return; } /** \return Whether this extension checks out - \brief Validate this extension + \brief Validate this extension - This function checks to make sure that the input extension has - a filename extension and a MIME type. Then it calls the parent - class' check function which also checks out the implmentation. + This function checks to make sure that the input extension has + a filename extension and a MIME type. Then it calls the parent + class' check function which also checks out the implmentation. */ bool Input::check (void) { - if (extension == NULL) - return FALSE; - if (mimetype == NULL) - return FALSE; + if (extension == NULL) + return FALSE; + if (mimetype == NULL) + return FALSE; - return Extension::check(); + return Extension::check(); } /** \return A new document - \brief This function creates a document from a file - \param uri The filename to create the document from - - This function acts as the first step in creating a new document - from a file. The first thing that this does is make sure that the - file actually exists. If it doesn't, a NULL is returned. If the - file exits, then it is opened using the implmentation of this extension. - - After opening the document the output_extension is set. What this - accomplishes is that save can try to use an extension that supports - the same fileformat. So something like opening and saveing an - Adobe Illustrator file can be transparent (not recommended, but - transparent). This is all done with undo being turned off. + \brief This function creates a document from a file + \param uri The filename to create the document from + + This function acts as the first step in creating a new document + from a file. The first thing that this does is make sure that the + file actually exists. If it doesn't, a NULL is returned. If the + file exits, then it is opened using the implmentation of this extension. + + After opening the document the output_extension is set. What this + accomplishes is that save can try to use an extension that supports + the same fileformat. So something like opening and saveing an + Adobe Illustrator file can be transparent (not recommended, but + transparent). This is all done with undo being turned off. */ SPDocument * Input::open (const gchar *uri) @@ -167,7 +167,7 @@ Input::open (const gchar *uri) /** \return IETF mime-type for the extension - \brief Get the mime-type that describes this extension + \brief Get the mime-type that describes this extension */ gchar * Input::get_mimetype(void) @@ -177,7 +177,7 @@ Input::get_mimetype(void) /** \return Filename extension for the extension - \brief Get the filename extension for this extension + \brief Get the filename extension for this extension */ gchar * Input::get_extension(void) @@ -187,7 +187,7 @@ Input::get_extension(void) /** \return The name of the filetype supported - \brief Get the name of the filetype supported + \brief Get the name of the filetype supported */ gchar * Input::get_filetypename(void) @@ -200,7 +200,7 @@ Input::get_filetypename(void) /** \return Tooltip giving more information on the filetype - \brief Get the tooltip for more information on the filetype + \brief Get the tooltip for more information on the filetype */ gchar * Input::get_filetypetooltip(void) @@ -210,16 +210,19 @@ Input::get_filetypetooltip(void) /** \return A dialog to get settings for this extension - \brief Create a dialog for preference for this extension + \brief Create a dialog for preference for this extension - Calls the implementation to get the preferences. + Calls the implementation to get the preferences. */ bool Input::prefs (const gchar *uri) { - if (!loaded()) + if (!loaded()) { set_state(Extension::STATE_LOADED); - if (!loaded()) return false; + } + if (!loaded()) { + return false; + } Gtk::Widget * controls; controls = imp->prefs_input(this, uri); diff --git a/src/extension/parambool.cpp b/src/extension/parambool.cpp index 72e32ff25..b324e6281 100644 --- a/src/extension/parambool.cpp +++ b/src/extension/parambool.cpp @@ -105,17 +105,16 @@ ParamBoolCheckButton::on_toggle (void) } /** \brief Return 'true' or 'false' */ -Glib::ustring * -ParamBool::string (void) +void +ParamBool::string (std::string &string) { - Glib::ustring * mystring; - - if (_value) - mystring = new Glib::ustring("true"); - else - mystring = new Glib::ustring("false"); + if (_value) { + string += "true"; + } else { + string += "false"; + } - return mystring; + return; } /** diff --git a/src/extension/parambool.h b/src/extension/parambool.h index a6d0c1b7b..7f1be0fcc 100644 --- a/src/extension/parambool.h +++ b/src/extension/parambool.h @@ -26,7 +26,7 @@ public: bool get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } bool set (bool in, SPDocument * doc, Inkscape::XML::Node * node); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); + void string (std::string &string); }; } /* namespace Extension */ diff --git a/src/extension/paramcolor.cpp b/src/extension/paramcolor.cpp index 2a32086a8..cb7437be0 100644 --- a/src/extension/paramcolor.cpp +++ b/src/extension/paramcolor.cpp @@ -45,7 +45,9 @@ ParamColor::set( guint32 in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node* _value = in; gchar * prefname = this->pref_name(); - prefs_set_string_attribute(PREF_DIR, prefname, this->string()->c_str()); + std::string value; + string(value); + prefs_set_string_attribute(PREF_DIR, prefname, value.c_str()); g_free(prefname); return _value; @@ -66,41 +68,40 @@ ParamColor::ParamColor (const gchar * name, const gchar * guitext, const gchar * if (paramval != NULL) defaulthex = paramval; - _value = atoi(defaulthex); + _value = atoi(defaulthex); return; } -/** \brief Return the value as a string */ -Glib::ustring * -ParamColor::string (void) +void +ParamColor::string (std::string &string) { char str[16]; - sprintf(str, "%i", _value); - - return new Glib::ustring(str); + sprintf(str, "%i", _value); + string += str; + return; } Gtk::Widget * ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * changeSignal ) { - _changeSignal = new sigc::signal<void>(*changeSignal); - Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); - SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK); - - ColorSelector* colorSelector = spColorSelector->base; - if (_value < 1) { - _value = 0xFF000000; - } - SPColor *color = new SPColor( _value ); - float alpha = (_value & 0xff) / 255.0F; + _changeSignal = new sigc::signal<void>(*changeSignal); + Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); + SPColorSelector* spColorSelector = (SPColorSelector*)sp_color_selector_new(SP_TYPE_COLOR_NOTEBOOK); + + ColorSelector* colorSelector = spColorSelector->base; + if (_value < 1) { + _value = 0xFF000000; + } + SPColor *color = new SPColor( _value ); + float alpha = (_value & 0xff) / 255.0F; colorSelector->setColorAlpha(*color, alpha); - hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0); - g_signal_connect(G_OBJECT(spColorSelector), "changed", G_CALLBACK(sp_color_param_changed), (void*)this); + hbox->pack_start (*Glib::wrap(&spColorSelector->vbox), true, true, 0); + g_signal_connect(G_OBJECT(spColorSelector), "changed", G_CALLBACK(sp_color_param_changed), (void*)this); - gtk_widget_show(GTK_WIDGET(spColorSelector)); - hbox->show(); + gtk_widget_show(GTK_WIDGET(spColorSelector)); + hbox->show(); return dynamic_cast<Gtk::Widget *>(hbox); } @@ -108,13 +109,13 @@ ParamColor::get_widget( SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, si void sp_color_param_changed(SPColorSelector *csel, GObject *obj) { - const SPColor color = csel->base->getColor(); - float alpha = csel->base->getAlpha(); + const SPColor color = csel->base->getColor(); + float alpha = csel->base->getAlpha(); ParamColor* ptr = (ParamColor*)obj; - ptr->set(color.toRGBA32( alpha ), NULL, NULL); + ptr->set(color.toRGBA32( alpha ), NULL, NULL); - ptr->_changeSignal->emit(); + ptr->_changeSignal->emit(); } }; /* namespace Extension */ diff --git a/src/extension/paramcolor.h b/src/extension/paramcolor.h index 2d5f3e2e4..87c0fdd9c 100644 --- a/src/extension/paramcolor.h +++ b/src/extension/paramcolor.h @@ -26,7 +26,7 @@ public: guint32 get( const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/ ) { return _value; } guint32 set (guint32 in, SPDocument * doc, Inkscape::XML::Node * node); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); + void string (std::string &string); sigc::signal<void> * _changeSignal; }; /* class ParamColor */ diff --git a/src/extension/paramenum.cpp b/src/extension/paramenum.cpp index 36020f6d1..199512e0e 100644 --- a/src/extension/paramenum.cpp +++ b/src/extension/paramenum.cpp @@ -172,12 +172,11 @@ ParamComboBox::changed (void) { \brief A function to get the value of the parameter in string form \return A string with the 'value' as command line argument */ -Glib::ustring * -ParamComboBox::string (void) +void +ParamComboBox::string (std::string &string) { - Glib::ustring * param_string = new Glib::ustring(""); - *param_string += _value; - return param_string; + string += _value; + return; } diff --git a/src/extension/paramenum.h b/src/extension/paramenum.h index 9118a07ad..b01a15344 100644 --- a/src/extension/paramenum.h +++ b/src/extension/paramenum.h @@ -1,5 +1,5 @@ -#ifndef INK_EXTENSION_PARAMENUM_H_SEEN -#define INK_EXTENSION_PARAMENUM_H_SEEN +#ifndef __INK_EXTENSION_PARAMENUM_H__ +#define __INK_EXTENSION_PARAMENUM_H__ /** \file * Enumeration parameter for extensions. @@ -30,21 +30,21 @@ namespace Extension { class ParamComboBox : public Parameter { private: /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. + been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; - + GSList * choices; /**< A table to store the choice strings */ - + public: ParamComboBox(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); virtual ~ParamComboBox(void); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); - - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + void string (std::string &string); + + const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); - + void changed (void); }; /* class ParamComboBox */ @@ -55,7 +55,7 @@ public: } /* namespace Extension */ } /* namespace Inkscape */ -#endif /* INK_EXTENSION_PARAMENUM_H_SEEN */ +#endif /* __INK_EXTENSION_PARAMENUM_H__ */ /* Local Variables: diff --git a/src/extension/parameter.cpp b/src/extension/parameter.cpp index 0db8d0199..9a7535a25 100644 --- a/src/extension/parameter.cpp +++ b/src/extension/parameter.cpp @@ -74,12 +74,12 @@ public: ParamEnum(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); ~ParamEnum(void); /** \brief Returns \c _value, with a \i const to protect it. */ - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _current_choice != NULL ? _current_choice->_value : NULL; } + const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _current_choice != NULL ? _current_choice->_value : NULL; } const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); Glib::ustring * string (void); }; /* class ParamEnum */ - + /** \return None \brief This function creates a parameter that can be used later. This @@ -169,7 +169,7 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * bool Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamBool * boolpntr = dynamic_cast<ParamBool *>(this); + ParamBool * boolpntr = dynamic_cast<ParamBool *>(this); if (boolpntr == NULL) throw Extension::param_not_bool_param(); return boolpntr->get(doc, node); @@ -179,7 +179,7 @@ Parameter::get_bool (const SPDocument * doc, const Inkscape::XML::Node * node) int Parameter::get_int (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamInt * intpntr = dynamic_cast<ParamInt *>(this); + ParamInt * intpntr = dynamic_cast<ParamInt *>(this); if (intpntr == NULL) throw Extension::param_not_int_param(); return intpntr->get(doc, node); @@ -189,7 +189,7 @@ Parameter::get_int (const SPDocument * doc, const Inkscape::XML::Node * node) float Parameter::get_float (const SPDocument * doc, const Inkscape::XML::Node * node) { - ParamFloat * floatpntr = dynamic_cast<ParamFloat *>(this); + ParamFloat * floatpntr = dynamic_cast<ParamFloat *>(this); if (floatpntr == NULL) throw Extension::param_not_float_param(); return floatpntr->get(doc, node); @@ -238,7 +238,7 @@ Parameter::set_bool (bool in, SPDocument * doc, Inkscape::XML::Node * node) int Parameter::set_int (int in, SPDocument * doc, Inkscape::XML::Node * node) { - ParamInt * intpntr = dynamic_cast<ParamInt *>(this); + ParamInt * intpntr = dynamic_cast<ParamInt *>(this); if (intpntr == NULL) throw Extension::param_not_int_param(); return intpntr->set(in, doc, node); @@ -259,7 +259,7 @@ Parameter::set_float (float in, SPDocument * doc, Inkscape::XML::Node * node) const gchar * Parameter::set_string (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node) { - ParamString * stringpntr = dynamic_cast<ParamString *>(this); + ParamString * stringpntr = dynamic_cast<ParamString *>(this); if (stringpntr == NULL) throw Extension::param_not_string_param(); return stringpntr->set(in, doc, node); @@ -357,24 +357,42 @@ Parameter::document_param_node (SPDocument * doc) /** \brief Basically, if there is no widget pass a NULL. */ Gtk::Widget * -Parameter::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * /*changeSignal*/) +Parameter::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { return NULL; } /** \brief If I'm not sure which it is, just don't return a value. */ -Glib::ustring * -Parameter::string (void) +void +Parameter::string (std::string &string) { - Glib::ustring * mystring = new Glib::ustring(""); - return mystring; + return; +} + +void +Parameter::string (std::list <std::string> &list) +{ + std::string value; + string(value); + if (value == "") { + return; + } + + std::string final; + final += "--"; + final += name(); + final += "="; + final += value; + + list.insert(list.end(), final); + return; } -ParamEnum::ParamEnum (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * /*xml*/) : +ParamEnum::ParamEnum (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : Parameter(name, guitext, desc, scope, ext), _current_choice(NULL) { return; @@ -395,13 +413,13 @@ ParamEnum::string (void) } Gtk::Widget * -ParamEnum::get_widget (SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/, sigc::signal<void> * /*changeSignal*/) +ParamEnum::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { return NULL; } const gchar * -ParamEnum::set (const gchar * /*in*/, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +ParamEnum::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node) { return NULL; } diff --git a/src/extension/parameter.h b/src/extension/parameter.h index 0d9668a55..c5d03226c 100644 --- a/src/extension/parameter.h +++ b/src/extension/parameter.h @@ -1,5 +1,5 @@ -#ifndef INK_EXTENSION_PARAM_H_SEEN -#define INK_EXTENSION_PARAM_H_SEEN +#ifndef __INK_EXTENSION_PARAM_H__ +#define __INK_EXTENSION_PARAM_H__ /** \file * Parameters for extensions. @@ -102,15 +102,16 @@ public: static Parameter * make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); virtual Gtk::Widget * get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - virtual Glib::ustring * string (void); - virtual void insert_subparam_strings(std::list <std::string> &/*retlist*/) {}; gchar const * get_tooltip (void) { return _desc; } + + void string (std::list <std::string> &list); + void string (std::string &string); }; } /* namespace Extension */ } /* namespace Inkscape */ -#endif /* INK_EXTENSION_PARAM_H_SEEN */ +#endif /* __INK_EXTENSION_PARAM_H__ */ /* Local Variables: diff --git a/src/extension/paramfloat.cpp b/src/extension/paramfloat.cpp index 11172ecbb..ee2284c8c 100644 --- a/src/extension/paramfloat.cpp +++ b/src/extension/paramfloat.cpp @@ -88,13 +88,13 @@ ParamFloat::set (float in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) } /** \brief Return the value as a string */ -Glib::ustring * -ParamFloat::string (void) +void +ParamFloat::string (std::string &string) { char startstring[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_dtostr(startstring, G_ASCII_DTOSTR_BUF_SIZE, _value); - Glib::ustring * mystring = new Glib::ustring(startstring); - return mystring; + string += startstring; + return; } /** \brief A class to make an adjustment that uses Extension params */ diff --git a/src/extension/paramfloat.h b/src/extension/paramfloat.h index 7fd621267..25edad7b2 100644 --- a/src/extension/paramfloat.h +++ b/src/extension/paramfloat.h @@ -32,7 +32,7 @@ public: float min (void) { return _min; } float precision (void) { return _precision; } Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); + void string (std::string &string); }; } /* namespace Extension */ diff --git a/src/extension/paramint.cpp b/src/extension/paramint.cpp index e59cf1c34..ca938141c 100644 --- a/src/extension/paramint.cpp +++ b/src/extension/paramint.cpp @@ -144,13 +144,13 @@ ParamInt::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal } /** \brief Return the value as a string */ -Glib::ustring * -ParamInt::string (void) +void +ParamInt::string (std::string &string) { char startstring[32]; sprintf(startstring, "%d", _value); - Glib::ustring * mystring = new Glib::ustring(startstring); - return mystring; + string += startstring; + return; } } /* namespace Extension */ diff --git a/src/extension/paramint.h b/src/extension/paramint.h index fe5de0d17..aa0d05aa7 100644 --- a/src/extension/paramint.h +++ b/src/extension/paramint.h @@ -30,7 +30,7 @@ public: int max (void) { return _max; } int min (void) { return _min; } Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); + void string (std::string &string); }; } /* namespace Extension */ diff --git a/src/extension/paramnotebook.cpp b/src/extension/paramnotebook.cpp index 041dd6370..ea74f10b4 100644 --- a/src/extension/paramnotebook.cpp +++ b/src/extension/paramnotebook.cpp @@ -48,16 +48,16 @@ private: This only gets created if there are parameters on this page */ Gtk::Tooltips * _tooltips; - + public: static ParamNotebookPage * makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * in_ext); ParamNotebookPage(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); ~ParamNotebookPage(void); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void insert_subparam_strings (std::list <std::string> &retlist); + void paramString (std::list <std::string> &list); gchar * get_guitext (void) {return _text;}; - + }; /* class ParamNotebookPage */ @@ -65,7 +65,7 @@ ParamNotebookPage::ParamNotebookPage (const gchar * name, const gchar * guitext, Parameter(name, guitext, desc, scope, ext) { parameters = NULL; - + // Read XML to build page if (xml != NULL) { Inkscape::XML::Node *child_repr = sp_repr_children(xml); @@ -81,7 +81,7 @@ ParamNotebookPage::ParamNotebookPage (const gchar * name, const gchar * guitext, child_repr = sp_repr_next(child_repr); } } - + return; } @@ -96,32 +96,19 @@ ParamNotebookPage::~ParamNotebookPage (void) g_slist_free(parameters); } -/** - \brief A function to get the subparameters in a string form - \return An array with all the subparameters in it. - - Look how this closely resembles Extension::paramListString -*/ +/** \brief Return the value as a string */ void -ParamNotebookPage::insert_subparam_strings (std::list <std::string> &retlist) +ParamNotebookPage::paramString (std::list <std::string> &list) { - for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { - Parameter * param = reinterpret_cast<Parameter *>(list->data); - - std::string param_string; - param_string += "--"; - param_string += param->name(); - param_string += "="; - Glib::ustring * out = param->string(); - param_string += *out; - delete out; - - retlist.insert(retlist.end(), param_string); + for (GSList * plist = parameters; plist != NULL; plist = g_slist_next(plist)) { + Parameter * param = reinterpret_cast<Parameter *>(plist->data); + param->string(list); } return; } + /** \return None \brief This function creates a page that can be used later. This @@ -179,7 +166,7 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: } ParamNotebookPage * page = new ParamNotebookPage(name, guitext, desc, scope, in_ext, in_repr); - + /* Note: page could equal NULL */ return page; } @@ -193,26 +180,26 @@ ParamNotebookPage::makepage (Inkscape::XML::Node * in_repr, Inkscape::Extension: */ Gtk::Widget * ParamNotebookPage::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) -{ +{ if (!_tooltips) _tooltips = new Gtk::Tooltips(); - + Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox); - vbox->set_border_width(5); - - // add parameters onto page (if any) + vbox->set_border_width(5); + + // add parameters onto page (if any) for (GSList * list = parameters; list != NULL; list = g_slist_next(list)) { Parameter * param = reinterpret_cast<Parameter *>(list->data); Gtk::Widget * widg = param->get_widget(doc, node, changeSignal); gchar const * tip = param->get_tooltip(); - + vbox->pack_start(*widg, true, true, 2); if (tip != NULL) { _tooltips->set_tip(*widg, Glib::ustring(tip)); } } - + vbox->show(); - + return dynamic_cast<Gtk::Widget *>(vbox); } @@ -228,7 +215,7 @@ ParamNotebook::ParamNotebook (const gchar * name, const gchar * guitext, const g Parameter(name, guitext, desc, scope, ext) { pages = NULL; - + // Read XML tree to add pages: if (xml != NULL) { Inkscape::XML::Node *child_repr = sp_repr_children(xml); @@ -244,7 +231,7 @@ ParamNotebook::ParamNotebook (const gchar * name, const gchar * guitext, const g child_repr = sp_repr_next(child_repr); } } - + // Initialize _value with the current page const char * defaultval = NULL; // set first page as default @@ -261,7 +248,7 @@ ParamNotebook::ParamNotebook (const gchar * name, const gchar * guitext, const g defaultval = paramval; if (defaultval != NULL) _value = g_strdup(defaultval); // allocate space for _value - + return; } @@ -292,7 +279,7 @@ ParamNotebook::~ParamNotebook (void) the passed in value is duplicated using \c g_strdup(). */ const gchar * -ParamNotebook::set (const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +ParamNotebook::set (const int in, SPDocument * doc, Inkscape::XML::Node * node) { ParamNotebookPage * page = NULL; int i = 0; @@ -300,9 +287,9 @@ ParamNotebook::set (const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /* page = reinterpret_cast<ParamNotebookPage *>(list->data); i++; } - + if (page == NULL) return _value; - + if (_value != NULL) g_free(_value); _value = g_strdup(page->name()); @@ -315,32 +302,33 @@ ParamNotebook::set (const int in, SPDocument * /*doc*/, Inkscape::XML::Node * /* /** - \brief A function to get the currentpage in a string form - \return A string with the 'value' -*/ -Glib::ustring * -ParamNotebook::string (void) -{ - Glib::ustring * param_string = new Glib::ustring(""); + \brief A function to get the currentpage and the parameters in a string form + \return A string with the 'value' and all the parameters on all pages as command line arguments - *param_string += "\""; - *param_string += _value; // the name of the current page - *param_string += "\""; + This is really a hack. The function is called by Extension::paramString() to build + the commandline string like: '--param1name=\"param1value\" --param2name=\"param2value\" ...' + Extension::paramString expects this function to return '\"param1value\"'; but instead, + this function returns: '\"param1value\" --page1param1name=\"page1param1value\" ...' - return param_string; -} - -/** - \brief A function to get the subparameters in a string form - \return An array with all the subparameters in it. + \TODO Do this better. For example, make Parameter::paramString() that returns '--name=\"value\"' + instead of just returning '\"value\"'. */ void -ParamNotebook::insert_subparam_strings (std::list <std::string> &retlist) +ParamNotebook::string (std::list <std::string> &list) { - for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { - ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(list->data); - - page->insert_subparam_strings(retlist); + std::string param_string; + param_string += "--"; + param_string += name(); + param_string += "="; + + param_string += "\""; + param_string += _value; // the name of the current page + param_string += "\""; + list.insert(list.end(), param_string); + + for (GSList * pglist = pages; pglist != NULL; pglist = g_slist_next(pglist)) { + ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(pglist->data); + page->paramString(list); } return; @@ -375,8 +363,8 @@ public: notebookpages are added or removed. */ void -ParamNotebookWdg::changed_page(GtkNotebookPage */*page*/, - guint pagenum) +ParamNotebookWdg::changed_page(GtkNotebookPage *page, + guint pagenum) { if (is_visible()) { _pref->set((int)pagenum, _doc, _node); @@ -396,11 +384,11 @@ ParamNotebook::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s { ParamNotebookWdg * nb = Gtk::manage(new ParamNotebookWdg(this, doc, node)); - // add pages (if any) + // add pages (if any) int i = -1; int pagenr = i; for (GSList * list = pages; list != NULL; list = g_slist_next(list)) { - i++; + i++; ParamNotebookPage * page = reinterpret_cast<ParamNotebookPage *>(list->data); Gtk::Widget * widg = page->get_widget(doc, node, changeSignal); nb->append_page(*widg, _(page->get_guitext())); @@ -410,7 +398,7 @@ ParamNotebook::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s } nb->show(); - + if (pagenr >= 0) nb->set_current_page(pagenr); return dynamic_cast<Gtk::Widget *>(nb); diff --git a/src/extension/paramnotebook.h b/src/extension/paramnotebook.h index 554c0826b..4b98ea967 100644 --- a/src/extension/paramnotebook.h +++ b/src/extension/paramnotebook.h @@ -1,5 +1,5 @@ -#ifndef INK_EXTENSION_PARAMNOTEBOOK_H_SEEN -#define INK_EXTENSION_PARAMNOTEBOOK_H_SEEN +#ifndef __INK_EXTENSION_PARAMNOTEBOOK_H__ +#define __INK_EXTENSION_PARAMNOTEBOOK_H__ /** \file * Notebook parameter for extensions. @@ -30,10 +30,10 @@ namespace Extension { class ParamNotebook : public Parameter { private: /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. + been allocated in memory. And should be free'd. It is the name of the current page. */ gchar * _value; - + GSList * pages; /**< A table to store the pages with parameters for this notebook. This only gets created if there are pages in this notebook */ @@ -41,10 +41,9 @@ public: ParamNotebook(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); virtual ~ParamNotebook(void); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); - virtual void insert_subparam_strings(std::list <std::string> &retlist); - - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + void string (std::list <std::string> &list); + + const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } const gchar * set (const int in, SPDocument * doc, Inkscape::XML::Node * node); }; /* class ParamNotebook */ @@ -55,7 +54,7 @@ public: } /* namespace Extension */ } /* namespace Inkscape */ -#endif /* INK_EXTENSION_PARAMNOTEBOOK_H_SEEN */ +#endif /* __INK_EXTENSION_PARAMNOTEBOOK_H__ */ /* Local Variables: diff --git a/src/extension/paramradiobutton.cpp b/src/extension/paramradiobutton.cpp index 1c7e3953f..5e8f20e52 100644 --- a/src/extension/paramradiobutton.cpp +++ b/src/extension/paramradiobutton.cpp @@ -167,12 +167,11 @@ ParamRadioButton::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::No \brief A function to get the current value of the parameter in a string form \return A string with the 'value' as command line argument */ -Glib::ustring * -ParamRadioButton::string (void) +void +ParamRadioButton::string (std::string &string) { - Glib::ustring * param_string = new Glib::ustring(""); - *param_string += _value; - return param_string; + string += _value; + return; } /** \brief A special radiobutton class to use in ParamRadioButton */ diff --git a/src/extension/paramradiobutton.h b/src/extension/paramradiobutton.h index be201a871..584e45219 100644 --- a/src/extension/paramradiobutton.h +++ b/src/extension/paramradiobutton.h @@ -1,5 +1,5 @@ -#ifndef INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN -#define INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN +#ifndef __INK_EXTENSION_PARAMRADIOBUTTON_H__ +#define __INK_EXTENSION_PARAMRADIOBUTTON_H__ /** \file * Radiobutton parameter for extensions. @@ -30,19 +30,19 @@ namespace Extension { class ParamRadioButton : public Parameter { private: /** \brief Internal value. This should point to a string that has - been allocated in memory. And should be free'd. + been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; - + GSList * choices; /**< A table to store the choice strings */ - + public: ParamRadioButton(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); virtual ~ParamRadioButton(void); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); - - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + void string (std::string &string); + + const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; } const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); }; /* class ParamRadioButton */ @@ -53,5 +53,5 @@ public: } /* namespace Extension */ } /* namespace Inkscape */ -#endif /* INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN */ +#endif /* __INK_EXTENSION_PARAMRADIOBUTTON_H__ */ diff --git a/src/extension/paramstring.cpp b/src/extension/paramstring.cpp index fe08bc500..953cb7daf 100644 --- a/src/extension/paramstring.cpp +++ b/src/extension/paramstring.cpp @@ -58,12 +58,14 @@ ParamString::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * } /** \brief Return the value as a string */ -Glib::ustring * -ParamString::string (void) +void +ParamString::string (std::string &string) { if (_value == NULL) - return new Glib::ustring(""); - return new Glib::ustring(_value); + return; + + string += _value; + return; } /** \brief Initialize the object, to do that, copy the data. */ diff --git a/src/extension/paramstring.h b/src/extension/paramstring.h index eaadd95d7..14a3f622f 100644 --- a/src/extension/paramstring.h +++ b/src/extension/paramstring.h @@ -28,7 +28,7 @@ public: const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - Glib::ustring * string (void); + void string (std::string &string); }; diff --git a/src/extension/prefdialog.cpp b/src/extension/prefdialog.cpp index 280269ec2..5a665330b 100644 --- a/src/extension/prefdialog.cpp +++ b/src/extension/prefdialog.cpp @@ -2,7 +2,7 @@ * Authors: * Ted Gould <ted@gould.cx> * - * Copyright (C) 2005-2007 Authors + * Copyright (C) 2005-2008 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -21,6 +21,7 @@ #include "preferences.h" #include "effect.h" +#include "implementation/implementation.h" #include "prefdialog.h" @@ -38,20 +39,27 @@ namespace Extension { in the title. It adds a few buttons and sets up handlers for them. It also places the passed in widgets into the dialog. */ -PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, ExecutionEnv * exEnv, Effect * effect, sigc::signal<void> * changeSignal) : +PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * controls, Effect * effect) : Gtk::Dialog::Dialog(_(name.c_str()), true, true), _help(help), _name(name), - _exEnv(exEnv), - _createdExEnv(false), _button_ok(NULL), _button_cancel(NULL), _button_preview(NULL), _param_preview(NULL), - _signal_param_change(changeSignal), - _effect(effect) + _effect(effect), + _exEnv(NULL) { Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox()); + if (controls == NULL) { + if (_effect == NULL) { + std::cout << "AH!!! No controls and no effect!!!" << std::endl; + return; + } + controls = _effect->get_imp()->prefs_effect(_effect, SP_ACTIVE_DESKTOP, &_signal_param_change, NULL); + _signal_param_change.connect(sigc::mem_fun(this, &PrefDialog::param_change)); + } + hbox->pack_start(*controls, true, true, 6); hbox->show(); this->get_vbox()->pack_start(*hbox, true, true, 6); @@ -64,17 +72,15 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co _button_cancel = add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CANCEL); _button_cancel->set_use_stock(true); - _button_ok = add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); + _button_ok = add_button(Gtk::Stock::APPLY, Gtk::RESPONSE_OK); _button_ok->set_use_stock(true); set_default_response(Gtk::RESPONSE_OK); _button_ok->grab_focus(); - // If we're working with an effect that can be live and - // the dialog can be pinned, put those options in too - if (_exEnv != NULL) { + if (_effect != NULL) { if (_param_preview == NULL) { XML::Document * doc = sp_repr_read_mem(live_param_xml, strlen(live_param_xml), NULL); - _param_preview = Parameter::make(doc->root(), _exEnv->_effect); + _param_preview = Parameter::make(doc->root(), _effect); } Gtk::HSeparator * sep = Gtk::manage(new Gtk::HSeparator()); @@ -88,33 +94,44 @@ PrefDialog::PrefDialog (Glib::ustring name, gchar const * help, Gtk::Widget * co hbox->show(); this->get_vbox()->pack_start(*hbox, true, true, 6); + Gtk::HBox * hbox = dynamic_cast<Gtk::HBox *>(_button_preview); + if (hbox != NULL) { + Gtk::Widget * back = hbox->children().back().get_widget(); + Gtk::CheckButton * cb = dynamic_cast<Gtk::CheckButton *>(back); + _checkbox_preview = cb; + } + preview_toggle(); _signal_preview.connect(sigc::mem_fun(this, &PrefDialog::preview_toggle)); - } GtkWidget *dlg = GTK_WIDGET(gobj()); sp_transientize(dlg); - if (_effect != NULL) { - _effect->set_pref_dialog(this); - } - return; } PrefDialog::~PrefDialog ( ) { - if (_effect != NULL) { - _effect->set_pref_dialog(NULL); - } if (_param_preview != NULL) { delete _param_preview; + _param_preview = NULL; + } + + if (_exEnv != NULL) { + _exEnv->cancel(); + delete _exEnv; + _exEnv = NULL; + } + + if (_effect != NULL) { + _effect->set_pref_dialog(NULL); } return; } +#if 0 /** \brief Runs the dialog \return The response to the dialog @@ -139,49 +156,76 @@ PrefDialog::run (void) { } return resp; } - -void -PrefDialog::setPreviewState (Glib::ustring state) { - (void)state; -} +#endif void PrefDialog::preview_toggle (void) { if(_param_preview->get_bool(NULL, NULL)) { set_modal(true); if (_exEnv == NULL) { - _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, _signal_param_change, this); - _createdExEnv = true; - _exEnv->livePreview(true); + _exEnv = new ExecutionEnv(_effect, SP_ACTIVE_DESKTOP, NULL, false, false); _exEnv->run(); } } else { - set_modal(false); - if (_exEnv != NULL) { - _exEnv->livePreview(false); - _exEnv->shutdown(_createdExEnv); + set_modal(false); + if (_exEnv != NULL) { + _exEnv->cancel(); + _exEnv->undo(); + delete _exEnv; _exEnv = NULL; - } + } } } void -PrefDialog::on_response (int signal) { +PrefDialog::param_change (void) { if (_exEnv != NULL) { - _param_preview->set_bool(false, NULL, NULL); - return; + _timersig.disconnect(); + _timersig = Glib::signal_timeout().connect(sigc::mem_fun(this, &PrefDialog::param_timer_expire), + 250, /* ms */ + Glib::PRIORITY_DEFAULT_IDLE); } + return; +} + +bool +PrefDialog::param_timer_expire (void) { + if (_exEnv != NULL) { + _exEnv->cancel(); + _exEnv->undo(); + _exEnv->run(); + } + + return false; +} + +void +PrefDialog::on_response (int signal) { if (signal == Gtk::RESPONSE_OK) { - if(_effect != NULL) - { + if (_exEnv == NULL) { _effect->effect(SP_ACTIVE_DESKTOP); + } else { + if (_exEnv->wait()) { + _exEnv->commit(); + } else { + _exEnv->undo(); + } + delete _exEnv; + _exEnv = NULL; } } - if (signal == Gtk::RESPONSE_CANCEL) { - // close the dialog - delete this; - } + + if (_param_preview != NULL) { + //_param_preview->set_bool(false, NULL, NULL); + _checkbox_preview->set_active(false); + //preview_toggle(); + } + + if (signal == Gtk::RESPONSE_CANCEL) { + // close the dialog + delete this; + } return; } diff --git a/src/extension/prefdialog.h b/src/extension/prefdialog.h index 32f0b8119..195ce8ea5 100644 --- a/src/extension/prefdialog.h +++ b/src/extension/prefdialog.h @@ -2,7 +2,7 @@ * Authors: * Ted Gould <ted@gould.cx> * - * Copyright (C) 2005 Authors + * Copyright (C) 2005,2007-2008 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -30,10 +30,6 @@ class PrefDialog : public Gtk::Dialog { gchar const * _help; /** \brief Name of the extension */ Glib::ustring _name; - /** \brief An execution environment if there is one */ - ExecutionEnv * _exEnv; - /** \brief Whether we created the \a _exEnv variable */ - bool _createdExEnv; /** \brief A pointer to the OK button */ Gtk::Button * _button_ok; @@ -42,44 +38,42 @@ class PrefDialog : public Gtk::Dialog { /** \brief Button to control live preview */ Gtk::Widget * _button_preview; - /** \brief Button to control whether the dialog is pinned */ - Gtk::Widget * _button_pinned; + /** \brief Checkbox for the preview */ + Gtk::CheckButton * _checkbox_preview; /** \brief Parameter to control live preview */ Parameter * _param_preview; - /** \brief Parameter to control pinning the dialog */ - Parameter * _param_pinned; - /** \brief XML to define the pinned parameter on the dialog */ - static const char * pinned_param_xml; /** \brief XML to define the live effects parameter on the dialog */ static const char * live_param_xml; /** \brief Signal that the user is changing the live effect state */ sigc::signal<void> _signal_preview; - /** \brief Signal that the user is changing the pinned state */ - sigc::signal<void> _signal_pinned; /** \brief Signal that one of the parameters change */ - sigc::signal<void> * _signal_param_change; + sigc::signal<void> _signal_param_change; + /** \brief If this is the preferences for an effect, the effect + that we're working with. */ Effect * _effect; + /** \brief If we're executing in preview mode here is the execution + environment for the effect. */ + ExecutionEnv * _exEnv; - void preview_toggle(void); - void pinned_toggle(void); + /** \brief The timer used to make it so that parameters don't respond + directly and allows for changes. */ + sigc::connection _timersig; + void preview_toggle(void); + void param_change(void); + bool param_timer_expire(void); void on_response (int signal); public: PrefDialog (Glib::ustring name, gchar const * help, - Gtk::Widget * controls, - ExecutionEnv * exEnv = NULL, - Effect * effect = NULL, - sigc::signal<void> * changeSignal = NULL); + Gtk::Widget * controls = NULL, + Effect * effect = NULL); virtual ~PrefDialog (); - int run (void); - - void setPreviewState (Glib::ustring state); }; |
