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"
|
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"
|
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"
|
2003-09-06 18:38:02 +00:00
|
|
|
|
#include "intl.h"
|
|
|
|
|
#include "iterators.h"
|
|
|
|
|
#include "kbmap.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"
|
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"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "lyxvc.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
|
#include "paragraph.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"
|
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"
|
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::DEC_DEPTH;
|
|
|
|
|
using bv_funcs::freefont2string;
|
|
|
|
|
using bv_funcs::INC_DEPTH;
|
|
|
|
|
|
|
|
|
|
using lyx::support::AddName;
|
|
|
|
|
using lyx::support::AddPath;
|
|
|
|
|
using lyx::support::bformat;
|
|
|
|
|
using lyx::support::ChangeExtension;
|
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;
|
|
|
|
|
using lyx::support::rtrim;
|
|
|
|
|
using lyx::support::split;
|
|
|
|
|
using lyx::support::strToInt;
|
|
|
|
|
using lyx::support::strToUnsignedInt;
|
|
|
|
|
using lyx::support::system_lyxdir;
|
|
|
|
|
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
|
|
|
|
|
2003-01-05 22:38:42 +00:00
|
|
|
|
Encoding const * encoding = view()->getEncoding();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
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"));
|
2003-10-21 16:15:14 +00:00
|
|
|
|
flag.disabled(true);
|
|
|
|
|
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);
|
2003-10-16 11:16:15 +00:00
|
|
|
|
flag.disabled(true);
|
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-02-13 07:30:59 +00:00
|
|
|
|
if (!lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)) {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
// Yes we need a buffer, do we have one?
|
|
|
|
|
if (buf) {
|
|
|
|
|
// yes
|
|
|
|
|
// Can we use a readonly buffer?
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (buf->isReadonly() &&
|
2004-02-13 07:30:59 +00:00
|
|
|
|
!lyxaction.funcHasFlag(cmd.action,
|
1999-12-10 00:07:59 +00:00
|
|
|
|
LyXAction::ReadOnly)) {
|
|
|
|
|
// no
|
2002-01-13 13:07:27 +00:00
|
|
|
|
setStatusMessage(N_("Document is read-only"));
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.disabled(true);
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// no
|
2002-01-13 13:07:27 +00:00
|
|
|
|
setStatusMessage(N_("Command not allowed with"
|
2003-10-17 18:01:15 +00:00
|
|
|
|
"out any document open"));
|
2003-10-21 16:15:14 +00:00
|
|
|
|
flag.disabled(true);
|
|
|
|
|
return flag;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-06 16:14:06 +00:00
|
|
|
|
UpdatableInset * tli = cur.inset() ? cur.inset()->asUpdatableInset() : 0;
|
2002-03-21 17:27:08 +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.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
bool disable = false;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
switch (cmd.action) {
|
2000-11-06 11:20:22 +00:00
|
|
|
|
case LFUN_EXPORT:
|
2004-02-13 07:30:59 +00:00
|
|
|
|
disable = cmd.argument != "custom"
|
|
|
|
|
&& !Exporter::IsExportable(*buf, cmd.argument);
|
2000-11-06 11:20:22 +00:00
|
|
|
|
break;
|
1999-12-16 06:43:25 +00:00
|
|
|
|
case LFUN_UNDO:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = buf->undostack().empty();
|
1999-12-16 06:43:25 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_REDO:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = buf->redostack().empty();
|
1999-12-16 06:43:25 +00:00
|
|
|
|
break;
|
2002-08-24 22:02:30 +00:00
|
|
|
|
case LFUN_CUT:
|
|
|
|
|
case LFUN_COPY:
|
2004-02-13 16:22:53 +00:00
|
|
|
|
disable = !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:
|
2003-03-29 09:48:03 +00:00
|
|
|
|
disable = !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:
|
2003-08-28 07:41:31 +00:00
|
|
|
|
disable = !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-02-06 16:14:06 +00:00
|
|
|
|
disable = !cur.innerInsetTabular();
|
2000-08-01 09:35:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2003-04-03 01:26:02 +00:00
|
|
|
|
case LFUN_DEPTH_MIN:
|
2004-02-13 07:30:59 +00:00
|
|
|
|
disable = !changeDepthAllowed(cur, view()->getLyXText(), DEC_DEPTH);
|
2003-04-03 01:26:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LFUN_DEPTH_PLUS:
|
2004-02-13 07:30:59 +00:00
|
|
|
|
disable = !changeDepthAllowed(cur, view()->getLyXText(), INC_DEPTH);
|
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:
|
|
|
|
|
disable = cur.inset()
|
|
|
|
|
&& cur.inset()->forceDefaultParagraphs(cur.inset());
|
2002-01-20 16:07:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2002-08-23 09:05:32 +00:00
|
|
|
|
case LFUN_INSET_OPTARG:
|
2004-02-06 16:14:06 +00:00
|
|
|
|
disable = cur.inMathed()
|
|
|
|
|
|| cur.paragraph().layout()->optionalargs == 0;
|
2002-08-23 09:05:32 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2000-08-01 09:35:42 +00:00
|
|
|
|
case LFUN_TABULAR_FEATURE:
|
2002-08-21 13:47:52 +00:00
|
|
|
|
#if 0
|
2004-02-06 16:14:06 +00:00
|
|
|
|
if (cur.inMathed()) {
|
2002-08-21 13:47:52 +00:00
|
|
|
|
// FIXME: check temporarily disabled
|
|
|
|
|
// valign code
|
2004-01-20 14:25:24 +00:00
|
|
|
|
char align = mathcursor::valign();
|
2002-08-21 13:47:52 +00:00
|
|
|
|
if (align == '\0') {
|
|
|
|
|
disable = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cmd.argument.empty()) {
|
2002-08-21 13:47:52 +00:00
|
|
|
|
flag.clear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (!contains("tcb", cmd.argument[0])) {
|
2002-08-21 13:47:52 +00:00
|
|
|
|
disable = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
flag.setOnOff(cmd.argument[0] == align);
|
2003-10-13 00:38:09 +00:00
|
|
|
|
} else {
|
2002-08-21 13:47:52 +00:00
|
|
|
|
disable = true;
|
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
char align = mathcursor::halign();
|
2002-08-21 13:47:52 +00:00
|
|
|
|
if (align == '\0') {
|
|
|
|
|
disable = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cmd.argument.empty()) {
|
2002-08-21 13:47:52 +00:00
|
|
|
|
flag.clear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (!contains("lcr", cmd.argument[0])) {
|
2002-08-21 13:47:52 +00:00
|
|
|
|
disable = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-02-13 07:30:59 +00:00
|
|
|
|
flag.setOnOff(cmd.argument[0] == align);
|
2002-08-21 13:47:52 +00:00
|
|
|
|
|
2004-01-20 14:25:24 +00:00
|
|
|
|
disable = !mathcursor::halign();
|
2002-08-21 13:47:52 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-20 16:07:42 +00:00
|
|
|
|
if (tli) {
|
2002-01-09 09:36:35 +00:00
|
|
|
|
FuncStatus ret;
|
2002-01-12 20:00:47 +00:00
|
|
|
|
//ret.disabled(true);
|
2004-02-06 16:14:06 +00:00
|
|
|
|
InsetTabular * tab = cur.innerInsetTabular();
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (tab) {
|
2004-02-13 07:30:59 +00:00
|
|
|
|
ret = tab->getStatus(cmd.argument);
|
2003-04-26 19:01:33 +00:00
|
|
|
|
flag |= ret;
|
|
|
|
|
disable = false;
|
|
|
|
|
} else {
|
|
|
|
|
disable = true;
|
2000-08-01 09:35:42 +00:00
|
|
|
|
}
|
2000-08-18 15:32:42 +00:00
|
|
|
|
} else {
|
2003-10-29 12:18:08 +00:00
|
|
|
|
static InsetTabular inset(*buf, 1, 1);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
disable = true;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
FuncStatus ret = inset.getStatus(cmd.argument);
|
2002-01-20 16:07:42 +00:00
|
|
|
|
if (ret.onoff(true) || ret.onoff(false))
|
|
|
|
|
flag.setOnOff(false);
|
2000-08-01 09:35:42 +00:00
|
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#endif
|
2000-08-01 09:35:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
|
case LFUN_VC_REGISTER:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = buf->lyxvc().inUse();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_VC_CHECKIN:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = !buf->lyxvc().inUse() || buf->isReadonly();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_VC_CHECKOUT:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = !buf->lyxvc().inUse() || !buf->isReadonly();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_VC_REVERT:
|
|
|
|
|
case LFUN_VC_UNDO:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = !buf->lyxvc().inUse();
|
2000-07-24 13:53:19 +00:00
|
|
|
|
break;
|
2003-02-17 18:40:04 +00:00
|
|
|
|
case LFUN_MENURELOAD:
|
|
|
|
|
disable = buf->isUnnamed() || buf->isClean();
|
|
|
|
|
break;
|
2001-01-28 18:31:36 +00:00
|
|
|
|
case LFUN_BOOKMARK_GOTO:
|
2003-10-29 12:18:08 +00:00
|
|
|
|
disable = !view()->
|
2004-02-13 07:30:59 +00:00
|
|
|
|
isSavedPosition(strToUnsignedInt(cmd.argument));
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_MERGE_CHANGES:
|
|
|
|
|
case LFUN_ACCEPT_CHANGE:
|
|
|
|
|
case LFUN_REJECT_CHANGE:
|
|
|
|
|
case LFUN_ACCEPT_ALL_CHANGES:
|
|
|
|
|
case LFUN_REJECT_ALL_CHANGES:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = !buf->params().tracking_changes;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
|
2003-04-26 19:01:33 +00:00
|
|
|
|
case LFUN_INSET_SETTINGS: {
|
|
|
|
|
disable = true;
|
2004-02-06 16:14:06 +00:00
|
|
|
|
if (!cur.inset())
|
|
|
|
|
break;
|
|
|
|
|
UpdatableInset * inset = cur.inset()->asUpdatableInset();
|
2003-04-26 19:01:33 +00:00
|
|
|
|
if (!inset)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
// jump back to owner if an InsetText, so
|
|
|
|
|
// we get back to the InsetTabular or whatever
|
2003-07-25 21:20:24 +00:00
|
|
|
|
if (inset->lyxCode() == InsetOld::TEXT_CODE)
|
2003-06-04 07:14:05 +00:00
|
|
|
|
inset = inset->owner();
|
2003-04-26 19:01:33 +00:00
|
|
|
|
|
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-02-13 07:30:59 +00:00
|
|
|
|
disable = 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-02-13 07:30:59 +00:00
|
|
|
|
disable = 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-02-13 07:30:59 +00:00
|
|
|
|
disable = 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-02-13 07:30:59 +00:00
|
|
|
|
disable = 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-02-13 07:30:59 +00:00
|
|
|
|
disable = 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-02-13 07:30:59 +00:00
|
|
|
|
disable = 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-02-13 07:30:59 +00:00
|
|
|
|
disable = cmd.argument != "box";
|
2003-10-07 07:42:15 +00:00
|
|
|
|
break;
|
2003-04-26 19:01:33 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
case LFUN_MATH_MUTATE:
|
2004-02-06 16:14:06 +00:00
|
|
|
|
if (cur.inMathed())
|
2004-02-13 07:30:59 +00:00
|
|
|
|
//flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
|
2002-08-15 14:33:14 +00:00
|
|
|
|
flag.setOnOff(false);
|
2002-07-03 10:36:44 +00:00
|
|
|
|
else
|
2001-06-27 14:10:35 +00:00
|
|
|
|
disable = true;
|
|
|
|
|
break;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
|
|
|
|
// we just need to be in math mode to enable that
|
2002-03-21 17:27:08 +00:00
|
|
|
|
case LFUN_MATH_SIZE:
|
2001-07-25 12:37:43 +00:00
|
|
|
|
case LFUN_MATH_SPACE:
|
2002-03-21 17:27:08 +00:00
|
|
|
|
case LFUN_MATH_LIMITS:
|
|
|
|
|
case LFUN_MATH_NONUMBER:
|
2001-07-06 12:09:32 +00:00
|
|
|
|
case LFUN_MATH_NUMBER:
|
2002-08-14 13:22:05 +00:00
|
|
|
|
case LFUN_MATH_EXTERN:
|
2004-02-06 16:14:06 +00:00
|
|
|
|
disable = cur.inTexted();
|
2001-07-06 12:09:32 +00:00
|
|
|
|
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);
|
2003-06-19 16:49:45 +00:00
|
|
|
|
if (!buf) {
|
|
|
|
|
disable = !(name == "aboutlyx" ||
|
|
|
|
|
name == "file" ||
|
|
|
|
|
name == "forks" ||
|
|
|
|
|
name == "preferences" ||
|
|
|
|
|
name == "texinfo");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (name == "print") {
|
2003-08-28 07:41:31 +00:00
|
|
|
|
disable = !Exporter::IsExportable(*buf, "dvi") ||
|
2003-06-19 16:49:45 +00:00
|
|
|
|
lyxrc.print_command == "none";
|
|
|
|
|
} else if (name == "character") {
|
2004-02-06 16:14:06 +00:00
|
|
|
|
InsetBase * inset = cur.inset();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
disable = inset && inset->lyxCode() == InsetOld::ERT_CODE;
|
2003-06-19 16:49:45 +00:00
|
|
|
|
} else if (name == "vclog") {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
disable = !buf->lyxvc().inUse();
|
2003-06-19 16:49:45 +00:00
|
|
|
|
} else if (name == "latexlog") {
|
|
|
|
|
disable = !IsFileReadable(buf->getLogName().second);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-16 06:43:25 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the functions which insert insets
|
2003-07-25 21:20:24 +00:00
|
|
|
|
InsetOld::Code code = InsetOld::NO_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-03-07 15:58:02 +00:00
|
|
|
|
case LFUN_DIALOG_SHOW_NEW_INSET:
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cmd.argument == "bibitem")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::BIBITEM_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "bibtex")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::BIBTEX_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "box")
|
2003-12-10 22:10:38 +00:00
|
|
|
|
code = InsetOld::BOX_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "branch")
|
2003-12-10 22:10:38 +00:00
|
|
|
|
code = InsetOld::BRANCH_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "citation")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::CITE_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "ert")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::ERT_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "external")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::EXTERNAL_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "float")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::FLOAT_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "graphics")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::GRAPHICS_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "include")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::INCLUDE_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "index")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::INDEX_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "label")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::LABEL_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "note")
|
2003-12-10 22:10:38 +00:00
|
|
|
|
code = InsetOld::NOTE_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "ref")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::REF_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "toc")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::TOC_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "url")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::URL_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "vspace")
|
2003-11-28 15:53:34 +00:00
|
|
|
|
code = InsetOld::VSPACE_CODE;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
else if (cmd.argument == "wrap")
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::WRAP_CODE;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
case LFUN_INSET_ERT:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::ERT_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_INSET_FOOTNOTE:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::FOOT_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2002-08-04 23:11:50 +00:00
|
|
|
|
case LFUN_TABULAR_INSERT:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::TABULAR_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_INSET_MARGINAL:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::MARGIN_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_INSET_FLOAT:
|
|
|
|
|
case LFUN_INSET_WIDE_FLOAT:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::FLOAT_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2002-09-10 10:18:58 +00:00
|
|
|
|
case LFUN_INSET_WRAP:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::WRAP_CODE;
|
2002-09-10 10:18:58 +00:00
|
|
|
|
break;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
case LFUN_FLOAT_LIST:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::FLOAT_LIST_CODE;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
break;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
#if 0
|
|
|
|
|
case LFUN_INSET_LIST:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::LIST_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_INSET_THEOREM:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::THEOREM_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2001-07-24 22:08:49 +00:00
|
|
|
|
#endif
|
2001-07-19 08:52:59 +00:00
|
|
|
|
case LFUN_INSET_CAPTION:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::CAPTION_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_INSERT_NOTE:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::NOTE_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
case LFUN_INSERT_CHARSTYLE:
|
|
|
|
|
code = InsetOld::CHARSTYLE_CODE;
|
|
|
|
|
if (buf->params().getLyXTextClass().charstyles().empty())
|
|
|
|
|
disable = true;
|
|
|
|
|
break;
|
2003-10-07 07:42:15 +00:00
|
|
|
|
case LFUN_INSERT_BOX:
|
|
|
|
|
code = InsetOld::BOX_CODE;
|
|
|
|
|
break;
|
2003-08-17 11:28:23 +00:00
|
|
|
|
case LFUN_INSERT_BRANCH:
|
|
|
|
|
code = InsetOld::BRANCH_CODE;
|
2003-09-09 17:00:19 +00:00
|
|
|
|
if (buf->params().branchlist().empty())
|
2003-08-17 11:28:23 +00:00
|
|
|
|
disable = true;
|
|
|
|
|
break;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
case LFUN_INSERT_LABEL:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::LABEL_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2002-08-23 09:05:32 +00:00
|
|
|
|
case LFUN_INSET_OPTARG:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::OPTARG_CODE;
|
2002-08-23 09:05:32 +00:00
|
|
|
|
break;
|
2003-03-13 11:16:56 +00:00
|
|
|
|
case LFUN_ENVIRONMENT_INSERT:
|
2003-12-14 13:47:40 +00:00
|
|
|
|
code = InsetOld::BOX_CODE;
|
2003-03-13 11:16:56 +00:00
|
|
|
|
break;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
case LFUN_INDEX_INSERT:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::INDEX_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
case LFUN_INDEX_PRINT:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::INDEX_PRINT_CODE;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
break;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
case LFUN_TOC_INSERT:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::TOC_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
case LFUN_HTMLURL:
|
|
|
|
|
case LFUN_URL:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::URL_CODE;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
case LFUN_QUOTE:
|
|
|
|
|
// always allow this, since we will inset a raw quote
|
|
|
|
|
// if an inset is not allowed.
|
|
|
|
|
break;
|
|
|
|
|
case LFUN_HYPHENATION:
|
|
|
|
|
case LFUN_LIGATURE_BREAK:
|
|
|
|
|
case LFUN_HFILL:
|
|
|
|
|
case LFUN_MENU_SEPARATOR:
|
|
|
|
|
case LFUN_LDOTS:
|
|
|
|
|
case LFUN_END_OF_SENTENCE:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::SPECIALCHAR_CODE;
|
2001-07-23 09:11:14 +00:00
|
|
|
|
break;
|
2003-05-22 10:40:57 +00:00
|
|
|
|
case LFUN_SPACE_INSERT:
|
2002-04-22 22:31:49 +00:00
|
|
|
|
// slight hack: we know this is allowed in math mode
|
2004-02-06 16:14:06 +00:00
|
|
|
|
if (cur.inTexted())
|
2003-07-25 21:20:24 +00:00
|
|
|
|
code = InsetOld::SPACE_CODE;
|
2002-04-22 22:31:49 +00:00
|
|
|
|
break;
|
2003-09-04 14:02:05 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_SHOW: {
|
2004-02-06 16:14:06 +00:00
|
|
|
|
InsetBase * inset = cur.nextInset();
|
2003-10-29 12:18:08 +00:00
|
|
|
|
disable = !inset;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
if (inset) {
|
2003-10-29 12:18:08 +00:00
|
|
|
|
code = inset->lyxCode();
|
|
|
|
|
if (!(code == InsetOld::INCLUDE_CODE
|
|
|
|
|
|| code == InsetOld::BIBTEX_CODE
|
|
|
|
|
|| code == InsetOld::FLOAT_LIST_CODE
|
|
|
|
|
|| code == InsetOld::TOC_CODE))
|
|
|
|
|
disable = true;
|
2003-09-04 14:02:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2003-10-29 12:18:08 +00:00
|
|
|
|
}
|
2001-07-19 08:52:59 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-07-25 21:20:24 +00:00
|
|
|
|
if (code != InsetOld::NO_CODE && tli && !tli->insetAllowed(code))
|
2001-07-19 08:52:59 +00:00
|
|
|
|
disable = true;
|
|
|
|
|
|
|
|
|
|
if (disable)
|
2002-07-21 15:51:07 +00:00
|
|
|
|
flag.disabled(true);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-21 13:55:24 +00:00
|
|
|
|
// A few general toggles
|
2004-02-13 07:30:59 +00:00
|
|
|
|
switch (cmd.action) {
|
2002-03-11 09:54:42 +00:00
|
|
|
|
case LFUN_TOOLTIPS_TOGGLE:
|
2002-08-13 14:40:38 +00:00
|
|
|
|
flag.setOnOff(owner->getDialogs().tooltipsEnabled());
|
2002-03-11 09:54:42 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
case LFUN_READ_ONLY_TOGGLE:
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.setOnOff(buf->isReadonly());
|
2001-07-19 08:52:59 +00:00
|
|
|
|
break;
|
2001-08-03 10:32:20 +00:00
|
|
|
|
case LFUN_APPENDIX:
|
2004-02-06 16:14:06 +00:00
|
|
|
|
flag.setOnOff(cur.inTexted()
|
|
|
|
|
&& cur.paragraph().params().startOfAppendix());
|
2001-08-03 10:32:20 +00:00
|
|
|
|
break;
|
2002-02-11 15:51:03 +00:00
|
|
|
|
case LFUN_SWITCHBUFFER:
|
|
|
|
|
// toggle on the current buffer, but do not toggle off
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// the other ones (is that a good idea?)
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cmd.argument == buf->fileName())
|
2002-02-11 15:51:03 +00:00
|
|
|
|
flag.setOnOff(true);
|
|
|
|
|
break;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
case LFUN_TRACK_CHANGES:
|
2003-09-09 09:47:59 +00:00
|
|
|
|
flag.setOnOff(buf->params().tracking_changes);
|
2003-02-08 19:18:01 +00:00
|
|
|
|
break;
|
2001-07-19 08:52:59 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#ifdef LOCK
|
2001-12-21 13:55:24 +00:00
|
|
|
|
// the font related toggles
|
2004-02-06 16:14:06 +00:00
|
|
|
|
if (cur.inTexted()) {
|
|
|
|
|
LyXFont const & font = cur.text()->real_current_font;
|
2004-02-13 07:30:59 +00:00
|
|
|
|
switch (cmd.action) {
|
2001-12-21 13:55:24 +00:00
|
|
|
|
case LFUN_EMPH:
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.setOnOff(font.emph() == LyXFont::ON);
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_NOUN:
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.setOnOff(font.noun() == LyXFont::ON);
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_BOLD:
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_SANS:
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_ROMAN:
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_CODE:
|
2002-01-09 09:36:35 +00:00
|
|
|
|
flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-07-18 20:15:29 +00:00
|
|
|
|
} else {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
string tc = mathcursor::getLastCode();
|
2004-02-13 07:30:59 +00:00
|
|
|
|
switch (cmd.action) {
|
2001-12-21 13:55:24 +00:00
|
|
|
|
case LFUN_BOLD:
|
2002-05-30 09:51:28 +00:00
|
|
|
|
flag.setOnOff(tc == "mathbf");
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_SANS:
|
2002-05-30 09:51:28 +00:00
|
|
|
|
flag.setOnOff(tc == "mathsf");
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_EMPH:
|
2002-05-30 09:51:28 +00:00
|
|
|
|
flag.setOnOff(tc == "mathcal");
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_ROMAN:
|
2002-05-30 09:51:28 +00:00
|
|
|
|
flag.setOnOff(tc == "mathrm");
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_CODE:
|
2002-05-30 09:51:28 +00:00
|
|
|
|
flag.setOnOff(tc == "mathtt");
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_NOUN:
|
2002-05-30 09:51:28 +00:00
|
|
|
|
flag.setOnOff(tc == "mathbb");
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case LFUN_DEFAULT:
|
2002-05-30 09:51:28 +00:00
|
|
|
|
flag.setOnOff(tc == "mathnormal");
|
2001-12-21 13:55:24 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-11-10 09:06:48 +00:00
|
|
|
|
#endif
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-07-21 15:51:07 +00:00
|
|
|
|
// this one is difficult to get right. As a half-baked
|
|
|
|
|
// solution, we consider only the first action of the sequence
|
2004-02-13 07:30:59 +00:00
|
|
|
|
if (cmd.action == LFUN_SEQUENCE) {
|
2002-07-21 15:51:07 +00:00
|
|
|
|
// argument contains ';'-terminated commands
|
2003-10-25 09:20:51 +00:00
|
|
|
|
#warning LyXAction arguments not handled here.
|
2004-02-13 07:30:59 +00:00
|
|
|
|
flag = getStatus(FuncRequest(
|
|
|
|
|
lyxaction.lookupFunc(token(cmd.argument, ';', 0))));
|
2002-07-21 15:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
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-01-30 11:41:12 +00:00
|
|
|
|
string argument = cmd.argument;
|
|
|
|
|
kb_action 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-02-11 14:45:44 +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-01-30 11:41:12 +00:00
|
|
|
|
if (getStatus(cmd).disabled()) {
|
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_ESCAPE: {
|
|
|
|
|
if (!view()->available())
|
|
|
|
|
break;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
view()->cursor().pop();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// Tell the paragraph dialog that we changed paragraph
|
|
|
|
|
dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
|
2003-07-28 22:34:48 +00:00
|
|
|
|
break;
|
2003-11-13 13:43:44 +00:00
|
|
|
|
}
|
2002-03-21 17:27:08 +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-01-07 17:00:03 +00:00
|
|
|
|
} else
|
2003-11-13 13:43:44 +00:00
|
|
|
|
searched_string = last_search;
|
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);
|
|
|
|
|
view()->dispatch(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
|
|
|
|
case LFUN_CENTER: // this is center and redraw.
|
|
|
|
|
view()->center();
|
|
|
|
|
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")
|
|
|
|
|
owner->getDialogs().showSendto();
|
|
|
|
|
else {
|
|
|
|
|
Exporter::Export(owner->buffer(), argument, false);
|
|
|
|
|
view()->showErrorList(BufferFormat(*owner->buffer()));
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
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:
|
|
|
|
|
view()->buffer(bufferlist.getBuffer(argument));
|
|
|
|
|
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_LAYOUT_TABULAR:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
if (InsetTabular * tab = view()->cursor().innerInsetTabular())
|
2003-11-13 13:43:44 +00:00
|
|
|
|
tab->openLayoutDialog(view());
|
|
|
|
|
break;
|
2000-08-01 09:35:42 +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
|
|
|
|
|
view()->buffer(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)) {
|
|
|
|
|
view()->buffer(bufferlist.getBuffer(s));
|
|
|
|
|
} 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 == "document")
|
2003-11-13 13:43:44 +00:00
|
|
|
|
owner->getDialogs().showDocument();
|
|
|
|
|
else if (name == "forks")
|
|
|
|
|
owner->getDialogs().showForks();
|
|
|
|
|
else if (name == "preamble")
|
|
|
|
|
owner->getDialogs().showPreamble();
|
|
|
|
|
else if (name == "preferences")
|
|
|
|
|
owner->getDialogs().showPreferences();
|
|
|
|
|
else if (name == "print")
|
|
|
|
|
owner->getDialogs().showPrint();
|
|
|
|
|
else if (name == "spellchecker")
|
|
|
|
|
owner->getDialogs().showSpellchecker();
|
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_INSET_DIALOG_SHOW: {
|
2004-02-03 08:56:28 +00:00
|
|
|
|
InsetBase * inset = view()->cursor().nextInset();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
if (inset)
|
2004-01-20 14:25:24 +00:00
|
|
|
|
inset->dispatch(view()->cursor(), FuncRequest(LFUN_INSET_DIALOG_SHOW));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
break;
|
2003-02-25 14:51:38 +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))
|
|
|
|
|
view()->buffer(bufferlist.getBuffer(filename));
|
|
|
|
|
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;
|
|
|
|
|
argument = split(argument, countstr, ' ');
|
|
|
|
|
istringstream is(countstr);
|
|
|
|
|
int count = 0;
|
|
|
|
|
is >> count;
|
|
|
|
|
lyxerr << "repeat: count: " << count << " cmd: " << argument << endl;
|
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
|
dispatch(lyxaction.lookupFunc(argument));
|
|
|
|
|
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;
|
|
|
|
|
argument = split(argument, first, ';');
|
|
|
|
|
dispatch(lyxaction.lookupFunc(first));
|
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
|
LColor::color col = lcolor.getFromLyXName(lyx_name);
|
|
|
|
|
if (!lcolor.setColor(col, 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_FORKS_KILL:
|
|
|
|
|
if (isStrInt(argument))
|
|
|
|
|
ForkedcallsController::get().kill(strToInt(argument));
|
2003-11-10 09:06:48 +00:00
|
|
|
|
break;
|
2002-02-27 09:59:52 +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
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
case LFUN_EXTERNAL_EDIT:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetExternal().dispatch(view()->cursor(), FuncRequest(action, argument));
|
2003-11-13 13:43:44 +00:00
|
|
|
|
break;
|
2003-06-11 11:01:34 +00:00
|
|
|
|
|
2004-01-15 17:34:44 +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
|
|
|
|
}
|
|
|
|
|
}
|
2001-02-23 16:10:03 +00:00
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (view()->cursor().inTexted())
|
2004-02-03 08:56:28 +00:00
|
|
|
|
view()->owner()->updateLayoutChoice();
|
2003-03-19 18:43:56 +00:00
|
|
|
|
|
|
|
|
|
if (view()->available()) {
|
2003-11-13 13:43:44 +00:00
|
|
|
|
view()->fitCursor();
|
|
|
|
|
view()->update();
|
2004-01-20 14:25:24 +00:00
|
|
|
|
view()->cursor().updatePos();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
// if we executed a mutating lfun, mark the buffer as dirty
|
2004-01-30 11:41:12 +00:00
|
|
|
|
if (!getStatus(cmd).disabled()
|
|
|
|
|
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
|
|
|
|
|
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
|
2003-03-19 18:43:56 +00:00
|
|
|
|
view()->buffer()->markDirty();
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-11 14:45:44 +00:00
|
|
|
|
if (view()->cursor().inTexted())
|
2004-02-03 08:56:28 +00:00
|
|
|
|
sendDispatchMessage(getMessage(), cmd, verbose);
|
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 {
|
2002-08-13 17:43:40 +00:00
|
|
|
|
view()->buffer(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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-07-18 20:15:29 +00:00
|
|
|
|
string const LyXFunc::view_status_message()
|
2001-04-17 15:15:59 +00:00
|
|
|
|
{
|
|
|
|
|
// When meta-fake key is pressed, show the key sequence so far + "M-".
|
|
|
|
|
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.
|
2001-12-03 13:17:04 +00:00
|
|
|
|
if (keyseq.length() > 0 && !keyseq.deleted()) {
|
2002-07-18 20:15:29 +00:00
|
|
|
|
return keyseq.printOptions();
|
2001-04-17 15:15:59 +00:00
|
|
|
|
}
|
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);
|
|
|
|
|
}
|