mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
Prompter: add a reset to default option
This commit is contained in:
parent
c9e13d49d4
commit
58b98e8c5c
2 changed files with 34 additions and 7 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <gtkmm/image.h>
|
||||||
#include <gtkmm/stock.h>
|
#include <gtkmm/stock.h>
|
||||||
|
|
||||||
#include "pbd/whitespace.h"
|
#include "pbd/whitespace.h"
|
||||||
|
|
@ -67,11 +68,17 @@ Prompter::init (bool with_cancel)
|
||||||
entryLabel.set_line_wrap (true);
|
entryLabel.set_line_wrap (true);
|
||||||
entryLabel.set_name ("PrompterLabel");
|
entryLabel.set_name ("PrompterLabel");
|
||||||
|
|
||||||
|
Widget* w = manage (new Gtk::Image (Gtk::Stock::REVERT_TO_SAVED, Gtk::ICON_SIZE_MENU));
|
||||||
|
w->show ();
|
||||||
|
resetButton.add (*w);
|
||||||
|
resetButton.set_no_show_all ();
|
||||||
|
|
||||||
entryBox.set_homogeneous (false);
|
entryBox.set_homogeneous (false);
|
||||||
entryBox.set_spacing (5);
|
entryBox.set_spacing (5);
|
||||||
entryBox.set_border_width (10);
|
entryBox.set_border_width (10);
|
||||||
entryBox.pack_start (entryLabel, false, false);
|
entryBox.pack_start (entryLabel, false, false);
|
||||||
entryBox.pack_start (entry, true, true);
|
entryBox.pack_start (entry, true, true);
|
||||||
|
entryBox.pack_start (resetButton, false, false);
|
||||||
|
|
||||||
get_vbox()->pack_start (entryBox);
|
get_vbox()->pack_start (entryBox);
|
||||||
show_all_children();
|
show_all_children();
|
||||||
|
|
@ -89,6 +96,26 @@ Prompter::set_allow_empty (bool yn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Prompter::set_initial_text (std::string txt, bool allow_replace)
|
||||||
|
{
|
||||||
|
entry.set_text (txt);
|
||||||
|
entry.select_region (0, entry.get_text_length());
|
||||||
|
if (allow_replace) {
|
||||||
|
on_entry_changed ();
|
||||||
|
}
|
||||||
|
resetButton.set_sensitive (txt != default_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Prompter::set_default_text (std::string const& txt)
|
||||||
|
{
|
||||||
|
default_text = txt;
|
||||||
|
resetButton.show ();
|
||||||
|
resetButton.signal_clicked ().connect (sigc::track_obj([this] { entry.set_text (default_text);}, *this));
|
||||||
|
resetButton.set_sensitive (entry.get_text() != default_text);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Prompter::on_show ()
|
Prompter::on_show ()
|
||||||
{
|
{
|
||||||
|
|
@ -149,4 +176,6 @@ Prompter::on_entry_changed ()
|
||||||
} else {
|
} else {
|
||||||
set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetButton.set_sensitive (entry.get_text() != default_text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gtkmm/box.h>
|
#include <gtkmm/box.h>
|
||||||
|
#include <gtkmm/button.h>
|
||||||
#include <gtkmm/entry.h>
|
#include <gtkmm/entry.h>
|
||||||
#include <gtkmm/label.h>
|
#include <gtkmm/label.h>
|
||||||
#include <gtkmm/dialog.h>
|
#include <gtkmm/dialog.h>
|
||||||
|
|
@ -46,13 +47,8 @@ public:
|
||||||
entryLabel.set_label (prompt);
|
entryLabel.set_label (prompt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_initial_text (std::string txt, bool allow_replace = false) {
|
void set_initial_text (std::string txt, bool allow_replace = false);
|
||||||
entry.set_text (txt);
|
void set_default_text (std::string const& txt);
|
||||||
entry.select_region (0, entry.get_text_length());
|
|
||||||
if (allow_replace) {
|
|
||||||
on_entry_changed ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void change_labels (std::string ok, std::string cancel);
|
void change_labels (std::string ok, std::string cancel);
|
||||||
|
|
||||||
|
|
@ -69,9 +65,11 @@ private:
|
||||||
Gtk::Entry entry;
|
Gtk::Entry entry;
|
||||||
Gtk::HBox entryBox;
|
Gtk::HBox entryBox;
|
||||||
Gtk::Label entryLabel;
|
Gtk::Label entryLabel;
|
||||||
|
Gtk::Button resetButton;
|
||||||
bool first_show;
|
bool first_show;
|
||||||
bool can_accept_from_entry;
|
bool can_accept_from_entry;
|
||||||
bool allow_empty;
|
bool allow_empty;
|
||||||
|
std::string default_text;
|
||||||
|
|
||||||
void init (bool with_cancel);
|
void init (bool with_cancel);
|
||||||
void entry_activated ();
|
void entry_activated ();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue