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. 10
      src/selectiondialog.h
  3. 2
      tests/stubs/selectiondialog.cc

24
src/selectiondialog.cc

@ -15,7 +15,7 @@ namespace sigc {
#endif #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); list_store = Gtk::ListStore::create(column_record);
set_model(list_store); set_model(list_store);
append_column("", cell_renderer); append_column("", cell_renderer);
@ -33,12 +33,12 @@ ListViewText::ListViewText(bool use_markup) : Gtk::TreeView(), use_markup(use_ma
set_rules_hint(true); 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(); auto new_row=list_store->append();
new_row->set_value(column_record.text, value); new_row->set_value(column_record.text, value);
} }
void ListViewText::clear() { void SelectionDialogBase::ListViewText::clear() {
unset_model(); unset_model();
list_store.reset(); list_store.reset();
} }
@ -261,21 +261,9 @@ bool SelectionDialog::on_key_press(GdkEventKey* key) {
hide(); hide();
return false; return false;
} }
else if(key->keyval==GDK_KEY_BackSpace) { else if(show_search_entry)
auto length=search_entry.get_text_length(); return search_entry.on_key_press_event(key);
if(length>0) hide();
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;
}
}
return false; return false;
} }

10
src/selectiondialog.h

@ -4,6 +4,7 @@
#include "gtkmm.h" #include "gtkmm.h"
#include <unordered_map> #include <unordered_map>
class SelectionDialogBase {
class ListViewText : public Gtk::TreeView { class ListViewText : public Gtk::TreeView {
class ColumnRecord : public Gtk::TreeModel::ColumnRecord { class ColumnRecord : public Gtk::TreeModel::ColumnRecord {
public: public:
@ -23,7 +24,12 @@ private:
Gtk::CellRendererText cell_renderer; Gtk::CellRendererText cell_renderer;
}; };
class SelectionDialogBase { 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); };
};
public: public:
SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, bool show_search_entry, bool use_markup); SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark, bool show_search_entry, bool use_markup);
~SelectionDialogBase(); ~SelectionDialogBase();
@ -48,7 +54,7 @@ protected:
Gtk::VBox vbox; Gtk::VBox vbox;
Gtk::ScrolledWindow scrolled_window; Gtk::ScrolledWindow scrolled_window;
ListViewText list_view_text; ListViewText list_view_text;
Gtk::Entry search_entry; SearchEntry search_entry;
bool show_search_entry; bool show_search_entry;
std::string last_row; std::string last_row;

2
tests/stubs/selectiondialog.cc

@ -1,6 +1,6 @@
#include "selectiondialog.h" #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): 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) {} text_view(text_view), list_view_text(use_markup) {}

Loading…
Cancel
Save