2001-02-12 14:09:09 +00:00
|
|
|
/**
|
|
|
|
* \file FormInclude.C
|
|
|
|
* Copyright 2001 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Alejandro Aguilar Sierra
|
2001-03-23 17:09:34 +00:00
|
|
|
* \author John Levon, moz@compsoc.man.ac.uk
|
2002-03-11 17:00:41 +00:00
|
|
|
* \author Angus Leeming, a.leeming@ic.ac.uk
|
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"
|
2001-03-23 17:09:34 +00:00
|
|
|
#include "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
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
typedef FormCB<ControlInclude, FormDB<FD_form_include> > base_class;
|
2001-02-12 14:09:09 +00:00
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
FormInclude::FormInclude(ControlInclude & c)
|
|
|
|
: base_class(c, _("Include file"))
|
|
|
|
{}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
|
2001-02-12 14:09:09 +00:00
|
|
|
void FormInclude::build()
|
|
|
|
{
|
2001-03-15 13:37:04 +00:00
|
|
|
dialog_.reset(build_include());
|
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()
|
|
|
|
{
|
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;
|
|
|
|
}
|
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-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);
|
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);
|
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);
|
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-01-21 10:47:19 +00:00
|
|
|
if (!strip(in_name).empty() && controller().fileExists(in_name)) {
|
|
|
|
// ApplyButton();
|
|
|
|
OKButton();
|
2001-07-25 12:37:43 +00:00
|
|
|
controller().load(strip(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);
|
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);
|
2001-06-12 12:39:26 +00:00
|
|
|
|
|
|
|
} else if (ob == dialog_->input_filename) {
|
|
|
|
string const in_name = fl_get_input(dialog_->input_filename);
|
|
|
|
if (strip(in_name).empty())
|
|
|
|
action = ButtonPolicy::SMI_INVALID;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
2001-06-12 12:39:26 +00:00
|
|
|
return action;
|
2001-03-23 17:09:34 +00:00
|
|
|
}
|