2857fb88a5e4c160f65ead579a4c427f2c197d41
1 /**
2 * Undo History dialog
3 *
4 * \brief A dialog for presenting an event log of commited, undone and redone events. Allows the
5 * user to undo and redo multiple events in a more convinient way than repateaded ctrl-z,
6 * ctrl-shift-z.
7 *
8 *
9 * Author:
10 * Gustav Broberg <broberg@kth.se>
11 *
12 * Copyright (C) 2006 Authors
13 *
14 * Released under GNU GPL. Read the file 'COPYING' for more information.
15 */
17 #ifndef INKSCAPE_UI_DIALOG_UNDO_HISTORY_H
18 #define INKSCAPE_UI_DIALOG_UNDO_HISTORY_H
20 #include <glibmm/refptr.h>
21 #include <gtkmm/cellrendererpixbuf.h>
22 #include <gtkmm/image.h>
23 #include <gtkmm/invisible.h>
24 #include <gtkmm/scrolledwindow.h>
25 #include <gtkmm/stock.h>
26 #include <gtkmm/treemodel.h>
27 #include <gtkmm/treeselection.h>
29 #include <functional>
30 #include <sstream>
32 #include "desktop.h"
33 #include "dialog.h"
34 #include "event-log.h"
36 #include "widgets/icon.h"
38 namespace Inkscape {
39 namespace UI {
40 namespace Dialog {
43 /* Custom cell renderers */
45 class CellRendererSPIcon : public Gtk::CellRendererPixbuf {
46 public:
48 CellRendererSPIcon() :
49 Glib::ObjectBase(typeid(CellRendererPixbuf)),
50 Gtk::CellRendererPixbuf(),
51 _property_icon(*this, "icon", Glib::RefPtr<Gdk::Pixbuf>(0)),
52 _property_event_type(*this, "event_type", 0)
53 { }
55 Glib::PropertyProxy<unsigned int>
56 property_event_type() { return _property_event_type.get_proxy(); }
58 protected:
60 virtual void
61 render_vfunc(const Glib::RefPtr<Gdk::Drawable>& window,
62 Gtk::Widget& widget,
63 const Gdk::Rectangle& background_area,
64 const Gdk::Rectangle& cell_area,
65 const Gdk::Rectangle& expose_area,
66 Gtk::CellRendererState flags);
67 private:
69 Glib::Property<Glib::RefPtr<Gdk::Pixbuf> > _property_icon;
70 Glib::Property<unsigned int> _property_event_type;
71 std::map<const unsigned int, Glib::RefPtr<Gdk::Pixbuf> > _icon_cache;
72 };
75 class CellRendererInt : public Gtk::CellRendererText {
76 public:
78 struct Filter : std::unary_function<int, bool> {
79 virtual ~Filter() {}
80 virtual bool operator() (const int&) const =0;
81 };
83 CellRendererInt(const Filter& filter=no_filter) :
84 Glib::ObjectBase(typeid(CellRendererText)),
85 Gtk::CellRendererText(),
86 _property_number(*this, "number", 0),
87 _filter (filter)
88 { }
91 Glib::PropertyProxy<int>
92 property_number() { return _property_number.get_proxy(); }
94 static const Filter& no_filter;
96 protected:
98 virtual void
99 render_vfunc(const Glib::RefPtr<Gdk::Drawable>& window,
100 Gtk::Widget& widget,
101 const Gdk::Rectangle& background_area,
102 const Gdk::Rectangle& cell_area,
103 const Gdk::Rectangle& expose_area,
104 Gtk::CellRendererState flags);
106 private:
108 Glib::Property<int> _property_number;
109 const Filter& _filter;
111 struct NoFilter : Filter { bool operator() (const int& x) const { return true; } };
112 };
115 /**
116 *
117 */
119 class UndoHistory : public Dialog {
120 public:
121 virtual ~UndoHistory();
123 static UndoHistory *create() { return new UndoHistory(); }
125 protected:
127 SPDesktop *_desktop;
128 SPDocument *_document;
129 EventLog *_event_log;
131 const EventLog::EventModelColumns *_columns;
133 Gtk::ScrolledWindow _scrolled_window;
135 Glib::RefPtr<Gtk::TreeModel> _event_list_store;
136 Gtk::TreeView _event_list_view;
137 Glib::RefPtr<Gtk::TreeSelection> _event_list_selection;
139 EventLog::CallbackMap _callback_connections;
141 void _onListSelectionChange();
142 void _onExpandEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
143 void _onCollapseEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
145 private:
147 // no default constructor, noncopyable, nonassignable
148 UndoHistory();
149 UndoHistory(UndoHistory const &d);
150 UndoHistory operator=(UndoHistory const &d);
152 struct GreaterThan : CellRendererInt::Filter {
153 GreaterThan(int _i) : i (_i) {}
154 bool operator() (const int& x) const { return x > i; }
155 int i;
156 };
158 static const CellRendererInt::Filter& greater_than_1;
159 };
162 } // namespace Dialog
163 } // namespace UI
164 } // namespace Inkscape
166 #endif //INKSCAPE_UI_DIALOG_UNDO_HISTORY_H
168 /*
169 Local Variables:
170 mode:c++
171 c-file-style:"stroustrup"
172 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
173 indent-tabs-mode:nil
174 fill-column:99
175 End:
176 */
177 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :