From: John Spray Date: Sat, 21 Jan 2006 11:10:33 +0000 (+0000) Subject: Add Bernhard's GTK+ citation dialog X-Git-Tag: 1.6.10~13685 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=465b672789f282445af7b64d3e90a1357c6c3b0a;p=features.git Add Bernhard's GTK+ citation dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10760 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index dd54a61e2e..c7eb0884e8 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,8 @@ +2006-01-20 Bernhard Reiter + + * GCitation.[Ch], glade/citation.glade: Add the citation dialog + * Dialogs.C, Makefile.am, glade/Makefile.am: Use GCitation + 2005-10-12 Bernhard Reiter * The Thesaurus dialog diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 2c23bc8a32..206f97be85 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -66,7 +66,7 @@ #include "FormBranch.h" #include "GChanges.h" #include "GCharacter.h" -#include "FormCitation.h" +#include "GCitation.h" #include "GDocument.h" #include "GErrorList.h" #include "GERT.h" @@ -182,7 +182,6 @@ Dialogs::DialogPtr Dialogs::build(string const & name) BOOST_ASSERT(isValidName(name)); DialogPtr dialog(new Dialog(lyxview_, name)); - dialog->bc().view(new xformsBC(dialog->bc())); if (name == "aboutlyx") { dialog->bc().view(new GBC(dialog->bc())); @@ -190,10 +189,12 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GAboutlyx(*dialog)); dialog->bc().bp(new OkCancelPolicy); } else if (name == "bibitem") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlCommand(*dialog, name)); dialog->setView(new FormBibitem(*dialog)); dialog->bc().bp(new OkCancelReadOnlyPolicy); } else if (name == "bibtex") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlBibtex(*dialog)); dialog->setView(new FormBibtex(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); @@ -213,8 +214,9 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GCharacter(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "citation") { + dialog->bc().view(new GBC(dialog->bc())); dialog->setController(new ControlCitation(*dialog)); - dialog->setView(new FormCitation(*dialog)); + dialog->setView(new GCitation(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "document") { dialog->bc().view(new GBC(dialog->bc())); @@ -232,6 +234,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GERT(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "external") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlExternal(*dialog)); dialog->setView(new FormExternal(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); @@ -293,6 +296,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(10, 4, 3, deco2_width, deco2_height, deco2_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -307,6 +311,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(4, 2, 2, darrow_width, darrow_height, darrow_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -318,6 +323,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(31, 4, 8, bop_width, bop_height, bop_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -329,6 +335,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(35, 4, 9, brel_width, brel_height, brel_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -342,6 +349,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(28, 7, 4, greek_width, greek_height, greek_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -359,6 +367,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(4, 2, 2, misc3_width, misc3_height, misc3_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -370,6 +379,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(4, 4, 1, dots_width, dots_height, dots_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -381,6 +391,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(14, 3, 5, varsz_width, varsz_height, varsz_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -394,6 +405,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(26, 3, 9, ams7_width, ams7_height, ams7_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -407,6 +419,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(6, 3, 2, ams3_width, ams3_height, ams3_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -418,6 +431,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(66, 6, 11, ams_rel_width, ams_rel_height, ams_rel_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -429,6 +443,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(51, 6, 9, ams_nrel_width, ams_nrel_height, ams_nrel_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -440,6 +455,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) bitmap->addBitmap( BitmapStore(23, 3, 8, ams_ops_width, ams_ops_height, ams_ops_bits, true)); + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(bitmap); dialog->bc().bp(new IgnorantPolicy); @@ -455,10 +471,12 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GMathsMatrix(*dialog)); dialog->bc().bp(new OkCancelReadOnlyPolicy); } else if (name == "mathspace") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(new FormMathsSpace(*dialog)); dialog->bc().bp(new IgnorantPolicy); } else if (name == "mathstyle") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlMath(*dialog)); dialog->setView(new FormMathsStyle(*dialog)); dialog->bc().bp(new IgnorantPolicy); @@ -468,6 +486,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GNote(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "branch") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlBranch(*dialog)); dialog->setView(new FormBranch(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); @@ -477,10 +496,12 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GParagraph(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "preamble") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlPreamble(*dialog)); dialog->setView(new FormPreamble(*dialog)); dialog->bc().bp(new OkApplyCancelPolicy); } else if (name == "prefs") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlPrefs(*dialog)); dialog->setView(new FormPreferences(*dialog)); dialog->bc().bp(new PreferencesPolicy); @@ -505,6 +526,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GSpellchecker(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); } else if (name == "tabular") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlTabular(*dialog)); dialog->setView(new FormTabular(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); @@ -541,6 +563,7 @@ Dialogs::DialogPtr Dialogs::build(string const & name) dialog->setView(new GVSpace(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); } else if (name == "wrap") { + dialog->bc().view(new xformsBC(dialog->bc())); dialog->setController(new ControlWrap(*dialog)); dialog->setView(new FormWrap(*dialog)); dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy); diff --git a/src/frontends/gtk/GCitation.C b/src/frontends/gtk/GCitation.C new file mode 100644 index 0000000000..c16c2e3ab1 --- /dev/null +++ b/src/frontends/gtk/GCitation.C @@ -0,0 +1,666 @@ +/** + * \file GCitation.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 "GCitation.h" +#include "ControlCitation.h" +#include "ghelpers.h" + +#include "bufferparams.h" + +#include "support/lstrings.h" + +#include + +using std::string; +using std::vector; + +namespace lyx { +namespace frontend { + +class bibModelColumns : public Gtk::TreeModel::ColumnRecord +{ +public: + + bibModelColumns() { add(name); add(cite); add(bib_order); add(info); } + + Gtk::TreeModelColumn name; + Gtk::TreeModelColumn cite; + Gtk::TreeModelColumn bib_order; + Gtk::TreeModelColumn info; +}; + +bibModelColumns bibColumns; + +class styleModelColumns : public Gtk::TreeModel::ColumnRecord +{ +public: + + styleModelColumns() { add(name); } + + Gtk::TreeModelColumn name; +}; + +bool GCitation::bib_visible(const Gtk::TreeModel::const_iterator& iter) +{ + if (iter) + return !((*iter)[bibColumns.cite]); + return true; +} + +styleModelColumns styleColumns; + + +GCitation::GCitation(Dialog & parent) + : GViewCB(parent, _("Citation"), false) +{} + + +void GCitation::doBuild() +{ + string const gladeName = findGladeFile("citation"); + xml_ = Gnome::Glade::Xml::create(gladeName); + + xml_->get_widget("Restore", restorebutton_); + setRestore(restorebutton_); + xml_->get_widget("Cancel", cancelbutton_); + setCancel(cancelbutton_); + xml_->get_widget("Apply", applybutton_); + setApply(applybutton_); + xml_->get_widget("OK", okbutton_); + setOK(okbutton_); + + xml_->get_widget("Remove", removebutton_); + xml_->get_widget("Add", addbutton_); + xml_->get_widget("Back", backbutton_); + xml_->get_widget("Forward", forwardbutton_); + xml_->get_widget("Up", upbutton_); + xml_->get_widget("Down", downbutton_); + + xml_->get_widget("CiteKeys", citekeysview_); + xml_->get_widget("BibKeys", bibkeysview_); + xml_->get_widget("Info", infoview_); + xml_->get_widget("CaseSensitive", casecheck_); + + xml_->get_widget("SearchCite", citeradio_); + xml_->get_widget("SearchBib", bibradio_); + xml_->get_widget("SearchString", findentry_); + xml_->get_widget("CaseSensitive", casecheck_); + xml_->get_widget("RegularExpression", regexpcheck_); + + xml_->get_widget("StyleLabel", stylelabel_); + xml_->get_widget("Style", stylecombo_); + xml_->get_widget("TextBeforeLabel", beforelabel_); + xml_->get_widget("TextBefore", beforeentry_); + xml_->get_widget("TextAfter", afterentry_); + xml_->get_widget("FullAuthorList", authorcheck_); + xml_->get_widget("ForceUpperCase", uppercasecheck_); + + info_ = Gtk::TextBuffer::create(); + infoview_->set_buffer(info_); + + allListStore_ = Gtk::ListStore::create(bibColumns); + + Gtk::TreeModel::Path rootpath; //required for gtkmm < 2.6 + + citekeysview_->append_column(_("CiteKeys"), bibColumns.name); + citeFilter_ = Gtk::TreeModelFilter::create(allListStore_, rootpath); + citeFilter_->set_visible_column(bibColumns.cite); + citekeysview_->set_model(citeFilter_); + citeselection_ = citekeysview_->get_selection(); + + bibkeysview_->append_column(_("BibKeys"), bibColumns.name); + bibSort_ = Gtk::TreeModelSort::create(allListStore_); + bibSort_->set_sort_column(bibColumns.bib_order, Gtk::SORT_ASCENDING ); + bibFilter_ = Gtk::TreeModelFilter::create(bibSort_, rootpath); + bibFilter_->set_visible_func(&GCitation::bib_visible); + bibkeysview_->set_model(bibFilter_); + bibselection_ = bibkeysview_->get_selection(); + + styleStore_ = Gtk::ListStore::create(styleColumns); + stylecombo_->set_model(styleStore_); + + upbutton_->signal_clicked().connect( + sigc::mem_fun(*this, &GCitation::up)); + downbutton_->signal_clicked().connect( + sigc::mem_fun(*this, &GCitation::down)); + addbutton_->signal_clicked().connect( + sigc::mem_fun(*this, &GCitation::add)); + removebutton_->signal_clicked().connect( + sigc::mem_fun(*this, &GCitation::remove)); + backbutton_->signal_clicked().connect( + sigc::mem_fun(*this, &GCitation::previous)); + forwardbutton_->signal_clicked().connect( + 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( + sigc::mem_fun(*this, &GCitation::set_search_buttons)); + + bibselection_->signal_changed().connect( + sigc::mem_fun(*this, &GCitation::bib_selected)); + citeselection_->signal_changed().connect( + sigc::mem_fun(*this, &GCitation::cite_selected)); + + beforeentry_->signal_changed().connect( + sigc::mem_fun(*this, &GCitation::enable_apply)); + afterentry_->signal_changed().connect( + sigc::mem_fun(*this, &GCitation::enable_apply)); + stylecombo_->signal_changed().connect( + sigc::mem_fun(*this, &GCitation::enable_apply)); +} + + +void GCitation::enable_apply() { + // if we passed !applylock_ directly as an argument, the restore button + // would be activated + if (!applylock_ && !(citeFilter_->children()).empty()) + bc().valid(true); +} + + +void GCitation::fill_styles() +{ + if ((citeFilter_->children()).empty()) { + stylecombo_->set_sensitive(false); + stylelabel_->set_sensitive(false); + return; + } + + int orig = stylecombo_->get_active_row_number(); + + Gtk::TreeModel::iterator iter = citeselection_->get_selected(); + if(!iter) + iter = (citeFilter_->children()).begin(); + string key = Glib::locale_from_utf8((*iter)[bibColumns.name]); + + std::vector const & sty = controller().getCiteStrings(key); + + biblio::CiteEngine const engine = controller().getEngine(); + bool const basic_engine = engine == biblio::ENGINE_BASIC; + + stylecombo_->set_sensitive(!sty.empty() && !basic_engine); + stylelabel_->set_sensitive(!sty.empty() && !basic_engine); + + vector::const_iterator it = sty.begin(); + vector::const_iterator const end = sty.end(); + + styleStore_->clear(); + for (; it != end; ++it) { + Gtk::TreeModel::iterator iter2 = styleStore_->append(); + (*iter2)[styleColumns.name] = Glib::locale_to_utf8(*it); + } + + if(orig) + stylecombo_->set_active(orig); +} + + +void GCitation::update_style() +{ + biblio::CiteEngine const engine = controller().getEngine(); + bool const natbib_engine = + engine == biblio::ENGINE_NATBIB_AUTHORYEAR || + engine == biblio::ENGINE_NATBIB_NUMERICAL; + bool const basic_engine = engine == biblio::ENGINE_BASIC; + + authorcheck_->set_sensitive(natbib_engine); + uppercasecheck_->set_sensitive(natbib_engine); + beforeentry_->set_sensitive(!basic_engine); + beforelabel_->set_sensitive(!basic_engine); + + string const & command = controller().params().getCmdName(); + + // Find the style of the citekeys + vector const & styles = + ControlCitation::getCiteStyles(); + biblio::CitationStyle const cs(command); + + vector::const_iterator cit = + std::find(styles.begin(), styles.end(), cs.style); + + //restore the latest natbib style + if (style_ >= 0 && Gtk::TreeModel::Children::size_type(style_) < + (styleStore_->children()).size()) + stylecombo_->set_active(style_); + else + stylecombo_->unset_active(); + + authorcheck_->set_active(false); + uppercasecheck_->set_active(false); + + if (cit != styles.end()) { + stylecombo_->set_active(cit - styles.begin()); + authorcheck_->set_active(cs.full); + uppercasecheck_->set_active(cs.forceUCase); + } +} + + +void GCitation::update_contents() +{ + // Make a list of all available bibliography keys + biblio::InfoMap const & theMap = controller().bibkeysInfo(); + std::vector bibkeys = biblio::getKeys(theMap); + std::vector citekeys = support::getVectorFromString( + controller().params().getContents()); + + int bib_order = 0; + allListStore_->clear(); + + for (std::vector::const_iterator cit = bibkeys.begin(); + cit != bibkeys.end(); ++cit) { + + Gtk::TreeModel::iterator iter = allListStore_->append(); + (*iter)[bibColumns.name] = Glib::locale_to_utf8(*cit); + (*iter)[bibColumns.cite] = false; //reset state + (*iter)[bibColumns.bib_order] = ++bib_order; + (*iter)[bibColumns.info] = Glib::locale_to_utf8( + biblio::getInfo(theMap,*cit)); + } + + // Now mark cite keys by setting their bibColumns.cite property to true + // so they will be filtered and displayed in citekeysview_ + for (std::vector::const_iterator ccit = citekeys.begin(); + ccit != citekeys.end(); ++ccit) { + + for (Gtk::TreeModel::const_iterator cbit = + (allListStore_->children()).begin(); + cbit != (allListStore_->children()).end(); ++cbit) { + + if ((*cbit)[bibColumns.name] == (*ccit)) { + (*cbit)[bibColumns.cite] = true; + allListStore_->move(cbit, + (allListStore_->children()).end()); + break; + } + + } + } +} + + +void GCitation::update() +{ + applylock_ = true; + + update_contents(); + + info_->set_text(""); // Clear Info field + + // Initialise style tab widgets + beforeentry_->set_text(Glib::locale_to_utf8( + controller().params().getSecOptions())); + afterentry_->set_text(Glib::locale_to_utf8( + controller().params().getOptions())); + + fill_styles(); + update_style(); + + // Deactivate all buttons + upbutton_->set_sensitive(false); + downbutton_->set_sensitive(false); + removebutton_->set_sensitive(false); + addbutton_->set_sensitive(false); + + set_search_buttons(); + applylock_ = false; +} + + +void GCitation::up() +{ + Gtk::TreeModel::iterator src = + citeselection_->get_selected(); + Gtk::TreeModel::iterator dest = src; + + if(--dest == (citeFilter_->children()).begin()) + upbutton_->set_sensitive(false); + + src = citeFilter_->convert_iter_to_child_iter(src); + dest = citeFilter_->convert_iter_to_child_iter(dest); + allListStore_->iter_swap(src, dest); + + bc().valid(true); + downbutton_->set_sensitive(true); +} + + +void GCitation::down() +{ + Gtk::TreeModel::iterator src = + citeselection_->get_selected(); + Gtk::TreeModel::iterator dest = src; + // Avoid slow operator-- by using an extra variable + Gtk::TreeModel::iterator endtest = ++dest; + + if(++endtest == (citeFilter_->children()).end()) + downbutton_->set_sensitive(false); + + src = citeFilter_->convert_iter_to_child_iter(src); + dest = citeFilter_->convert_iter_to_child_iter(dest); + allListStore_->iter_swap(src, dest); + + bc().valid(true); + upbutton_->set_sensitive(true); +} + + +void GCitation::add() +{ + Gtk::TreeModel::iterator iter = bibselection_->get_selected(); + + if (iter) { + Gtk::TreeModel::iterator next_iter = iter; + + // Select the right key in bibkeysview_ afterwards + if(++next_iter == (bibFilter_->children()).end()) { + if(iter != (bibFilter_->children()).begin()) { + bibselection_->select(--iter); + ++iter; + } else { // bibkeysview_ will be left empty... + addbutton_->set_sensitive(false); + } + } else { + bibselection_->select(next_iter); + } + + iter = bibFilter_->convert_iter_to_child_iter(iter); + iter = bibSort_->convert_iter_to_child_iter(iter); + (*iter)[bibColumns.cite] = true; + + // Move key to the right position + // If a cite key is selected, move bib key to the position above + // Otherwise to the last position in citekeysview_ + Gtk::TreeModel::iterator cite_iter(citeselection_->get_selected()); + if (cite_iter) { + cite_iter = citeFilter_->convert_iter_to_child_iter(cite_iter); + } else { + cite_iter = (allListStore_->children()).end(); + } + allListStore_->move(iter,cite_iter); + + // Highlight and scroll to newly inserted key + iter = citeFilter_->convert_child_iter_to_iter(iter); + citeselection_->select(iter); + citekeysview_->scroll_to_row(Gtk::TreePath(iter)); + + // Set button states + removebutton_->set_sensitive(true); + set_search_buttons(); + + bc().valid(true); + } +} + + +void GCitation::remove() +{ + Gtk::TreeModel::iterator iter(citeselection_->get_selected()); + + if (iter) { + Gtk::TreeModel::iterator next_iter(iter); + + if(++next_iter == (citeFilter_->children()).end()) { + if(iter != (citeFilter_->children()).begin()) { + citeselection_->select(--iter); + ++iter; + bc().valid(true); + } else { // citekeysview_ will be left empty... + removebutton_->set_sensitive(false); + bc().valid(false); + } + } else { + citeselection_->select(next_iter); + bc().valid(true); + } + + // Get an iterator to allListStore_ + iter = citeFilter_->convert_iter_to_child_iter(iter); + (*iter)[bibColumns.cite] = false; + + // Highlight and scroll to newly inserted key + iter = bibSort_->convert_child_iter_to_iter(iter); + iter = bibFilter_->convert_child_iter_to_iter(iter); + bibselection_->select(iter); + bibkeysview_->scroll_to_row(Gtk::TreePath(iter)); + + // Set button states + addbutton_->set_sensitive(true); + set_search_buttons(); + } +} + +void GCitation::cite_selected() +{ + Gtk::TreeModel::iterator iter = + citeselection_->get_selected(); + + if (iter) { + info_->set_text((*iter)[bibColumns.info]); + removebutton_->set_sensitive(true); + + // Set sensitivity of Up/Down buttons + if (iter == (citeFilter_->children()).begin()) { + upbutton_->set_sensitive(false); + } else { + upbutton_->set_sensitive(true); + } + + if (++iter == (citeFilter_->children()).end()) { + downbutton_->set_sensitive(false); + } else { + downbutton_->set_sensitive(true); + } + + } else { + info_->set_text(""); + removebutton_->set_sensitive(false); + + // Set sensitivity of Up/Down buttons + upbutton_->set_sensitive(false); + downbutton_->set_sensitive(false); + } + +} + + +void GCitation::bib_selected() +{ + Gtk::TreeModel::iterator iter = + bibselection_->get_selected(); + + if (iter) { + info_->set_text((*iter)[bibColumns.info]); + addbutton_->set_sensitive(true); + } else { + info_->set_text(""); + addbutton_->set_sensitive(false); + } +} + +void GCitation::apply() +{ + vector const & styles = + ControlCitation::getCiteStyles(); + + int const choice = stylecombo_->get_active_row_number(); + style_ = stylecombo_->get_active_row_number(); + + bool const full = authorcheck_->get_active(); + bool const force = uppercasecheck_->get_active(); + + string const command = + biblio::CitationStyle(styles[choice], full, force) + .asLatexStr(); + + Gtk::TreeNodeChildren children(citeFilter_->children()); + + string citekeys; + int i = 0; + for (Gtk::TreeModel::const_iterator cit=children.begin(); + cit!=children.end(); ++cit) { + + string item(support::trim(Glib::locale_from_utf8((*cit)[bibColumns.name]))); + if (item.empty()) + continue; + if (i++ > 0) + citekeys += ","; + citekeys += item; + } + + controller().params().setCmdName(command); + controller().params().setContents(citekeys); + + controller().params().setSecOptions(Glib::locale_from_utf8(beforeentry_->get_text())); + controller().params().setOptions(Glib::locale_from_utf8(afterentry_->get_text())); + + update(); +} + +void GCitation::find(biblio::Direction dir) +{ + biblio::InfoMap const & theMap = controller().bibkeysInfo(); + std::vector bibkeys; + + biblio::Search const type = regexpcheck_->get_active() + ? biblio::REGEX : biblio::SIMPLE; + + vector::const_iterator start; + + bool search_cite = citeradio_->get_active(); + bool const casesens = casecheck_->get_active(); + string const str = Glib::locale_from_utf8(findentry_->get_text()); + + Gtk::TreeModel::iterator iter; + Gtk::TreeModel::Children::difference_type sel = 0; + + if (search_cite) { + for (iter = (citeFilter_->children()).begin(); + iter != (citeFilter_->children()).end(); ++iter) { + + bibkeys.push_back(Glib::locale_from_utf8( + (*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); + } + + start = bibkeys.begin(); + + if (sel >= 0 && + Gtk::TreeModel::Children::size_type(sel) < bibkeys.size()) + std::advance(start, sel); + + bool is_cite = !search_cite; + while(is_cite != search_cite) { + + // Find the NEXT instance... + if (dir == biblio::FORWARD) + ++start; + + vector::const_iterator cit = + biblio::searchKeys(theMap, bibkeys, str, + start, type, dir, casesens); + + 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::const_iterator bibstart = bibkeys.begin(); + vector::difference_type const found = + std::distance(bibstart, cit); + if (found == sel) + return; + + start = cit; + if (search_cite) + iter = (citeFilter_->children()).begin(); + else + iter = (bibFilter_->children()).begin(); + std::advance(iter, found); + is_cite = (*iter)[bibColumns.cite]; + } + + // Highlight and scroll to the key that was found + if (search_cite) { + citeselection_->select(iter); + citekeysview_->set_cursor(Gtk::TreePath(iter)); + citekeysview_->scroll_to_row(Gtk::TreePath(iter)); + 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() +{ + bool val = findentry_->get_text_length() && ( + (citeradio_->get_active() && !(citeFilter_->children()).empty()) + || (bibradio_->get_active() && !(bibFilter_->children()).empty()) + ); + backbutton_->set_sensitive(val); + forwardbutton_->set_sensitive(val); +} + +void GCitation::previous() +{ + find(biblio::BACKWARD); +} + + +void GCitation::next() +{ + find(biblio::FORWARD); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GCitation.h b/src/frontends/gtk/GCitation.h new file mode 100644 index 0000000000..daf6b3ee3a --- /dev/null +++ b/src/frontends/gtk/GCitation.h @@ -0,0 +1,139 @@ +// -*- C++ -*- +/** + * \file GCitation.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 GCITATION_H +#define GCITATION_H + +#include "GViewBase.h" + +#include "ControlCitation.h" + +#include "bufferparams.h" + + +namespace lyx { +namespace frontend { + +class ControlCitation; + +/** This class provides a GTK+ implementation of the Citation Dialog. + */ +class GCitation : public GViewCB { +public: + GCitation(Dialog & parent); +private: + virtual void apply(); + virtual void doBuild(); + virtual void update(); + + /// Update dialog before/whilst showing it. + virtual void update_contents(); + + /// fill the styles combo + void fill_styles(); + + /// set the styles combo + void update_style(); + + /// enable the apply button if applylock_ is false + void enable_apply(); + + /// Move selected inset key up one line in list + void up(); + /// Move selected inset key down one line in list + void down(); + + /// Add bibliography key to inset key list, remove it from bibliography view + void add(); + /// Remove inset key from list, move it back to bibliography key view + void remove(); + + /// Find previous occurence of search string in selected key view + void previous(); + /// Find next occurence of search string in selected key view + void next(); + /// Find function, called by previous() and next() + void find(biblio::Direction); + + /// Called when inset key is (un)selected + void cite_selected(); + /// Called when bibliography key is (un)selected + void bib_selected(); + + /** Set previous and next buttons according to state of the search + string entry, the radio buttons and the selected keys in the inset + and bibliography views. + */ + inline void set_search_buttons(); + + /** Helper function for bibFilter_; true if argument's + [bibColumns.cite] is false. + */ + static inline bool bib_visible(const Gtk::TreeModel::const_iterator&); + + /** apply() won't act when this is true. + true if no text is selected when the citation dialog is opened + */ + bool applylock_; + + /// Last selected stylecombo_ item + int style_; + + Gtk::Button * restorebutton_; + Gtk::Button * cancelbutton_; + Gtk::Button * okbutton_; + Gtk::Button * applybutton_; + + Gtk::Button * addbutton_; + Gtk::Button * removebutton_; + Gtk::Button * backbutton_; + Gtk::Button * forwardbutton_; + Gtk::Button * upbutton_; + Gtk::Button * downbutton_; + + Gtk::TreeView * citekeysview_; + Gtk::TreeView * bibkeysview_; + + Gtk::TextView * infoview_; + + Gtk::Entry * findentry_; + Gtk::CheckButton * citeradio_; + Gtk::CheckButton * bibradio_; + Gtk::CheckButton * casecheck_; + Gtk::CheckButton * regexpcheck_; + + Gtk::Label * stylelabel_; + Gtk::ComboBox * stylecombo_; + + Gtk::Label * beforelabel_; + Gtk::Entry * beforeentry_; + Gtk::Entry * afterentry_; + Gtk::CheckButton * authorcheck_; + Gtk::CheckButton * uppercasecheck_; + + Glib::RefPtr info_; + + Glib::RefPtr allListStore_; + Glib::RefPtr styleStore_; + + Glib::RefPtr citeselection_; + Glib::RefPtr bibselection_; + + Glib::RefPtr citeFilter_; + Glib::RefPtr bibFilter_; + Glib::RefPtr bibSort_; + +}; + +} // namespace frontend +} // namespace lyx + +#endif // GCITATION_H diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index dcccffb866..61acd4ebda 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -37,6 +37,8 @@ libgtk_la_SOURCES = \ GChanges.h \ GCharacter.C \ GCharacter.h \ + GCitation.C \ + GCitation.h \ GDocument.C \ GDocument.h \ GErrorList.C \ @@ -137,7 +139,6 @@ xforms_objects = \ ../xforms/FormBibtex.lo \ ../xforms/FormBranch.lo \ ../xforms/FormBrowser.lo \ - ../xforms/FormCitation.lo \ ../xforms/FormColorpicker.lo \ ../xforms/FormDialogView.lo \ ../xforms/FormExternal.lo \ diff --git a/src/frontends/gtk/glade/Makefile.am b/src/frontends/gtk/glade/Makefile.am index e5d2cc25b1..d5f29c8b23 100644 --- a/src/frontends/gtk/glade/Makefile.am +++ b/src/frontends/gtk/glade/Makefile.am @@ -8,6 +8,7 @@ dist_glade_DATA = \ box.glade \ changes.glade \ character.glade \ + citation.glade \ document.glade \ errors.glade \ ERT.glade \ diff --git a/src/frontends/gtk/glade/citation.glade b/src/frontends/gtk/glade/citation.glade new file mode 100644 index 0000000000..245a54e302 --- /dev/null +++ b/src/frontends/gtk/glade/citation.glade @@ -0,0 +1,931 @@ + + + + + + + True + dialog1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + True + False + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-undo + True + GTK_RELIEF_NORMAL + True + 0 + + + + + + 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 + + + + + + 6 + True + True + True + True + GTK_POS_TOP + False + False + + + + 6 + True + False + 0 + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + False + 6 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + True + True + False + False + False + + + + + 0 + True + True + + + + + + True + GTK_BUTTONBOX_DEFAULT_STYLE + 6 + + + + True + True + True + gtk-go-up + True + GTK_RELIEF_NORMAL + True + + + + + + True + True + True + gtk-go-down + True + GTK_RELIEF_NORMAL + True + + + + + 0 + False + False + + + + + + + + + + True + <b>_Selected keys</b> + True + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 3 + True + True + + + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + False + 6 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + False + True + False + False + False + + + + + 0 + True + True + + + + + + True + GTK_BUTTONBOX_DEFAULT_STYLE + 6 + + + + True + True + True + gtk-remove + True + GTK_RELIEF_NORMAL + True + + + + + + True + True + True + gtk-add + True + GTK_RELIEF_NORMAL + True + + + + + 0 + False + False + + + + + + + + + + True + <b>_Available keys</b> + True + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 3 + False + True + + + + + + True + False + 0 + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + False + True + GTK_JUSTIFY_LEFT + GTK_WRAP_WORD + True + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + + + True + <b>Info</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + True + True + + + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + False + 0 + + + + True + True + True + True + 0 + + True + * + False + + + 0 + False + False + + + + + + True + True + Inset keys + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + True + Bibliography keys + True + GTK_RELIEF_NORMAL + True + False + False + True + SearchCite + + + 0 + False + False + + + + + + True + True + _Case sensitive + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + True + Regular e_xpression + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + GTK_BUTTONBOX_DEFAULT_STYLE + 6 + + + + True + True + True + gtk-go-back + True + GTK_RELIEF_NORMAL + True + + + + + + True + True + True + gtk-go-forward + True + GTK_RELIEF_NORMAL + True + + + + + 0 + True + True + + + + + + + + + + True + <b>_Find</b> + True + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + False + False + + + + + 3 + True + True + + + + + False + True + + + + + + True + _Keys + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + + 12 + True + False + 6 + + + + True + 3 + 2 + False + 0 + 0 + + + + True + _Citation style: + True + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Text _before: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + TextBefore + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + _Text after: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + TextAfter + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 2 + 3 + 3 + 3 + + + + + + + True + True + True + True + 0 + + True + * + False + + + 1 + 2 + 1 + 2 + 3 + 3 + + + + + + + True + + False + True + + + 1 + 2 + 0 + 1 + 3 + 3 + fill + fill + + + + + 0 + False + True + + + + + + True + True + _Full author list + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + + True + True + Force _upper case + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + + False + True + + + + + + True + _Style + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + + + + 0 + True + True + + + + + + +