Code

Translations. POTFILES.in, inkcape.pot and fr.po updated.
[inkscape.git] / src / event-log.h
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, 2007 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 {
42         
43 public:
44     typedef Gtk::TreeModel::iterator iterator;
45     typedef Gtk::TreeModel::const_iterator const_iterator;
47     EventLog(SPDocument* document);
48     virtual ~EventLog();
50     /**
51      * Event datatype
52      */
54     struct EventModelColumns : public Gtk::TreeModelColumnRecord
55     {
56         Gtk::TreeModelColumn<Event *> event;
57         Gtk::TreeModelColumn<unsigned int> type;
58         Gtk::TreeModelColumn<Glib::ustring> description;
59         Gtk::TreeModelColumn<int> child_count;
61         EventModelColumns()
62         { 
63             add(event); add(type); add(description); add(child_count);
64         }
65     };
67     /**
68      * Implementation of Inkscape::UndoStackObserver methods
69      * \brief Modifies the log's entries and the view's selection when triggered
70      */
72     void notifyUndoEvent(Event *log);
73     void notifyRedoEvent(Event *log);
74     void notifyUndoCommitEvent(Event *log);
75     void notifyClearUndoEvent();
76     void notifyClearRedoEvent();
78     /**
79      * Accessor functions
80      */
82     Glib::RefPtr<Gtk::TreeModel> getEventListStore() const { return _event_list_store; }
83     const EventModelColumns& getColumns() const            { return _columns; }
84     iterator getCurrEvent() const                          { return _curr_event; }
85     iterator getCurrEventParent() const                    { return _curr_event_parent; }
87     void setCurrEvent(iterator event)          { _curr_event = event; }
88     void setCurrEventParent(iterator event)    { _curr_event_parent = event; }
89     void blockNotifications(bool status=true)  { _notifications_blocked = status; }
90     void rememberFileSave()                    { _last_saved = _curr_event; }
92     /* 
93      * Callback types for TreeView changes.
94      */
96     enum CallbackTypes { 
97         CALLB_SELECTION_CHANGE, 
98         CALLB_EXPAND, 
99         CALLB_COLLAPSE, 
100         CALLB_LAST 
101     };
103     typedef std::map<const CallbackTypes, sigc::connection> CallbackMap;
105     /**
106      * Connect with a TreeView.
107      */
108     void connectWithDialog(Gtk::TreeView *event_list_view, CallbackMap *callback_connections);
110     /*
111      * Updates the sensitivity and names of SP_VERB_EDIT_UNDO and SP_VERB_EDIT_REDO to reflect the
112      * current state.
113      */
114     void updateUndoVerbs();
116 private:
117     bool _connected;             //< connected with dialog
118     SPDocument *_document;       //< document that is logged
120     const EventModelColumns _columns;
122     Glib::RefPtr<Gtk::TreeStore> _event_list_store; 
123     Glib::RefPtr<Gtk::TreeSelection> _event_list_selection;
124     Gtk::TreeView *_event_list_view;
126     iterator _curr_event;        //< current event in _event_list_store
127     iterator _last_event;        //< end position in _event_list_store
128     iterator _curr_event_parent; //< parent to current event, if any
130     iterator _last_saved;        //< position where last document save occurred
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     /**
138      * Helper functions
139      */
141     const_iterator _getUndoEvent() const; //< returns the current undoable event or NULL if none
142     const_iterator _getRedoEvent() const; //< returns the current redoable event or NULL if none
144     void _clearUndo();  //< erase all previously commited events
145     void _clearRedo();  //< erase all previously undone events
147     void checkForVirginity(); //< marks the document as untouched if undo/redo reaches a previously saved state
149     // noncopyable, nonassignable
150     EventLog(EventLog const &other);
151     EventLog& operator=(EventLog const &other);
153 };
155 } // namespace Inkscape
157 #endif // INKSCAPE_EVENT_LOG_H
159 /*
160   Local Variables:
161   mode:c++
162   c-file-style:"stroustrup"
163   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
164   indent-tabs-mode:nil
165   fill-column:99
166   End:
167 */
168 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :