Text encoding hack and removal of cited-keys searching

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14023 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Spray 2006-06-06 17:47:28 +00:00
parent 87ce9b7647
commit 84d0c509b4
4 changed files with 121 additions and 130 deletions

View File

@ -1,6 +1,9 @@
2006-06-06 John Spray <spray@lyx.org> 2006-06-06 John Spray <spray@lyx.org>
* Alert_pimpl.C: escape special characters in strings before * Alert_pimpl.C: escape special characters in strings before
passing them to Gtk::Dialog as markup passing them to Gtk::Dialog as markup
* GCitation.[Ch]: text encoding hack to avoid crashing with
special characters in bibtex database. Simplify UI by removing
searching in cited keys.
2006-04-19 Bernhard Reiter <ockham@gmx.net> 2006-04-19 Bernhard Reiter <ockham@gmx.net>
* GExternal.[Ch], glade/external.glade: implement external dialog * GExternal.[Ch], glade/external.glade: implement external dialog

View File

@ -98,8 +98,6 @@ void GCitation::doBuild()
xml_->get_widget("Info", infoview_); xml_->get_widget("Info", infoview_);
xml_->get_widget("CaseSensitive", casecheck_); xml_->get_widget("CaseSensitive", casecheck_);
xml_->get_widget("SearchCite", citeradio_);
xml_->get_widget("SearchBib", bibradio_);
xml_->get_widget("SearchString", findentry_); xml_->get_widget("SearchString", findentry_);
xml_->get_widget("CaseSensitive", casecheck_); xml_->get_widget("CaseSensitive", casecheck_);
xml_->get_widget("RegularExpression", regexpcheck_); xml_->get_widget("RegularExpression", regexpcheck_);
@ -149,10 +147,6 @@ void GCitation::doBuild()
forwardbutton_->signal_clicked().connect( forwardbutton_->signal_clicked().connect(
sigc::mem_fun(*this, &GCitation::next)); sigc::mem_fun(*this, &GCitation::next));
bibradio_->signal_toggled().connect(
sigc::mem_fun(*this, &GCitation::set_search_buttons));
citeradio_->signal_toggled().connect(
sigc::mem_fun(*this, &GCitation::set_search_buttons));
findentry_->signal_changed().connect( findentry_->signal_changed().connect(
sigc::mem_fun(*this, &GCitation::set_search_buttons)); sigc::mem_fun(*this, &GCitation::set_search_buttons));
@ -279,11 +273,13 @@ void GCitation::update_contents()
cit != bibkeys.end(); ++cit) { cit != bibkeys.end(); ++cit) {
Gtk::TreeModel::iterator iter = allListStore_->append(); Gtk::TreeModel::iterator iter = allListStore_->append();
(*iter)[bibColumns.name] = Glib::locale_to_utf8(*cit); // ENCODING, FIXME: assuming ISO-8859 only for key name and info fields
// This is a hack to avoid a crash when populating the dialog from bibtex
// files containing non-ASCII characters.
(*iter)[bibColumns.name] = Glib::convert(*cit, "UTF-8", "ISO-8859-1");
(*iter)[bibColumns.cite] = false; //reset state (*iter)[bibColumns.cite] = false; //reset state
(*iter)[bibColumns.bib_order] = ++bib_order; (*iter)[bibColumns.bib_order] = ++bib_order;
(*iter)[bibColumns.info] = Glib::locale_to_utf8( (*iter)[bibColumns.info] = Glib::convert(biblio::getInfo(theMap,*cit), "UTF-8", "ISO-8859-1");
biblio::getInfo(theMap,*cit));
} }
// Now mark cite keys by setting their bibColumns.cite property to true // Now mark cite keys by setting their bibColumns.cite property to true
@ -309,11 +305,11 @@ void GCitation::update_contents()
// working on a document away from the bibtex file // working on a document away from the bibtex file
// we should keep it anyway. // we should keep it anyway.
Gtk::TreeModel::iterator iter = allListStore_->append(); Gtk::TreeModel::iterator iter = allListStore_->append();
(*iter)[bibColumns.name] = Glib::locale_to_utf8(*ccit); (*iter)[bibColumns.name] = Glib::convert(*ccit, "UTF-8", "ISO-8859-1");
(*iter)[bibColumns.cite] = true; (*iter)[bibColumns.cite] = true;
(*iter)[bibColumns.bib_order] = ++bib_order; (*iter)[bibColumns.bib_order] = ++bib_order;
(*iter)[bibColumns.info] = Glib::locale_to_utf8( (*iter)[bibColumns.info] = Glib::convert(
biblio::getInfo(theMap,*ccit)); biblio::getInfo(theMap,*ccit), "UTF-8", "ISO-8859-1");
} }
} }
} }
@ -540,7 +536,9 @@ void GCitation::apply()
for (Gtk::TreeModel::const_iterator cit=children.begin(); for (Gtk::TreeModel::const_iterator cit=children.begin();
cit!=children.end(); ++cit) { cit!=children.end(); ++cit) {
string item(support::trim(Glib::locale_from_utf8((*cit)[bibColumns.name]))); string item(support::trim(Glib::convert(
static_cast<Glib::ustring>((*cit)[bibColumns.name]),
"ISO-8859-1", "UTF-8")));
if (item.empty()) if (item.empty())
continue; continue;
if (i++ > 0) if (i++ > 0)
@ -567,106 +565,75 @@ void GCitation::find(biblio::Direction dir)
vector<string>::const_iterator start; vector<string>::const_iterator start;
bool search_cite = citeradio_->get_active();
bool const casesens = casecheck_->get_active(); bool const casesens = casecheck_->get_active();
string const str = Glib::locale_from_utf8(findentry_->get_text()); string const str = Glib::locale_from_utf8(findentry_->get_text());
Gtk::TreeModel::iterator iter; Gtk::TreeModel::iterator iter;
Gtk::TreeModel::Children::difference_type sel = 0; Gtk::TreeModel::Children::difference_type sel = 0;
if (search_cite) { for (iter = (bibFilter_->children()).begin();
for (iter = (citeFilter_->children()).begin(); iter != (bibFilter_->children()).end(); ++iter) {
iter != (citeFilter_->children()).end(); ++iter) {
bibkeys.push_back(Glib::locale_from_utf8( bibkeys.push_back(Glib::locale_from_utf8(
(*iter)[bibColumns.name])); (*iter)[bibColumns.name]));
}
iter = citeselection_->get_selected();
if (iter)
sel = std::distance((citeFilter_->children()).begin(), iter);
} else {
for (iter = (bibFilter_->children()).begin();
iter != (bibFilter_->children()).end(); ++iter) {
bibkeys.push_back(Glib::locale_from_utf8(
(*iter)[bibColumns.name]));
}
iter = bibselection_->get_selected();
if (iter)
sel = std::distance(
(bibFilter_->children()).begin(), iter);
} }
iter = bibselection_->get_selected();
if (iter)
sel = std::distance(
(bibFilter_->children()).begin(), iter);
start = bibkeys.begin(); start = bibkeys.begin();
if (sel >= 0 && if (sel >= 0 &&
Gtk::TreeModel::Children::size_type(sel) < bibkeys.size()) Gtk::TreeModel::Children::size_type(sel) < bibkeys.size())
std::advance(start, sel); std::advance(start, sel);
bool is_cite = !search_cite; // Find the NEXT instance...
while(is_cite != search_cite) { if (dir == biblio::FORWARD)
++start;
// Find the NEXT instance... vector<string>::const_iterator cit =
if (dir == biblio::FORWARD) biblio::searchKeys(theMap, bibkeys, str,
++start; start, type, dir, casesens);
vector<string>::const_iterator cit = if (cit == bibkeys.end()) {
biblio::searchKeys(theMap, bibkeys, str, if (dir == biblio::FORWARD) {
start, type, dir, casesens); start = bibkeys.begin();
}
else {
start = bibkeys.end();
--start;
}
cit = biblio::searchKeys(theMap, bibkeys, str,
start, type, dir, casesens);
if (cit == bibkeys.end()) { if (cit == bibkeys.end()) {
if (dir == biblio::FORWARD) {
start = bibkeys.begin();
}
else {
start = bibkeys.end();
--start;
}
cit = biblio::searchKeys(theMap, bibkeys, str,
start, type, dir, casesens);
if (cit == bibkeys.end()) {
return;
}
}
vector<string>::const_iterator bibstart = bibkeys.begin();
vector<string>::difference_type const found =
std::distance(bibstart, cit);
if (found == sel)
return; return;
}
start = cit;
if (search_cite)
iter = (citeFilter_->children()).begin();
else
iter = (bibFilter_->children()).begin();
std::advance(iter, found);
is_cite = (*iter)[bibColumns.cite];
} }
vector<string>::const_iterator bibstart = bibkeys.begin();
vector<string>::difference_type const found =
std::distance(bibstart, cit);
if (found == sel)
return;
start = cit;
iter = (bibFilter_->children()).begin();
std::advance(iter, found);
// Highlight and scroll to the key that was found // Highlight and scroll to the key that was found
if (search_cite) { bibselection_->select(iter);
citeselection_->select(iter); bibkeysview_->set_cursor(Gtk::TreePath(iter));
citekeysview_->set_cursor(Gtk::TreePath(iter)); bibkeysview_->scroll_to_row(Gtk::TreePath(iter));
citekeysview_->scroll_to_row(Gtk::TreePath(iter)); bib_selected();
cite_selected();
} else {
bibselection_->select(iter);
bibkeysview_->set_cursor(Gtk::TreePath(iter));
bibkeysview_->scroll_to_row(Gtk::TreePath(iter));
bib_selected();
}
} }
void GCitation::set_search_buttons() void GCitation::set_search_buttons()
{ {
bool val = findentry_->get_text_length() && ( bool val = findentry_->get_text_length()
(citeradio_->get_active() && !(citeFilter_->children()).empty()) && !(bibFilter_->children()).empty();
|| (bibradio_->get_active() && !(bibFilter_->children()).empty())
);
backbutton_->set_sensitive(val); backbutton_->set_sensitive(val);
forwardbutton_->set_sensitive(val); forwardbutton_->set_sensitive(val);
} }

View File

@ -108,8 +108,6 @@ private:
Gtk::TextView * infoview_; Gtk::TextView * infoview_;
Gtk::Entry * findentry_; Gtk::Entry * findentry_;
Gtk::CheckButton * citeradio_;
Gtk::CheckButton * bibradio_;
Gtk::CheckButton * casecheck_; Gtk::CheckButton * casecheck_;
Gtk::CheckButton * regexpcheck_; Gtk::CheckButton * regexpcheck_;

View File

@ -36,11 +36,73 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_default">True</property> <property name="can_default">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="label">gtk-undo</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property> <property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property> <property name="focus_on_click">True</property>
<property name="response_id">0</property> <property name="response_id">0</property>
<child>
<widget class="GtkAlignment" id="alignment19">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox10">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="stock">gtk-undo</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label25">
<property name="visible">True</property>
<property name="label">R_evert</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="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget> </widget>
</child> </child>
@ -452,45 +514,6 @@
<property name="homogeneous">False</property> <property name="homogeneous">False</property>
<property name="spacing">0</property> <property name="spacing">0</property>
<child>
<widget class="GtkRadioButton" id="SearchCite">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">S_elected keys</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="SearchBib">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">A_vailable keys</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
<property name="group">SearchCite</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child> <child>
<widget class="GtkCheckButton" id="CaseSensitive"> <widget class="GtkCheckButton" id="CaseSensitive">
<property name="visible">True</property> <property name="visible">True</property>
@ -533,7 +556,7 @@
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>
<property name="expand">True</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
</packing> </packing>
</child> </child>