2002-09-05 14:10:50 +00:00
|
|
|
/**
|
2002-03-07 15:06:57 +00:00
|
|
|
* \file FormSendto.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.
|
2002-03-07 15:06:57 +00:00
|
|
|
*
|
2002-12-01 22:59:25 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-03-07 15:06:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "FormSendto.h"
|
|
|
|
#include "ControlSendto.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "forms/form_sendto.h"
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
#include "Tooltips.h"
|
2002-03-07 15:06:57 +00:00
|
|
|
#include "xforms_helpers.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "xformsBC.h"
|
|
|
|
|
2003-02-28 09:49:49 +00:00
|
|
|
#include "format.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
|
2003-05-23 14:33:01 +00:00
|
|
|
#include "support/lstrings.h"
|
2002-03-07 15:06:57 +00:00
|
|
|
|
2003-09-05 13:15:43 +00:00
|
|
|
#include "lyx_forms.h"
|
|
|
|
|
2002-03-07 15:06:57 +00:00
|
|
|
using std::vector;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2002-03-07 15:06:57 +00:00
|
|
|
|
2004-05-19 15:11:37 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using support::trim;
|
|
|
|
|
|
|
|
namespace frontend {
|
2003-09-05 13:15:43 +00:00
|
|
|
|
2004-03-27 23:11:46 +00:00
|
|
|
typedef FormController<ControlSendto, FormView<FD_sendto> > base_class;
|
2002-03-07 15:06:57 +00:00
|
|
|
|
2004-03-27 23:11:46 +00:00
|
|
|
FormSendto::FormSendto(Dialog & parent)
|
|
|
|
: base_class(parent, _("Send document to command"))
|
2002-03-07 15:06:57 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void FormSendto::build()
|
|
|
|
{
|
2002-06-13 13:43:51 +00:00
|
|
|
dialog_.reset(build_sendto(this));
|
2002-03-07 15:06:57 +00:00
|
|
|
|
|
|
|
fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
|
2002-03-11 18:24:31 +00:00
|
|
|
setPrehandler(dialog_->input_command);
|
2002-03-07 15:06:57 +00:00
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
// Manage the ok, apply, restore and cancel/close buttons
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview().setOK(dialog_->button_ok);
|
|
|
|
bcview().setApply(dialog_->button_apply);
|
|
|
|
bcview().setCancel(dialog_->button_close);
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
|
|
// Set up the tooltip mechanism
|
2002-04-02 17:04:23 +00:00
|
|
|
string str = _("Export the buffer to this format before running the command below on it.");
|
2002-03-18 15:56:00 +00:00
|
|
|
tooltips().init(dialog_->browser_formats, str);
|
2002-03-11 09:54:42 +00:00
|
|
|
|
2002-04-02 17:04:23 +00:00
|
|
|
str = _("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
|
2002-03-18 15:56:00 +00:00
|
|
|
tooltips().init(dialog_->input_command, str);
|
2002-03-07 15:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormSendto::update()
|
|
|
|
{
|
|
|
|
all_formats_ = controller().allFormats();
|
|
|
|
|
|
|
|
// Check whether the current contents of the browser will be
|
|
|
|
// changed by loading the contents of formats
|
|
|
|
vector<string> keys;
|
|
|
|
keys.resize(all_formats_.size());
|
|
|
|
|
|
|
|
vector<string>::iterator result = keys.begin();
|
|
|
|
vector<Format const *>::const_iterator it = all_formats_.begin();
|
|
|
|
vector<Format const *>::const_iterator end = all_formats_.end();
|
|
|
|
for (; it != end; ++it, ++result) {
|
|
|
|
*result = (*it)->prettyname();
|
|
|
|
}
|
2002-03-11 09:54:42 +00:00
|
|
|
|
2002-03-07 15:06:57 +00:00
|
|
|
vector<string> const browser_keys =
|
2002-07-21 15:51:07 +00:00
|
|
|
getVector(dialog_->browser_formats);
|
2002-03-07 15:06:57 +00:00
|
|
|
|
|
|
|
if (browser_keys == keys)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Reload the browser
|
|
|
|
fl_clear_browser(dialog_->browser_formats);
|
|
|
|
|
|
|
|
for (vector<string>::const_iterator it = keys.begin();
|
|
|
|
it < keys.end(); ++it) {
|
|
|
|
fl_add_browser_line(dialog_->browser_formats, it->c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
fl_set_input(dialog_->input_command, controller().getCommand().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-11 09:54:42 +00:00
|
|
|
ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
|
2002-03-07 15:06:57 +00:00
|
|
|
{
|
|
|
|
int const line = fl_get_browser(dialog_->browser_formats);
|
|
|
|
if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
|
|
|
|
return ButtonPolicy::SMI_INVALID;
|
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
string cmd = getString(dialog_->input_command);
|
2002-07-28 22:50:13 +00:00
|
|
|
cmd = trim(cmd);
|
2002-03-07 15:06:57 +00:00
|
|
|
if (cmd.empty())
|
|
|
|
return ButtonPolicy::SMI_INVALID;
|
|
|
|
|
|
|
|
return ButtonPolicy::SMI_VALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormSendto::apply()
|
|
|
|
{
|
|
|
|
int const line = fl_get_browser(dialog_->browser_formats);
|
|
|
|
if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
|
|
|
|
return;
|
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
string const cmd = getString(dialog_->input_command);
|
2002-03-07 15:06:57 +00:00
|
|
|
|
|
|
|
controller().setFormat(all_formats_[line-1]);
|
|
|
|
controller().setCommand(cmd);
|
|
|
|
}
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|