2000-08-08 15:36:25 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
#include <algorithm>
|
2000-08-08 15:36:25 +00:00
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Dialogs.h"
|
|
|
|
#include "FormRef.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "form_ref.h"
|
|
|
|
#include "lyxfunc.h"
|
2001-01-21 21:41:35 +00:00
|
|
|
#include "insets/insetref.h"
|
2001-03-05 19:02:40 +00:00
|
|
|
#include "xforms_helpers.h"
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
using std::find;
|
|
|
|
using std::max;
|
2000-08-08 15:36:25 +00:00
|
|
|
using std::sort;
|
|
|
|
using std::vector;
|
|
|
|
|
2001-02-27 12:32:01 +00:00
|
|
|
bool saved_position;
|
|
|
|
|
2000-08-08 15:36:25 +00:00
|
|
|
FormRef::FormRef(LyXView * lv, Dialogs * d)
|
2000-11-29 15:06:42 +00:00
|
|
|
: FormCommand(lv, d, _("Reference"), new NoRepeatedApplyPolicy),
|
2001-02-27 12:32:01 +00:00
|
|
|
at_ref(false), dialog_(0)
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
|
|
|
// let the dialog be shown
|
|
|
|
// These are permanent connections so we won't bother
|
|
|
|
// storing a copy because we won't be disconnecting.
|
|
|
|
d->showRef.connect(slot(this, &FormRef::showInset));
|
|
|
|
d->createRef.connect(slot(this, &FormRef::createInset));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FormRef::~FormRef()
|
|
|
|
{
|
|
|
|
delete dialog_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-03 05:53:25 +00:00
|
|
|
FL_FORM * FormRef::form() const
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
if (dialog_) return dialog_->form;
|
2000-10-03 05:53:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-13 05:57:05 +00:00
|
|
|
void FormRef::disconnect()
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
|
|
|
refs.clear();
|
2000-10-13 05:57:05 +00:00
|
|
|
FormCommand::disconnect();
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::build()
|
|
|
|
{
|
|
|
|
dialog_ = build_ref();
|
|
|
|
|
2001-01-21 21:41:35 +00:00
|
|
|
for (int i = 0; !InsetRef::types[i].latex_name.empty(); ++i)
|
|
|
|
fl_addto_choice(dialog_->type,
|
|
|
|
_(InsetRef::types[i].gui_name.c_str()));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-10-20 09:50:09 +00:00
|
|
|
// Workaround dumb xforms sizing bug
|
|
|
|
minw_ = form()->w;
|
|
|
|
minh_ = form()->h;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
// Force the user to use the browser to change refs.
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_deactivate_object(dialog_->ref);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-28 06:46:06 +00:00
|
|
|
// Manage the ok and cancel/close buttons
|
2000-11-14 02:01:57 +00:00
|
|
|
bc_.setOK(dialog_->button_ok);
|
2000-11-29 15:06:42 +00:00
|
|
|
bc_.setApply(dialog_->button_apply);
|
2000-11-14 02:01:57 +00:00
|
|
|
bc_.setCancel(dialog_->button_cancel);
|
2000-11-29 15:06:42 +00:00
|
|
|
bc_.setUndoAll(dialog_->button_restore);
|
2000-10-02 00:10:25 +00:00
|
|
|
bc_.refresh();
|
2000-11-28 06:46:06 +00:00
|
|
|
|
2001-01-21 20:10:48 +00:00
|
|
|
#warning I had to uncomment this so the buttons could be disabled in update() (dekel)
|
|
|
|
//bc_.addReadOnly(dialog_->type);
|
|
|
|
//bc_.addReadOnly(dialog_->name);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-24 13:13:59 +00:00
|
|
|
void FormRef::update()
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2001-01-21 20:10:48 +00:00
|
|
|
if (inset_) {
|
|
|
|
fl_set_input(dialog_->ref, params.getContents().c_str());
|
|
|
|
fl_set_input(dialog_->name, params.getOptions().c_str());
|
2001-01-26 17:11:01 +00:00
|
|
|
fl_set_choice(dialog_->type,
|
|
|
|
InsetRef::getType(params.getCmdName()) + 1);
|
2001-01-21 20:10:48 +00:00
|
|
|
}
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-02-27 12:32:01 +00:00
|
|
|
at_ref = false;
|
2000-10-03 05:53:25 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Goto reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-01-21 20:10:48 +00:00
|
|
|
// Name is irrelevant to LaTeX/Literate documents, while
|
|
|
|
// type is irrelevant to LinuxDoc/DocBook.
|
|
|
|
if (lv_->buffer()->isLatex() || lv_->buffer()->isLatex()) {
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->name, false);
|
|
|
|
setEnabled(dialog_->type, true);
|
2001-01-21 20:10:48 +00:00
|
|
|
} else {
|
2001-01-21 21:41:35 +00:00
|
|
|
fl_set_choice(dialog_->type, 1);
|
2001-01-21 20:10:48 +00:00
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->name, true);
|
|
|
|
setEnabled(dialog_->type, false);
|
2000-11-29 15:06:42 +00:00
|
|
|
}
|
2000-11-29 19:27:43 +00:00
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
refs = lv_->buffer()->getLabelList();
|
|
|
|
updateBrowser(refs);
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
bc_.readOnly(lv_->buffer()->isReadonly());
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
void FormRef::updateBrowser(vector<string> const & akeys) const
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
vector<string> keys(akeys);
|
2000-11-29 19:27:43 +00:00
|
|
|
if (fl_get_button(dialog_->sort))
|
2000-11-14 02:01:57 +00:00
|
|
|
sort(keys.begin(), keys.end());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_clear_browser(dialog_->browser);
|
2000-11-04 10:00:12 +00:00
|
|
|
for (vector<string>::const_iterator it = keys.begin();
|
2000-11-14 02:01:57 +00:00
|
|
|
it != keys.end(); ++it)
|
|
|
|
fl_add_browser_line(dialog_->browser, (*it).c_str());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
if (keys.empty()) {
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_add_browser_line(dialog_->browser,
|
|
|
|
_("*** No labels found in document ***"));
|
2001-03-05 19:02:40 +00:00
|
|
|
|
|
|
|
setEnabled(dialog_->browser, false);
|
|
|
|
setEnabled(dialog_->sort, false);
|
2000-11-14 02:01:57 +00:00
|
|
|
|
2001-01-21 21:41:35 +00:00
|
|
|
fl_set_input(dialog_->ref, "");
|
2000-08-08 15:36:25 +00:00
|
|
|
} else {
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->browser, true);
|
|
|
|
setEnabled(dialog_->sort, true);
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
string ref = fl_get_input(dialog_->ref);
|
|
|
|
vector<string>::const_iterator cit =
|
2000-11-29 19:27:43 +00:00
|
|
|
find(keys.begin(), keys.end(), ref);
|
2001-01-28 18:31:36 +00:00
|
|
|
if (cit == keys.end()) {
|
2001-01-21 20:10:48 +00:00
|
|
|
cit = keys.begin();
|
2001-01-28 18:31:36 +00:00
|
|
|
fl_set_input(dialog_->ref, (*cit).c_str());
|
|
|
|
} else if (ref.empty())
|
2001-01-21 21:41:35 +00:00
|
|
|
fl_set_input(dialog_->ref, (*cit).c_str());
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-01-21 20:10:48 +00:00
|
|
|
int const i = static_cast<int>(cit - keys.begin());
|
|
|
|
fl_set_browser_topline(dialog_->browser, max(i-5, 1));
|
|
|
|
fl_select_browser_line(dialog_->browser, i+1);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormRef::apply()
|
|
|
|
{
|
|
|
|
if (!lv_->view()->available())
|
|
|
|
return;
|
|
|
|
|
2001-01-21 21:41:35 +00:00
|
|
|
int const type = fl_get_choice(dialog_->type) - 1;
|
2001-01-26 17:11:01 +00:00
|
|
|
params.setCmdName(InsetRef::getName(type));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-09-19 11:18:35 +00:00
|
|
|
params.setOptions(fl_get_input(dialog_->name));
|
2000-11-29 15:06:42 +00:00
|
|
|
params.setContents(fl_get_input(dialog_->ref));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-09-19 11:18:35 +00:00
|
|
|
if (inset_ != 0) {
|
2000-08-08 15:36:25 +00:00
|
|
|
// Only update if contents have changed
|
2000-10-03 05:53:25 +00:00
|
|
|
if (params != inset_->params()) {
|
2000-09-19 11:18:35 +00:00
|
|
|
inset_->setParams(params);
|
|
|
|
lv_->view()->updateInset(inset_, true);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-09-19 11:18:35 +00:00
|
|
|
lv_->getLyXFunc()->Dispatch(LFUN_REF_INSERT,
|
|
|
|
params.getAsString());
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
bool FormRef::input(FL_OBJECT *, long data)
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
bool activate(true);
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (data) {
|
2000-08-08 15:36:25 +00:00
|
|
|
// goto reference / go back
|
|
|
|
case 1:
|
|
|
|
{
|
2000-11-29 15:06:42 +00:00
|
|
|
// No change to data
|
|
|
|
activate = false;
|
|
|
|
|
2001-02-27 12:32:01 +00:00
|
|
|
at_ref = !at_ref;
|
|
|
|
if (at_ref) {
|
|
|
|
lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_SAVE, "0");
|
2000-08-08 15:36:25 +00:00
|
|
|
lv_->getLyXFunc()->
|
|
|
|
Dispatch(LFUN_REF_GOTO,
|
2001-01-17 19:00:12 +00:00
|
|
|
fl_get_input(dialog_->ref));
|
2000-10-03 05:53:25 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Go back"));
|
2001-02-27 12:32:01 +00:00
|
|
|
} else {
|
2001-01-28 18:31:36 +00:00
|
|
|
lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_GOTO, "0");
|
2000-10-13 05:57:05 +00:00
|
|
|
fl_set_object_label(dialog_->button_go,
|
|
|
|
_("Goto reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// choose browser key
|
|
|
|
case 2:
|
|
|
|
{
|
2000-11-14 02:01:57 +00:00
|
|
|
unsigned int sel = fl_get_browser(dialog_->browser);
|
|
|
|
if (sel < 1 || sel > refs.size()) break;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
if (!lv_->buffer()->isReadonly()) {
|
|
|
|
string s = fl_get_browser_line(dialog_->browser, sel);
|
|
|
|
fl_set_input(dialog_->ref, s.c_str());
|
|
|
|
}
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-02-27 12:32:01 +00:00
|
|
|
if (at_ref)
|
|
|
|
lv_->getLyXFunc()->Dispatch(LFUN_BOOKMARK_GOTO, "0");
|
|
|
|
at_ref = false;
|
2000-10-03 05:53:25 +00:00
|
|
|
fl_set_object_label(dialog_->button_go, _("Goto reference"));
|
2000-08-08 15:36:25 +00:00
|
|
|
|
2001-03-05 19:02:40 +00:00
|
|
|
setEnabled(dialog_->type, true);
|
|
|
|
setEnabled(dialog_->button_go, true);
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_set_object_lcol(dialog_->ref, FL_BLACK);
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// update or sort
|
|
|
|
case 3:
|
2000-11-29 19:27:43 +00:00
|
|
|
refs = lv_->buffer()->getLabelList();
|
|
|
|
|
|
|
|
// fall through to...
|
|
|
|
case 4:
|
2000-11-14 02:01:57 +00:00
|
|
|
fl_freeze_form(form());
|
|
|
|
updateBrowser(refs);
|
|
|
|
fl_unfreeze_form(form());
|
2000-11-29 19:27:43 +00:00
|
|
|
break;
|
2000-08-08 15:36:25 +00:00
|
|
|
|
|
|
|
// changed reference type
|
2000-11-29 19:27:43 +00:00
|
|
|
case 5:
|
2000-08-08 15:36:25 +00:00
|
|
|
{
|
2001-01-21 21:41:35 +00:00
|
|
|
int const type = fl_get_choice(dialog_->type) - 1;
|
2001-01-26 17:11:01 +00:00
|
|
|
if (params.getCmdName() == InsetRef::getName(type) && inset_) {
|
2000-10-02 00:10:25 +00:00
|
|
|
activate = false;
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-11-29 15:06:42 +00:00
|
|
|
|
2000-10-02 00:10:25 +00:00
|
|
|
return activate;
|
2000-08-08 15:36:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|