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 convenient 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 "event-log.h"
35 #include "ui/widget/panel.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 Widget::Panel {
120 public:
121 virtual ~UndoHistory();
123 static UndoHistory &getInstance();
124 void setDesktop(SPDesktop* desktop);
126 sigc::connection _document_replaced_connection;
128 protected:
130 SPDocument *_document;
131 EventLog *_event_log;
133 const EventLog::EventModelColumns *_columns;
135 Gtk::ScrolledWindow _scrolled_window;
137 Glib::RefPtr<Gtk::TreeModel> _event_list_store;
138 Gtk::TreeView _event_list_view;
139 Glib::RefPtr<Gtk::TreeSelection> _event_list_selection;
141 EventLog::CallbackMap _callback_connections;
143 void _onListSelectionChange();
144 void _onExpandEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
145 void _onCollapseEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
147 private:
148 UndoHistory();
150 // no default constructor, noncopyable, nonassignable
151 UndoHistory(UndoHistory const &d);
152 UndoHistory operator=(UndoHistory const &d);
154 struct GreaterThan : CellRendererInt::Filter {
155 GreaterThan(int _i) : i (_i) {}
156 bool operator() (const int& x) const { return x > i; }
157 int i;
158 };
160 static const CellRendererInt::Filter& greater_than_1;
161 };
163 } // namespace Dialog
164 } // namespace UI
165 } // namespace Inkscape
167 #endif //INKSCAPE_UI_DIALOG_UNDO_HISTORY_H
169 /*
170 Local Variables:
171 mode:c++
172 c-file-style:"stroustrup"
173 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
174 indent-tabs-mode:nil
175 fill-column:99
176 End:
177 */
178 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :