more work on citation dialog for MVC

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1857 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Kalle Dalheimer 2001-03-29 21:17:17 +00:00
parent a24a97ed14
commit 24cdf09610
6 changed files with 247 additions and 302 deletions

View File

@ -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<string>::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<string>::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<string>::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<string>::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<string>::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<string>::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()
{

View File

@ -31,6 +31,8 @@ class ControlCitation;
class FormCitationDialogImpl;
class FormCitation : public Qt2CB<ControlCitation, Qt2DB<FormCitationDialogImpl> > {
friend class FormCitationDialogImpl;
public:
///
FormCitation(ControlCitation &);

View File

@ -248,6 +248,10 @@
<name>name</name>
<cstring>infoML</cstring>
</property>
<property stdset="1">
<name>wordWrap</name>
<enum>WidgetWidth</enum>
</property>
<property>
<name>toolTip</name>
<string>Reference entry text</string>
@ -319,7 +323,7 @@
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>PushButton14</cstring>
<cstring>previousPB</cstring>
</property>
<property stdset="1">
<name>text</name>
@ -387,7 +391,7 @@
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>PushButton15</cstring>
<cstring>nextPB</cstring>
</property>
<property stdset="1">
<name>text</name>
@ -643,12 +647,6 @@
</image>
</images>
<connections>
<connection>
<sender>citeLB</sender>
<signal>selected(int)</signal>
<receiver>FormCitationDialog</receiver>
<slot>slotInsetSelected(int)</slot>
</connection>
<connection>
<sender>bibLB</sender>
<signal>selected(int)</signal>
@ -686,37 +684,59 @@
<slot>slotRestoreClicked()</slot>
</connection>
<connection>
<sender>okPB</sender>
<signal>clicked()</signal>
<sender>citeLB</sender>
<signal>selected(int)</signal>
<receiver>FormCitationDialog</receiver>
<slot>apply_adaptor()</slot>
<slot>slotCiteSelected(int)</slot>
</connection>
<connection>
<sender>okPB</sender>
<signal>clicked()</signal>
<sender>searchTypePB</sender>
<signal>toggled(bool)</signal>
<receiver>FormCitationDialog</receiver>
<slot>close_adaptor()</slot>
<slot>slotSearchTypeSelected(bool)</slot>
</connection>
<connection>
<sender>applyPB</sender>
<sender>previousPB</sender>
<signal>clicked()</signal>
<receiver>FormCitationDialog</receiver>
<slot>apply_adaptor()</slot>
<slot>slotPreviousClicked()</slot>
</connection>
<connection>
<sender>cancelPB</sender>
<sender>nextPB</sender>
<signal>clicked()</signal>
<receiver>FormCitationDialog</receiver>
<slot>close_adaptor()</slot>
<slot>slotNextClicked()</slot>
</connection>
<slot access="protected">apply_adaptor()</slot>
<slot access="protected">close_adaptor()</slot>
<connection>
<sender>citationStyleCO</sender>
<signal>activated(int)</signal>
<receiver>FormCitationDialog</receiver>
<slot>slotCitationStyleSelected(int)</slot>
</connection>
<connection>
<sender>textBeforeED</sender>
<signal>returnPressed()</signal>
<receiver>FormCitationDialog</receiver>
<slot>slotTextBeforeReturn()</slot>
</connection>
<connection>
<sender>textAfterED</sender>
<signal>returnPressed()</signal>
<receiver>FormCitationDialog</receiver>
<slot>slotTextAfterReturn()</slot>
</connection>
<slot access="protected">slotTextAfterReturn()</slot>
<slot access="protected">slotAddClicked()</slot>
<slot access="protected">slotBibSelected(int)</slot>
<slot access="protected">slotCitationStyleSelected(int)</slot>
<slot access="protected">slotCiteSelected(int)</slot>
<slot access="protected">slotDelClicked()</slot>
<slot access="protected">slotDownClicked()</slot>
<slot access="protected">slotIUpClicked()</slot>
<slot access="protected">slotInsetSelected(int)</slot>
<slot access="protected">slotNextClicked()</slot>
<slot access="protected">slotPreviousClicked()</slot>
<slot access="protected">slotRestoreClicked()</slot>
<slot access="protected">slotSearchTypeSelected(bool)</slot>
<slot access="protected">slotTextBeforeReturn()</slot>
</connections>
</UI>

View File

@ -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 <qlineedit.h>
#include <qlistbox.h>
#include <qmultilineedit.h>
#include <qpushbutton.h>
#undef emit
#include <algorithm>
@ -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();
biblio::InfoMap const & theMap = form_->controller().bibkeysInfo();
if( sel < 0 || sel > form_->bibkeys.size()-1)
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<string>::iterator it =
::find(form_->citekeys.begin(), form_->citekeys.end(), form_->bibkeys[sel]);
infoML->setText( biblio::getInfo( theMap,
form_->bibkeys[sel-1] ).c_str() );
if (it != form_->citekeys.end()) {
int n = static_cast<int>(it - form_->citekeys.begin());
insetKeysLB->setSelected( n, true );
// Highlight the selected browser_bib key in browser_cite if
// present
vector<string>::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<string>::iterator it =
::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]);
vector<string>::const_iterator cit =
std::find(form_->bibkeys.begin(), form_->bibkeys.end(), form_->citekeys[sel]);
if (it != form_->bibkeys.end()) {
int n = static_cast<int>(it - form_->bibkeys.begin());
bibliographyKeysLB->setSelected( n, true );
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
// 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]);
citeLB->insertItem( form_->bibkeys[sel].c_str() );
form_->citekeys.push_back( form_->bibkeys[sel] );
int n = static_cast<int>(form_->citekeys.size());
insetKeysLB->setSelected( n, true );
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<string>::iterator it = form_->citekeys.begin() + sel;
string tmp = *it;
string const tmp = *it;
insetKeysLB->removeItem( sel );
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<string>::iterator it = form_->citekeys.begin() + sel;
string tmp = *it;
string const tmp = *it;
insetKeysLB->removeItem( sel );
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()
{
form_->close();
hide();
doPreviousNext( false );
}
#endif
void FormCitationDialogImpl::slotNextClicked()
{
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<string>::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<string>::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 );
}
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 );
}

View File

@ -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,13 +18,20 @@ 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_;

View File

@ -1,7 +1,7 @@
Dialog Maintainer MVC conversion
----------------------------------------------
Character Edwin
Citation Kalle
Citation Kalle In progress
Copyright Kalle Done
Credits
Document Kalle In progress