1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#include <gtkmm/scrolledwindow.h>
#include "documentation_box.h"
#include "base/string_utilities.h"
#include "grt/common.h"
#include "grtpp_util.h"
#define TIMER_INTERVAL 700
DocumentationBox::DocumentationBox(wb::WBContextUI *wbui)
: Gtk::VBox(false, 0), _wbui(wbui), _multiple_items(false)
{
pack_start(_combo, false, false);
Gtk::ScrolledWindow *swin= Gtk::manage(new Gtk::ScrolledWindow());
swin->add(_text);
swin->set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
swin->set_shadow_type(Gtk::SHADOW_IN);
_text.set_wrap_mode(Gtk::WRAP_WORD_CHAR);
_text.signal_key_press_event().connect_notify(sigc::mem_fun(this, &DocumentationBox::text_key_press));
_text.signal_button_press_event().connect_notify(sigc::mem_fun(this, &DocumentationBox::text_button_press));
_text.get_buffer()->signal_changed().connect(sigc::mem_fun(this, &DocumentationBox::text_changed));
_combo.signal_changed().connect(sigc::mem_fun(this, &DocumentationBox::combo_changed));
pack_start(*swin, true, true);
show_all();
}
DocumentationBox::~DocumentationBox()
{
if(_timer)
_timer.disconnect();
}
void DocumentationBox::update_for_form(bec::UIForm *form)
{
if (_timer)
commit();
_initializing= true;
std::vector<std::string> items;
grt::ListRef<GrtObject> new_object_list;
std::string description;
_selected_form= form;
if (form)
description = _wbui->get_description_for_selection(form, new_object_list, items);
else
description = _wbui->get_description_for_selection(new_object_list, items);
// update only if selection was changed
if (!grt::compare_list_contents(_object_list, new_object_list))
{
_combo.clear();
// Set description text
_object_list= new_object_list;
// Set properties
_multiple_items= items.size() > 1;
// handle different number of selected items
if (!items.empty())
{
std::for_each(items.begin(), items.end(), sigc::mem_fun(_combo, &Gtk::ComboBoxText::append_text));
_combo.set_active(0);
// lock on multi selection
if (_multiple_items)
{
_text.get_buffer()->set_text("<double-click to overwrite multiple objects>");
_text.set_editable(false);
}
else
{
_text.get_buffer()->set_text(description);
_text.set_editable(true);
}
}
else
{
_combo.clear();
_combo.append_text(_("No Selection"));
_combo.set_active(0);
_text.get_buffer()->set_text("");
_text.set_editable(false);
}
}
_initializing= false;
}
void DocumentationBox::commit()
{
puts("COMMIT");
_timer.disconnect();
_wbui->set_description_for_selection(_object_list, _text.get_buffer()->get_text());
}
void DocumentationBox::text_changed()
{
if (!_initializing)
{
_timer.disconnect();
_timer= Glib::signal_timeout().connect(sigc::bind_return(sigc::mem_fun(this, &DocumentationBox::commit),false), TIMER_INTERVAL);
}
}
void DocumentationBox::text_button_press(GdkEventButton *ev)
{
if (ev->type == GDK_2BUTTON_PRESS && _multiple_items && !_text.get_editable())
{
_initializing= true;
_text.set_editable(true);
_text.get_buffer()->set_text("");
_initializing= false;
}
}
void DocumentationBox::combo_changed()
{
if (_combo.get_model()->children().size())
_combo.set_active(0);
}
void DocumentationBox::text_key_press(GdkEventKey *key)
{
if (key->state & GDK_CONTROL_MASK && key->keyval == GDK_Return && _text.get_editable())
{
commit();
}
}
|