fix Window->Common move for show-mixer
[ardour.git] / libs / surfaces / faderport / gui.cc
index 9e08885f883d5a6f16b4664f80ae0af88cee4e6c..5b0921e9ac051f351ac57647b4e4cd9b4b3695bb 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2009-2012 Paul Davis
+    Copyright (C) 2015 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-#include <iostream>
-#include <list>
-#include <vector>
-#include <string>
-
-#include <gtkmm/adjustment.h>
 #include <gtkmm/alignment.h>
-#include <gtkmm/box.h>
-#include <gtkmm/combobox.h>
-#include <gtkmm/liststore.h>
 #include <gtkmm/label.h>
-#include <gtkmm/spinbutton.h>
-#include <gtkmm/table.h>
-#include <gtkmm/treestore.h>
-
-namespace Gtk {
-       class CellRendererCombo;
-}
+#include <gtkmm/liststore.h>
 
 #include "pbd/unwind.h"
 #include "pbd/strsplit.h"
+#include "pbd/file_utils.h"
 
 #include "gtkmm2ext/actions.h"
+#include "gtkmm2ext/bindings.h"
 #include "gtkmm2ext/gtk_ui.h"
 #include "gtkmm2ext/gui_thread.h"
 #include "gtkmm2ext/utils.h"
 
 #include "ardour/audioengine.h"
+#include "ardour/filesystem_paths.h"
 
 #include "faderport.h"
+#include "gui.h"
 
-#include "i18n.h"
-
-namespace ArdourSurface {
-
-class FPGUI : public Gtk::VBox
-{
-public:
-       FPGUI (FaderPort&);
-       ~FPGUI ();
-
-private:
-       FaderPort& fp;
-       Gtk::Table table;
-       Gtk::ComboBox input_combo;
-       Gtk::ComboBox output_combo;
-       Gtk::ComboBox mix_combo;
-       Gtk::ComboBox proj_combo;
-       Gtk::ComboBox trns_combo;
-
-       void update_port_combos (std::vector<std::string> const&, std::vector<std::string> const&);
-       PBD::ScopedConnection connection_change_connection;
-       void connection_handler ();
-
-       struct MidiPortColumns : public Gtk::TreeModel::ColumnRecord {
-               MidiPortColumns() {
-                       add (short_name);
-                       add (full_name);
-               }
-               Gtk::TreeModelColumn<std::string> short_name;
-               Gtk::TreeModelColumn<std::string> full_name;
-       };
-
-       MidiPortColumns midi_port_columns;
-       bool ignore_active_change;
-
-       Glib::RefPtr<Gtk::ListStore> build_midi_port_list (std::vector<std::string> const & ports, bool for_input);
-       void active_port_changed (Gtk::ComboBox*,bool for_input);
-
-       struct ActionColumns : public Gtk::TreeModel::ColumnRecord {
-               ActionColumns() {
-                       add (name);
-                       add (path);
-               }
-               Gtk::TreeModelColumn<std::string> name;
-               Gtk::TreeModelColumn<std::string> path;
-       };
-
-       ActionColumns action_columns;
-       Glib::RefPtr<Gtk::TreeStore> available_action_model;
-       std::map<std::string,std::string> action_map; // map from action names to paths
-
-       void build_mix_action_combo (Gtk::ComboBox&);
-       void build_proj_action_combo (Gtk::ComboBox&);
-       void build_trns_action_combo (Gtk::ComboBox&);
-
-       void build_available_action_menu ();
-       void action_changed (Gtk::ComboBox*, FaderPort::ButtonID);
-};
-
-}
+#include "pbd/i18n.h"
 
 using namespace PBD;
 using namespace ARDOUR;
@@ -136,7 +66,7 @@ FaderPort::tear_down_gui ()
                        delete w;
                }
        }
-       delete (FPGUI*) gui;
+       delete static_cast<FPGUI*> (gui);
        gui = 0;
 }
 
@@ -151,6 +81,7 @@ FaderPort::build_gui ()
 FPGUI::FPGUI (FaderPort& p)
        : fp (p)
        , table (2, 5)
+       , action_table (5, 4)
        , ignore_active_change (false)
 {
        set_border_width (12);
@@ -160,68 +91,184 @@ FPGUI::FPGUI (FaderPort& p)
        table.set_border_width (12);
        table.set_homogeneous (false);
 
+       std::string data_file_path;
+       string name = "faderport-small.png";
+       Searchpath spath(ARDOUR::ardour_data_search_path());
+       spath.add_subdirectory_to_paths ("icons");
+       find_file (spath, name, data_file_path);
+       if (!data_file_path.empty()) {
+               image.set (data_file_path);
+               hpacker.pack_start (image, false, false);
+       }
+
        Gtk::Label* l;
        Gtk::Alignment* align;
        int row = 0;
 
-       vector<string> midi_inputs;
-       vector<string> midi_outputs;
-
-       ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsPhysical), midi_inputs);
-       ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsPhysical), midi_outputs);
-
-       update_port_combos (midi_inputs, midi_outputs);
-
        input_combo.pack_start (midi_port_columns.short_name);
        output_combo.pack_start (midi_port_columns.short_name);
 
        input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &input_combo, true));
        output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::active_port_changed), &output_combo, false));
 
-       l = manage (new Gtk::Label (_("Sends MIDI via:")));
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Incoming MIDI on:")));
        l->set_alignment (1.0, 0.5);
        table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
        table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
        row++;
 
-       l = manage (new Gtk::Label (_("Receives MIDI via:")));
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Outgoing MIDI on:")));
        l->set_alignment (1.0, 0.5);
        table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
        table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
        row++;
 
-       build_mix_action_combo (mix_combo);
-       build_proj_action_combo (proj_combo);
-       build_trns_action_combo (trns_combo);
+       build_mix_action_combo (mix_combo[0], FaderPort::ButtonState(0));
+       build_mix_action_combo (mix_combo[1], FaderPort::ShiftDown);
+       build_mix_action_combo (mix_combo[2], FaderPort::LongPress);
+
+       build_proj_action_combo (proj_combo[0], FaderPort::ButtonState(0));
+       build_proj_action_combo (proj_combo[1], FaderPort::ShiftDown);
+       build_proj_action_combo (proj_combo[2], FaderPort::LongPress);
+
+       build_trns_action_combo (trns_combo[0], FaderPort::ButtonState(0));
+       build_trns_action_combo (trns_combo[1], FaderPort::ShiftDown);
+       build_trns_action_combo (trns_combo[2], FaderPort::LongPress);
 
-       l = manage (new Gtk::Label (_("Mix Button")));
+       build_available_action_menu ();
+
+       build_foot_action_combo (foot_combo[0], FaderPort::ButtonState(0));
+       build_foot_action_combo (foot_combo[1], FaderPort::ShiftDown);
+       build_foot_action_combo (foot_combo[2], FaderPort::LongPress);
+
+       /* No shift-press combo for User because that is labelled as "next"
+        * (marker)
+        */
+
+       build_user_action_combo (user_combo[0], FaderPort::ButtonState(0));
+       build_user_action_combo (user_combo[1], FaderPort::LongPress);
+
+       action_table.set_row_spacings (4);
+       action_table.set_col_spacings (6);
+       action_table.set_border_width (12);
+       action_table.set_homogeneous (false);
+
+       int action_row = 0;
+
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Press Action")));
+       l->set_alignment (0.5, 0.5);
+       action_table.attach (*l, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Shift-Press Action")));
+       l->set_alignment (0.5, 0.5);
+       action_table.attach (*l, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Long Press Action")));
+       l->set_alignment (0.5, 0.5);
+       action_table.attach (*l, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_row++;
+
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Mix")));
        l->set_alignment (1.0, 0.5);
-       table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        align = manage (new Alignment);
        align->set (0.0, 0.5);
-       align->add (mix_combo);
-       table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
-       row++;
+       align->add (mix_combo[0]);
+       action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (mix_combo[1]);
+       action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (mix_combo[2]);
+       action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_row++;
 
-       l = manage (new Gtk::Label (_("Proj Button")));
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Proj")));
        l->set_alignment (1.0, 0.5);
-       table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        align = manage (new Alignment);
        align->set (0.0, 0.5);
-       align->add (proj_combo);
-       table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
-       row++;
+       align->add (proj_combo[0]);
+       action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (proj_combo[1]);
+       action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (proj_combo[2]);
+       action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_row++;
+
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Trns")));
+       l->set_alignment (1.0, 0.5);
+       action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (trns_combo[0]);
+       action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (trns_combo[1]);
+       action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (trns_combo[2]);
+       action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_row++;
 
-       l = manage (new Gtk::Label (_("Trns Button")));
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("User")));
        l->set_alignment (1.0, 0.5);
-       table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        align = manage (new Alignment);
        align->set (0.0, 0.5);
-       align->add (trns_combo);
-       table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align->add (user_combo[0]);
+       action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       /* skip shift press combo */
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (user_combo[1]);
+       action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_row++;
+
+       l = manage (new Gtk::Label);
+       l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Footswitch")));
+       l->set_alignment (1.0, 0.5);
+       action_table.attach (*l, 0, 1, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (foot_combo[0]);
+       action_table.attach (*align, 1, 2, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (foot_combo[1]);
+       action_table.attach (*align, 2, 3, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       align = manage (new Alignment);
+       align->set (0.0, 0.5);
+       align->add (foot_combo[2]);
+       action_table.attach (*align, 3, 4, action_row, action_row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+       action_row++;
+
+       table.attach (action_table, 0, 5, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
        row++;
 
-       pack_start (table, false, false);
+       hpacker.pack_start (table, true, true);
+       pack_start (hpacker, false, false);
+
+       /* update the port connection combos */
+
+       update_port_combos ();
+
+       /* catch future changes to connection state */
 
        fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FPGUI::connection_handler, this), gui_context());
 }
@@ -240,18 +287,18 @@ FPGUI::connection_handler ()
 
        PBD::Unwinder<bool> ici (ignore_active_change, true);
 
+       update_port_combos ();
+}
+
+void
+FPGUI::update_port_combos ()
+{
        vector<string> midi_inputs;
        vector<string> midi_outputs;
 
        ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
        ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
 
-       update_port_combos (midi_inputs, midi_outputs);
-}
-
-void
-FPGUI::update_port_combos (vector<string> const& midi_inputs, vector<string> const& midi_outputs)
-{
        Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
        Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
        bool input_found = false;
@@ -311,12 +358,14 @@ FPGUI::build_available_action_menu ()
        vector<string> labels;
        vector<string> tooltips;
        vector<string> keys;
-       vector<AccelKey> bindings;
+       vector<Glib::RefPtr<Gtk::Action> > actions;
+
+       ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
+
        typedef std::map<string,TreeIter> NodeMap;
        NodeMap nodes;
        NodeMap::iterator r;
 
-       ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
 
        vector<string>::iterator k;
        vector<string>::iterator p;
@@ -325,14 +374,14 @@ FPGUI::build_available_action_menu ()
 
        available_action_model->clear ();
 
-       /* Because there are button bindings built in that are not
-       in the key binding map, there needs to be a way to undo
-       a profile edit. */
        TreeIter rowp;
        TreeModel::Row parent;
+
+       /* Disabled item (row 0) */
+
        rowp = available_action_model->append();
        parent = *(rowp);
-       parent[action_columns.name] = _("Remove Binding");
+       parent[action_columns.name] = _("Disabled");
 
        /* Key aliasing */
 
@@ -406,42 +455,169 @@ FPGUI::build_available_action_menu ()
                        action_map[*l] = *p;
                }
 
-               row[action_columns.path] = (*p);
+               string path = (*p);
+               /* ControlProtocol::access_action() is not interested in the
+                  legacy "<Actions>/" prefix part of a path.
+               */
+               path = path.substr (strlen ("<Actions>/"));
+
+               row[action_columns.path] = path;
        }
 }
 
 void
-FPGUI::build_mix_action_combo (Gtk::ComboBox& cb)
+FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
+{
+       TreeModel::const_iterator row = cb->get_active ();
+       string action_path = (*row)[action_columns.path];
+
+       /* release binding */
+       fp.set_action (id, action_path, false, bs);
+}
+
+void
+FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
 {
        Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
        TreeIter rowp;
        TreeModel::Row row;
+       string current_action = fp.get_action (id, false, bs); /* lookup release action */
+       int active_row = -1;
+       int n;
+       vector<pair<string,string> >::const_iterator i;
 
        rowp = model->append();
        row = *(rowp);
-       row[action_columns.name] = _("Toggle Editor & Mixer Windows");
-       row[action_columns.path] = X_("Common/toggle-editor-mixer");
+       row[action_columns.name] = _("Disabled");
+       row[action_columns.path] = string();
 
-       rowp = model->append();
-       row = *(rowp);
-       row[action_columns.name] = _("Show/Hide Editor mixer strip");
-       row[action_columns.path] = X_("Editor/show-editor-mixer");
+       if (current_action.empty()) {
+               active_row = 0;
+       }
+
+       for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
+               rowp = model->append();
+               row = *(rowp);
+               row[action_columns.name] = i->first;
+               row[action_columns.path] = i->second;
+               if (current_action == i->second) {
+                       active_row = n+1;
+               }
+       }
 
        cb.set_model (model);
        cb.pack_start (action_columns.name);
 
-       cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, FaderPort::Mix));
+       if (active_row >= 0) {
+               cb.set_active (active_row);
+       }
+
+       cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, id, bs));
 }
 
 void
-FPGUI::build_proj_action_combo (Gtk::ComboBox& cb)
+FPGUI::build_mix_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
 {
+       vector<pair<string,string> > actions;
+
+       actions.push_back (make_pair (string (_("Show Mixer Window")), string (X_("Common/show-mixer"))));
+       actions.push_back (make_pair (string (_("Show/Hide Mixer list")), string (X_("Common/ToggleMixerList"))));
+       actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
+       actions.push_back (make_pair (string (_("Show/Hide Editor mixer strip")), string (X_("Editor/show-editor-mixer"))));
+
+       build_action_combo (cb, actions, FaderPort::Mix, bs);
 }
 
