7b900fde5c1d67e41aef6e36773bf1d46be6e608
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();
124 void setDesktop(SPDesktop* desktop);
126 sigc::connection _document_replaced_connection;
128 protected:
130 SPDesktop *_desktop;
131 SPDocument *_document;
132 EventLog *_event_log;
134 const EventLog::EventModelColumns *_columns;
136 Gtk::ScrolledWindow _scrolled_window;
138 Glib::RefPtr<Gtk::TreeModel> _event_list_store;
139 Gtk::TreeView _event_list_view;
140 Glib::RefPtr<Gtk::TreeSelection> _event_list_selection;
142 EventLog::CallbackMap _callback_connections;
144 void _onListSelectionChange();
145 void _onExpandEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
146 void _onCollapseEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &path);
148 private:
150 // no default constructor, noncopyable, nonassignable
151 UndoHistory();
152 UndoHistory(UndoHistory const &d);
153 UndoHistory operator=(UndoHistory const &d);
155 struct GreaterThan : CellRendererInt::Filter {
156 GreaterThan(int _i) : i (_i) {}
157 bool operator() (const int& x) const { return x > i; }
158 int i;
159 };
161 static const CellRendererInt::Filter& greater_than_1;
162 };
164 } // namespace Dialog
165 } // namespace UI
166 } // namespace Inkscape
168 #endif //INKSCAPE_UI_DIALOG_UNDO_HISTORY_H
170 /*
171 Local Variables:
172 mode:c++
173 c-file-style:"stroustrup"
174 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
175 indent-tabs-mode:nil
176 fill-column:99
177 End:
178 */
179 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :