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