+void
+FPGUI::build_proj_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
+{
+       vector<pair<string,string> > actions;
+
+       actions.push_back (make_pair (string (_("Show Editor Window")), string (X_("Mixer/show-editor"))));
+       actions.push_back (make_pair (string("Toggle Editor Lists"), string(X_("Editor/show-editor-list"))));
+       actions.push_back (make_pair (string("Toggle Summary"), string(X_("Editor/ToggleSummary"))));
+       actions.push_back (make_pair (string("Toggle Meterbridge"), string(X_("Common/toggle-meterbridge"))));
+       actions.push_back (make_pair (string (_("Zoom to Session")), string (X_("Editor/zoom-to-session"))));
+
+//     actions.push_back (make_pair (string (_("Zoom In")), string (X_("Editor/temporal-zoom-in"))));
+//     actions.push_back (make_pair (string (_("Zoom Out")), string (X_("Editor/temporal-zoom-out"))));
+
+       build_action_combo (cb, actions, FaderPort::Proj, bs);
+}
 
 void
-FPGUI::build_trns_action_combo (Gtk::ComboBox& cb)
+FPGUI::build_trns_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
 {
+       vector<pair<string,string> > actions;
+
+       actions.push_back (make_pair (string("Toggle Big Clock"), string(X_("Window/toggle-big-clock"))));  //note:  this would really make sense if the Big Clock had transport buttons on it
+       actions.push_back (make_pair (string("Toggle Locations window"), string(X_("Window/toggle-locations"))));
+       actions.push_back (make_pair (string("Toggle Metronome"), string(X_("Transport/ToggleClick"))));
+       actions.push_back (make_pair (string("Toggle External Sync"), string(X_("Transport/ToggleExternalSync"))));
+       actions.push_back (make_pair (string("Toggle Follow Playhead"), string(X_("Editor/toggle-follow-playhead"))));
+
+//     actions.push_back (make_pair (string("Set Playhead @pointer"), string(X_("Editor/set-playhead"))));
+
+
+       build_action_combo (cb, actions, FaderPort::Trns, bs);
+}
+
+void
+FPGUI::build_foot_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
+{
+       vector<pair<string,string> > actions;
+
+       actions.push_back (make_pair (string("Toggle Roll"), string(X_("Transport/ToggleRoll"))));
+       actions.push_back (make_pair (string("Toggle Rec-Enable"), string(X_("Transport/Record"))));
+       actions.push_back (make_pair (string("Toggle Roll+Rec"), string(X_("Transport/record-roll"))));
+       actions.push_back (make_pair (string("Toggle Loop"), string(X_("Transport/Loop"))));
+       actions.push_back (make_pair (string("Toggle Click"), string(X_("Transport/ToggleClick"))));
+       actions.push_back (make_pair (string("Record with Pre-Roll"), string(X_("Transport/RecordPreroll"))));
+       actions.push_back (make_pair (string("Record with Count-In"), string(X_("Transport/RecordCountIn"))));
+
+       build_action_combo (cb, actions, FaderPort::Footswitch, bs);
+}
+
+bool
+FPGUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
+{
+       TreeModel::Row row = *iter;
+       string path = row[action_columns.path];
+
+       if (path == action_path) {
+               *found = iter;
+               return true;
+       }
+
+       return false;
+}
+
+void
+FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
+{
+       cb.set_model (available_action_model);
+       cb.pack_start (action_columns.name);
+       cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, FaderPort::User, bs));
+
+       /* set the active "row" to the right value for the current button binding */
+
+       string current_action = fp.get_action (FaderPort::User, false, bs); /* lookup release action */
+
+       if (current_action.empty()) {
+               cb.set_active (0); /* "disabled" */
+               return;
+       }
+
+       TreeModel::iterator iter = available_action_model->children().end();
+
+       available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
+
+       if (iter != available_action_model->children().end()) {
+               cb.set_active (iter);
+       } else {
+               cb.set_active (0);
+       }
+
 }
 
 Glib::RefPtr<Gtk::ListStore>
@@ -499,14 +675,3 @@ FPGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
                }
        }
 }
-
-void
-FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id)
-{
-       TreeModel::const_iterator row = cb->get_active ();
-       string action_path = (*row)[action_columns.path];
-
-       cerr << "Change " << id << " to " << action_path << endl;
-       
-       fp.set_action (id, action_path, true);
-}