update keyeditor when action label changes
[ardour.git] / gtk2_ardour / keyeditor.h
1 /*
2     Copyright (C) 2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_gtk_key_editor_h__
21 #define __ardour_gtk_key_editor_h__
22
23 #include <string>
24
25 #include <gtkmm/buttonbox.h>
26 #include <gtkmm/notebook.h>
27 #include <gtkmm/scrolledwindow.h>
28 #include <gtkmm/treeview.h>
29 #include <gtkmm/treestore.h>
30 #include "gtkmm2ext/searchbar.h"
31
32 #include "ardour_window.h"
33
34 namespace Gtkmm2ext {
35         class Bindings;
36 }
37
38 class KeyEditor : public ArdourWindow
39 {
40   public:
41         KeyEditor ();
42
43         void add_tab (std::string const &name, Gtkmm2ext::Bindings&);
44         void remove_tab (std::string const &name);
45
46         static sigc::signal<void> UpdateBindings;
47
48         private:
49         class Tab : public Gtk::VBox
50         {
51                 public:
52                 Tab (KeyEditor&, std::string const &name, Gtkmm2ext::Bindings*);
53
54                 uint32_t populate ();
55                 void unbind ();
56                 void bind (GdkEventKey* release_event, guint pressed_key);
57                 void action_selected ();
58                 void sort_column_changed ();
59                 void tab_mapped ();
60                 bool visible_func(const Gtk::TreeModel::const_iterator& iter) const;
61
62                 struct KeyEditorColumns : public Gtk::TreeModel::ColumnRecord {
63                         KeyEditorColumns () {
64                                 add (name);
65                                 add (binding);
66                                 add (path);
67                                 add (bindable);
68                                 add (action);
69                         }
70                         Gtk::TreeModelColumn<std::string> name;
71                         Gtk::TreeModelColumn<std::string> binding;
72                         Gtk::TreeModelColumn<std::string> path;
73                         Gtk::TreeModelColumn<bool> bindable;
74                         Gtk::TreeModelColumn<Glib::RefPtr<Gtk::Action> > action;
75                 };
76
77                 Gtk::VBox vpacker;
78                 /* give KeyEditor full access to these. This is just a helper
79                    class with no special semantics
80                 */
81
82                 KeyEditor& owner;
83                 std::string name;
84                 Gtkmm2ext::Bindings* bindings;
85                 Gtk::ScrolledWindow scroller;
86                 Gtk::TreeView view;
87                 Glib::RefPtr<Gtk::TreeStore> data_model;
88                 Glib::RefPtr<Gtk::TreeModelFilter> filter;
89                 Glib::RefPtr<Gtk::TreeModelSort> sorted_filter;
90                 KeyEditorColumns columns;
91                 guint last_keyval;
92
93                 protected:
94                 bool key_press_event (GdkEventKey*);
95                 bool key_release_event (GdkEventKey*);
96                 Gtk::TreeModel::iterator find_action_path (Gtk::TreeModel::const_iterator begin, Gtk::TreeModel::const_iterator end, const std::string& path) const;
97         };
98
99         friend class Tab;
100
101         Gtk::VBox vpacker;
102         Gtk::Notebook notebook;
103         Gtk::Button unbind_button;
104         Gtk::HButtonBox unbind_box;
105         Gtk::HBox reset_box;
106         Gtk::Button reset_button;
107         Gtk::Label reset_label;
108         Gtkmm2ext::SearchBar filter_entry;
109         std::string filter_string;
110
111         typedef std::vector<Tab*> Tabs;
112
113         Tabs tabs;
114         Tab* current_tab();
115
116         void unbind ();
117         void reset ();
118         void refresh ();
119         void page_change (GtkNotebookPage*, guint);
120
121         unsigned int sort_column;
122         Gtk::SortType sort_type;
123         void toggle_sort_type ();
124         void search_string_updated (const std::string&);
125 };
126
127 #endif /* __ardour_gtk_key_editor_h__ */