2001-02-12 14:09:09 +00:00
|
|
|
/**
|
|
|
|
* \file FormInclude.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2001-02-12 14:09:09 +00:00
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author John Levon
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2001-02-12 14:09:09 +00:00
|
|
|
*/
|
2001-03-23 17:09:34 +00:00
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
#include <config.h>
|
2001-02-12 14:09:09 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "xformsBC.h"
|
|
|
|
#include "ControlInclude.h"
|
2001-02-12 14:09:09 +00:00
|
|
|
#include "FormInclude.h"
|
2002-06-13 13:43:51 +00:00
|
|
|
#include "forms/form_include.h"
|
2001-03-14 10:57:39 +00:00
|
|
|
#include "insets/insetinclude.h"
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "xforms_helpers.h" // setEnabled
|
2001-06-12 12:39:26 +00:00
|
|
|
#include "support/lstrings.h" // strip
|
2002-06-13 13:43:51 +00:00
|
|
|
#include FORMS_H_LOCATION
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2002-06-13 13:43:51 +00:00
|
|
|
typedef FormCB<ControlInclude, FormDB<FD_include> > base_class;
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2002-08-12 14:28:43 +00:00
|
|
|
FormInclude::FormInclude()
|
|
|
|
: base_class(_("Include file"))
|
2001-03-23 17:09:34 +00:00
|
|
|
{}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
|
2001-02-12 14:09:09 +00:00
|
|
|
void FormInclude::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_include(this));
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
|
2002-03-11 18:24:31 +00:00
|
|
|
setPrehandler(dialog_->input_filename);
|
2001-06-12 12:39:26 +00:00
|
|
|
|
2001-02-12 14:09:09 +00:00
|
|
|
// Manage the ok and cancel buttons
|
2001-03-23 17:09:34 +00:00
|
|
|
bc().setOK(dialog_->button_ok);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().setCancel(dialog_->button_close);
|
2001-03-23 17:09:34 +00:00
|
|
|
|
|
|
|
bc().addReadOnly(dialog_->button_browse);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().addReadOnly(dialog_->radio_verbatim);
|
2001-03-23 17:09:34 +00:00
|
|
|
bc().addReadOnly(dialog_->check_typeset);
|
2002-03-12 14:11:15 +00:00
|
|
|
bc().addReadOnly(dialog_->radio_useinput);
|
|
|
|
bc().addReadOnly(dialog_->radio_useinclude);
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormInclude::update()
|
|
|
|
{
|
2002-07-04 09:58:16 +00:00
|
|
|
#if 0
|
|
|
|
// I believe this is not needed.
|
|
|
|
// Anyway, it is plain wrong (JSpitzm 3/7/02)
|
2001-03-23 17:09:34 +00:00
|
|
|
if (controller().params().noload) {
|
2001-03-14 10:57:39 +00:00
|
|
|
fl_set_input(dialog_->input_filename, "");
|
|
|
|
fl_set_button(dialog_->check_typeset, 0);
|
2002-03-12 14:11:15 +00:00
|
|
|
fl_set_button(dialog_->radio_useinput, 0);
|
|
|
|
fl_set_button(dialog_->radio_useinclude, 1);
|
|
|
|
fl_set_button(dialog_->radio_verbatim, 0);
|
2001-03-14 10:57:39 +00:00
|
|
|
fl_set_button(dialog_->check_visiblespace, 0);
|
|
|
|
fl_deactivate_object(dialog_->check_visiblespace);
|
|
|
|
fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE);
|
2001-02-12 14:09:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-07-04 09:58:16 +00:00
|
|
|
#endif
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
fl_set_input(dialog_->input_filename,
|
|
|
|
controller().params().cparams.getContents().c_str());
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
string const cmdname = controller().params().cparams.getCmdName();
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
fl_set_button(dialog_->check_typeset,
|
|
|
|
int(controller().params().noload));
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2002-08-02 18:25:25 +00:00
|
|
|
if (cmdname == "input")
|
|
|
|
fl_set_button(dialog_->check_preview,
|
|
|
|
int(controller().params().cparams.preview()));
|
|
|
|
else
|
|
|
|
fl_set_button(dialog_->check_preview, 0);
|
|
|
|
|
|
|
|
setEnabled(dialog_->check_preview, (cmdname == "input"));
|
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
fl_set_button(dialog_->radio_useinput, cmdname == "input");
|
|
|
|
fl_set_button(dialog_->radio_useinclude, cmdname == "include");
|
2001-02-12 14:09:09 +00:00
|
|
|
if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") {
|
2002-03-12 14:11:15 +00:00
|
|
|
fl_set_button(dialog_->radio_verbatim, 1);
|
2001-03-14 10:57:39 +00:00
|
|
|
fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*");
|
|
|
|
setEnabled(dialog_->check_visiblespace, true);
|
2002-05-30 21:39:54 +00:00
|
|
|
setEnabled(dialog_->button_load, false);
|
2001-02-12 14:09:09 +00:00
|
|
|
} else {
|
2001-03-14 10:57:39 +00:00
|
|
|
fl_set_button(dialog_->check_visiblespace, 0);
|
|
|
|
setEnabled(dialog_->check_visiblespace, false);
|
2002-05-30 21:39:54 +00:00
|
|
|
setEnabled(dialog_->button_load, true);
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
if (cmdname.empty())
|
2002-03-12 14:11:15 +00:00
|
|
|
fl_set_button(dialog_->radio_useinclude, 1);
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormInclude::apply()
|
|
|
|
{
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().noload = fl_get_button(dialog_->check_typeset);
|
2002-08-02 18:25:25 +00:00
|
|
|
controller().params().cparams
|
|
|
|
.preview(fl_get_button(dialog_->check_preview));
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2002-01-21 10:47:19 +00:00
|
|
|
string const file = fl_get_input(dialog_->input_filename);
|
|
|
|
if (controller().fileExists(file))
|
2002-03-21 16:59:12 +00:00
|
|
|
controller().params().cparams.setContents(file);
|
2002-01-21 10:47:19 +00:00
|
|
|
else
|
2002-03-21 16:59:12 +00:00
|
|
|
controller().params().cparams.setContents("");
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
if (fl_get_button(dialog_->radio_useinput))
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::INPUT;
|
2002-03-12 14:11:15 +00:00
|
|
|
else if (fl_get_button(dialog_->radio_useinclude))
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::INCLUDE;
|
2002-03-12 14:11:15 +00:00
|
|
|
else if (fl_get_button(dialog_->radio_verbatim)) {
|
2001-03-14 10:57:39 +00:00
|
|
|
if (fl_get_button(dialog_->check_visiblespace))
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::VERBAST;
|
2001-02-12 14:09:09 +00:00
|
|
|
else
|
2001-03-23 17:09:34 +00:00
|
|
|
controller().params().flag = InsetInclude::VERB;
|
2001-02-12 14:09:09 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
|
|
|
ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long)
|
2001-02-12 14:09:09 +00:00
|
|
|
{
|
2001-06-12 12:39:26 +00:00
|
|
|
ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID;
|
|
|
|
|
2001-03-30 09:51:46 +00:00
|
|
|
if (ob == dialog_->button_browse) {
|
|
|
|
ControlInclude::Type type;
|
2002-03-12 14:11:15 +00:00
|
|
|
if (fl_get_button(dialog_->radio_useinput))
|
2001-03-30 09:51:46 +00:00
|
|
|
type = ControlInclude::INPUT;
|
2002-03-12 14:11:15 +00:00
|
|
|
else if (fl_get_button(dialog_->radio_verbatim))
|
2001-03-30 09:51:46 +00:00
|
|
|
type = ControlInclude::VERBATIM;
|
|
|
|
else
|
|
|
|
type = ControlInclude::INCLUDE;
|
|
|
|
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
2002-03-21 21:21:28 +00:00
|
|
|
fl_freeze_form(form());
|
2001-03-30 09:51:46 +00:00
|
|
|
string const out_name = controller().Browse(in_name, type);
|
|
|
|
fl_set_input(dialog_->input_filename, out_name.c_str());
|
2002-03-21 21:21:28 +00:00
|
|
|
fl_unfreeze_form(form());
|
2001-03-30 09:51:46 +00:00
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
} else if (ob == dialog_->button_load) {
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
2002-07-28 22:50:13 +00:00
|
|
|
if (!rtrim(in_name).empty() && controller().fileExists(in_name)) {
|
2002-01-21 10:47:19 +00:00
|
|
|
// ApplyButton();
|
2002-08-12 14:28:43 +00:00
|
|
|
controller().OKButton();
|
2002-07-28 22:50:13 +00:00
|
|
|
controller().load(rtrim(in_name));
|
2001-06-12 12:39:26 +00:00
|
|
|
action = ButtonPolicy::SMI_NOOP;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (ob == dialog_->radio_verbatim) {
|
2001-03-23 17:09:34 +00:00
|
|
|
setEnabled(dialog_->check_visiblespace, true);
|
2002-05-30 21:39:54 +00:00
|
|
|
setEnabled(dialog_->button_load, false);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (ob == dialog_->radio_useinclude ||
|
|
|
|
ob == dialog_->radio_useinput) {
|
2001-03-23 17:09:34 +00:00
|
|
|
fl_set_button(dialog_->check_visiblespace, 0);
|
|
|
|
setEnabled(dialog_->check_visiblespace, false);
|
2002-05-30 21:39:54 +00:00
|
|
|
setEnabled(dialog_->button_load, true);
|
2001-06-12 12:39:26 +00:00
|
|
|
|
|
|
|
} else if (ob == dialog_->input_filename) {
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
2002-07-28 22:50:13 +00:00
|
|
|
if (rtrim(in_name).empty())
|
2001-06-12 12:39:26 +00:00
|
|
|
action = ButtonPolicy::SMI_INVALID;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2002-08-02 18:25:25 +00:00
|
|
|
if (ob == dialog_->radio_useinput) {
|
|
|
|
setEnabled(dialog_->check_preview, true);
|
|
|
|
} else if (ob == dialog_->radio_verbatim ||
|
|
|
|
ob == dialog_->radio_useinclude) {
|
|
|
|
fl_set_button(dialog_->check_preview, 0);
|
|
|
|
setEnabled(dialog_->check_preview, false);
|
|
|
|
}
|
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
return action;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|