From: Kalle Dalheimer Date: Thu, 29 Mar 2001 21:17:17 +0000 (+0000) Subject: more work on citation dialog for MVC X-Git-Tag: 1.6.10~21371 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=24cdf09610ca744df05cb86d24b1a71d45dad94b;p=features.git more work on citation dialog for MVC git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1857 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/qt2/FormCitation.C b/src/frontends/qt2/FormCitation.C index ddaa65496d..99431eccf7 100644 --- a/src/frontends/qt2/FormCitation.C +++ b/src/frontends/qt2/FormCitation.C @@ -31,7 +31,6 @@ #include "ControlCitation.h" #include "gettext.h" #include "support/lstrings.h" -#include "biblio.h" #include "helper_funcs.h" @@ -93,205 +92,6 @@ void FormCitation::build() bc().refresh(); } -#if K -ButtonPolicy::SMInput FormCitation::input(FL_OBJECT * ob, long) -{ - ButtonPolicy::SMInput activate = ButtonPolicy::SMI_NOOP; - - biblio::InfoMap const & theMap = controller().bibkeysInfo(); - - if (ob == dialog_->browser_bib) { - fl_deselect_browser(dialog_->browser_cite); - - unsigned int const sel = fl_get_browser(dialog_->browser_bib); - if (sel < 1 || sel > bibkeys.size()) - return ButtonPolicy::SMI_NOOP; - - // Put into browser_info the additional info associated with - // the selected browser_bib key - fl_clear_browser(dialog_->browser_info); - - string const tmp = formatted(biblio::getInfo(theMap, - bibkeys[sel-1]), - dialog_->browser_info->w-10 ); - fl_add_browser_line(dialog_->browser_info, tmp.c_str()); - - // Highlight the selected browser_bib key in browser_cite if - // present - vector::const_iterator cit = - find(citekeys.begin(), citekeys.end(), bibkeys[sel-1]); - - if (cit != citekeys.end()) { - int const n = int(cit - citekeys.begin()); - fl_select_browser_line(dialog_->browser_cite, n+1); - fl_set_browser_topline(dialog_->browser_cite, n+1); - } - - if (!controller().isReadonly()) { - if (cit != citekeys.end()) { - setBibButtons(OFF); - setCiteButtons(ON); - } else { - setBibButtons(ON); - setCiteButtons(OFF); - } - } - - } else if (ob == dialog_->browser_cite) { - unsigned int const sel = fl_get_browser(dialog_->browser_cite); - if (sel < 1 || sel > citekeys.size()) - return ButtonPolicy::SMI_NOOP; - - if (!controller().isReadonly()) { - setBibButtons(OFF); - setCiteButtons(ON); - } - - // Highlight the selected browser_cite key in browser_bib - vector::const_iterator cit = - find(bibkeys.begin(), bibkeys.end(), citekeys[sel-1]); - - if (cit != bibkeys.end()) { - int const n = int(cit - bibkeys.begin()); - fl_select_browser_line(dialog_->browser_bib, n+1); - fl_set_browser_topline(dialog_->browser_bib, n+1); - - // Put into browser_info the additional info associated - // with the selected browser_cite key - fl_clear_browser(dialog_->browser_info); - string const tmp = - formatted(biblio::getInfo(theMap, - bibkeys[sel-1]), - dialog_->browser_info->w-10); - fl_add_browser_line(dialog_->browser_info, tmp.c_str()); - } - - } else if (ob == dialog_->button_add) { - unsigned int const sel = fl_get_browser(dialog_->browser_bib); - if (sel < 1 || sel > bibkeys.size()) - return ButtonPolicy::SMI_NOOP; - - // Add the selected browser_bib key to browser_cite - fl_addto_browser(dialog_->browser_cite, - bibkeys[sel-1].c_str()); - citekeys.push_back(bibkeys[sel-1]); - - int const n = int(citekeys.size()); - fl_select_browser_line(dialog_->browser_cite, n); - - setBibButtons(OFF); - setCiteButtons(ON); - activate = ButtonPolicy::SMI_VALID; - - } else if (ob == dialog_->button_del) { - unsigned int const sel = fl_get_browser(dialog_->browser_cite); - if (sel < 1 || sel > citekeys.size()) - return ButtonPolicy::SMI_NOOP; - - // Remove the selected key from browser_cite - fl_delete_browser_line(dialog_->browser_cite, sel) ; - citekeys.erase(citekeys.begin() + sel-1); - - setBibButtons(ON); - setCiteButtons(OFF); - activate = ButtonPolicy::SMI_VALID; - - } else if (ob == dialog_->button_up) { - unsigned int const sel = fl_get_browser(dialog_->browser_cite); - if (sel < 2 || sel > citekeys.size()) - return ButtonPolicy::SMI_NOOP; - - // Move the selected key up one line - vector::iterator it = citekeys.begin() + sel-1; - string const tmp = *it; - - fl_delete_browser_line(dialog_->browser_cite, sel); - citekeys.erase(it); - - fl_insert_browser_line(dialog_->browser_cite, sel-1, tmp.c_str()); - fl_select_browser_line(dialog_->browser_cite, sel-1); - citekeys.insert(it-1, tmp); - setCiteButtons(ON); - activate = ButtonPolicy::SMI_VALID; - - } else if (ob == dialog_->button_down) { - unsigned int const sel = fl_get_browser(dialog_->browser_cite); - if (sel < 1 || sel > citekeys.size()-1) - return ButtonPolicy::SMI_NOOP; - - // Move the selected key down one line - vector::iterator it = citekeys.begin() + sel-1; - string const tmp = *it; - - fl_delete_browser_line(dialog_->browser_cite, sel); - citekeys.erase(it); - - fl_insert_browser_line(dialog_->browser_cite, sel+1, tmp.c_str()); - fl_select_browser_line(dialog_->browser_cite, sel+1); - citekeys.insert(it+1, tmp); - setCiteButtons(ON); - activate = ButtonPolicy::SMI_VALID; - - } else if (ob == dialog_->button_search_type) { - if (fl_get_button(dialog_->button_search_type)) - fl_set_object_label(dialog_->button_search_type, - _("Regex")); - else - fl_set_object_label(dialog_->button_search_type, - _("Simple")); - return ButtonPolicy::SMI_NOOP; - - } else if (ob == dialog_->button_previous || - ob == dialog_->button_next) { - - string const str = fl_get_input(dialog_->input_search); - - biblio::Direction const dir = - (ob == dialog_->button_previous) ? - biblio::BACKWARD : biblio::FORWARD; - - biblio::Search const type = - fl_get_button(dialog_->button_search_type) ? - biblio::REGEX : biblio::SIMPLE; - - vector::const_iterator start = bibkeys.begin(); - int const sel = fl_get_browser(dialog_->browser_bib); - if (sel >= 1 && sel <= int(bibkeys.size())) - start += sel-1; - - // Find the NEXT instance... - if (dir == biblio::FORWARD) - start += 1; - else - start -= 1; - - vector::const_iterator const cit = - biblio::searchKeys(theMap, bibkeys, str, - start, type, dir); - - if (cit == bibkeys.end()) - return ButtonPolicy::SMI_NOOP; - - int const found = int(cit - bibkeys.begin()) + 1; - if (found == sel) - return ButtonPolicy::SMI_NOOP; - - // Update the display - int const top = max(found-5, 1); - fl_set_browser_topline(dialog_->browser_bib, top); - fl_select_browser_line(dialog_->browser_bib, found); - input(dialog_->browser_bib, 0); - - } else if (ob == dialog_->choice_style || - ob == dialog_->input_before || - ob == dialog_->input_after) { - activate = ButtonPolicy::SMI_VALID; - } - - return activate; -} -#endif - void FormCitation::update() { diff --git a/src/frontends/qt2/FormCitation.h b/src/frontends/qt2/FormCitation.h index 17d62785b8..0f66001426 100644 --- a/src/frontends/qt2/FormCitation.h +++ b/src/frontends/qt2/FormCitation.h @@ -31,6 +31,8 @@ class ControlCitation; class FormCitationDialogImpl; class FormCitation : public Qt2CB > { + friend class FormCitationDialogImpl; + public: /// FormCitation(ControlCitation &); diff --git a/src/frontends/qt2/FormCitationDialog.ui b/src/frontends/qt2/FormCitationDialog.ui index 3b8743becd..936e4bd26a 100644 --- a/src/frontends/qt2/FormCitationDialog.ui +++ b/src/frontends/qt2/FormCitationDialog.ui @@ -248,6 +248,10 @@ name infoML + + wordWrap + WidgetWidth + toolTip Reference entry text @@ -319,7 +323,7 @@ QPushButton name - PushButton14 + previousPB text @@ -387,7 +391,7 @@ QPushButton name - PushButton15 + nextPB text @@ -643,12 +647,6 @@ - - citeLB - selected(int) - FormCitationDialog - slotInsetSelected(int) - bibLB selected(int) @@ -686,37 +684,59 @@ slotRestoreClicked() - okPB - clicked() + citeLB + selected(int) FormCitationDialog - apply_adaptor() + slotCiteSelected(int) - okPB - clicked() + searchTypePB + toggled(bool) FormCitationDialog - close_adaptor() + slotSearchTypeSelected(bool) - applyPB + previousPB clicked() FormCitationDialog - apply_adaptor() + slotPreviousClicked() - cancelPB + nextPB clicked() FormCitationDialog - close_adaptor() + slotNextClicked() + + + citationStyleCO + activated(int) + FormCitationDialog + slotCitationStyleSelected(int) + + + textBeforeED + returnPressed() + FormCitationDialog + slotTextBeforeReturn() + + + textAfterED + returnPressed() + FormCitationDialog + slotTextAfterReturn() - apply_adaptor() - close_adaptor() + slotTextAfterReturn() slotAddClicked() slotBibSelected(int) + slotCitationStyleSelected(int) + slotCiteSelected(int) slotDelClicked() slotDownClicked() slotIUpClicked() - slotInsetSelected(int) + slotNextClicked() + slotPreviousClicked() slotRestoreClicked() + slotSearchTypeSelected(bool) + slotTextBeforeReturn() diff --git a/src/frontends/qt2/FormCitationDialogImpl.C b/src/frontends/qt2/FormCitationDialogImpl.C index c1878ff61d..86d9a6d8df 100644 --- a/src/frontends/qt2/FormCitationDialogImpl.C +++ b/src/frontends/qt2/FormCitationDialogImpl.C @@ -1,13 +1,18 @@ /** - * $Id: FormCitationDialogImpl.C,v 1.3 2001/03/29 18:58:47 kalle Exp $ + * $Id: FormCitationDialogImpl.C,v 1.4 2001/03/29 21:17:17 kalle Exp $ */ #include "FormCitationDialogImpl.h" #include "Dialogs.h" #include "FormCitation.h" +#include "qt2BC.h" +#include "controllers/biblio.h" +#include "controllers/ControlCitation.h" +#include #include #include +#include #undef emit #include @@ -17,8 +22,6 @@ using std::vector; using std::find; -// PENDING(kalle) Wire text before and citation style - /* * Constructs a FormCitationDialogImpl which is a child of 'parent', with the * name 'name' and widget flags set to 'f' @@ -30,6 +33,14 @@ FormCitationDialogImpl::FormCitationDialogImpl( FormCitation* form, QWidget* par : FormCitationDialog( parent, name, modal, fl ), form_( form ) { + connect( okPB, SIGNAL( clicked() ), + form, SLOT( slotOK() ) ); + connect( cancelPB, SIGNAL( clicked() ), + form, SLOT( slotCancel() ) ); + connect( restorePB, SIGNAL( clicked() ), + form, SLOT( slotRestore() ) ); + connect( applyPB, SIGNAL( clicked() ), + form, SLOT( slotApply() ) ); } /* @@ -41,31 +52,39 @@ FormCitationDialogImpl::~FormCitationDialogImpl() } -#if 0 // These slots correspond to the XForms input() method. void FormCitationDialogImpl::slotBibSelected( int sel ) { - insetKeysLB->clearSelection(); - - if( sel < 0 || sel > form_->bibkeys.size()-1) + biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); + + citeLB->clearSelection(); + + if (sel < 0 || sel >= (int)form_->bibkeys.size()) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); return; - + } + // Put into browser_info the additional info associated with // the selected browser_bib key infoML->clear(); - infoML->append( form_->bibkeysInfo[sel].c_str() ); - - // Highlight the selected browser_bib key in browser_cite if present - vector::iterator it = - ::find(form_->citekeys.begin(), form_->citekeys.end(), form_->bibkeys[sel]); - - if (it != form_->citekeys.end()) { - int n = static_cast(it - form_->citekeys.begin()); - insetKeysLB->setSelected( n, true ); + + infoML->setText( biblio::getInfo( theMap, + form_->bibkeys[sel-1] ).c_str() ); + + // Highlight the selected browser_bib key in browser_cite if + // present + vector::const_iterator cit = + std::find(form_->citekeys.begin(), form_->citekeys.end(), + form_->bibkeys[sel]); + + if (cit != form_->citekeys.end()) { + int const n = int(cit - form_->citekeys.begin()); + citeLB->setSelected( n, true ); + citeLB->setTopItem( n ); } - - if (!form_->lv_->buffer()->isReadonly()) { - if (it != form_->citekeys.end()) { + + if (!form_->controller().isReadonly()) { + if (cit != form_->citekeys.end()) { form_->setBibButtons(FormCitation::OFF); form_->setCiteButtons(FormCitation::ON); } else { @@ -74,121 +93,218 @@ void FormCitationDialogImpl::slotBibSelected( int sel ) } } + form_->bc().input( ButtonPolicy::SMI_VALID ); } -void FormCitationDialogImpl::slotInsetSelected( int sel ) +void FormCitationDialogImpl::slotCiteSelected( int sel ) { - if (sel < 0 || sel > form_->citekeys.size() -1 ) - return; + biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); - if (!form_->lv_->buffer()->isReadonly()) { + if (sel < 0 || sel >= (int)form_->citekeys.size()) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); + return; + } + + if (!form_->controller().isReadonly()) { form_->setBibButtons(FormCitation::OFF); form_->setCiteButtons(FormCitation::ON); } - + // Highlight the selected browser_cite key in browser_bib - vector::iterator it = - ::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]); - - if (it != form_->bibkeys.end()) { - int n = static_cast(it - form_->bibkeys.begin()); - bibliographyKeysLB->setSelected( n, true ); - - // Put into browser_info the additional info associated with - // the selected browser_cite key + vector::const_iterator cit = + std::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]); + + if (cit != form_->bibkeys.end()) { + int const n = int(cit - form_->bibkeys.begin()); + bibLB->setSelected( n, true ); + bibLB->setTopItem( n ); + + // Put into browser_info the additional info associated + // with the selected browser_cite key infoML->clear(); - infoML->append( form_->bibkeysInfo[n].c_str() ); + infoML->setText( biblio::getInfo( theMap, form_->bibkeys[sel] ).c_str() ); } + + form_->bc().input( ButtonPolicy::SMI_VALID ); } void FormCitationDialogImpl::slotAddClicked() { - qDebug( "FormCitationDialogImpl::slotAddClicked()" ); - int sel = bibliographyKeysLB->currentItem(); - if (sel < 0 || sel > form_->bibkeys.size() -1 ) + int const sel = bibLB->currentItem(); + if (sel < 0 || sel >= (int)form_->bibkeys.size()) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); return; - - qDebug( "sel = %d" ); - qDebug( "bibkeys.size() = %d", form_->bibkeys.size() ); - + } + // Add the selected browser_bib key to browser_cite - insetKeysLB->insertItem( form_->bibkeys[sel].c_str()); - form_->citekeys.push_back(form_->bibkeys[sel]); - - int n = static_cast(form_->citekeys.size()); - insetKeysLB->setSelected( n, true ); + citeLB->insertItem( form_->bibkeys[sel].c_str() ); + form_->citekeys.push_back( form_->bibkeys[sel] ); + int const n = int(form_->citekeys.size()); + citeLB->setSelected( n-1, true ); + form_->setBibButtons(FormCitation::OFF); form_->setCiteButtons(FormCitation::ON); + + form_->bc().input( ButtonPolicy::SMI_VALID ); } void FormCitationDialogImpl::slotDelClicked() { - int sel = insetKeysLB->currentItem(); - if (sel < 0 || sel > form_->citekeys.size()-1) + int const sel = citeLB->currentItem(); + if (sel < 0 || sel >= (int)form_->citekeys.size()) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); return; - + } + // Remove the selected key from browser_cite - insetKeysLB->removeItem( sel ); - form_->citekeys.erase(form_->citekeys.begin() + sel); - + citeLB->removeItem( sel ); + form_->citekeys.erase(form_->citekeys.begin() + sel ); + form_->setBibButtons(FormCitation::ON); form_->setCiteButtons(FormCitation::OFF); + + form_->bc().input( ButtonPolicy::SMI_VALID ); } void FormCitationDialogImpl::slotUpClicked() { - int sel = insetKeysLB->currentItem(); - if (sel < 1 || sel > form_->citekeys.size()-1) + int const sel = citeLB->currentItem(); + if (sel < 1 || sel >= (int)form_->citekeys.size()) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); return; - + } + // Move the selected key up one line vector::iterator it = form_->citekeys.begin() + sel; - string tmp = *it; - - insetKeysLB->removeItem( sel ); + string const tmp = *it; + + citeLB->removeItem( sel ); form_->citekeys.erase(it); - - insetKeysLB->insertItem( tmp.c_str(), sel-1 ); - insetKeysLB->setSelected( sel-1, true ); + + citeLB->insertItem( tmp.c_str(), sel-1 ); + citeLB->setSelected( sel-1, true ); form_->citekeys.insert(it-1, tmp); form_->setCiteButtons(FormCitation::ON); + + form_->bc().input( ButtonPolicy::SMI_VALID ); } void FormCitationDialogImpl::slotDownClicked() { - int sel = insetKeysLB->currentItem(); - if (sel < 0 || sel > form_->citekeys.size()-2) + int const sel = citeLB->currentItem(); + if (sel < 0 || sel >= (int)form_->citekeys.size()-1) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); return; - + } + // Move the selected key down one line vector::iterator it = form_->citekeys.begin() + sel; - string tmp = *it; - - insetKeysLB->removeItem( sel ); + string const tmp = *it; + + citeLB->removeItem( sel ); form_->citekeys.erase(it); - - insetKeysLB->insertItem( tmp.c_str(), sel+1 ); - insetKeysLB->setSelected( sel+1, true ); + + citeLB->insertItem( tmp.c_str(), sel+1 ); + citeLB->setSelected( sel+1, true ); form_->citekeys.insert(it+1, tmp); form_->setCiteButtons(FormCitation::ON); + + form_->bc().input( ButtonPolicy::SMI_VALID ); } -void FormCitationDialogImpl::apply_adaptor() +void FormCitationDialogImpl::slotSearchTypeToggled( bool toggle ) { - form_->apply(); + if( toggle ) + searchTypePB->setText( _( "Regex" ) ); + else + searchTypePB->setText( _( "Simple" ) ); + + form_->bc().input( ButtonPolicy::SMI_NOOP ); } -void FormCitationDialogImpl::close_adaptor() +void FormCitationDialogImpl::slotPreviousClicked() +{ + doPreviousNext( false ); +} + + +void FormCitationDialogImpl::slotNextClicked() { - form_->close(); - hide(); + doPreviousNext( true ); +} + + +void FormCitationDialogImpl::doPreviousNext( bool next ) +{ + biblio::InfoMap const & theMap = form_->controller().bibkeysInfo(); + string const str = searchED->text().latin1(); + + biblio::Direction const dir = + next ? + biblio::FORWARD : biblio::BACKWARD; + + biblio::Search const type = + searchTypePB->isOn() ? + biblio::REGEX : biblio::SIMPLE; + + vector::const_iterator start = form_->bibkeys.begin(); + int const sel = bibLB->currentItem(); + if (sel >= 0 && sel <= int(form_->bibkeys.size()-1)) + start += sel; + + // Find the NEXT instance... + if (dir == biblio::FORWARD) + start += 1; + else + start -= 1; + + vector::const_iterator const cit = + biblio::searchKeys(theMap, form_->bibkeys, str, + start, type, dir); + + if (cit == form_->bibkeys.end()) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); + return; + } + + int const found = int(cit - form_->bibkeys.begin()); + if (found == sel) { + form_->bc().input( ButtonPolicy::SMI_NOOP ); + return; + } + + // Update the display + int const top = max(found-5, 1); + bibLB->setTopItem( top ); + bibLB->setSelected( found, true ); + slotBibSelected( 0 ); + + form_->bc().input( ButtonPolicy::SMI_VALID ); } -#endif + + +void FormCitationDialogImpl::slotCitationStyleSelected( int ) +{ + form_->bc().input( ButtonPolicy::SMI_VALID ); +} + + +void FormCitationDialogImpl::slotTextBeforeReturn() +{ + form_->bc().input( ButtonPolicy::SMI_VALID ); +} + + +void FormCitationDialogImpl::slotTextAfterReturn() +{ + form_->bc().input( ButtonPolicy::SMI_VALID ); +} + diff --git a/src/frontends/qt2/FormCitationDialogImpl.h b/src/frontends/qt2/FormCitationDialogImpl.h index 76bdc1cbab..a65126e38a 100644 --- a/src/frontends/qt2/FormCitationDialogImpl.h +++ b/src/frontends/qt2/FormCitationDialogImpl.h @@ -1,5 +1,5 @@ /** - * $Id: FormCitationDialogImpl.h,v 1.1 2001/03/16 17:20:06 kalle Exp $ + * $Id: FormCitationDialogImpl.h,v 1.2 2001/03/29 21:17:17 kalle Exp $ */ #ifndef FORMCITATIONDIALOGIMPL_H @@ -18,14 +18,21 @@ public: protected slots: virtual void slotBibSelected( int sel ); - virtual void slotInsetSelected( int sel ); + virtual void slotCiteSelected( int sel ); virtual void slotAddClicked(); virtual void slotDelClicked(); virtual void slotUpClicked(); virtual void slotDownClicked(); - virtual void apply_adaptor(); - virtual void close_adaptor(); + virtual void slotPreviousClicked(); + virtual void slotNextClicked(); + virtual void slotSearchTypeToggled( bool ); + virtual void slotCitationStyleSelected( int ); + virtual void slotTextBeforeReturn(); + virtual void slotTextAfterReturn(); +private: + void doPreviousNext( bool ); + private: FormCitation* form_; }; diff --git a/src/frontends/qt2/dialogs-qt2.txt b/src/frontends/qt2/dialogs-qt2.txt index ccc4149794..881c9d8c03 100644 --- a/src/frontends/qt2/dialogs-qt2.txt +++ b/src/frontends/qt2/dialogs-qt2.txt @@ -1,7 +1,7 @@ Dialog Maintainer MVC conversion ---------------------------------------------- Character Edwin -Citation Kalle +Citation Kalle In progress Copyright Kalle Done Credits Document Kalle In progress