Browse Source

SelectionDialogs: improved search entry

merge-requests/365/head
Ole Christian Eidheim 10 years ago
parent
commit
a896ab7e3e
  1. 24
      src/selectiondialog.cc
  2. 18
      src/selectiondialog.h
  3. 2
      tests/stubs/selectiondialog.cc

24
src/selectiondialog.cc

@ -15,7 +15,7 @@ namespace sigc {
#endif
}
ListViewText::ListViewText(bool use_markup) : Gtk::TreeView(), use_markup(use_markup) {
SelectionDialogBase::ListViewText::ListViewText(bool use_markup) : Gtk::TreeView(), use_markup(use_markup) {
list_store = Gtk::ListStore::create(column_record);
set_model(list_store);
append_column("", cell_renderer);
@ -33,12 +33,12 @@ ListViewText::ListViewText(bool use_markup) : Gtk::TreeView(), use_markup(use_ma
set_rules_hint(true);
}
void ListViewText::append(const std::string& value) {
void SelectionDialogBase::ListViewText::append(const std::string& value) {
auto new_row=list_store->append();
new_row->set_value(column_record.text, value);
}
void ListViewText::clear() {
void SelectionDialogBase::ListViewText::clear() {
unset_model();
list_store.reset();
}
@ -261,21 +261,9 @@ bool SelectionDialog::on_key_press(GdkEventKey* key) {
hide();
return false;
}
else if(key->keyval==GDK_KEY_BackSpace) {
auto length=search_entry.get_text_length();
if(length>0)
search_entry.delete_text(length-1, length);
return true;
}
else {
gunichar unicode=gdk_keyval_to_unicode(key->keyval);
if(unicode>=32 && unicode!=126) {
int length=search_entry.get_text_length();
auto ustr=Glib::ustring(1, unicode);
search_entry.insert_text(ustr, ustr.bytes(), length);
return true;
}
}
else if(show_search_entry)
return search_entry.on_key_press_event(key);
hide();
return false;
}

18
src/selectiondialog.h

@ -4,7 +4,8 @@
#include "gtkmm.h"
#include <unordered_map>
class ListViewText : public Gtk::TreeView {
class SelectionDialogBase {
class ListViewText : public Gtk::TreeView {
class ColumnRecord : public Gtk::TreeModel::ColumnRecord {
public:
ColumnRecord() {
@ -12,18 +13,23 @@ class ListViewText : public Gtk::TreeView {
}
Gtk::TreeModelColumn<std::string> text;
};
public:
public:
bool use_markup;
ListViewText(bool use_markup);
void append(const std::string& value);
void clear();
private:
private:
Glib::RefPtr<Gtk::ListStore> list_store;
ColumnRecord column_record;
Gtk::CellRendererText cell_renderer;
};
};
class SearchEntry : public Gtk::Entry {
public:
SearchEntry() : Gtk::Entry() {}
bool on_key_press_event(GdkEventKey *event) override { return Gtk::Entry::on_key_press_event(event); };
};
class SelectionDialogBase {
public:
SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, bool show_search_entry, bool use_markup);
~SelectionDialogBase();
@ -48,7 +54,7 @@ protected:
Gtk::VBox vbox;
Gtk::ScrolledWindow scrolled_window;
ListViewText list_view_text;
Gtk::Entry search_entry;
SearchEntry search_entry;
bool show_search_entry;
std::string last_row;

2
tests/stubs/selectiondialog.cc

@ -1,6 +1,6 @@
#include "selectiondialog.h"
ListViewText::ListViewText(bool use_markup) {}
SelectionDialogBase::ListViewText::ListViewText(bool use_markup) {}
SelectionDialogBase::SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, bool show_search_entry, bool use_markup):
text_view(text_view), list_view_text(use_markup) {}

Loading…
Cancel
Save