From 9912b702d1f761cbcb527644c2c637e6a84466e8 Mon Sep 17 00:00:00 2001 From: gouldtj Date: Thu, 1 Mar 2007 07:15:16 +0000 Subject: [PATCH] r14632@tres: ted | 2007-02-28 23:12:58 -0800 Splitting out the command line action class to try and leave SOME dependencies out of main.cpp. --- src/Makefile_insert | 1 + src/main-cmdlineact.cpp | 107 ++++++++++++++++++++++++++++++++++++++++ src/main-cmdlineact.h | 51 +++++++++++++++++++ src/main.cpp | 2 + 4 files changed, 161 insertions(+) create mode 100644 src/main-cmdlineact.cpp create mode 100644 src/main-cmdlineact.h diff --git a/src/Makefile_insert b/src/Makefile_insert index 04cebc866..281e8e148 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -91,6 +91,7 @@ libinkpre_a_SOURCES = \ layer-fns.cpp layer-fns.h \ layer-manager.cpp layer-manager.h \ macros.h \ + main-cmdlineact.cpp main-cmdlineact.h \ marker-status.cpp marker-status.h \ media.cpp media.h \ message-context.cpp message-context.h \ diff --git a/src/main-cmdlineact.cpp b/src/main-cmdlineact.cpp new file mode 100644 index 000000000..dc59e1a93 --- /dev/null +++ b/src/main-cmdlineact.cpp @@ -0,0 +1,107 @@ +/* + * Authors: + * Ted Gould + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL v2, read the file 'COPYING' for more information + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "main-cmdlineact.h" + +namespace Inkscape { + +std::list CmdLineAction::_list; + +CmdLineAction::CmdLineAction (bool isVerb, gchar const * arg) : _isVerb(isVerb), _arg(NULL) { + if (arg != NULL) { + _arg = g_strdup(arg); + } + + _list.insert(_list.end(), this); + + return; +} + +CmdLineAction::~CmdLineAction () { + if (_arg != NULL) { + g_free(_arg); + } +} + +void +CmdLineAction::doIt (Inkscape::UI::View::View * view) { + //printf("Doing: %s\n", _arg); + if (_isVerb) { + Inkscape::Verb * verb = Inkscape::Verb::getbyid(_arg); + if (verb == NULL) { + printf(_("Unable to find verb ID '%s' specified on the command line.\n"), _arg); + return; + } + SPAction * action = verb->get_action(view); + sp_action_perform(action, NULL); + } else { + SPDesktop * desktop = dynamic_cast(view); + if (desktop == NULL) { return; } + + SPDocument * doc = view->doc(); + SPObject * obj = doc->getObjectById(_arg); + if (obj == NULL) { + printf(_("Unable to find node ID: '%s'\n"), _arg); + return; + } + + Inkscape::Selection * selection = sp_desktop_selection(desktop); + selection->add(obj, false); + } + return; +} + +void +CmdLineAction::doList (Inkscape::UI::View::View * view) { + for (std::list::iterator i = _list.begin(); + i != _list.end(); i++) { + CmdLineAction * entry = *i; + entry->doIt(view); + } +} + +bool +CmdLineAction::idle (void) { + std::list desktops; + inkscape_get_all_desktops(desktops); + + // We're going to assume one desktop per document, because no one + // should have had time to make more at this point. + for (std::list::iterator i = desktops.begin(); + i != desktops.end(); i++) { + SPDesktop * desktop = *i; + //Inkscape::UI::View::View * view = dynamic_cast(desktop); + doList(desktop); + } + return false; +} + +} // Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/main-cmdlineact.h b/src/main-cmdlineact.h new file mode 100644 index 000000000..bcf94c5a2 --- /dev/null +++ b/src/main-cmdlineact.h @@ -0,0 +1,51 @@ + +#ifndef __INK_MAIN_CMD_LINE_ACTIONS_H__ +#define __INK_MAIN_CMD_LINE_ACTIONS_H__ + +/** \file + * Small actions that can be queued at the command line + */ + +/* + * Authors: + * Ted Gould + * + * Copyright (C) 2007 Authors + * + * Released under GNU GPL v2.x, read the file 'COPYING' for more information + */ + + +namespace Inkscape { + +class CmdLineAction { + bool _isVerb; + gchar * _arg; + + static std::list _list; + +public: + CmdLineAction (bool isVerb, gchar const * arg); + ~CmdLineAction (); + + void doIt (Inkscape::UI::View::View * view); + static void doList (Inkscape::UI::View::View * view); + static bool idle (void); +}; + +} // Inkscape + + + +#endif /* __INK_MAIN_CMD_LINE_ACTIONS_H__ */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/main.cpp b/src/main.cpp index d9e3138f9..dbca3f74c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -108,6 +108,8 @@ using Inkscape::Extension::Internal::PrintWin32; #include "application/application.h" +#include "main-cmdlineact.h" + enum { SP_ARG_NONE, SP_ARG_NOGUI, -- 2.30.2