summaryrefslogtreecommitdiffstats
path: root/src/extension/execution-env.h
blob: d33bdc41766c02e0f5b55007069862b9acdb78d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Authors:
 *   Ted Gould <ted@gould.cx>
 *
 * Copyright (C) 2007 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef INKSCAPE_EXTENSION_EXECUTION_ENV_H__
#define INKSCAPE_EXTENSION_EXECUTION_ENV_H__

#include <glibmm/main.h>
#include <glibmm/ustring.h>

#include <gtkmm/dialog.h>

namespace Inkscape {

namespace UI {
namespace View {
class View;
} // namespace View
} // namespace UI

namespace Extension {

class Effect;

namespace  Implementation
{
class ImplementationDocumentCache;
}

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;
    /** \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 document cache if we were passed one. */
    Implementation::ImplementationDocumentCache * _docCache;

    /** \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;
public:

    /** \brief  Create a new context for execution 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,
                  Implementation::ImplementationDocumentCache * docCache = nullptr,
                  bool show_working = true,
                  bool show_errors = true);
    virtual ~ExecutionEnv ();

    /** \brief Starts the execution of the effect
        \return Returns whether the effect was executed to completion */
    void run ();
    /** \brief Cancel the execution of the effect */
    void cancel ();
    /** \brief Commit the changes to the document */
    void commit ();
    /** \brief Undoes what the effect completed. */
    void undo ();
    /** \brief Wait for the effect to complete if it hasn't. */
    bool wait ();
    void reselect ();

    /** \brief Return reference to working dialog (if any) */
    Gtk::Dialog *get_working_dialog () { return _visibleDialog; };

private:
    void runComplete ();
    void createWorkingDialog ();
    void workingCanceled (const int resp);
    void genDocCache ();
    void killDocCache ();
};

} }  /* namespace Inkscape, Extension */
#endif /* INKSCAPE_EXTENSION_EXECUTION_ENV_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 :