1 /**
2 * Inkscape::EventLog
3 *
4 * A simple log for maintaining a history of commited, undone and redone events along with their
5 * type. It implements the UndoStackObserver and should be registered with a
6 * CompositeUndoStackObserver for each document. The event log is then notified on all commit, undo
7 * and redo events and will store a representation of them in an internal Gtk::TreeStore.
8 *
9 * Consecutive events of the same type are grouped with the first event as a parent and following
10 * as its children.
11 *
12 * If a Gtk::TreeView is connected to the event log, the TreeView's selection and its nodes
13 * expanded/collapsed state will be updated as events are commited, undone and redone. Whenever
14 * this happens, the event log will block the TreeView's callbacks to prevent circular updates.
15 *
16 * Author:
17 * Gustav Broberg <broberg@kth.se>
18 *
19 * Copyright (c) 2006 Authors
20 *
21 * Released under GNU GPL, read the file 'COPYING' for more information
22 */
24 #ifndef INKSCAPE_EVENT_LOG_H
25 #define INKSCAPE_EVENT_LOG_H
27 #include <gdkmm/pixbuf.h>
28 #include <glibmm/refptr.h>
29 #include <gtkmm/treestore.h>
30 #include <gtkmm/treeselection.h>
31 #include <gtkmm/treeview.h>
33 #include "undo-stack-observer.h"
34 #include "event.h"
36 namespace Inkscape {
38 /**
39 *
40 */
41 class EventLog : public UndoStackObserver {
43 public:
44 typedef Gtk::TreeModel::iterator iterator;
45 typedef Gtk::TreeModel::const_iterator const_iterator;
47 EventLog();
48 ~EventLog();
50 /**
51 * Event datatype
52 */
54 struct EventModelColumns : public Gtk::TreeModelColumnRecord
55 {
56 Gtk::TreeModelColumn<unsigned int> type;
57 Gtk::TreeModelColumn<Glib::ustring> description;
58 Gtk::TreeModelColumn<int> child_count;
60 EventModelColumns()
61 {
62 add(type); add(description); add(child_count);
63 }
64 };
66 /**
67 * Implementation of Inkscape::UndoStackObserver methods
68 * \brief Modifies the log's entries and the view's selection when triggered
69 */
71 void notifyUndoEvent(Event *log);
72 void notifyRedoEvent(Event *log);
73 void notifyUndoCommitEvent(Event *log);
75 /**
76 * Accessor functions
77 */
79 Glib::RefPtr<Gtk::TreeModel> getEventListStore() const { return _event_list_store; }
80 const EventModelColumns& getColumns() const { return _columns; }
81 iterator getCurrEvent() const { return _curr_event; }
82 iterator getCurrEventParent() const { return _curr_event_parent; }
84 void setCurrEvent(iterator event) { _curr_event = event; }
85 void setCurrEventParent(iterator event) { _curr_event_parent = event; }
86 void blockNotifications(bool status=true) { _notifications_blocked = status; }
88 void setDocument(SPDocument *document);
90 /*
91 * Callback types for TreeView changes.
92 */
94 enum CallbackTypes {
95 CALLB_SELECTION_CHANGE,
96 CALLB_EXPAND,
97 CALLB_COLLAPSE,
98 CALLB_LAST
99 };
101 typedef std::map<const CallbackTypes, sigc::connection> CallbackMap;
103 /**
104 * Connect with a TreeView.
105 */
106 void connectWithDialog(Gtk::TreeView *event_list_view, CallbackMap *callback_connections);
108 /*
109 * Updates the sensitivity and names of SP_VERB_EDIT_UNDO and SP_VERB_EDIT_REDO to reflect the
110 * current state.
111 */
112 void updateUndoVerbs();
114 private:
115 bool _connected; //< connected with dialog
116 SPDocument *_document; //< document that is logged
118 const EventModelColumns _columns;
120 /**
121 * Helper functions for initialization
122 */
124 Glib::RefPtr<Gtk::TreeStore> _event_list_store;
125 Glib::RefPtr<Gtk::TreeSelection> _event_list_selection;
126 Gtk::TreeView *_event_list_view;
128 iterator _curr_event; //< current event in _event_list_store
129 iterator _last_event; //< end position in _event_list_store
130 iterator _curr_event_parent; //< parent to current event, if any
132 bool _notifications_blocked; //< if notifications should be handled
134 // Map of connections used to temporary block/unblock callbacks in a TreeView
135 CallbackMap *_callback_connections;
137 const_iterator _getUndoEvent() const; //< returns the current undoable event or NULL if none
138 const_iterator _getRedoEvent() const; //< returns the current redoable event or NULL if none
140 // noncopyable, nonassignable
141 EventLog(EventLog const &other);
142 EventLog& operator=(EventLog const &other);
144 };
146 } // namespace Inkscape
148 #endif // INKSCAPE_EVENT_LOG_H
150 /*
151 Local Variables:
152 mode:c++
153 c-file-style:"stroustrup"
154 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
155 indent-tabs-mode:nil
156 fill-column:99
157 End:
158 */
159 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :