On 4/17/06, Aaron Spike <aaron@...749...> wrote:
Do I create a Verb and hook it up through there?
Yes, I think it's better to do this a verb.
If so, where can I find an example of how to use a verb with a button on a dialog?
I'm not sure about dialogs - looks like we didn't have it so far. But on toolbars, see sp_toolbox_button_new_from_verb in widgets/toolbox.cpp
I noticed that very few functions in Inkscape actually get to be Verbs. Should there be more verbs?
Absolutely. The test is simple: if a user may ever want to assign a key to the command or have it in the menu, it should be a verb. Also, if any other vector editor has a key for a similar action or has it in a menu, make it a verb as well.
From where should a verb get access to the active desktop/document?
They extract it from the action itself in one of the *::perform functions in verb.cpp. For example:
void EditVerb::perform(SPAction *action, void *data, void *pdata) { SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action)); if (!dt) return;
switch (reinterpret_caststd::size_t(data)) { case SP_VERB_EDIT_UNDO: sp_undo(dt, SP_DT_DOCUMENT(dt)); break;
Should I use sigc::bind() to pass the active desktop to the function directly in the dialog code?
Hmm, here's a problem. You pass the desktop (i.e. view) when you get the action from verb, and you then make a button with that action. For example in toolbox.cpp:
sp_toolbox_button_new_from_verb_with_doubleclick(GtkWidget *t, Inkscape::IconSize size, SPButtonType type, Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb,
Inkscape::UI::View::View *view, GtkTooltips *tt) { SPAction *action = verb->get_action(view); if (!action) return NULL; ... GtkWidget *b = sp_button_new(size, type, action, doubleclick_action, tt);
This works for toolbar buttons because they are always on the same fixed desktop. But dialog buttons may apply, with their dialog, to different desktops. Do we have to recreate the action on each desktop switch (sensed by the dialog) and reassign that new action to the button? Mental, can you suggest a solution?
Is SP_ACTIVE_DESKTOP evil?
Not by itself. You just need to know where it's safe to use. For example within verbs you should avoid it (though currently it's still much used in functions called by verbs, this needs to be fixed). This is because verbs can at some time be called by scripts or in some weird situations where there's no current desktop, or where you want to act on a non-current one. But in e.g. dialog which uses it to find out which desktop is active, SP_ACTIVE_DESKTOP is perfectly OK.
-- bulia byak Inkscape. Draw Freely. http://www.inkscape.org