summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e0afed3)
raw | patch | inline | side by side (parent: e0afed3)
author | gouldtj <gouldtj@users.sourceforge.net> | |
Fri, 29 Feb 2008 21:37:22 +0000 (21:37 +0000) | ||
committer | gouldtj <gouldtj@users.sourceforge.net> | |
Fri, 29 Feb 2008 21:37:22 +0000 (21:37 +0000) |
Okay, sadly I'm not keeping the version history because I'm not convenced
that SVK will do it right. One mega-patch, but that's life.
Reshuffle the exection-env and prefdialog code so that the state machines
aren't intertwines, which fixes a whole host of bugs with them. I think
the behavior is correct now.
Make it so that the effects can count how many preferences they have to
determine if the dialog should be shown (fix above). Once this code was
written it was easy to make it show an ellipsis on the verb if there is
a dialog or not. This involved removing ellipsis from those effects that
had it hard coded.
Make it so that the parameters know that their command line options are
going into a list. They don't have to acknowledge it, but they can, and
specifically notebook does and handles it differently. This should fix
the notebooks on Win32, but doesn't apparently completely.
Change the script extension on windows to use pythonw instead of python
so that the command line doesn't appear all the time.
that SVK will do it right. One mega-patch, but that's life.
Reshuffle the exection-env and prefdialog code so that the state machines
aren't intertwines, which fixes a whole host of bugs with them. I think
the behavior is correct now.
Make it so that the effects can count how many preferences they have to
determine if the dialog should be shown (fix above). Once this code was
written it was easy to make it show an ellipsis on the verb if there is
a dialog or not. This involved removing ellipsis from those effects that
had it hard coded.
Make it so that the parameters know that their command line options are
going into a list. They don't have to acknowledge it, but they can, and
specifically notebook does and handles it differently. This should fix
the notebooks on Win32, but doesn't apparently completely.
Change the script extension on windows to use pythonw instead of python
so that the command line doesn't appear all the time.
31 files changed:
index 647caade702016deb2ec019803bdfccaa1ca9f43..211ecb31555fa8c69859a068dafebd248f0788c5 100644 (file)
<inkscape-extension>\r
- <_name>Custom...</_name>\r
+ <_name>Custom</_name>\r
<id>org.inkscape.color.custom</id>\r
<dependency type="executable" location="extensions">coloreffect.py</dependency>\r
<dependency type="executable" location="extensions">color_custom.py</dependency>\r
<script>\r
<command reldir="extensions" interpreter="python">color_custom.py</command>\r
</script>\r
-</inkscape-extension>
\ No newline at end of file
+</inkscape-extension>\r
index fe2fc612bf902e4313e5d46f1bc2357d415e5b6b..21816f0156568989dd401e75de45be8566c4458d 100644 (file)
<inkscape-extension>\r
- <_name>Replace color...</_name>\r
+ <_name>Replace color</_name>\r
<id>org.inkscape.color.replacecolor</id>\r
<dependency type="executable" location="extensions">coloreffect.py</dependency>\r
<dependency type="executable" location="extensions">color_replace.py</dependency>\r
index 547e85c89a92b82b25e2739e897d468dbc964557..a63c555126abe4cd20209f01bd0a87d5ca4bb184 100644 (file)
<inkscape-extension>\r
- <_name>Replace text...</_name>\r
+ <_name>Replace text</_name>\r
<id>org.inkscape.text.replacetext</id>\r
<dependency type="executable" location="extensions">chardataeffect.py</dependency>\r
<dependency type="executable" location="extensions">text_replace.py</dependency>\r
<script>\r
<command reldir="extensions" interpreter="python">text_replace.py</command>\r
</script>\r
-</inkscape-extension>
\ No newline at end of file
+</inkscape-extension>
index 76af73ed38e13950e269095beb8589357c1dde17..a45ef019953d27c009afae3957c586452db0c87a 100644 (file)
--- a/src/extension/effect.cpp
+++ b/src/extension/effect.cpp
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;
}
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;
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 44d18146af28c533629dcedebe8f1c4df68b9637..58e39c63dc084804efe07da2b3da87a1cb096604 100644 (file)
--- a/src/extension/effect.h
+++ b/src/extension/effect.h
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:
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);
+ }
}
};
index a978ec7cb4ba7a3873065af3c6c1e6ed6ce6dba2..fae764a9d156f62ab412e2f3259955ba8f0a7271 100644 (file)
* 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
*/
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());
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;
}
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 */
index 949d09db6294116df8081a6f705e53f18025f35c..c2d4e7e4aaffb07998cc0f4caf517962969137f1 100644 (file)
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 */
index 84f09aedb37b644f44f79a43606f84160ea8a97b..07803c187735eaff2be498dcad40c15ee79d39af 100644 (file)
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;
index e4f2dc88ecf1256667654f3d9eb9fcf25c7676a1..4af65dc92fb5b5f7fea833a1ce859ab159ace026 100644 (file)
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 */
This only gets created if there are parameters in this
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 {};
index 09dc9eb30dd4f99a00294da59cef9fcdb69fb361..37e4e15b81e23f54f127c739c5dcc4a09da19797 100644 (file)
*/
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 }
}
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");
Inkscape::Extension::db.get(SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE),
view->doc(), _filename.c_str(), FALSE, FALSE, FALSE);
- return;
+ return;
}
ScriptDocCache::~ScriptDocCache ( )
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);
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;
}
index 7ac97b9ed19895989a74aee6c33607da9b356d46..cdc4f32f4f288db3b511c2c9b779ecec80c52175 100644 (file)
--- a/src/extension/input.cpp
+++ b/src/extension/input.cpp
}
/**
- \return None
- \brief Destroys an Input extension
+ \return None
+ \brief Destroys an Input extension
*/
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)
/**
\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)
/**
\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)
/**
\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)
/**
\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)
/**
\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);
index 72e32ff25c0ef5c694fa014d37a57d3e3558240f..b324e6281478c1d25f82c003cdd702633c196de9 100644 (file)
}
/** \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;
}
/**
index a6d0c1b7bbed53bf9d7d0aba7fec6a039c0ca449..7f1be0fcc2a2998f7a7dc7e1a5d61915401c08a1 100644 (file)
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 */
index 2a32086a8bcab397851f00b38948e6b3d62a2f77..cb7437be03e96f8a1925f80b8cf480333536e5f6 100644 (file)
_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 */
index 2d5f3e2e497fa2367b085b497be7b7877b35c185..87c0fdd9c03ba2aa4c0fce6ca3c5f5be5ac5d692 100644 (file)
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 */
index 36020f6d141a35b637712dda40eef14f4c5fbbaa..199512e0ef13f2c68c017a992d2f5bcb841babc2 100644 (file)
\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;
}
index 9118a07addcfcba08d88946a6bc9f85336422e4d..b01a1534424888ad3284bce51ef390c17b095070 100644 (file)
-#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.
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 */
} /* namespace Extension */
} /* namespace Inkscape */
-#endif /* INK_EXTENSION_PARAMENUM_H_SEEN */
+#endif /* __INK_EXTENSION_PARAMENUM_H__ */
/*
Local Variables:
index 0db8d0199e1b4005cc591f192b392b4d108d3d6f..9a7535a257721c75405ff963553baa06fa951e36 100644 (file)
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);
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);
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);
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);
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);
/** \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;
}
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;
}
index 0d9668a550d7c1f4041b1eb3ffab5c2601855892..c5d03226cc487ae67ac98364bcd7599c46ede02b 100644 (file)
-#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.
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:
index 11172ecbb858018c5cf9c8b3d29e7c972c33b0f8..ee2284c8c3a62698d6df62b38325c14a5248ebbf 100644 (file)
@@ -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 */
index 7fd62126739d59b8e311e3023fa0386988cefacc..25edad7b201b372be7a1be062d0aea19945e786a 100644 (file)
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 */
index e59cf1c3469b50dfc9efedde0bd7ec79248cedcd..ca938141cb0f37b82c20d9e7f4f949d6a422d670 100644 (file)
@@ -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 */
index fe5de0d17b554686a5b291664cac2f8442704830..aa0d05aa7e43a56385b3e47f61be6edc24fb0559 100644 (file)
--- a/src/extension/paramint.h
+++ b/src/extension/paramint.h
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 */
index 041dd6370b8f8a4a08f71b2993ed1d171cebb87e..ea74f10b4b8842678a85a62323df36cf768bd0fb 100644 (file)
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 */
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);
child_repr = sp_repr_next(child_repr);
}
}
-
+
return;
}
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;
}
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;
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);
index 554c0826ba2982c14e248f2172236a1ffd255e4b..4b98ea967f1d4070734d3097906094b99a42a915 100644 (file)
-#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.
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 */
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 */
} /* namespace Extension */
} /* namespace Inkscape */
-#endif /* INK_EXTENSION_PARAMNOTEBOOK_H_SEEN */
+#endif /* __INK_EXTENSION_PARAMNOTEBOOK_H__ */
/*
Local Variables:
index 1c7e3953f2857661916f5e8b151fb534c8bd0325..5e8f20e521e9f555a6b3254002b54417b4a7b4dd 100644 (file)
@@ -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 */
index be201a8719a62bc7a8b3b7c69a588afb7926bdd9..584e45219b5f95ff29057721130bfde13ebe1fe1 100644 (file)
-#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.
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 */
} /* namespace Extension */
} /* namespace Inkscape */
-#endif /* INK_EXTENSION_PARAMRADIOBUTTON_H_SEEN */
+#endif /* __INK_EXTENSION_PARAMRADIOBUTTON_H__ */
index fe08bc5007368caa66fb4fd0b12f26cdcc344915..953cb7dafa0b74f3ab1a163796bd53bab95789d0 100644 (file)
}
/** \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. */
index eaadd95d7cfd41987bc5dd4022e10b127d4e6655..14a3f622fecbc729a231221d68115cb0e4ebbea8 100644 (file)
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);
};
index 280269ec277910d55b2783babbf1aa3ddd03f9c9..5a665330b3121e2357eb7b3839c84af748166885 100644 (file)
* 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
*/
#include "preferences.h"
#include "effect.h"
+#include "implementation/implementation.h"
#include "prefdialog.h"
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
}
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;
}
index 32f0b811919d1186789893edf363070b593ddd85..195ce8ea54252e6b27827fec226dc0edce7790f2 100644 (file)
* 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
*/
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;
/** \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);
};