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
This commit is contained in:
Georg Baum 2005-10-14 15:59:20 +00:00
parent e9b54d910b
commit 0688b5face
3 changed files with 403 additions and 0 deletions

View File

@ -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 <config.h>
// 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 <libglademm.h>
using std::string;
namespace lyx {
namespace frontend {
class synModelColumns : public Gtk::TreeModel::ColumnRecord
{
public:
synModelColumns() { add(name); }
Gtk::TreeModelColumn<Glib::ustring> name;
};
synModelColumns synColumns;
GThesaurus::GThesaurus(Dialog & parent)
: GViewCB<ControlThesaurus, GViewGladeB>(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, &GThesaurus::update_lists));
// Single click in meanings (synonyms) list
meaningsview_->signal_cursor_changed().connect(
sigc::mem_fun(*this, &GThesaurus::selection_changed));
// Double click in meanings (synonyms) list
meaningsview_->signal_row_activated().connect(
sigc::mem_fun(*this, &GThesaurus::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<string>::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

View File

@ -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<ControlThesaurus, GViewGladeB> {
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<Gtk::TreeStore> synTreeStore_;
};
} // namespace frontend
} // namespace lyx
#endif // GTHESAURUS_H

View File

@ -0,0 +1,177 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkDialog" id="dialog">
<property name="visible">True</property>
<property name="title" translatable="yes">dialog1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">True</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">True</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area2">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="Apply">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-apply</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-10</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="Cancel">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="OK">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">6</property>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">_Keyword:</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="mnemonic_widget">Keyword</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="Keyword">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">3</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="Meanings">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">3</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>