Prompter: add a reset to default option
This commit is contained in:
parent
c9e13d49d4
commit
58b98e8c5c
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <gtkmm/image.h>
|
||||
#include <gtkmm/stock.h>
|
||||
|
||||
#include "pbd/whitespace.h"
|
||||
@ -67,11 +68,17 @@ Prompter::init (bool with_cancel)
|
||||
entryLabel.set_line_wrap (true);
|
||||
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_spacing (5);
|
||||
entryBox.set_border_width (10);
|
||||
entryBox.pack_start (entryLabel, false, false);
|
||||
entryBox.pack_start (entry, true, true);
|
||||
entryBox.pack_start (resetButton, false, false);
|
||||
|
||||
get_vbox()->pack_start (entryBox);
|
||||
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
|
||||
Prompter::on_show ()
|
||||
{
|
||||
@ -149,4 +176,6 @@ Prompter::on_entry_changed ()
|
||||
} else {
|
||||
set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
|
||||
}
|
||||
|
||||
resetButton.set_sensitive (entry.get_text() != default_text);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <gtkmm/box.h>
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/entry.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/dialog.h>
|
||||
@ -46,13 +47,8 @@ public:
|
||||
entryLabel.set_label (prompt);
|
||||
}
|
||||
|
||||
void set_initial_text (std::string txt, bool allow_replace = false) {
|
||||
entry.set_text (txt);
|
||||
entry.select_region (0, entry.get_text_length());
|
||||
if (allow_replace) {
|
||||
on_entry_changed ();
|
||||
}
|
||||
}
|
||||
void set_initial_text (std::string txt, bool allow_replace = false);
|
||||
void set_default_text (std::string const& txt);
|
||||
|
||||
void change_labels (std::string ok, std::string cancel);
|
||||
|
||||
@ -69,9 +65,11 @@ private:
|
||||
Gtk::Entry entry;
|
||||
Gtk::HBox entryBox;
|
||||
Gtk::Label entryLabel;
|
||||
Gtk::Button resetButton;
|
||||
bool first_show;
|
||||
bool can_accept_from_entry;
|
||||
bool allow_empty;
|
||||
std::string default_text;
|
||||
|
||||
void init (bool with_cancel);
|
||||
void entry_activated ();
|
||||
|
Loading…
Reference in New Issue
Block a user