From: Georg Baum Date: Fri, 14 Oct 2005 15:59:20 +0000 (+0000) Subject: new files for gtk thesaurus dialog from Bernhard Reiter X-Git-Tag: 1.6.10~13834 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0688b5facebac4855cbe4951072e0880aec83506;p=features.git new files for gtk thesaurus dialog from Bernhard Reiter git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10555 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/gtk/GThesaurus.C b/src/frontends/gtk/GThesaurus.C new file mode 100644 index 0000000000..2ffe591f03 --- /dev/null +++ b/src/frontends/gtk/GThesaurus.C @@ -0,0 +1,170 @@ +/** + * \file GThesaurus.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Bernhard Reiter + * + * Full author contact details are available in file CREDITS. + */ + +#include + +// Too hard to make concept checks work with this file +#ifdef _GLIBCXX_CONCEPT_CHECKS +#undef _GLIBCXX_CONCEPT_CHECKS +#endif +#ifdef _GLIBCPP_CONCEPT_CHECKS +#undef _GLIBCPP_CONCEPT_CHECKS +#endif + +#include "GThesaurus.h" +#include "ControlThesaurus.h" +#include "ghelpers.h" + +#include "support/lstrings.h" + +#include + +using std::string; + +namespace lyx { +namespace frontend { + +class synModelColumns : public Gtk::TreeModel::ColumnRecord +{ +public: + + synModelColumns() { add(name); } + + Gtk::TreeModelColumn name; +}; + +synModelColumns synColumns; + + +GThesaurus::GThesaurus(Dialog & parent) + : GViewCB(parent, _("Thesaurus"), false) +{} + + +void GThesaurus::doBuild() +{ + string const gladeName = findGladeFile("thesaurus"); + xml_ = Gnome::Glade::Xml::create(gladeName); + + xml_->get_widget("Cancel", cancelbutton_); + setCancel(cancelbutton_); + xml_->get_widget("Apply", applybutton_); + setApply(applybutton_); + xml_->get_widget("OK", okbutton_); + setOK(okbutton_); + + xml_->get_widget("Keyword", keywordentry_); + xml_->get_widget("Meanings", meaningsview_); + + meaningsview_->append_column(_("Synonym"), synColumns.name); + + + // Keyword entry changed + keywordentry_->signal_changed().connect( + sigc::mem_fun(*this, >hesaurus::update_lists)); + + // Single click in meanings (synonyms) list + meaningsview_->signal_cursor_changed().connect( + sigc::mem_fun(*this, >hesaurus::selection_changed)); + + // Double click in meanings (synonyms) list + meaningsview_->signal_row_activated().connect( + sigc::mem_fun(*this, >hesaurus::meaningsview_activated)); + +} + +void GThesaurus::update() +{ + string const contents = support::trim(controller().text()); + if (contents.empty()) { + applylock_ = true; + bc().valid(false); + } else { + applylock_ = false; + keywordentry_->set_text(Glib::locale_to_utf8(contents)); + bc().valid(true); + } + keywordentry_->grab_focus(); + update_lists(); + +} + + +void GThesaurus::selection_changed() +{ + Gtk::TreeModel::iterator iter = meaningsview_->get_selection()->get_selected(); + if(iter) { + if (!applylock_) bc().valid(true); + } + +} + + +void GThesaurus::meaningsview_activated(const Gtk::TreeModel::Path&, Gtk::TreeViewColumn*) +{ + Gtk::TreeModel::iterator iter = meaningsview_->get_selection()->get_selected(); + if(iter) { + Gtk::TreeModel::Row row = *iter; + keywordentry_->set_text(row[synColumns.name]); + } + selection_changed(); + update_lists(); + if (!applylock_) bc().valid(true); +} + + +void GThesaurus::apply() +{ + Gtk::TreeModel::iterator iter = meaningsview_->get_selection()->get_selected(); + if(iter) { + controller().replace(Glib::locale_from_utf8((*iter)[synColumns.name])); + } else if (keywordentry_->get_text_length()) { + controller().replace(Glib::locale_from_utf8(keywordentry_->get_text())); + } + update(); +} + + +void GThesaurus::update_lists() +{ + Thesaurus::Meanings meanings = controller().getMeanings(keywordentry_->get_text()); + synTreeStore_ = Gtk::TreeStore::create(synColumns); + + if (!meanings.empty()) { + for (Thesaurus::Meanings::const_iterator cit = meanings.begin(); + cit != meanings.end(); ++cit) { + + Gtk::TreeModel::Row row = *(synTreeStore_->append()); + row[synColumns.name] = cit->first; + + for (std::vector::const_iterator cit2 = cit->second.begin(); + cit2 != cit->second.end(); ++cit2) { + Gtk::TreeModel::Row childrow = *(synTreeStore_->append(row.children())); + childrow[synColumns.name] = *cit2; + } + } + meaningsview_->set_sensitive(true); + } else { + Gtk::TreeModel::Row row = *(synTreeStore_->append()); + row[synColumns.name] = _("No synonyms found"); + meaningsview_->set_sensitive(false); + } + meaningsview_->set_model(synTreeStore_); + + if (keywordentry_->get_text_length()) { + if (!applylock_) bc().valid(true); + } else { + bc().valid(false); + } +} + + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GThesaurus.h b/src/frontends/gtk/GThesaurus.h new file mode 100644 index 0000000000..1f98c2771c --- /dev/null +++ b/src/frontends/gtk/GThesaurus.h @@ -0,0 +1,56 @@ +// -*- C++ -*- +/** + * \file GThesaurus.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Bernhard Reiter + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GTHESAURUS_H +#define GTHESAURUS_H + +#include "GViewBase.h" + +namespace lyx { +namespace frontend { + +class ControlThesaurus; + +/** This class provides a GTK+ implementation of the Thesaurus Dialog. + */ +class GThesaurus : public GViewCB { +public: + GThesaurus(Dialog & parent); +private: + virtual void apply(); + virtual void doBuild(); + virtual void update(); + + /// updates the synonym list (e.g. when the keyword is changed) + void update_lists(); + /// enables the apply button if a synonym is selected from the list + void selection_changed(); + /// changes the keyword entry content to the synonym double-clicked on + void meaningsview_activated(const Gtk::TreeModel::Path&, Gtk::TreeViewColumn*); + + /** apply() won't act when this is true. + true if no text is selected when the thesaurus dialog is opened + */ + bool applylock_; + + Gtk::Button * cancelbutton_; + Gtk::Button * okbutton_; + Gtk::Button * applybutton_; + Gtk::Entry * keywordentry_; + Gtk::TreeView * meaningsview_; + Glib::RefPtr synTreeStore_; + +}; + +} // namespace frontend +} // namespace lyx + +#endif // GTHESAURUS_H diff --git a/src/frontends/gtk/glade/thesaurus.glade b/src/frontends/gtk/glade/thesaurus.glade new file mode 100644 index 0000000000..ca3f28cfa0 --- /dev/null +++ b/src/frontends/gtk/glade/thesaurus.glade @@ -0,0 +1,177 @@ + + + + + + + True + dialog1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-apply + True + GTK_RELIEF_NORMAL + True + -10 + + + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + True + -6 + + + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + 12 + True + False + 0 + + + + True + False + 6 + + + + True + _Keyword: + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + Keyword + + + 0 + False + False + + + + + + True + True + True + True + 0 + + True + * + False + + + 0 + True + True + + + + + 3 + False + True + + + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + False + True + + + + + 3 + True + True + + + + + 0 + True + True + + + + + + +