2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file lyxfunc.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Alfredo Braunstein
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \author Allan Rae
|
|
|
|
|
* \author Dekel Tsur
|
|
|
|
|
* \author Martin Vermeer
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2000-04-11 22:55:29 +00:00
|
|
|
|
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "lyxfunc.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
|
2003-09-09 17:00:19 +00:00
|
|
|
|
#include "BranchList.h"
|
2003-05-23 13:54:09 +00:00
|
|
|
|
#include "buffer.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "bufferlist.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "BufferView.h"
|
2003-09-17 16:44:51 +00:00
|
|
|
|
#include "cursor.h"
|
2004-03-30 16:19:50 +00:00
|
|
|
|
#include "CutAndPaste.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-01-05 22:38:42 +00:00
|
|
|
|
#include "encoding.h"
|
2004-03-30 16:19:50 +00:00
|
|
|
|
#include "errorlist.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "exporter.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "format.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "importer.h"
|
2004-03-30 12:36:33 +00:00
|
|
|
|
#include "insetiterator.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "intl.h"
|
|
|
|
|
#include "kbmap.h"
|
2004-03-30 16:19:50 +00:00
|
|
|
|
#include "language.h"
|
2003-09-16 10:30:59 +00:00
|
|
|
|
#include "LColor.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "lyx_cb.h"
|
|
|
|
|
#include "LyXAction.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "lyxfind.h"
|
2004-03-30 16:19:50 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-09-06 23:36:02 +00:00
|
|
|
|
#include "lyxrc.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "lyxrow.h"
|
|
|
|
|
#include "lyxserver.h"
|
2004-03-30 16:19:50 +00:00
|
|
|
|
#include "lyxtextclasslist.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "lyxvc.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.h"
|
2004-03-28 22:00:22 +00:00
|
|
|
|
#include "pariterator.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "ParagraphParameters.h"
|
2003-10-14 13:01:49 +00:00
|
|
|
|
#include "undo.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-12-10 22:10:38 +00:00
|
|
|
|
#include "insets/insetbox.h"
|
|
|
|
|
#include "insets/insetbranch.h"
|
2002-09-09 17:32:53 +00:00
|
|
|
|
#include "insets/insetcommand.h"
|
2003-12-10 22:10:38 +00:00
|
|
|
|
#include "insets/insetert.h"
|
2003-06-11 11:01:34 +00:00
|
|
|
|
#include "insets/insetexternal.h"
|
2003-12-10 22:10:38 +00:00
|
|
|
|
#include "insets/insetfloat.h"
|
|
|
|
|
#include "insets/insetgraphics.h"
|
|
|
|
|
#include "insets/insetnote.h"
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#include "insets/insettabular.h"
|
2003-11-28 15:53:34 +00:00
|
|
|
|
#include "insets/insetvspace.h"
|
2003-12-10 22:10:38 +00:00
|
|
|
|
#include "insets/insetwrap.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "frontends/Alert.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "frontends/Dialogs.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "frontends/FileDialog.h"
|
|
|
|
|
#include "frontends/lyx_gui.h"
|
2003-09-06 20:08:10 +00:00
|
|
|
|
#include "frontends/LyXKeySym.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
#include "frontends/Menubar.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "frontends/Toolbar.h"
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/FileInfo.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/filetools.h"
|
2002-02-27 09:59:52 +00:00
|
|
|
|
#include "support/forkedcontr.h"
|
2004-01-08 10:59:51 +00:00
|
|
|
|
#include "support/globbing.h"
|
2004-03-28 14:12:33 +00:00
|
|
|
|
#include "support/lstrings.h"
|
1999-11-15 12:01:38 +00:00
|
|
|
|
#include "support/path.h"
|
2003-07-27 21:04:02 +00:00
|
|
|
|
#include "support/path_defines.h"
|
2004-03-27 23:11:46 +00:00
|
|
|
|
#include "support/systemcall.h"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "support/tostr.h"
|
|
|
|
|
#include "support/std_sstream.h"
|
2003-10-14 11:35:50 +00:00
|
|
|
|
#include "support/os.h"
|
2001-12-10 20:06:59 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using bv_funcs::freefont2string;
|
|
|
|
|
|
|
|
|
|
using lyx::support::AddName;
|
|
|
|
|
using lyx::support::AddPath;
|
|
|
|
|
using lyx::support::bformat;
|
|
|
|
|
using lyx::support::ChangeExtension;
|
2004-03-27 23:11:46 +00:00
|
|
|
|
using lyx::support::contains;
|
2004-01-08 10:59:51 +00:00
|
|
|
|
using lyx::support::FileFilterList;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::FileInfo;
|
|
|
|
|
using lyx::support::FileSearch;
|
|
|
|
|
using lyx::support::ForkedcallsController;
|
|
|
|
|
using lyx::support::i18nLibFileSearch;
|
|
|
|
|
using lyx::support::IsDirWriteable;
|
|
|
|
|
using lyx::support::IsFileReadable;
|
|
|
|
|
using lyx::support::isStrInt;
|
|
|
|
|
using lyx::support::MakeAbsPath;
|
|
|
|
|
using lyx::support::MakeDisplayPath;
|
|
|
|
|
using lyx::support::Path;
|
2004-03-28 14:12:33 +00:00
|
|
|
|
using lyx::support::QuoteName;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::rtrim;
|
|
|
|
|
using lyx::support::split;
|
|
|
|
|
using lyx::support::strToInt;
|
|
|
|
|
using lyx::support::strToUnsignedInt;
|
2004-03-27 23:11:46 +00:00
|
|
|
|
using lyx::support::subst;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::system_lyxdir;
|
2004-03-27 23:11:46 +00:00
|
|
|
|
using lyx::support::Systemcall;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::token;
|
|
|
|
|
using lyx::support::trim;
|
|
|
|
|
using lyx::support::user_lyxdir;
|
2003-10-14 11:35:50 +00:00
|
|
|
|
using lyx::support::prefixIs;
|
|
|
|
|
using lyx::support::os::getTmpDir;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
using std::make_pair;
|
2003-12-05 13:37:23 +00:00
|
|
|
|
using std::pair;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
extern BufferList bufferlist;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
extern LyXServer * lyxserver;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
extern bool selection_possible;
|
|
|
|
|
|
2001-03-07 16:18:05 +00:00
|
|
|
|
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// (alkis)
|
|
|
|
|
extern tex_accent_struct get_accent(kb_action action);
|
|
|
|
|
|
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
LyXFunc::LyXFunc(LyXView * lv)
|
|
|
|
|
: owner(lv),
|
2003-01-05 22:38:42 +00:00
|
|
|
|
encoded_last_key(0),
|
2001-11-30 13:25:38 +00:00
|
|
|
|
keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
|
2002-10-21 16:21:56 +00:00
|
|
|
|
cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get()),
|
|
|
|
|
meta_fake_bit(key_modifier::none)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
2001-02-23 16:10:03 +00:00
|
|
|
|
void LyXFunc::handleKeyFunc(kb_action action)
|
|
|
|
|
{
|
2003-01-05 22:38:42 +00:00
|
|
|
|
char c = encoded_last_key;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2003-01-05 22:38:42 +00:00
|
|
|
|
if (keyseq.length()) {
|
2001-11-30 13:25:38 +00:00
|
|
|
|
c = 0;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner->getIntl().getTransManager()
|
2003-07-28 22:34:48 +00:00
|
|
|
|
.deadkey(c, get_accent(action).accent, view()->getLyXText());
|
2001-11-30 13:25:38 +00:00
|
|
|
|
// Need to clear, in case the minibuffer calls these
|
2001-02-23 16:10:03 +00:00
|
|
|
|
// actions
|
2001-11-30 13:25:38 +00:00
|
|
|
|
keyseq.clear();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
// copied verbatim from do_accent_char
|
2004-01-20 14:25:24 +00:00
|
|
|
|
view()->cursor().resetAnchor();
|
2003-08-04 09:06:35 +00:00
|
|
|
|
view()->update();
|
2001-02-23 16:10:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
void LyXFunc::processKeySym(LyXKeySymPtr keysym, key_modifier::state state)
|
2000-08-14 15:31:16 +00:00
|
|
|
|
{
|
2004-02-03 14:29:00 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "KeySym is " << keysym->getSymbolName() << endl;
|
2002-11-04 02:12:42 +00:00
|
|
|
|
|
2000-08-14 15:31:16 +00:00
|
|
|
|
// Do nothing if we have nothing (JMarc)
|
2002-08-07 08:11:41 +00:00
|
|
|
|
if (!keysym->isOK()) {
|
2000-08-14 15:31:16 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
|
|
|
|
|
<< endl;
|
2001-05-17 01:23:29 +00:00
|
|
|
|
return;
|
2000-08-14 15:31:16 +00:00
|
|
|
|
}
|
2000-10-12 01:18:11 +00:00
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
if (keysym->isModifier()) {
|
2002-12-12 13:46:06 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "isModifier true" << endl;
|
2001-05-17 01:23:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
Encoding const * encoding = view()->cursor().getEncoding();
|
2003-01-05 22:38:42 +00:00
|
|
|
|
|
|
|
|
|
encoded_last_key = keysym->getISOEncoded(encoding ? encoding->Name() : "");
|
|
|
|
|
|
2000-08-14 15:31:16 +00:00
|
|
|
|
// Do a one-deep top-level lookup for
|
|
|
|
|
// cancel and meta-fake keys. RVDK_PATCH_5
|
|
|
|
|
cancel_meta_seq.reset();
|
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
FuncRequest func = cancel_meta_seq.addkey(keysym, state);
|
|
|
|
|
lyxerr[Debug::KEY] << "action first set to [" << func.action << ']' << endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
// When not cancel or meta-fake, do the normal lookup.
|
2000-08-14 15:31:16 +00:00
|
|
|
|
// Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
|
2002-05-26 17:33:14 +00:00
|
|
|
|
// Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
|
2003-09-21 23:00:47 +00:00
|
|
|
|
if ((func.action != LFUN_CANCEL) && (func.action != LFUN_META_FAKE)) {
|
2000-08-14 15:31:16 +00:00
|
|
|
|
// remove Caps Lock and Mod2 as a modifiers
|
2003-09-21 23:00:47 +00:00
|
|
|
|
func = keyseq.addkey(keysym, (state | meta_fake_bit));
|
2002-08-06 00:54:20 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "action now set to ["
|
2003-09-21 23:00:47 +00:00
|
|
|
|
<< func.action << ']' << endl;
|
2000-08-14 15:31:16 +00:00
|
|
|
|
}
|
2002-08-10 15:21:07 +00:00
|
|
|
|
|
2000-08-14 15:31:16 +00:00
|
|
|
|
// Dont remove this unless you know what you are doing.
|
2002-05-26 17:33:14 +00:00
|
|
|
|
meta_fake_bit = key_modifier::none;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
|
|
// can this happen now ?
|
2003-09-21 23:00:47 +00:00
|
|
|
|
if (func.action == LFUN_NOACTION) {
|
|
|
|
|
func = FuncRequest(LFUN_PREFIX);
|
2001-11-30 13:25:38 +00:00
|
|
|
|
}
|
2000-08-14 15:31:16 +00:00
|
|
|
|
|
|
|
|
|
if (lyxerr.debugging(Debug::KEY)) {
|
2001-05-29 09:50:02 +00:00
|
|
|
|
lyxerr << "Key [action="
|
2003-09-21 23:00:47 +00:00
|
|
|
|
<< func.action << "]["
|
2002-11-27 10:30:28 +00:00
|
|
|
|
<< keyseq.print() << ']'
|
2000-08-14 15:31:16 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// already here we know if it any point in going further
|
|
|
|
|
// why not return already here if action == -1 and
|
|
|
|
|
// num_bytes == 0? (Lgb)
|
|
|
|
|
|
2002-03-01 14:13:01 +00:00
|
|
|
|
if (keyseq.length() > 1) {
|
2001-11-30 13:25:38 +00:00
|
|
|
|
owner->message(keyseq.print());
|
2000-08-14 15:31:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-02-13 16:53:15 +00:00
|
|
|
|
|
2002-12-12 13:46:06 +00:00
|
|
|
|
// Maybe user can only reach the key via holding down shift.
|
|
|
|
|
// Let's see. But only if shift is the only modifier
|
2003-09-21 23:00:47 +00:00
|
|
|
|
if (func.action == LFUN_UNKNOWN_ACTION &&
|
|
|
|
|
state == key_modifier::shift) {
|
2002-12-12 13:46:06 +00:00
|
|
|
|
lyxerr[Debug::KEY] << "Trying without shift" << endl;
|
2003-09-21 23:00:47 +00:00
|
|
|
|
func = keyseq.addkey(keysym, key_modifier::none);
|
|
|
|
|
lyxerr[Debug::KEY] << "Action now " << func.action << endl;
|
2002-12-12 13:46:06 +00:00
|
|
|
|
}
|
2003-02-13 16:53:15 +00:00
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
if (func.action == LFUN_UNKNOWN_ACTION) {
|
2002-12-12 13:46:06 +00:00
|
|
|
|
// Hmm, we didn't match any of the keysequences. See
|
|
|
|
|
// if it's normal insertable text not already covered
|
|
|
|
|
// by a binding
|
|
|
|
|
if (keysym->isText() && keyseq.length() == 1) {
|
|
|
|
|
lyxerr[Debug::KEY] << "isText() is true, inserting." << endl;
|
2003-09-21 23:00:47 +00:00
|
|
|
|
func = FuncRequest(LFUN_SELFINSERT);
|
2002-12-12 13:46:06 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::KEY] << "Unknown, !isText() - giving up" << endl;
|
2001-05-17 01:23:29 +00:00
|
|
|
|
owner->message(_("Unknown function."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
if (func.action == LFUN_SELFINSERT) {
|
2003-01-05 22:38:42 +00:00
|
|
|
|
if (encoded_last_key != 0) {
|
2004-02-06 09:34:04 +00:00
|
|
|
|
string arg(1, encoded_last_key);
|
2004-01-15 17:34:44 +00:00
|
|
|
|
dispatch(FuncRequest(LFUN_SELFINSERT, arg));
|
2004-02-03 14:29:00 +00:00
|
|
|
|
lyxerr[Debug::KEY]
|
|
|
|
|
<< "SelfInsert arg[`" << arg << "']" << endl;
|
2003-01-05 22:38:42 +00:00
|
|
|
|
}
|
2002-06-18 17:22:17 +00:00
|
|
|
|
} else {
|
2003-09-21 23:00:47 +00:00
|
|
|
|
dispatch(func);
|
2002-06-18 17:22:17 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2000-08-14 15:31:16 +00:00
|
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
2004-03-18 13:57:20 +00:00
|
|
|
|
//lyxerr << "LyXFunc::getStatus: cmd: " << cmd << endl;
|
2002-01-09 09:36:35 +00:00
|
|
|
|
FuncStatus flag;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Buffer * buf = owner->buffer();
|
2004-02-06 16:14:06 +00:00
|
|
|
|
LCursor & cur = view()->cursor();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cmd.action == LFUN_NOACTION) {
|
2002-03-27 23:27:12 +00:00
|
|
|
|
setStatusMessage(N_("Nothing to do"));
|
2004-03-18 13:57:20 +00:00
|
|
|
|
flag.enabled(false);
|
2003-10-21 16:15:14 +00:00
|
|
|
|
return flag;
|
2002-03-27 23:27:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
switch (cmd.action) {
|
2002-12-18 14:24:32 +00:00
|
|
|
|
case LFUN_UNKNOWN_ACTION:
|
|
|
|
|
#ifndef HAVE_LIBAIKSAURUS
|
|
|
|
|
case LFUN_THESAURUS_ENTRY:
|
|
|
|
|
#endif
|
|
|
|
|
flag.unknown(true);
|
2004-03-18 13:57:20 +00:00
|
|
|
|
flag.enabled(false);
|
2002-12-18 14:24:32 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2004-02-13 07:30:59 +00:00
|
|
|
|
flag |= lyx_gui::getStatus(cmd);
|
2002-12-18 14:24:32 +00:00
|
|
|
|
}
|
2003-02-13 16:53:15 +00:00
|
|
|
|
|
2002-12-18 14:24:32 +00:00
|
|
|
|
if (flag.unknown()) {
|
2002-01-13 13:07:27 +00:00
|
|
|
|
setStatusMessage(N_("Unknown action"));
|
2002-12-18 14:24:32 +00:00
|
|
|
|
return flag;
|
2000-06-12 11:27:15 +00:00
|
|
|
|
}
|
2002-02-06 15:12:40 +00:00
|
|
|
|
|
|
|
|
|
// the default error message if we disable the command
|
|
|
|
|
setStatusMessage(N_("Command disabled"));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
// Check whether we need a buffer
|
2004-03-23 11:22:11 +00:00
|
|
|
|
if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !buf) {
|
|
|
|
|
// no, exit directly
|
|
|
|
|
setStatusMessage(N_("Command not allowed with"
|
|
|
|
|
"out any document open"));
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
return flag;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
|
// I would really like to avoid having this switch and rather try to
|
|
|
|
|
// encode this in the function itself.
|
2004-03-18 13:57:20 +00:00
|
|
|
|
// -- And I'd rather let an inset decide which LFUNs it is willing
|
|
|
|
|
// to handle (Andre')
|
|
|
|
|
bool enable = true;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
switch (cmd.action) {
|
2004-03-18 13:57:20 +00:00
|
|
|
|
case LFUN_TOOLTIPS_TOGGLE:
|
|
|
|
|
flag.setOnOff(owner->getDialogs().tooltipsEnabled());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_READ_ONLY_TOGGLE:
|
|
|
|
|
flag.setOnOff(buf->isReadonly());
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_SWITCHBUFFER:
|
|
|
|
|
// toggle on the current buffer, but do not toggle off
|
|
|
|
|
// the other ones (is that a good idea?)
|
|
|
|
|
if (cmd.argument == buf->fileName())
|
|
|
|
|
flag.setOnOff(true);
|
|
|
|
|
break;
|
|
|
|
|
|
2000-11-06 11:20:22 +00:00
|
|
|
|
case LFUN_EXPORT:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "custom"
|
|
|
|
|
|| Exporter::IsExportable(*buf, cmd.argument);
|
2000-11-06 11:20:22 +00:00
|
|
|
|
break;
|
2002-08-24 22:02:30 +00:00
|
|
|
|
case LFUN_CUT:
|
|
|
|
|
case LFUN_COPY:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cur.selection();
|
2002-08-24 22:02:30 +00:00
|
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
case LFUN_RUNCHKTEX:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = buf->isLatex() && lyxrc.chktex_command != "none";
|
1999-12-16 06:43:25 +00:00
|
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
|
2000-07-25 10:46:18 +00:00
|
|
|
|
case LFUN_BUILDPROG:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = Exporter::IsExportable(*buf, "program");
|
2000-07-31 12:51:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2000-08-01 09:35:42 +00:00
|
|
|
|
case LFUN_LAYOUT_TABULAR:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cur.innerInsetOfType(InsetBase::TABULAR_CODE);
|
2003-04-03 01:26:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2002-01-20 23:17:17 +00:00
|
|
|
|
case LFUN_LAYOUT:
|
2004-02-06 16:14:06 +00:00
|
|
|
|
case LFUN_LAYOUT_PARAGRAPH:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = !cur.inset().forceDefaultParagraphs(&cur.inset());
|
2000-08-01 09:35:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
case LFUN_VC_REGISTER:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = !buf->lyxvc().inUse();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_VC_CHECKIN:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = buf->lyxvc().inUse() && !buf->isReadonly();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_VC_CHECKOUT:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = buf->lyxvc().inUse() && buf->isReadonly();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_VC_REVERT:
|
|
|
|
|
case LFUN_VC_UNDO:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = buf->lyxvc().inUse();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
2003-02-17 18:40:04 +00:00
|
|
|
|
case LFUN_MENURELOAD:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = !buf->isUnnamed() && !buf->isClean();
|
2003-02-17 18:40:04 +00:00
|
|
|
|
break;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
|
|
|
|
|
|
2003-04-26 19:01:33 +00:00
|
|
|
|
case LFUN_INSET_SETTINGS: {
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = false;
|
|
|
|
|
if (!cur.size())
|
|
|
|
|
break;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
UpdatableInset * inset = cur.inset().asUpdatableInset();
|
2004-03-18 13:57:20 +00:00
|
|
|
|
lyxerr << "inset: " << inset << endl;
|
2003-04-26 19:01:33 +00:00
|
|
|
|
if (!inset)
|
|
|
|
|
break;
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld::Code code = inset->lyxCode();
|
2003-04-26 19:01:33 +00:00
|
|
|
|
switch (code) {
|
2003-07-25 21:20:24 +00:00
|
|
|
|
case InsetOld::TABULAR_CODE:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "tabular";
|
2003-04-26 19:01:33 +00:00
|
|
|
|
break;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
case InsetOld::ERT_CODE:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "ert";
|
2003-04-26 19:01:33 +00:00
|
|
|
|
break;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
case InsetOld::FLOAT_CODE:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "float";
|
2003-04-26 19:01:33 +00:00
|
|
|
|
break;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
case InsetOld::WRAP_CODE:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "wrap";
|
2003-04-26 19:01:33 +00:00
|
|
|
|
break;
|
2003-07-25 21:20:24 +00:00
|
|
|
|
case InsetOld::NOTE_CODE:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "note";
|
2003-07-15 23:52:05 +00:00
|
|
|
|
break;
|
2003-08-17 11:28:23 +00:00
|
|
|
|
case InsetOld::BRANCH_CODE:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "branch";
|
2003-08-17 11:28:23 +00:00
|
|
|
|
break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
case InsetOld::BOX_CODE:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cmd.argument == "box";
|
2003-10-07 07:42:15 +00:00
|
|
|
|
break;
|
2003-04-26 19:01:33 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
case LFUN_DIALOG_SHOW: {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
string const name = cmd.getArg(0);
|
2004-03-18 12:53:43 +00:00
|
|
|
|
if (!buf)
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = name == "aboutlyx"
|
|
|
|
|
|| name == "file"
|
2004-03-25 09:16:36 +00:00
|
|
|
|
|| name == "forks"
|
2004-03-31 18:51:11 +00:00
|
|
|
|
|| name == "prefs"
|
2004-03-18 13:57:20 +00:00
|
|
|
|
|| name == "texinfo";
|
2004-03-18 12:53:43 +00:00
|
|
|
|
else if (name == "print")
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = Exporter::IsExportable(*buf, "dvi")
|
|
|
|
|
&& lyxrc.print_command != "none";
|
2004-03-18 12:53:43 +00:00
|
|
|
|
else if (name == "character")
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = cur.inset().lyxCode() != InsetOld::ERT_CODE;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
else if (name == "vclog")
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = buf->lyxvc().inUse();
|
2004-03-18 12:53:43 +00:00
|
|
|
|
else if (name == "latexlog")
|
2004-03-18 13:57:20 +00:00
|
|
|
|
enable = IsFileReadable(buf->getLogName().second);
|
2003-06-19 16:49:45 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
case LFUN_MENUNEW:
|
|
|
|
|
case LFUN_MENUNEWTMPLT:
|
|
|
|
|
case LFUN_WORDFINDFORWARD:
|
|
|
|
|
case LFUN_WORDFINDBACKWARD:
|
|
|
|
|
case LFUN_PREFIX:
|
|
|
|
|
case LFUN_EXEC_COMMAND:
|
|
|
|
|
case LFUN_CANCEL:
|
|
|
|
|
case LFUN_META_FAKE:
|
|
|
|
|
case LFUN_CLOSEBUFFER:
|
|
|
|
|
case LFUN_MENUWRITE:
|
|
|
|
|
case LFUN_WRITEAS:
|
|
|
|
|
case LFUN_UPDATE:
|
|
|
|
|
case LFUN_PREVIEW:
|
|
|
|
|
case LFUN_IMPORT:
|
|
|
|
|
case LFUN_QUIT:
|
|
|
|
|
case LFUN_TOCVIEW:
|
|
|
|
|
case LFUN_AUTOSAVE:
|
|
|
|
|
case LFUN_RECONFIGURE:
|
|
|
|
|
case LFUN_HELP_OPEN:
|
|
|
|
|
case LFUN_FILE_NEW:
|
|
|
|
|
case LFUN_FILE_OPEN:
|
|
|
|
|
case LFUN_DROP_LAYOUTS_CHOICE:
|
|
|
|
|
case LFUN_MENU_OPEN_BY_NAME:
|
|
|
|
|
case LFUN_GETNAME:
|
|
|
|
|
case LFUN_NOTIFY:
|
|
|
|
|
case LFUN_GOTOFILEROW:
|
|
|
|
|
case LFUN_GOTO_PARAGRAPH:
|
2003-03-07 15:58:02 +00:00
|
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
case LFUN_DIALOG_SHOW_NEXT_INSET:
|
|
|
|
|
case LFUN_DIALOG_UPDATE:
|
|
|
|
|
case LFUN_DIALOG_HIDE:
|
|
|
|
|
case LFUN_DIALOG_DISCONNECT_INSET:
|
|
|
|
|
case LFUN_CHILDOPEN:
|
|
|
|
|
case LFUN_TOGGLECURSORFOLLOW:
|
|
|
|
|
case LFUN_KMAP_OFF:
|
|
|
|
|
case LFUN_KMAP_PRIM:
|
|
|
|
|
case LFUN_KMAP_SEC:
|
|
|
|
|
case LFUN_KMAP_TOGGLE:
|
|
|
|
|
case LFUN_REPEAT:
|
2004-03-27 23:11:46 +00:00
|
|
|
|
case LFUN_EXPORT_CUSTOM:
|
2004-03-28 14:12:33 +00:00
|
|
|
|
case LFUN_PRINT:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
case LFUN_SEQUENCE:
|
|
|
|
|
case LFUN_SAVEPREFERENCES:
|
|
|
|
|
case LFUN_SCREEN_FONT_UPDATE:
|
|
|
|
|
case LFUN_SET_COLOR:
|
|
|
|
|
case LFUN_MESSAGE:
|
|
|
|
|
case LFUN_EXTERNAL_EDIT:
|
2004-03-30 12:36:33 +00:00
|
|
|
|
case LFUN_ALL_INSETS_TOGGLE:
|
2004-03-30 16:19:50 +00:00
|
|
|
|
case LFUN_LANGUAGE_BUFFER:
|
|
|
|
|
case LFUN_TEXTCLASS_APPLY:
|
|
|
|
|
case LFUN_TEXTCLASS_LOAD:
|
|
|
|
|
case LFUN_SAVE_AS_DEFAULT:
|
|
|
|
|
case LFUN_BUFFERPARAMS_APPLY:
|
2004-03-31 16:50:59 +00:00
|
|
|
|
case LFUN_LYXRC_APPLY:
|
2004-03-18 13:57:20 +00:00
|
|
|
|
// these are handled in our dispatch()
|
2003-03-07 15:58:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
default:
|
2004-04-01 08:58:45 +00:00
|
|
|
|
|
2004-03-18 13:57:20 +00:00
|
|
|
|
cur.getStatus(cmd, flag);
|
2004-04-01 08:58:45 +00:00
|
|
|
|
if (!flag.enabled())
|
|
|
|
|
flag = view()->getStatus(cmd);
|
2002-07-21 15:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-23 11:22:11 +00:00
|
|
|
|
if (!enable)
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
|
|
|
|
|
// Can we use a readonly buffer?
|
2004-03-30 16:19:50 +00:00
|
|
|
|
if (buf && buf->isReadonly()
|
2004-03-23 11:22:11 +00:00
|
|
|
|
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)
|
|
|
|
|
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
|
|
|
|
|
setStatusMessage(N_("Document is read-only"));
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-10 12:26:40 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2003-10-13 00:38:09 +00:00
|
|
|
|
bool ensureBufferClean(BufferView * bv)
|
|
|
|
|
{
|
|
|
|
|
Buffer & buf = *bv->buffer();
|
|
|
|
|
if (buf.isClean())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
string const file = MakeDisplayPath(buf.fileName(), 30);
|
|
|
|
|
string text = bformat(_("The document %1$s has unsaved "
|
|
|
|
|
"changes.\n\nDo you want to save "
|
|
|
|
|
"the document?"), file);
|
|
|
|
|
int const ret = Alert::prompt(_("Save changed document?"),
|
|
|
|
|
text, 0, 1, _("&Save"),
|
|
|
|
|
_("&Cancel"));
|
|
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
|
bv->owner()->dispatch(FuncRequest(LFUN_MENUWRITE));
|
|
|
|
|
|
|
|
|
|
return buf.isClean();
|
|
|
|
|
}
|
2003-07-25 21:20:24 +00:00
|
|
|
|
|
2004-03-31 09:44:40 +00:00
|
|
|
|
|
2004-03-28 14:12:33 +00:00
|
|
|
|
void showPrintError(string const & name)
|
|
|
|
|
{
|
2004-03-31 09:44:40 +00:00
|
|
|
|
string str = bformat(_("Could not print the document %1$s.\n"
|
|
|
|
|
"Check that your printer is set up correctly."),
|
|
|
|
|
MakeDisplayPath(name, 50));
|
|
|
|
|
Alert::error(_("Print document failed"), str);
|
2004-03-28 14:12:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-31 09:44:40 +00:00
|
|
|
|
|
|
|
|
|
void loadTextclass(string const & name)
|
|
|
|
|
{
|
|
|
|
|
std::pair<bool, lyx::textclass_type> const tc_pair =
|
|
|
|
|
textclasslist.NumberOfClass(name);
|
|
|
|
|
|
|
|
|
|
if (!tc_pair.first) {
|
|
|
|
|
lyxerr << "Document class \"" << name
|
|
|
|
|
<< "\" does not exist."
|
|
|
|
|
<< std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyx::textclass_type const tc = tc_pair.second;
|
|
|
|
|
|
|
|
|
|
if (!textclasslist[tc].load()) {
|
|
|
|
|
string s = bformat(_("The document could not be converted\n"
|
|
|
|
|
"into the document class %1$s."),
|
|
|
|
|
textclasslist[tc].name());
|
|
|
|
|
Alert::error(_("Could not change class"), s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-10 12:26:40 +00:00
|
|
|
|
} //namespace anon
|
2002-01-12 20:00:47 +00:00
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
|
2002-01-12 20:00:47 +00:00
|
|
|
|
{
|
2004-03-18 12:53:43 +00:00
|
|
|
|
string const argument = cmd.argument;
|
|
|
|
|
kb_action const action = cmd.action;
|
2003-09-21 23:00:47 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
|
2004-03-08 21:14:45 +00:00
|
|
|
|
//lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
|
2002-01-12 20:00:47 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// we have not done anything wrong yet.
|
|
|
|
|
errorstat = false;
|
2002-01-12 20:00:47 +00:00
|
|
|
|
dispatch_buffer.erase();
|
1999-12-10 00:07:59 +00:00
|
|
|
|
selection_possible = false;
|
2002-01-12 20:00:47 +00:00
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
// We cannot use this function here
|
2004-03-18 13:57:20 +00:00
|
|
|
|
if (!getStatus(cmd).enabled()) {
|
2002-07-20 20:47:54 +00:00
|
|
|
|
lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
|
2002-01-12 20:00:47 +00:00
|
|
|
|
<< lyxaction.getActionName(action)
|
|
|
|
|
<< " [" << action << "] is disabled at this location"
|
2001-07-24 22:08:49 +00:00
|
|
|
|
<< endl;
|
2002-01-13 13:07:27 +00:00
|
|
|
|
setErrorMessage(getStatusMessage());
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (view()->available())
|
|
|
|
|
view()->hideCursor();
|
2003-05-03 18:05:53 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
switch (action) {
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_WORDFINDFORWARD:
|
|
|
|
|
case LFUN_WORDFINDBACKWARD: {
|
|
|
|
|
static string last_search;
|
|
|
|
|
string searched_string;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (!argument.empty()) {
|
|
|
|
|
last_search = argument;
|
|
|
|
|
searched_string = argument;
|
2004-03-18 16:12:51 +00:00
|
|
|
|
} else {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
searched_string = last_search;
|
2004-03-18 16:12:51 +00:00
|
|
|
|
}
|
2004-01-07 17:00:03 +00:00
|
|
|
|
|
|
|
|
|
if (searched_string.empty())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
bool const fw = action == LFUN_WORDFINDFORWARD;
|
|
|
|
|
string const data =
|
2004-01-15 17:34:44 +00:00
|
|
|
|
lyx::find::find2string(searched_string, true, false, fw);
|
2004-03-25 09:16:36 +00:00
|
|
|
|
lyx::find::find(view(), FuncRequest(LFUN_WORD_FIND, data));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_PREFIX:
|
|
|
|
|
owner->message(keyseq.printOptions());
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_EXEC_COMMAND:
|
|
|
|
|
owner->focus_command_buffer();
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_CANCEL:
|
|
|
|
|
keyseq.reset();
|
|
|
|
|
meta_fake_bit = key_modifier::none;
|
|
|
|
|
if (view()->available())
|
|
|
|
|
// cancel any selection
|
|
|
|
|
dispatch(FuncRequest(LFUN_MARK_OFF));
|
|
|
|
|
setMessage(N_("Cancel"));
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_META_FAKE:
|
|
|
|
|
meta_fake_bit = key_modifier::alt;
|
|
|
|
|
setMessage(keyseq.print());
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_READ_ONLY_TOGGLE:
|
|
|
|
|
if (owner->buffer()->lyxvc().inUse())
|
|
|
|
|
owner->buffer()->lyxvc().toggleReadOnly();
|
|
|
|
|
else
|
|
|
|
|
owner->buffer()->setReadonly(
|
|
|
|
|
!owner->buffer()->isReadonly());
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// --- Menus -----------------------------------------------
|
|
|
|
|
case LFUN_MENUNEW:
|
|
|
|
|
menuNew(argument, false);
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_MENUNEWTMPLT:
|
|
|
|
|
menuNew(argument, true);
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_CLOSEBUFFER:
|
|
|
|
|
closeBuffer();
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_MENUWRITE:
|
|
|
|
|
if (!owner->buffer()->isUnnamed()) {
|
|
|
|
|
string const str = bformat(_("Saving document %1$s..."),
|
|
|
|
|
MakeDisplayPath(owner->buffer()->fileName()));
|
|
|
|
|
owner->message(str);
|
|
|
|
|
MenuWrite(owner->buffer());
|
|
|
|
|
owner->message(str + _(" done."));
|
|
|
|
|
} else
|
|
|
|
|
WriteAs(owner->buffer());
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_WRITEAS:
|
|
|
|
|
WriteAs(owner->buffer(), argument);
|
|
|
|
|
break;
|
2003-03-29 07:44:44 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_MENURELOAD: {
|
|
|
|
|
string const file = MakeDisplayPath(view()->buffer()->fileName(), 20);
|
|
|
|
|
string text = bformat(_("Any changes will be lost. Are you sure "
|
|
|
|
|
"you want to revert to the saved version of the document %1$s?"), file);
|
|
|
|
|
int const ret = Alert::prompt(_("Revert to saved document?"),
|
|
|
|
|
text, 0, 1, _("&Revert"), _("&Cancel"));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (ret == 0)
|
|
|
|
|
view()->reload();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_UPDATE:
|
|
|
|
|
Exporter::Export(owner->buffer(), argument, true);
|
|
|
|
|
view()->showErrorList(BufferFormat(*owner->buffer()));
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_PREVIEW:
|
|
|
|
|
Exporter::Preview(owner->buffer(), argument);
|
|
|
|
|
view()->showErrorList(BufferFormat(*owner->buffer()));
|
|
|
|
|
break;
|
2002-03-19 03:56:23 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_BUILDPROG:
|
|
|
|
|
Exporter::Export(owner->buffer(), "program", true);
|
|
|
|
|
view()->showErrorList(_("Build"));
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_RUNCHKTEX:
|
|
|
|
|
owner->buffer()->runChktex();
|
|
|
|
|
view()->showErrorList(_("ChkTeX"));
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_EXPORT:
|
|
|
|
|
if (argument == "custom")
|
2004-03-27 23:11:46 +00:00
|
|
|
|
owner->getDialogs().show("sendto");
|
2003-11-13 13:43:44 +00:00
|
|
|
|
else {
|
|
|
|
|
Exporter::Export(owner->buffer(), argument, false);
|
|
|
|
|
view()->showErrorList(BufferFormat(*owner->buffer()));
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-03-27 23:11:46 +00:00
|
|
|
|
case LFUN_EXPORT_CUSTOM: {
|
|
|
|
|
string format_name;
|
|
|
|
|
string command = split(argument, format_name, ' ');
|
|
|
|
|
Format const * format = formats.getFormat(format_name);
|
|
|
|
|
if (!format) {
|
|
|
|
|
lyxerr << "Format \"" << format_name
|
|
|
|
|
<< "\" not recognized!"
|
|
|
|
|
<< std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer * buffer = owner->buffer();
|
|
|
|
|
|
|
|
|
|
// The name of the file created by the conversion process
|
|
|
|
|
string filename;
|
|
|
|
|
|
|
|
|
|
// Output to filename
|
|
|
|
|
if (format->name() == "lyx") {
|
|
|
|
|
string const latexname =
|
|
|
|
|
buffer->getLatexName(false);
|
|
|
|
|
filename = ChangeExtension(latexname,
|
|
|
|
|
format->extension());
|
|
|
|
|
filename = AddName(buffer->temppath(), filename);
|
|
|
|
|
|
|
|
|
|
if (!buffer->writeFile(filename))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
Exporter::Export(buffer, format_name, true,
|
|
|
|
|
filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Substitute $$FName for filename
|
|
|
|
|
if (!contains(command, "$$FName"))
|
|
|
|
|
command = "( " + command + " ) < $$FName";
|
|
|
|
|
command = subst(command, "$$FName", filename);
|
|
|
|
|
|
|
|
|
|
// Execute the command in the background
|
|
|
|
|
Systemcall call;
|
|
|
|
|
call.startscript(Systemcall::DontWait, command);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-28 14:12:33 +00:00
|
|
|
|
case LFUN_PRINT: {
|
|
|
|
|
string target;
|
|
|
|
|
string target_name;
|
|
|
|
|
string command = split(split(argument, target, ' '),
|
|
|
|
|
target_name, ' ');
|
|
|
|
|
|
|
|
|
|
if (target.empty()
|
|
|
|
|
|| target_name.empty()
|
|
|
|
|
|| command.empty()) {
|
|
|
|
|
lyxerr << "Unable to parse \""
|
|
|
|
|
<< argument << '"' << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (target != "printer" && target != "file") {
|
|
|
|
|
lyxerr << "Unrecognized target \""
|
|
|
|
|
<< target << '"' << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Buffer * buffer = owner->buffer();
|
|
|
|
|
|
|
|
|
|
if (!Exporter::Export(buffer, "dvi", true)) {
|
|
|
|
|
showPrintError(buffer->fileName());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Push directory path.
|
|
|
|
|
string const path = buffer->temppath();
|
|
|
|
|
Path p(path);
|
|
|
|
|
|
|
|
|
|
// there are three cases here:
|
|
|
|
|
// 1. we print to a file
|
|
|
|
|
// 2. we print directly to a printer
|
|
|
|
|
// 3. we print using a spool command (print to file first)
|
|
|
|
|
Systemcall one;
|
|
|
|
|
int res = 0;
|
|
|
|
|
string const dviname =
|
|
|
|
|
ChangeExtension(buffer->getLatexName(true),
|
|
|
|
|
"dvi");
|
|
|
|
|
|
|
|
|
|
if (target == "printer") {
|
|
|
|
|
if (!lyxrc.print_spool_command.empty()) {
|
|
|
|
|
// case 3: print using a spool
|
|
|
|
|
string const psname =
|
|
|
|
|
ChangeExtension(dviname,".ps");
|
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
|
+ QuoteName(psname)
|
|
|
|
|
+ ' '
|
|
|
|
|
+ QuoteName(dviname);
|
|
|
|
|
|
|
|
|
|
string command2 =
|
|
|
|
|
lyxrc.print_spool_command +' ';
|
|
|
|
|
if (target_name != "default") {
|
|
|
|
|
command2 += lyxrc.print_spool_printerprefix
|
|
|
|
|
+ target_name
|
|
|
|
|
+ ' ';
|
|
|
|
|
}
|
|
|
|
|
command2 += QuoteName(psname);
|
|
|
|
|
// First run dvips.
|
|
|
|
|
// If successful, then spool command
|
|
|
|
|
res = one.startscript(
|
|
|
|
|
Systemcall::Wait,
|
|
|
|
|
command);
|
|
|
|
|
|
|
|
|
|
if (res == 0)
|
|
|
|
|
res = one.startscript(
|
|
|
|
|
Systemcall::DontWait,
|
|
|
|
|
command2);
|
|
|
|
|
} else {
|
|
|
|
|
// case 2: print directly to a printer
|
|
|
|
|
res = one.startscript(
|
|
|
|
|
Systemcall::DontWait,
|
|
|
|
|
command + QuoteName(dviname));
|
|
|
|
|
}
|
2004-03-30 16:19:50 +00:00
|
|
|
|
|
2004-03-28 14:12:33 +00:00
|
|
|
|
} else {
|
|
|
|
|
// case 1: print to a file
|
|
|
|
|
command += lyxrc.print_to_file
|
|
|
|
|
+ QuoteName(MakeAbsPath(target_name,
|
|
|
|
|
path))
|
|
|
|
|
+ ' '
|
|
|
|
|
+ QuoteName(dviname);
|
|
|
|
|
res = one.startscript(Systemcall::DontWait,
|
|
|
|
|
command);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (res != 0)
|
|
|
|
|
showPrintError(buffer->fileName());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_IMPORT:
|
|
|
|
|
doImport(argument);
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_QUIT:
|
|
|
|
|
QuitLyX();
|
|
|
|
|
break;
|
2000-08-01 17:33:32 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_TOCVIEW: {
|
|
|
|
|
InsetCommandParams p("tableofcontents");
|
|
|
|
|
string const data = InsetCommandMailer::params2string("toc", p);
|
|
|
|
|
owner->getDialogs().show("toc", data, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_AUTOSAVE:
|
|
|
|
|
AutoSave(view());
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_RECONFIGURE:
|
|
|
|
|
Reconfigure(view());
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
2003-11-13 13:43:44 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_HELP_OPEN: {
|
|
|
|
|
string const arg = argument;
|
|
|
|
|
if (arg.empty()) {
|
|
|
|
|
setErrorMessage(N_("Missing argument"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
string const fname = i18nLibFileSearch("doc", arg, "lyx");
|
|
|
|
|
if (fname.empty()) {
|
|
|
|
|
lyxerr << "LyX: unable to find documentation file `"
|
|
|
|
|
<< arg << "'. Bad installation?" << endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
owner->message(bformat(_("Opening help file %1$s..."),
|
|
|
|
|
MakeDisplayPath(fname)));
|
|
|
|
|
view()->loadLyXFile(fname, false);
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// --- version control -------------------------------
|
|
|
|
|
case LFUN_VC_REGISTER:
|
|
|
|
|
if (!ensureBufferClean(view()))
|
|
|
|
|
break;
|
|
|
|
|
if (!owner->buffer()->lyxvc().inUse()) {
|
|
|
|
|
owner->buffer()->lyxvc().registrer();
|
|
|
|
|
view()->reload();
|
|
|
|
|
}
|
2003-07-10 12:26:40 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_VC_CHECKIN:
|
|
|
|
|
if (!ensureBufferClean(view()))
|
|
|
|
|
break;
|
|
|
|
|
if (owner->buffer()->lyxvc().inUse()
|
|
|
|
|
&& !owner->buffer()->isReadonly()) {
|
|
|
|
|
owner->buffer()->lyxvc().checkIn();
|
|
|
|
|
view()->reload();
|
|
|
|
|
}
|
2003-07-10 12:26:40 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_VC_CHECKOUT:
|
|
|
|
|
if (!ensureBufferClean(view()))
|
|
|
|
|
break;
|
|
|
|
|
if (owner->buffer()->lyxvc().inUse()
|
|
|
|
|
&& owner->buffer()->isReadonly()) {
|
|
|
|
|
owner->buffer()->lyxvc().checkOut();
|
|
|
|
|
view()->reload();
|
|
|
|
|
}
|
2003-07-10 12:26:40 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_VC_REVERT:
|
|
|
|
|
owner->buffer()->lyxvc().revert();
|
|
|
|
|
view()->reload();
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_VC_UNDO:
|
|
|
|
|
owner->buffer()->lyxvc().undoLast();
|
|
|
|
|
view()->reload();
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// --- buffers ----------------------------------------
|
|
|
|
|
case LFUN_SWITCHBUFFER:
|
2004-03-18 12:53:43 +00:00
|
|
|
|
view()->setBuffer(bufferlist.getBuffer(argument));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
break;
|
2000-07-24 13:53:19 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_FILE_NEW:
|
|
|
|
|
NewFile(view(), argument);
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_FILE_OPEN:
|
|
|
|
|
open(argument);
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_DROP_LAYOUTS_CHOICE:
|
|
|
|
|
owner->getToolbar().openLayoutList();
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_MENU_OPEN_BY_NAME:
|
|
|
|
|
owner->getMenubar().openByName(argument);
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// --- lyxserver commands ----------------------------
|
|
|
|
|
case LFUN_GETNAME:
|
|
|
|
|
setMessage(owner->buffer()->fileName());
|
|
|
|
|
lyxerr[Debug::INFO] << "FNAME["
|
|
|
|
|
<< owner->buffer()->fileName()
|
|
|
|
|
<< "] " << endl;
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_NOTIFY:
|
|
|
|
|
dispatch_buffer = keyseq.print();
|
|
|
|
|
lyxserver->notifyClient(dispatch_buffer);
|
|
|
|
|
break;
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_GOTOFILEROW: {
|
|
|
|
|
string file_name;
|
|
|
|
|
int row;
|
|
|
|
|
istringstream is(argument);
|
|
|
|
|
is >> file_name >> row;
|
|
|
|
|
if (prefixIs(file_name, getTmpDir())) {
|
|
|
|
|
// Needed by inverse dvi search. If it is a file
|
|
|
|
|
// in tmpdir, call the apropriated function
|
2004-03-18 12:53:43 +00:00
|
|
|
|
view()->setBuffer(bufferlist.getBufferFromTmp(file_name));
|
2003-10-14 11:35:50 +00:00
|
|
|
|
} else {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// Must replace extension of the file to be .lyx
|
|
|
|
|
// and get full path
|
|
|
|
|
string const s = ChangeExtension(file_name, ".lyx");
|
|
|
|
|
// Either change buffer or load the file
|
|
|
|
|
if (bufferlist.exists(s)) {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
view()->setBuffer(bufferlist.getBuffer(s));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
view()->loadLyXFile(s);
|
|
|
|
|
}
|
2003-10-14 11:35:50 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
view()->setCursorFromRow(row);
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
view()->center();
|
|
|
|
|
// see BufferView_pimpl::center()
|
|
|
|
|
view()->updateScrollbar();
|
2001-03-30 19:24:28 +00:00
|
|
|
|
break;
|
2001-06-29 06:30:53 +00:00
|
|
|
|
}
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_GOTO_PARAGRAPH: {
|
|
|
|
|
istringstream is(argument);
|
|
|
|
|
int id;
|
|
|
|
|
is >> id;
|
|
|
|
|
ParIterator par = owner->buffer()->getParFromID(id);
|
|
|
|
|
if (par == owner->buffer()->par_iterator_end()) {
|
|
|
|
|
lyxerr[Debug::INFO] << "No matching paragraph found! ["
|
|
|
|
|
<< id << ']' << endl;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::INFO] << "Paragraph " << par->id()
|
|
|
|
|
<< " found." << endl;
|
|
|
|
|
}
|
2003-10-25 09:20:51 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// Set the cursor
|
2004-02-02 11:07:51 +00:00
|
|
|
|
view()->setCursor(par, 0);
|
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
view()->switchKeyMap();
|
|
|
|
|
owner->view_state_changed();
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
view()->center();
|
|
|
|
|
// see BufferView_pimpl::center()
|
|
|
|
|
view()->updateScrollbar();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-07-25 10:46:18 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_DIALOG_SHOW: {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
|
string data = trim(cmd.argument.substr(name.size()));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
|
|
|
|
|
if (name == "character") {
|
|
|
|
|
data = freefont2string();
|
|
|
|
|
if (!data.empty())
|
|
|
|
|
owner->getDialogs().show("character", data);
|
2003-12-05 13:37:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (name == "latexlog") {
|
|
|
|
|
pair<Buffer::LogType, string> const logfile =
|
|
|
|
|
owner->buffer()->getLogName();
|
|
|
|
|
switch (logfile.first) {
|
|
|
|
|
case Buffer::latexlog:
|
|
|
|
|
data = "latex ";
|
|
|
|
|
break;
|
|
|
|
|
case Buffer::buildlog:
|
|
|
|
|
data = "literate ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
data += logfile.second;
|
|
|
|
|
owner->getDialogs().show("log", data);
|
|
|
|
|
}
|
|
|
|
|
else if (name == "vclog") {
|
|
|
|
|
string const data = "vc " +
|
|
|
|
|
owner->buffer()->lyxvc().getLogFile();
|
|
|
|
|
owner->getDialogs().show("log", data);
|
|
|
|
|
}
|
2003-11-13 13:43:44 +00:00
|
|
|
|
else
|
|
|
|
|
owner->getDialogs().show(name, data);
|
|
|
|
|
break;
|
2003-02-25 14:51:38 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET: {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string const name = cmd.getArg(0);
|
|
|
|
|
string data = trim(cmd.argument.substr(name.size()));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (name == "bibitem" ||
|
2003-12-10 22:10:38 +00:00
|
|
|
|
name == "bibtex" ||
|
|
|
|
|
name == "include" ||
|
|
|
|
|
name == "index" ||
|
|
|
|
|
name == "label" ||
|
|
|
|
|
name == "ref" ||
|
|
|
|
|
name == "toc" ||
|
|
|
|
|
name == "url") {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
InsetCommandParams p(name);
|
|
|
|
|
data = InsetCommandMailer::params2string(name, p);
|
2003-12-10 22:10:38 +00:00
|
|
|
|
} else if (name == "box") {
|
|
|
|
|
// \c data == "Boxed" || "Frameless" etc
|
|
|
|
|
InsetBoxParams p(data);
|
|
|
|
|
data = InsetBoxMailer::params2string(p);
|
|
|
|
|
} else if (name == "branch") {
|
|
|
|
|
InsetBranchParams p;
|
|
|
|
|
data = InsetBranchMailer::params2string(p);
|
2003-11-13 13:43:44 +00:00
|
|
|
|
} else if (name == "citation") {
|
|
|
|
|
InsetCommandParams p("cite");
|
|
|
|
|
data = InsetCommandMailer::params2string(name, p);
|
2003-12-10 22:10:38 +00:00
|
|
|
|
} else if (name == "ert") {
|
|
|
|
|
data = InsetERTMailer::params2string(InsetCollapsable::Open);
|
|
|
|
|
} else if (name == "external") {
|
|
|
|
|
InsetExternalParams p;
|
|
|
|
|
Buffer const & buffer = *owner->buffer();
|
|
|
|
|
data = InsetExternalMailer::params2string(p, buffer);
|
|
|
|
|
} else if (name == "float") {
|
|
|
|
|
InsetFloatParams p;
|
|
|
|
|
data = InsetFloatMailer::params2string(p);
|
|
|
|
|
} else if (name == "graphics") {
|
|
|
|
|
InsetGraphicsParams p;
|
|
|
|
|
Buffer const & buffer = *owner->buffer();
|
|
|
|
|
data = InsetGraphicsMailer::params2string(p, buffer);
|
|
|
|
|
} else if (name == "note") {
|
|
|
|
|
InsetNoteParams p;
|
|
|
|
|
data = InsetNoteMailer::params2string(p);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
} else if (name == "vspace") {
|
|
|
|
|
VSpace space;
|
|
|
|
|
data = InsetVSpaceMailer::params2string(space);
|
2003-12-10 22:10:38 +00:00
|
|
|
|
} else if (name == "wrap") {
|
|
|
|
|
InsetWrapParams p;
|
|
|
|
|
data = InsetWrapMailer::params2string(p);
|
2003-11-13 13:43:44 +00:00
|
|
|
|
}
|
|
|
|
|
owner->getDialogs().show(name, data, 0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_DIALOG_SHOW_NEXT_INSET:
|
|
|
|
|
break;
|
2003-09-09 17:25:35 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_DIALOG_UPDATE: {
|
|
|
|
|
string const & name = argument;
|
|
|
|
|
// Can only update a dialog connected to an existing inset
|
|
|
|
|
InsetBase * inset = owner->getDialogs().getOpenInset(name);
|
|
|
|
|
if (inset) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
FuncRequest fr(LFUN_INSET_DIALOG_UPDATE, cmd.argument);
|
2004-01-20 14:25:24 +00:00
|
|
|
|
inset->dispatch(view()->cursor(), fr);
|
2003-11-13 13:43:44 +00:00
|
|
|
|
} else if (name == "paragraph") {
|
|
|
|
|
dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_DIALOG_HIDE:
|
|
|
|
|
Dialogs::hide(argument, 0);
|
|
|
|
|
break;
|
2003-02-25 14:51:38 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_DIALOG_DISCONNECT_INSET:
|
|
|
|
|
owner->getDialogs().disconnect(argument);
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_CHILDOPEN: {
|
|
|
|
|
string const filename =
|
|
|
|
|
MakeAbsPath(argument, owner->buffer()->filePath());
|
|
|
|
|
setMessage(N_("Opening child document ") +
|
|
|
|
|
MakeDisplayPath(filename) + "...");
|
|
|
|
|
view()->savePosition(0);
|
2003-11-24 20:48:21 +00:00
|
|
|
|
string const parentfilename = owner->buffer()->fileName();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (bufferlist.exists(filename))
|
2004-03-18 12:53:43 +00:00
|
|
|
|
view()->setBuffer(bufferlist.getBuffer(filename));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
else
|
|
|
|
|
view()->loadLyXFile(filename);
|
2003-11-24 20:48:21 +00:00
|
|
|
|
// Set the parent name of the child document.
|
|
|
|
|
// This makes insertion of citations and references in the child work,
|
|
|
|
|
// when the target is in the parent or another child document.
|
|
|
|
|
owner->buffer()->setParentName(parentfilename);
|
2003-11-13 13:43:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_TOGGLECURSORFOLLOW:
|
|
|
|
|
lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_KMAP_OFF:
|
|
|
|
|
owner->getIntl().KeyMapOn(false);
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_KMAP_PRIM:
|
|
|
|
|
owner->getIntl().KeyMapPrim();
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_KMAP_SEC:
|
|
|
|
|
owner->getIntl().KeyMapSec();
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_KMAP_TOGGLE:
|
|
|
|
|
owner->getIntl().ToggleKeyMap();
|
|
|
|
|
break;
|
2003-10-27 12:41:26 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_REPEAT: {
|
|
|
|
|
// repeat command
|
|
|
|
|
string countstr;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
string rest = split(argument, countstr, ' ');
|
2003-11-13 13:43:44 +00:00
|
|
|
|
istringstream is(countstr);
|
|
|
|
|
int count = 0;
|
|
|
|
|
is >> count;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
lyxerr << "repeat: count: " << count << " cmd: " << rest << endl;
|
2003-11-13 13:43:44 +00:00
|
|
|
|
for (int i = 0; i < count; ++i)
|
2004-03-18 12:53:43 +00:00
|
|
|
|
dispatch(lyxaction.lookupFunc(rest));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_SEQUENCE:
|
|
|
|
|
// argument contains ';'-terminated commands
|
|
|
|
|
while (!argument.empty()) {
|
|
|
|
|
string first;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
string rest = split(argument, first, ';');
|
|
|
|
|
dispatch(lyxaction.lookupFunc(rest));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2000-08-14 05:24:35 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_SAVEPREFERENCES: {
|
|
|
|
|
Path p(user_lyxdir());
|
|
|
|
|
lyxrc.write("preferences");
|
2000-06-26 15:33:13 +00:00
|
|
|
|
break;
|
2003-10-27 12:41:26 +00:00
|
|
|
|
}
|
2000-06-26 15:33:13 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_SCREEN_FONT_UPDATE:
|
|
|
|
|
// handle the screen font changes.
|
|
|
|
|
lyxrc.set_font_norm_type();
|
|
|
|
|
lyx_gui::update_fonts();
|
|
|
|
|
// All visible buffers will need resize
|
|
|
|
|
view()->resize();
|
2000-06-26 15:33:13 +00:00
|
|
|
|
break;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_SET_COLOR: {
|
|
|
|
|
string lyx_name;
|
|
|
|
|
string const x11_name = split(argument, lyx_name, ' ');
|
|
|
|
|
if (lyx_name.empty() || x11_name.empty()) {
|
|
|
|
|
setErrorMessage(N_("Syntax: set-color <lyx_name>"
|
|
|
|
|
" <x11_name>"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool const graphicsbg_changed =
|
|
|
|
|
(lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
|
|
|
|
|
x11_name != lcolor.getX11Name(LColor::graphicsbg));
|
|
|
|
|
|
2004-03-25 15:51:21 +00:00
|
|
|
|
if (!lcolor.setColor(lyx_name, x11_name)) {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
setErrorMessage(
|
|
|
|
|
bformat(_("Set-color \"%1$s\" failed "
|
|
|
|
|
"- color is undefined or "
|
|
|
|
|
"may not be redefined"), lyx_name));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
|
2002-02-27 09:59:52 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (graphicsbg_changed) {
|
2002-06-25 15:59:10 +00:00
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning FIXME!! The graphics cache no longer has a changeDisplay method.
|
|
|
|
|
#endif
|
|
|
|
|
#if 0
|
2003-11-13 13:43:44 +00:00
|
|
|
|
lyx::graphics::GCache::get().changeDisplay(true);
|
2002-06-25 15:59:10 +00:00
|
|
|
|
#endif
|
2003-11-13 13:43:44 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2002-02-27 09:59:52 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_MESSAGE:
|
|
|
|
|
owner->message(argument);
|
|
|
|
|
break;
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_TOOLTIPS_TOGGLE:
|
|
|
|
|
owner->getDialogs().toggleTooltips();
|
|
|
|
|
break;
|
2002-03-11 09:54:42 +00:00
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
case LFUN_EXTERNAL_EDIT: {
|
|
|
|
|
FuncRequest fr(action, argument);
|
|
|
|
|
InsetExternal().dispatch(view()->cursor(), fr);
|
2003-11-13 13:43:44 +00:00
|
|
|
|
break;
|
2004-03-18 12:53:43 +00:00
|
|
|
|
}
|
2003-06-11 11:01:34 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
case LFUN_BREAKLINE: {
|
|
|
|
|
#warning swallow 'Return' if the minibuffer is focused. But how?
|
2004-03-30 12:36:33 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_ALL_INSETS_TOGGLE: {
|
|
|
|
|
string action;
|
|
|
|
|
string const name = split(argument, action, ' ');
|
|
|
|
|
InsetBase::Code const inset_code =
|
|
|
|
|
InsetBase::translate(name);
|
|
|
|
|
|
|
|
|
|
LCursor & cur = view()->cursor();
|
|
|
|
|
FuncRequest fr(LFUN_INSET_TOGGLE, action);
|
|
|
|
|
|
|
|
|
|
InsetBase & inset = owner->buffer()->inset();
|
|
|
|
|
InsetIterator it = inset_iterator_begin(inset);
|
|
|
|
|
InsetIterator const end = inset_iterator_end(inset);
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
if (inset_code == InsetBase::NO_CODE
|
2004-03-31 08:43:47 +00:00
|
|
|
|
|| inset_code == it->lyxCode())
|
2004-03-30 12:36:33 +00:00
|
|
|
|
it->dispatch(cur, fr);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-03-25 09:16:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
|
case LFUN_LANGUAGE_BUFFER: {
|
|
|
|
|
Buffer & buffer = *owner->buffer();
|
|
|
|
|
Language const * oldL = buffer.params().language;
|
|
|
|
|
Language const * newL = languages.getLanguage(argument);
|
|
|
|
|
if (!newL || oldL == newL)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (oldL->RightToLeft() == newL->RightToLeft()
|
|
|
|
|
&& !buffer.isMultiLingual())
|
|
|
|
|
buffer.changeLanguage(oldL, newL);
|
|
|
|
|
else
|
|
|
|
|
buffer.updateDocLang(newL);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_BUFFERPARAMS_APPLY: {
|
|
|
|
|
istringstream ss(argument);
|
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(ss);
|
|
|
|
|
int const unknown_tokens =
|
|
|
|
|
owner->buffer()->readHeader(lex);
|
|
|
|
|
|
|
|
|
|
if (unknown_tokens != 0) {
|
|
|
|
|
lyxerr << "Warning in LFUN_BUFFERPARAMS_APPLY!\n"
|
|
|
|
|
<< unknown_tokens << " unknown token"
|
|
|
|
|
<< (unknown_tokens == 1 ? "" : "s")
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_TEXTCLASS_APPLY: {
|
|
|
|
|
Buffer * buffer = owner->buffer();
|
|
|
|
|
|
|
|
|
|
lyx::textclass_type const old_class =
|
|
|
|
|
buffer->params().textclass;
|
|
|
|
|
|
2004-03-31 09:44:40 +00:00
|
|
|
|
loadTextclass(argument);
|
2004-03-30 16:19:50 +00:00
|
|
|
|
|
|
|
|
|
std::pair<bool, lyx::textclass_type> const tc_pair =
|
|
|
|
|
textclasslist.NumberOfClass(argument);
|
|
|
|
|
|
|
|
|
|
if (!tc_pair.first)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
lyx::textclass_type const new_class = tc_pair.second;
|
|
|
|
|
if (old_class == new_class)
|
|
|
|
|
// nothing to do
|
|
|
|
|
break;
|
|
|
|
|
|
2004-03-31 19:11:56 +00:00
|
|
|
|
owner->message(_("Converting document to new document class..."));
|
2004-03-30 16:19:50 +00:00
|
|
|
|
ErrorList el;
|
|
|
|
|
lyx::cap::SwitchLayoutsBetweenClasses(
|
|
|
|
|
old_class, new_class,
|
|
|
|
|
buffer->paragraphs(), el);
|
|
|
|
|
|
|
|
|
|
bufferErrors(*buffer, el);
|
|
|
|
|
view()->showErrorList(_("Class switch"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-31 09:44:40 +00:00
|
|
|
|
case LFUN_TEXTCLASS_LOAD:
|
|
|
|
|
loadTextclass(argument);
|
2004-03-30 16:19:50 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-03-31 16:50:59 +00:00
|
|
|
|
case LFUN_LYXRC_APPLY: {
|
|
|
|
|
istringstream ss(argument);
|
|
|
|
|
bool const success = lyxrc.read(ss) == 0;
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
lyxerr << "Warning in LFUN_LYXRC_APPLY!\n"
|
|
|
|
|
<< "Unable to read lyxrc data"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-18 12:53:43 +00:00
|
|
|
|
default: {
|
2004-02-03 09:08:15 +00:00
|
|
|
|
DispatchResult res = view()->cursor().dispatch(cmd);
|
|
|
|
|
if (!res.dispatched());
|
|
|
|
|
view()->dispatch(cmd);
|
2004-01-15 17:34:44 +00:00
|
|
|
|
break;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (view()->available()) {
|
|
|
|
|
view()->fitCursor();
|
|
|
|
|
view()->update();
|
|
|
|
|
// if we executed a mutating lfun, mark the buffer as dirty
|
|
|
|
|
if (getStatus(cmd).enabled()
|
|
|
|
|
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
|
|
|
|
|
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
|
|
|
|
|
view()->buffer()->markDirty();
|
|
|
|
|
}
|
2003-03-19 18:43:56 +00:00
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
|
if (view()->cursor().inTexted()) {
|
|
|
|
|
view()->owner()->updateLayoutChoice();
|
|
|
|
|
sendDispatchMessage(getMessage(), cmd, verbose);
|
|
|
|
|
}
|
2004-03-18 12:53:43 +00:00
|
|
|
|
}
|
2002-07-18 20:15:29 +00:00
|
|
|
|
}
|
1999-11-22 16:19:48 +00:00
|
|
|
|
|
|
|
|
|
|
2003-09-21 23:00:47 +00:00
|
|
|
|
void LyXFunc::sendDispatchMessage(string const & msg,
|
2004-01-30 11:41:12 +00:00
|
|
|
|
FuncRequest const & cmd, bool verbose)
|
2002-07-18 20:15:29 +00:00
|
|
|
|
{
|
2002-01-13 13:07:27 +00:00
|
|
|
|
owner->updateMenubar();
|
|
|
|
|
owner->updateToolbar();
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (cmd.action == LFUN_SELFINSERT || !verbose) {
|
2002-07-18 20:15:29 +00:00
|
|
|
|
lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
|
|
|
|
|
if (!msg.empty())
|
|
|
|
|
owner->message(msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2002-08-07 08:11:41 +00:00
|
|
|
|
string dispatch_msg = msg;
|
2002-07-18 20:15:29 +00:00
|
|
|
|
if (!dispatch_msg.empty())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
dispatch_msg += ' ';
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string comname = lyxaction.getActionName(cmd.action);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-07-18 20:15:29 +00:00
|
|
|
|
bool argsadded = false;
|
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (!cmd.argument.empty()) {
|
|
|
|
|
if (cmd.action != LFUN_UNKNOWN_ACTION) {
|
|
|
|
|
comname += ' ' + cmd.argument;
|
2002-07-18 20:15:29 +00:00
|
|
|
|
argsadded = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-11-22 16:19:48 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
string const shortcuts = toplevel_keymap->findbinding(cmd);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-07-18 20:15:29 +00:00
|
|
|
|
if (!shortcuts.empty()) {
|
|
|
|
|
comname += ": " + shortcuts;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
} else if (!argsadded && !cmd.argument.empty()) {
|
|
|
|
|
comname += ' ' + cmd.argument;
|
2002-07-18 20:15:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!comname.empty()) {
|
2002-07-28 22:50:13 +00:00
|
|
|
|
comname = rtrim(comname);
|
2002-11-27 10:30:28 +00:00
|
|
|
|
dispatch_msg += '(' + comname + ')';
|
2002-07-18 20:15:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
|
|
|
|
|
if (!dispatch_msg.empty())
|
|
|
|
|
owner->message(dispatch_msg);
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
void LyXFunc::setupLocalKeymap()
|
|
|
|
|
{
|
2003-11-13 13:43:44 +00:00
|
|
|
|
keyseq.stdmap = toplevel_keymap.get();
|
|
|
|
|
keyseq.curmap = toplevel_keymap.get();
|
|
|
|
|
cancel_meta_seq.stdmap = toplevel_keymap.get();
|
|
|
|
|
cancel_meta_seq.curmap = toplevel_keymap.get();
|
1999-12-16 06:43:25 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2002-07-11 15:13:21 +00:00
|
|
|
|
void LyXFunc::menuNew(string const & name, bool fromTemplate)
|
1999-12-16 06:43:25 +00:00
|
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
|
string initpath = lyxrc.document_path;
|
2002-07-11 15:13:21 +00:00
|
|
|
|
string filename(name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
|
if (view()->available()) {
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string const trypath = owner->buffer()->filePath();
|
1999-12-16 06:43:25 +00:00
|
|
|
|
// If directory is writeable, use this as default.
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (IsDirWriteable(trypath))
|
1999-12-16 06:43:25 +00:00
|
|
|
|
initpath = trypath;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-04 23:57:32 +00:00
|
|
|
|
static int newfile_number;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-07-11 15:13:21 +00:00
|
|
|
|
if (filename.empty()) {
|
|
|
|
|
filename = AddName(lyxrc.document_path,
|
2000-10-02 16:44:47 +00:00
|
|
|
|
"newfile" + tostr(++newfile_number) + ".lyx");
|
2002-07-11 15:13:21 +00:00
|
|
|
|
FileInfo fi(filename);
|
|
|
|
|
while (bufferlist.exists(filename) || fi.readable()) {
|
2000-08-08 11:08:07 +00:00
|
|
|
|
++newfile_number;
|
2002-07-11 15:13:21 +00:00
|
|
|
|
filename = AddName(lyxrc.document_path,
|
2000-10-02 16:44:47 +00:00
|
|
|
|
"newfile" + tostr(newfile_number) +
|
|
|
|
|
".lyx");
|
2002-07-11 15:13:21 +00:00
|
|
|
|
fi.newFile(filename);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-12-16 06:43:25 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
// The template stuff
|
|
|
|
|
string templname;
|
|
|
|
|
if (fromTemplate) {
|
2003-02-21 12:22:25 +00:00
|
|
|
|
FileDialog fileDlg(_("Select template file"),
|
2001-03-07 14:25:31 +00:00
|
|
|
|
LFUN_SELECT_FILE_SYNC,
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Documents|#o#O")),
|
2001-04-17 15:15:59 +00:00
|
|
|
|
string(lyxrc.document_path)),
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Templates|#T#t")),
|
2001-04-17 15:15:59 +00:00
|
|
|
|
string(lyxrc.template_path)));
|
|
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2002-11-17 08:32:09 +00:00
|
|
|
|
fileDlg.open(lyxrc.template_path,
|
2004-01-08 10:59:51 +00:00
|
|
|
|
FileFilterList(_("LyX Documents (*.lyx)")),
|
|
|
|
|
string());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return;
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (result.second.empty())
|
2001-03-07 14:25:31 +00:00
|
|
|
|
return;
|
2003-11-13 13:43:44 +00:00
|
|
|
|
templname = result.second;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-07-07 08:37:02 +00:00
|
|
|
|
view()->newFile(filename, templname, !name.empty());
|
1999-12-16 06:43:25 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-16 15:42:57 +00:00
|
|
|
|
void LyXFunc::open(string const & fname)
|
1999-12-16 06:43:25 +00:00
|
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
|
string initpath = lyxrc.document_path;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
|
if (view()->available()) {
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string const trypath = owner->buffer()->filePath();
|
1999-12-16 06:43:25 +00:00
|
|
|
|
// If directory is writeable, use this as default.
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (IsDirWriteable(trypath))
|
1999-12-16 06:43:25 +00:00
|
|
|
|
initpath = trypath;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
string filename;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
if (fname.empty()) {
|
2003-02-21 12:22:25 +00:00
|
|
|
|
FileDialog fileDlg(_("Select document to open"),
|
2001-03-07 14:25:31 +00:00
|
|
|
|
LFUN_FILE_OPEN,
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Documents|#o#O")),
|
2001-04-17 15:15:59 +00:00
|
|
|
|
string(lyxrc.document_path)),
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Examples|#E#e")),
|
2003-07-27 21:04:02 +00:00
|
|
|
|
string(AddPath(system_lyxdir(), "examples"))));
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
|
|
|
|
FileDialog::Result result =
|
2002-11-17 08:32:09 +00:00
|
|
|
|
fileDlg.open(initpath,
|
2004-01-08 10:59:51 +00:00
|
|
|
|
FileFilterList(_("LyX Documents (*.lyx)")),
|
|
|
|
|
string());
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filename = result.second;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
|
// check selected filename
|
|
|
|
|
if (filename.empty()) {
|
2001-04-24 17:33:01 +00:00
|
|
|
|
owner->message(_("Canceled."));
|
2001-03-07 14:25:31 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
filename = fname;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
// get absolute path of file and add ".lyx" to the filename if
|
|
|
|
|
// necessary
|
2001-08-01 10:08:53 +00:00
|
|
|
|
string const fullpath = FileSearch(string(), filename, "lyx");
|
2002-08-01 22:26:30 +00:00
|
|
|
|
if (!fullpath.empty()) {
|
|
|
|
|
filename = fullpath;
|
2001-08-01 10:08:53 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-14 17:58:49 +00:00
|
|
|
|
string const disp_fn(MakeDisplayPath(filename));
|
|
|
|
|
|
2002-08-01 22:26:30 +00:00
|
|
|
|
// if the file doesn't exist, let the user create one
|
|
|
|
|
FileInfo const f(filename, true);
|
|
|
|
|
if (!f.exist()) {
|
|
|
|
|
// the user specifically chose this name. Believe them.
|
2003-07-07 08:37:02 +00:00
|
|
|
|
view()->newFile(filename, "", true);
|
2002-08-01 22:26:30 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
owner->message(bformat(_("Opening document %1$s..."), disp_fn));
|
2001-06-14 17:58:49 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string str2;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
if (view()->loadLyXFile(filename)) {
|
2003-05-13 09:48:57 +00:00
|
|
|
|
str2 = bformat(_("Document %1$s opened."), disp_fn);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2003-05-13 09:48:57 +00:00
|
|
|
|
str2 = bformat(_("Could not open document %1$s"), disp_fn);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2003-05-13 09:48:57 +00:00
|
|
|
|
owner->message(str2);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
|
void LyXFunc::doImport(string const & argument)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-10-23 12:16:05 +00:00
|
|
|
|
string format;
|
|
|
|
|
string filename = split(argument, format, ' ');
|
2002-05-30 19:49:00 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
|
2001-06-27 14:10:35 +00:00
|
|
|
|
<< " file: " << filename << endl;
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-05-30 19:49:00 +00:00
|
|
|
|
// need user interaction
|
|
|
|
|
if (filename.empty()) {
|
2000-04-28 11:18:04 +00:00
|
|
|
|
string initpath = lyxrc.document_path;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
|
if (view()->available()) {
|
2002-01-14 23:31:23 +00:00
|
|
|
|
string const trypath = owner->buffer()->filePath();
|
2000-04-28 11:18:04 +00:00
|
|
|
|
// If directory is writeable, use this as default.
|
2001-08-01 10:08:53 +00:00
|
|
|
|
if (IsDirWriteable(trypath))
|
2000-04-28 11:18:04 +00:00
|
|
|
|
initpath = trypath;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string const text = bformat(_("Select %1$s file to import"),
|
|
|
|
|
formats.prettyName(format));
|
2001-03-07 14:25:31 +00:00
|
|
|
|
|
2003-02-21 12:22:25 +00:00
|
|
|
|
FileDialog fileDlg(text,
|
2001-03-07 14:25:31 +00:00
|
|
|
|
LFUN_IMPORT,
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Documents|#o#O")),
|
2001-04-17 15:15:59 +00:00
|
|
|
|
string(lyxrc.document_path)),
|
2002-01-13 15:01:25 +00:00
|
|
|
|
make_pair(string(_("Examples|#E#e")),
|
2003-07-27 21:04:02 +00:00
|
|
|
|
string(AddPath(system_lyxdir(), "examples"))));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
|
string const filter = formats.prettyName(format)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
+ " (*." + formats.extension(format) + ')';
|
2001-03-07 14:25:31 +00:00
|
|
|
|
|
2004-01-08 10:59:51 +00:00
|
|
|
|
FileDialog::Result result =
|
|
|
|
|
fileDlg.open(initpath,
|
|
|
|
|
FileFilterList(filter),
|
|
|
|
|
string());
|
2001-03-07 14:25:31 +00:00
|
|
|
|
|
|
|
|
|
if (result.first == FileDialog::Later)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
filename = result.second;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-04-28 11:18:04 +00:00
|
|
|
|
// check selected filename
|
2001-04-17 15:15:59 +00:00
|
|
|
|
if (filename.empty())
|
2001-04-24 17:33:01 +00:00
|
|
|
|
owner->message(_("Canceled."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (filename.empty())
|
2000-04-28 11:18:04 +00:00
|
|
|
|
return;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// get absolute path of file
|
|
|
|
|
filename = MakeAbsPath(filename);
|
|
|
|
|
|
2000-11-14 02:01:57 +00:00
|
|
|
|
string const lyxfile = ChangeExtension(filename, ".lyx");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Check if the document already is open
|
2003-03-31 02:59:34 +00:00
|
|
|
|
if (lyx_gui::use_gui && bufferlist.exists(lyxfile)) {
|
2003-04-26 15:24:56 +00:00
|
|
|
|
if (!bufferlist.close(bufferlist.getBuffer(lyxfile), true)) {
|
2003-03-29 07:09:13 +00:00
|
|
|
|
owner->message(_("Canceled."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
// if the file exists already, and we didn't do
|
2002-05-30 19:49:00 +00:00
|
|
|
|
// -i lyx thefile.lyx, warn
|
|
|
|
|
if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
|
2003-03-29 07:09:13 +00:00
|
|
|
|
string const file = MakeDisplayPath(lyxfile, 30);
|
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
string text = bformat(_("The document %1$s already exists.\n\n"
|
|
|
|
|
"Do you want to over-write that document?"), file);
|
2003-03-29 07:09:13 +00:00
|
|
|
|
int const ret = Alert::prompt(_("Over-write document?"),
|
2003-04-27 16:40:50 +00:00
|
|
|
|
text, 0, 1, _("&Over-write"), _("&Cancel"));
|
2003-03-29 07:09:13 +00:00
|
|
|
|
|
|
|
|
|
if (ret == 1) {
|
2003-01-06 14:02:24 +00:00
|
|
|
|
owner->message(_("Canceled."));
|
2002-05-30 19:49:00 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2000-10-23 12:16:05 +00:00
|
|
|
|
Importer::Import(owner, filename, format);
|
2000-03-20 18:55:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-16 15:42:57 +00:00
|
|
|
|
void LyXFunc::closeBuffer()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-29 07:09:13 +00:00
|
|
|
|
if (bufferlist.close(owner->buffer(), true) && !quitting) {
|
1999-11-05 06:02:34 +00:00
|
|
|
|
if (bufferlist.empty()) {
|
2003-07-25 17:11:25 +00:00
|
|
|
|
// need this otherwise SEGV may occur while
|
2003-07-11 12:21:31 +00:00
|
|
|
|
// trying to set variables that don't exist
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// since there's no current buffer
|
2002-08-13 14:40:38 +00:00
|
|
|
|
owner->getDialogs().hideBufferDependent();
|
2000-11-14 02:01:57 +00:00
|
|
|
|
} else {
|
2004-03-18 12:53:43 +00:00
|
|
|
|
view()->setBuffer(bufferlist.first());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Each "owner" should have it's own message method. lyxview and
|
|
|
|
|
// the minibuffer would use the minibuffer, but lyxserver would
|
|
|
|
|
// send an ERROR signal to its client. Alejandro 970603
|
2004-01-30 11:41:12 +00:00
|
|
|
|
// This function is bit problematic when it comes to NLS, to make the
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// lyx servers client be language indepenent we must not translate
|
|
|
|
|
// strings sent to this func.
|
1999-11-22 16:19:48 +00:00
|
|
|
|
void LyXFunc::setErrorMessage(string const & m) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
dispatch_buffer = m;
|
|
|
|
|
errorstat = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void LyXFunc::setMessage(string const & m) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
dispatch_buffer = m;
|
|
|
|
|
}
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
|
|
|
|
|
2002-01-13 13:07:27 +00:00
|
|
|
|
void LyXFunc::setStatusMessage(string const & m) const
|
|
|
|
|
{
|
|
|
|
|
status_buffer = m;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-02-20 08:44:11 +00:00
|
|
|
|
string const LyXFunc::viewStatusMessage()
|
2001-04-17 15:15:59 +00:00
|
|
|
|
{
|
|
|
|
|
// When meta-fake key is pressed, show the key sequence so far + "M-".
|
2004-02-20 08:44:11 +00:00
|
|
|
|
if (wasMetaKey())
|
2002-07-18 20:15:29 +00:00
|
|
|
|
return keyseq.print() + "M-";
|
2001-04-17 15:15:59 +00:00
|
|
|
|
|
|
|
|
|
// Else, when a non-complete key sequence is pressed,
|
|
|
|
|
// show the available options.
|
2004-02-20 08:44:11 +00:00
|
|
|
|
if (keyseq.length() > 0 && !keyseq.deleted())
|
2002-07-18 20:15:29 +00:00
|
|
|
|
return keyseq.printOptions();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-13 17:43:40 +00:00
|
|
|
|
if (!view()->available())
|
2002-07-18 20:15:29 +00:00
|
|
|
|
return _("Welcome to LyX!");
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2004-02-13 07:30:59 +00:00
|
|
|
|
return view()->cursor().currentState();
|
2002-08-13 17:43:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BufferView * LyXFunc::view() const
|
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(owner);
|
2002-08-13 17:43:40 +00:00
|
|
|
|
return owner->view().get();
|
2001-04-17 15:15:59 +00:00
|
|
|
|
}
|
2003-07-28 22:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXFunc::wasMetaKey() const
|
|
|
|
|
{
|
|
|
|
|
return (meta_fake_bit != key_modifier::none);
|
|
|
|
|
}
|