Code

simplify sketch result to fix crash
[inkscape.git] / src / main-cmdlineact.cpp
1 /*
2  * Authors:
3  *   Ted Gould <ted@gould.cx>
4  *
5  * Copyright (C) 2007 Authors
6  *
7  * Released under GNU GPL v2, read the file 'COPYING' for more information
8  */
10 #include <ui/view/view.h>
11 #include <desktop.h>
12 #include <desktop-handles.h>
13 #include <helper/action.h>
14 #include <selection.h>
15 #include <verbs.h>
16 #include <inkscape.h>
17 #include <document.h>
19 #include <glibmm/i18n.h>
21 #include "main-cmdlineact.h"
23 namespace Inkscape {
25 std::list <CmdLineAction *> CmdLineAction::_list;
27 CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) {
28         if (arg != NULL) {
29                 _arg = g_strdup(arg);
30         }
32         _list.insert(_list.end(), this);
34         return;
35 }
37 CmdLineAction::~CmdLineAction () {
38         if (_arg != NULL) {
39                 g_free(_arg);
40         }
41 }
43 void
44 CmdLineAction::doIt (Inkscape::UI::View::View * view) {
45         //printf("Doing: %s\n", _arg);
46         if (_isVerb) {
47                 Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg);
48                 if (verb == NULL) {
49                         printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg);
50                         return;
51                 }
52                 SPAction * action = verb->get_action(view);
53                 sp_action_perform(action, NULL);
54         } else {
55                 SPDesktop * desktop = dynamic_cast<SPDesktop *>(view);
56                 if (desktop == NULL) { return; }
58                 SPDocument * doc = view->doc();
59                 SPObject * obj = doc->getObjectById(_arg);
60                 if (obj == NULL) {
61                         printf(_("Unable to find node ID: '%s'\n"), _arg);
62                         return;
63                 }
65                 Inkscape::Selection * selection = sp_desktop_selection(desktop);
66                 selection->add(obj, false);
67         }
68         return;
69 }
71 void
72 CmdLineAction::doList (Inkscape::UI::View::View * view) {
73         for (std::list<CmdLineAction *>::iterator i = _list.begin();
74                         i != _list.end(); i++) {
75                 CmdLineAction * entry = *i;
76                 entry->doIt(view);
77         }
78 }
80 bool
81 CmdLineAction::idle (void) {
82         std::list<SPDesktop *> desktops;
83         inkscape_get_all_desktops(desktops);
85         // We're going to assume one desktop per document, because no one
86         // should have had time to make more at this point.
87         for (std::list<SPDesktop *>::iterator i = desktops.begin();
88                         i != desktops.end(); i++) {
89                 SPDesktop * desktop = *i;
90                 //Inkscape::UI::View::View * view = dynamic_cast<Inkscape::UI::View::View *>(desktop);
91                 doList(desktop);
92         }
93         return false;
94 }
96 } // Inkscape
98 /*
99   Local Variables:
100   mode:c++
101   c-file-style:"stroustrup"
102   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
103   indent-tabs-mode:nil
104   fill-column:99
105   End:
106 */
107 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :