/* This file is part of
- * ======================================================
- *
+ * ======================================================
+ *
* LyX, The Document Processor
- *
+ *
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
#include "lyxrow.h"
#include "bufferlist.h"
#include "BufferView.h"
-#include "ColorHandler.h"
#include "lyxserver.h"
#include "intl.h"
#include "lyx_main.h"
#include "Lsstream.h"
#include "trans_mgr.h"
#include "layout.h"
-#include "WorkArea.h"
#include "bufferview_funcs.h"
-#include "minibuffer.h"
+#include "frontends/LyXView.h"
+#include "frontends/lyx_gui.h"
#include "vspace.h"
-#include "LyXView.h"
-#include "lyx_gui_misc.h"
#include "FloatList.h"
#include "converter.h"
#include "exporter.h"
#include "importer.h"
-#include "FontLoader.h"
#include "TextCache.h"
#include "lyxfind.h"
#include "undo_funcs.h"
#include "ParagraphParameters.h"
-#include "figureForm.h"
#include "insets/inseturl.h"
#include "insets/insetlatexaccent.h"
#include "frontends/Menubar.h"
#include "frontends/Alert.h"
+#include "graphics/GraphicsCache.h"
+
#include "support/lyxalgo.h"
#include "support/LAssert.h"
#include "support/filetools.h"
#include "support/FileInfo.h"
-#include "support/syscall.h"
+#include "support/forkedcontr.h"
#include "support/lstrings.h"
#include "support/path.h"
#include "support/lyxfunctional.h"
#include <cstdlib>
#include <cctype>
-#include <utility>
-#include <algorithm>
-
+#include <utility>
+#include <algorithm>
using std::pair;
-using std::make_pair;
+using std::make_pair;
using std::endl;
using std::find_if;
+using std::vector;
+using std::transform;
+using std::back_inserter;
extern BufferList bufferlist;
extern LyXServer * lyxserver;
extern bool selection_possible;
-extern void MenuSendto();
extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
-extern void show_symbols_form(LyXFunc *);
-
-extern LyXAction lyxaction;
// (alkis)
extern tex_accent_struct get_accent(kb_action action);
extern void ShowLatexLog();
-#if 0
-
-///
-class MiniBufferController : public SigC::Object {
-public:
- ///
- MiniBufferController() {
- minibuffer
- .cmdReady
- .connect(slot(this,
- &MiniBufferController::receiveCommand));
- minibuffer
- .argReady
- .connect(slot(this,
- &MiniBufferController::receiveArg));
- }
- ///
- void receiveCmd(string const & cmd) {}
- ///
- void receiveArg(string const & arg) {}
-
-
-private:
-};
-
-namespace {
-
-MiniBufferController mb_ctrl;
-
-}
-#endif
-
-
-/* === globals =========================================================== */
-
-// Initialization of static member var
-bool LyXFunc::show_sc = true;
-
-
LyXFunc::LyXFunc(LyXView * o)
: owner(o),
keyseq(toplevel_keymap.get(), toplevel_keymap.get()),
cancel_meta_seq(toplevel_keymap.get(), toplevel_keymap.get())
{
- meta_fake_bit = 0;
+ meta_fake_bit = key_modifier::none;
lyx_dead_action = LFUN_NOACTION;
lyx_calling_dead_action = LFUN_NOACTION;
}
LyXText * LyXFunc::TEXT(bool flag = true) const
{
if (flag)
- return owner->view()->text;
- return owner->view()->getLyXText();
+ return view()->text;
+ return view()->getLyXText();
}
-// I changed this func slightly. I commented out the ...FinishUndo(),
-// this means that all places that used to have a moveCursorUpdate, now
-// have a ...FinishUndo() as the preceeding statement. I have also added
-// a moveCursorUpdate to some of the functions that updated the cursor, but
-// that did not show its new position.
inline
void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
{
if (selecting || TEXT(flag)->selection.mark()) {
- TEXT(flag)->setSelection(owner->view());
+ TEXT(flag)->setSelection(view());
if (TEXT(flag)->bv_owner)
- owner->view()->toggleToggle();
- }
- owner->view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
- owner->view()->showCursor();
-
- /* ---> Everytime the cursor is moved, show the current font state. */
- // should this too me moved out of this func?
- owner->view()->setState();
+ view()->toggleToggle();
+ }
+ view()->update(TEXT(flag), BufferView::SELECT|BufferView::FITCUR);
+ view()->showCursor();
+
+ view()->switchKeyMap();
}
void LyXFunc::handleKeyFunc(kb_action action)
{
- char c = keyseq.getiso();
+ char c = keyseq.getLastKeyEncoded();
if (keyseq.length() > 1) {
c = 0;
}
-
- owner->getIntl()->getTrans()
+
+ owner->getIntl().getTransManager()
.deadkey(c, get_accent(action).accent, TEXT(false));
// Need to clear, in case the minibuffer calls these
// actions
keyseq.clear();
// copied verbatim from do_accent_char
- owner->view()->update(TEXT(false),
+ view()->update(TEXT(false),
BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
TEXT(false)->selection.cursor = TEXT(false)->cursor;
}
-void LyXFunc::processKeySym(KeySym keysym, unsigned int state)
+void LyXFunc::processKeySym(LyXKeySymPtr keysym,
+ key_modifier::state state)
{
string argument;
-
+
if (lyxerr.debugging(Debug::KEY)) {
- char const * tmp = XKeysymToString(keysym);
- string const stm = (tmp ? tmp : "");
lyxerr << "KeySym is "
- << stm
- << "["
- << keysym << "] State is ["
- << state << "]"
+ << keysym->getSymbolName()
<< endl;
}
// Do nothing if we have nothing (JMarc)
- if (keysym == NoSymbol) {
+ if (!keysym->isOK()) {
lyxerr[Debug::KEY] << "Empty kbd action (probably composing)"
<< endl;
return;
}
- // Can we be sure that this will work for all X Window
- // implementations? (Lgb)
- // This code snippet makes lyx ignore some keys. Perhaps
- // all of them should be explictly mentioned?
- if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
- || keysym == XK_Mode_switch || keysym == 0x0) {
+ if (keysym->isModifier()) {
return;
}
-
+
// Do a one-deep top-level lookup for
// cancel and meta-fake keys. RVDK_PATCH_5
cancel_meta_seq.reset();
- int action = cancel_meta_seq.addkey(keysym, state
- &(ShiftMask|ControlMask
- |Mod1Mask));
+ int action = cancel_meta_seq.addkey(keysym, state);
if (lyxerr.debugging(Debug::KEY)) {
lyxerr << "action first set to [" << action << "]" << endl;
}
-
- // When not cancel or meta-fake, do the normal lookup.
+
+ // When not cancel or meta-fake, do the normal lookup.
// Note how the meta_fake Mod1 bit is OR-ed in and reset afterwards.
- // Mostly, meta_fake_bit = 0. RVDK_PATCH_5.
+ // Mostly, meta_fake_bit = key_modifier::none. RVDK_PATCH_5.
if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) {
- if (lyxerr.debugging(Debug::KEY)) {
- lyxerr << "meta_fake_bit is ["
- << meta_fake_bit << "]" << endl;
- }
// remove Caps Lock and Mod2 as a modifiers
- action = keyseq.addkey(keysym,
- (state | meta_fake_bit)
- &(ShiftMask|ControlMask
- |Mod1Mask));
- if (lyxerr.debugging(Debug::KEY)) {
- lyxerr << "action now set to ["
- << action << "]" << endl;
- }
+ action = keyseq.addkey(keysym, (state | meta_fake_bit));
+ lyxerr[Debug::KEY] << "action now set to ["
+ << action << "]" << endl;
}
+
// Dont remove this unless you know what you are doing.
- meta_fake_bit = 0;
-
- // can this happen now ?
+ meta_fake_bit = key_modifier::none;
+
+ // can this happen now ?
if (action == LFUN_NOACTION) {
action = LFUN_PREFIX;
}
// why not return already here if action == -1 and
// num_bytes == 0? (Lgb)
- if (keyseq.length() > 1 && !keyseq.deleted()) {
+ if (keyseq.length() > 1) {
owner->message(keyseq.print());
}
if (action == LFUN_UNKNOWN_ACTION) {
// It is unknown, but what if we remove all
// the modifiers? (Lgb)
- action = keyseq.addkey(keysym, 0);
+ action = keyseq.addkey(keysym, key_modifier::none);
+
+ lyxerr[Debug::KEY] << "Removing modifiers...\n"
+ << "Action now set to ["
+ << action << "]" << endl;
- if (lyxerr.debugging(Debug::KEY)) {
- lyxerr << "Removing modifiers...\n"
- << "Action now set to ["
- << action << "]" << endl;
- }
if (action == LFUN_UNKNOWN_ACTION) {
owner->message(_("Unknown function."));
return;
}
if (action == LFUN_SELFINSERT) {
- // This is very X dependent.
- unsigned int c = keysym;
-
- c = kb_keymap::getiso(c);
+ char c = keysym->getISOEncoded();
+ string argument;
+
+ if (c != 0)
+ argument = c;
- if (c > 0)
- argument = static_cast<char>(c);
+ dispatch(FuncRequest(view(), LFUN_SELFINSERT, argument));
lyxerr[Debug::KEY] << "SelfInsert arg[`"
<< argument << "']" << endl;
+ } else {
+ dispatch(action);
}
-
- bool tmp_sc = show_sc;
- show_sc = false;
- dispatch(action, argument);
- show_sc = tmp_sc;
-
- //return 0;
-}
+}
-func_status::value_type LyXFunc::getStatus(int ac) const
+FuncStatus LyXFunc::getStatus(int ac) const
{
- return getStatus(ac, string());
+ return getStatus(lyxaction.retrieveActionArg(ac));
}
-func_status::value_type LyXFunc::getStatus(int ac,
- string const & not_to_use_arg) const
+
+FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const
{
- kb_action action;
- func_status::value_type flag = func_status::OK;
- string argument;
+ FuncStatus flag;
Buffer * buf = owner->buffer();
-
- if (lyxaction.isPseudoAction(ac))
- action = lyxaction.retrieveActionArg(ac, argument);
- else {
- action = static_cast<kb_action>(ac);
- if (!not_to_use_arg.empty())
- argument = not_to_use_arg; // exept here
- }
-
- if (action == LFUN_UNKNOWN_ACTION) {
- setErrorMessage(N_("Unknown action"));
- return func_status::Unknown;
+
+ if (ev.action == LFUN_NOACTION) {
+ setStatusMessage(N_("Nothing to do"));
+ return flag.disabled(true);
+ }
+
+ if (ev.action == LFUN_UNKNOWN_ACTION) {
+ setStatusMessage(N_("Unknown action"));
+ return flag.unknown(true);
}
-
+
+ // the default error message if we disable the command
+ setStatusMessage(N_("Command disabled"));
+
// Check whether we need a buffer
- if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) {
+ if (!lyxaction.funcHasFlag(ev.action, LyXAction::NoBuffer)) {
// Yes we need a buffer, do we have one?
if (buf) {
// yes
// Can we use a readonly buffer?
- if (buf->isReadonly() &&
- !lyxaction.funcHasFlag(action,
+ if (buf->isReadonly() &&
+ !lyxaction.funcHasFlag(ev.action,
LyXAction::ReadOnly)) {
// no
- setErrorMessage(N_("Document is read-only"));
- flag |= func_status::Disabled;
+ setStatusMessage(N_("Document is read-only"));
+ flag.disabled(true);
}
} else {
// no
- setErrorMessage(N_("Command not allowed with"
+ setStatusMessage(N_("Command not allowed with"
"out any document open"));
- flag |= func_status::Disabled;
- return flag;
+ return flag.disabled(true);
}
}
+ UpdatableInset * tli = view()->theLockingInset();
+
// I would really like to avoid having this switch and rather try to
// encode this in the function itself.
- bool disable = false;
- switch (action) {
+ bool disable = false;
+ switch (ev.action) {
case LFUN_MENUPRINT:
disable = !Exporter::IsExportable(buf, "dvi")
|| lyxrc.print_command == "none";
break;
case LFUN_EXPORT:
- disable = argument == "fax" &&
- !Exporter::IsExportable(buf, argument);
+ disable = ev.argument == "fax" &&
+ !Exporter::IsExportable(buf, ev.argument);
break;
case LFUN_UNDO:
disable = buf->undostack.empty();
case LFUN_REDO:
disable = buf->redostack.empty();
break;
- case LFUN_SPELLCHECK:
- disable = lyxrc.isp_command == "none";
- break;
#ifndef HAVE_LIBAIKSAURUS
case LFUN_THESAURUS_ENTRY:
disable = true;
disable = !Exporter::IsExportable(buf, "program");
break;
+ case LFUN_LAYOUT_CHARACTER:
+ disable = tli && tli->lyxCode() == Inset::ERT_CODE;
+ break;
+
case LFUN_LAYOUT_TABULAR:
- disable = true;
- if (owner->view()->theLockingInset()) {
- disable = (owner->view()->theLockingInset()->lyxCode() != Inset::TABULAR_CODE) &&
- !owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE);
- }
+ disable = !tli
+ || (tli->lyxCode() != Inset::TABULAR_CODE
+ && !tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
break;
+ case LFUN_LAYOUT:
+ case LFUN_LAYOUT_PARAGRAPH: {
+ Inset * inset = TEXT(false)->cursor.par()->inInset();
+ disable = inset && inset->forceDefaultParagraphs(inset);
+ break;
+ }
+
case LFUN_TABULAR_FEATURE:
disable = true;
- if (owner->view()->theLockingInset()) {
- func_status::value_type ret = func_status::Disabled;
- if (owner->view()->theLockingInset()->lyxCode() == Inset::TABULAR_CODE) {
- ret = static_cast<InsetTabular *>
- (owner->view()->theLockingInset())->
- getStatus(argument);
- } else if (owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
+ if (tli) {
+ FuncStatus ret;
+ //ret.disabled(true);
+ if (tli->lyxCode() == Inset::TABULAR_CODE) {
+ ret = static_cast<InsetTabular *>(tli)
+ ->getStatus(ev.argument);
+ } else if (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE)) {
ret = static_cast<InsetTabular *>
- (owner->view()->theLockingInset()->
- getFirstLockingInsetOfType(Inset::TABULAR_CODE))->
- getStatus(argument);
+ (tli->getFirstLockingInsetOfType(Inset::TABULAR_CODE))
+ ->getStatus(ev.argument);
}
flag |= ret;
disable = false;
} else {
static InsetTabular inset(*owner->buffer(), 1, 1);
- func_status::value_type ret;
+ FuncStatus ret;
disable = true;
- ret = inset.getStatus(argument);
- if ((ret & func_status::ToggleOn) ||
- (ret & func_status::ToggleOff))
- flag |= func_status::ToggleOff;
+ ret = inset.getStatus(ev.argument);
+ if (ret.onoff(true) || ret.onoff(false))
+ flag.setOnOff(false);
}
break;
disable = !buf->lyxvc.inUse();
break;
case LFUN_BOOKMARK_GOTO:
- disable = !owner->view()->
- isSavedPosition(strToUnsignedInt(argument));
+ disable = !view()->
+ isSavedPosition(strToUnsignedInt(ev.argument));
break;
-
-
- case LFUN_INSET_TOGGLE:
- disable = (TEXT(false)->getInset() == 0);
+ case LFUN_INSET_TOGGLE: {
+ LyXText * lt = view()->getLyXText();
+ disable = !(isEditableInset(lt->getInset())
+ || (lt->inset_owner
+ && lt->inset_owner->owner()
+ && lt->inset_owner->owner()->isOpen()));
break;
-
- case LFUN_MATH_VALIGN: {
- // I think this test can be simplified (Andre')
- // mathcursor is != 0 iff we are in math mode
- //Inset * tli = owner->view()->theLockingInset();
- //if (tli && (tli->lyxCode() == Inset::MATH_CODE
- // || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
- //
+ }
+ case LFUN_LATEX_LOG:
+ disable = !IsFileReadable(buf->getLogName().second);
+ break;
+ case LFUN_MATH_VALIGN:
if (mathcursor) {
char align = mathcursor->valign();
if (align == '\0') {
disable = true;
break;
}
- if (argument.empty()) {
- flag = func_status::OK;
+ if (ev.argument.empty()) {
+ flag.clear();
break;
}
- if (!contains("tcb", argument[0])) {
+ if (!contains("tcb", ev.argument[0])) {
disable = true;
break;
}
- func_status::toggle(flag, argument[0] == align);
+ flag.setOnOff(ev.argument[0] == align);
} else
disable = true;
break;
- }
- case LFUN_MATH_HALIGN: {
- //Inset * tli = owner->view()->theLockingInset();
- //if (tli && (tli->lyxCode() == Inset::MATH_CODE
- // || tli->lyxCode() == Inset::MATHMACRO_CODE)) {
+
+ case LFUN_MATH_HALIGN:
if (mathcursor) {
char align = mathcursor->halign();
if (align == '\0') {
disable = true;
break;
}
- if (argument.empty()) {
- flag = func_status::OK;
+ if (ev.argument.empty()) {
+ flag.clear();
break;
}
- if (!contains("lcr", argument[0])) {
+ if (!contains("lcr", ev.argument[0])) {
disable = true;
break;
}
- func_status::toggle(flag, argument[0] == align);
+ flag.setOnOff(ev.argument[0] == align);
} else
disable = true;
break;
- }
- case LFUN_MATH_MUTATE: {
- Inset * tli = owner->view()->theLockingInset();
- if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
- MathInsetTypes type = mathcursor->formula()->getType();
- if (argument == "inline") {
- func_status::toggle(flag, type == LM_OT_SIMPLE);
- } else if (argument == "display") {
- func_status::toggle(flag, type == LM_OT_EQUATION);
- } else if (argument == "eqnarray") {
- func_status::toggle(flag, type == LM_OT_EQNARRAY);
- } else if (argument == "align") {
- func_status::toggle(flag, type == LM_OT_ALIGN);
- } else {
- disable = true;
- }
- } else
+
+ case LFUN_MATH_MUTATE:
+ if (mathcursor)
+ //flag.setOnOff(mathcursor->formula()->hullType() == ev.argument);
+ flag.setOnOff(false);
+ else
disable = true;
break;
- }
// we just need to be in math mode to enable that
- case LFUN_MATH_SIZE:
+ case LFUN_MATH_SIZE:
case LFUN_MATH_SPACE:
- case LFUN_MATH_LIMITS:
- case LFUN_MATH_NONUMBER:
+ case LFUN_MATH_LIMITS:
+ case LFUN_MATH_NONUMBER:
case LFUN_MATH_NUMBER:
- case LFUN_SUBSCRIPT:
- case LFUN_SUPERSCRIPT:
+ case LFUN_MATH_EXTERN:
disable = !mathcursor;
break;
// we need to be math mode and a math array for that
// Hack: halign produces non-zero result iff we are in a math array
- case LFUN_MATH_ROW_INSERT:
- case LFUN_MATH_ROW_DELETE:
- case LFUN_MATH_COLUMN_INSERT:
- case LFUN_MATH_COLUMN_DELETE:
+ case LFUN_MATH_ROW_INSERT:
+ case LFUN_MATH_ROW_DELETE:
+ case LFUN_MATH_COLUMN_INSERT:
+ case LFUN_MATH_COLUMN_DELETE:
disable = !mathcursor || !mathcursor->halign();
break;
// the functions which insert insets
Inset::Code code = Inset::NO_CODE;
- switch (action) {
- case LFUN_INSET_TEXT:
- code = Inset::TEXT_CODE;
- break;
+ switch (ev.action) {
case LFUN_INSET_ERT:
- code = Inset::ERT_CODE;
+ code = Inset::ERT_CODE;
break;
- case LFUN_FIGURE:
case LFUN_INSET_GRAPHICS:
code = Inset::GRAPHICS_CODE;
break;
case LFUN_INSET_FOOTNOTE:
code = Inset::FOOT_CODE;
break;
- case LFUN_DIALOG_TABULAR_INSERT:
- case LFUN_INSET_TABULAR:
+ case LFUN_TABULAR_INSERT:
code = Inset::TABULAR_CODE;
break;
case LFUN_INSET_EXTERNAL:
code = Inset::CAPTION_CODE;
break;
case LFUN_INSERT_NOTE:
- code = Inset::IGNORE_CODE;
+ code = Inset::NOTE_CODE;
break;
case LFUN_INSERT_LABEL:
code = Inset::LABEL_CODE;
code = Inset::BIBTEX_CODE;
break;
case LFUN_INDEX_INSERT:
- case LFUN_INDEX_INSERT_LAST:
- case LFUN_INDEX_CREATE:
code = Inset::INDEX_CODE;
break;
case LFUN_INDEX_PRINT:
case LFUN_MENU_SEPARATOR:
case LFUN_LDOTS:
case LFUN_END_OF_SENTENCE:
- case LFUN_PROTECTEDSPACE:
code = Inset::SPECIALCHAR_CODE;
break;
+ case LFUN_PROTECTEDSPACE:
+ // slight hack: we know this is allowed in math mode
+ if (!mathcursor)
+ code = Inset::SPECIALCHAR_CODE;
+ break;
default:
break;
}
- if (code != Inset::NO_CODE
- && owner->view()->theLockingInset()
- && !owner->view()->theLockingInset()->insetAllowed(code)) {
+ if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) {
disable = true;
}
if (disable)
- flag |= func_status::Disabled;
-
+ flag.disabled(true);
+
// A few general toggles
- switch (action) {
+ switch (ev.action) {
+ case LFUN_TOOLTIPS_TOGGLE:
+ flag.setOnOff(owner->getDialogs().tooltipsEnabled());
+ break;
+
case LFUN_READ_ONLY_TOGGLE:
- func_status::toggle(flag, buf->isReadonly());
+ flag.setOnOff(buf->isReadonly());
break;
case LFUN_APPENDIX:
- func_status::toggle(flag, TEXT(false)->cursor.par()->params().startOfAppendix());
+ flag.setOnOff(TEXT(false)->cursor.par()->params().startOfAppendix());
+ break;
+ case LFUN_SWITCHBUFFER:
+ // toggle on the current buffer, but do not toggle off
+ // the other ones (is that a good idea?)
+ if (ev.argument == buf->fileName())
+ flag.setOnOff(true);
break;
default:
break;
// the font related toggles
if (!mathcursor) {
LyXFont const & font = TEXT(false)->real_current_font;
- switch (action) {
+ switch (ev.action) {
case LFUN_EMPH:
- func_status::toggle(flag, font.emph() == LyXFont::ON);
+ flag.setOnOff(font.emph() == LyXFont::ON);
break;
case LFUN_NOUN:
- func_status::toggle(flag, font.noun() == LyXFont::ON);
+ flag.setOnOff(font.noun() == LyXFont::ON);
break;
case LFUN_BOLD:
- func_status::toggle(flag, font.series() == LyXFont::BOLD_SERIES);
+ flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
break;
case LFUN_SANS:
- func_status::toggle(flag, font.family() == LyXFont::SANS_FAMILY);
+ flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
break;
case LFUN_ROMAN:
- func_status::toggle(flag, font.family() == LyXFont::ROMAN_FAMILY);
+ flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
break;
case LFUN_CODE:
- func_status::toggle(flag, font.family() == LyXFont::TYPEWRITER_FAMILY);
+ flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
break;
default:
break;
}
- }
-#if 0
- else {
- MathTextCodes tc = mathcursor->getLastCode();
- switch (action) {
+ } else {
+ string tc = mathcursor->getLastCode();
+ switch (ev.action) {
case LFUN_BOLD:
- func_status::toggle(flag, tc == LM_TC_BF);
+ flag.setOnOff(tc == "mathbf");
break;
case LFUN_SANS:
- func_status::toggle(flag, tc == LM_TC_SF);
+ flag.setOnOff(tc == "mathsf");
break;
case LFUN_EMPH:
- func_status::toggle(flag, tc == LM_TC_CAL);
+ flag.setOnOff(tc == "mathcal");
break;
case LFUN_ROMAN:
- func_status::toggle(flag, tc == LM_TC_RM);
+ flag.setOnOff(tc == "mathrm");
break;
case LFUN_CODE:
- func_status::toggle(flag, tc == LM_TC_TT);
+ flag.setOnOff(tc == "mathtt");
break;
case LFUN_NOUN:
- func_status::toggle(flag, tc == LM_TC_BB);
+ flag.setOnOff(tc == "mathbb");
break;
case LFUN_DEFAULT:
- func_status::toggle(flag, tc == LM_TC_VAR);
+ flag.setOnOff(tc == "mathnormal");
break;
default:
break;
}
}
- #endif
-
- return flag;
-}
-
-// temporary dispatch method
-void LyXFunc::miniDispatch(string const & s)
-{
- string s2(frontStrip(strip(s)));
-
- if (!s2.empty()) {
- dispatch(s2);
+ // this one is difficult to get right. As a half-baked
+ // solution, we consider only the first action of the sequence
+ if (ev.action == LFUN_SEQUENCE) {
+ // argument contains ';'-terminated commands
+ flag = getStatus(lyxaction.LookupFunc(token(ev.argument, ';', 0)));
}
+
+ return flag;
}
-string const LyXFunc::dispatch(string const & s)
+void LyXFunc::dispatch(string const & s, bool verbose)
{
- // Split command string into command and argument
- string cmd;
- string line = frontStrip(s);
- string const arg = strip(frontStrip(split(line, cmd, ' ')));
+ int const action = lyxaction.LookupFunc(s);
- int action = lyxaction.LookupFunc(cmd);
-
if (action == LFUN_UNKNOWN_ACTION) {
string const msg = string(_("Unknown function ("))
- + cmd + ")";
+ + s + ")";
owner->message(msg);
- return string();
- } else {
- return dispatch(action, arg);
- }
+ return;
+ }
+
+ dispatch(action, verbose);
}
-string const LyXFunc::dispatch(int ac,
- string const & do_not_use_this_arg)
+void LyXFunc::dispatch(int ac, bool verbose)
{
- lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac
- <<"] arg[" << do_not_use_this_arg << "]" << endl;
-
- string argument;
- kb_action action;
-
- // we have not done anything wrong yet.
- errorstat = false;
+ dispatch(lyxaction.retrieveActionArg(ac), verbose);
+}
+
+
+
+void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
+{
+ lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << ev.action
+ <<"] arg[" << ev.argument << "]" << endl;
+
+ // we have not done anything wrong yet.
+ errorstat = false;
dispatch_buffer.erase();
-
- // if action is a pseudo-action, we need the real action
- if (lyxaction.isPseudoAction(ac)) {
- string tmparg;
- action = static_cast<kb_action>
- (lyxaction.retrieveActionArg(ac, tmparg));
- if (!tmparg.empty())
- argument = tmparg;
- } else {
- action = static_cast<kb_action>(ac);
- if (!do_not_use_this_arg.empty())
- argument = do_not_use_this_arg; // except here
- }
-
#ifdef NEW_DISPATCHER
// We try do call the most specific dispatcher first:
// 1. the lockinginset's dispatch
// 2. the bufferview's dispatch
// 3. the lyxview's dispatch
#endif
-
+
selection_possible = false;
-
- if (owner->view()->available())
- owner->view()->hideCursor();
+
+ if (view()->available())
+ view()->hideCursor();
+
+ string argument = ev.argument;
+ kb_action action = ev.action;
// We cannot use this function here
- if (getStatus(ac, do_not_use_this_arg) & func_status::Disabled) {
- lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: "
- << lyxaction.getActionName(ac)
- << " [" << ac << "] is disabled at this location"
+ if (getStatus(ev).disabled()) {
+ lyxerr[Debug::ACTION] << "LyXFunc::dispatch: "
+ << lyxaction.getActionName(action)
+ << " [" << action << "] is disabled at this location"
<< endl;
+ setErrorMessage(getStatusMessage());
goto exit_with_message;
}
- if (owner->view()->available() && owner->view()->theLockingInset()) {
- UpdatableInset::RESULT result;
+ if (view()->available() && view()->theLockingInset()) {
+ Inset::RESULT result;
if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
(!keyseq.deleted())))
{
- if ((action==LFUN_UNKNOWN_ACTION) && argument.empty()){
- argument = keyseq.getiso();
+ UpdatableInset * inset = view()->theLockingInset();
+#if 1
+ int inset_x;
+ int dummy_y;
+ inset->getCursorPos(view(), inset_x, dummy_y);
+#endif
+ if ((action == LFUN_UNKNOWN_ACTION)
+ && argument.empty()) {
+ argument = keyseq.getLastKeyEncoded();
}
// Undo/Redo is a bit tricky for insets.
if (action == LFUN_UNDO) {
- owner->view()->menuUndo();
- return string();
+ view()->menuUndo();
+ goto exit_with_message;
} else if (action == LFUN_REDO) {
- owner->view()->menuRedo();
- return string();
- } else if (((result=owner->view()->theLockingInset()->
- localDispatch(owner->view(), action, argument)) ==
- UpdatableInset::DISPATCHED) ||
- (result == UpdatableInset::DISPATCHED_NOUPDATE))
- return string();
+ view()->menuRedo();
+ goto exit_with_message;
+ } else if (((result=inset->
+ // Hand-over to inset's own dispatch:
+ localDispatch(FuncRequest(view(), action, argument))) ==
+ UpdatableInset::DISPATCHED) ||
+ (result == UpdatableInset::DISPATCHED_NOUPDATE))
+ goto exit_with_message;
+ // If UNDISPATCHED, just soldier on
else if (result == UpdatableInset::FINISHED) {
- if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
- TEXT()->cursorRight(owner->view());
- moveCursorUpdate(true, false);
- owner->showState();
- }
- return string();
+ goto exit_with_message;
+ // We do not need special RTL handling here:
+ // FINISHED means that the cursor should be
+ // one position after the inset.
} else if (result == UpdatableInset::FINISHED_RIGHT) {
- if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
- TEXT()->cursorRight(owner->view());
- moveCursorUpdate(true, false);
- owner->showState();
- }
- return string();
+ TEXT()->cursorRight(view());
+ moveCursorUpdate(true, false);
+ owner->view_state_changed();
+ goto exit_with_message;
} else if (result == UpdatableInset::FINISHED_UP) {
- if (TEXT()->cursor.row()->previous()) {
- TEXT()->cursorUp(owner->view());
+ if (TEXT()->cursor.irow()->previous()) {
+#if 1
+ TEXT()->setCursorFromCoordinates(
+ view(), TEXT()->cursor.ix() + inset_x,
+ TEXT()->cursor.iy() -
+ TEXT()->cursor.irow()->baseline() - 1);
+ TEXT()->cursor.x_fix(TEXT()->cursor.x());
+#else
+ TEXT()->cursorUp(view());
+#endif
moveCursorUpdate(true, false);
- owner->showState();
+ owner->view_state_changed();
+ } else {
+ view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
}
- return string();
+ goto exit_with_message;
} else if (result == UpdatableInset::FINISHED_DOWN) {
- if (TEXT()->cursor.row()->next())
- TEXT()->cursorDown(owner->view());
- else
- TEXT()->cursorRight(owner->view());
+ if (TEXT()->cursor.irow()->next()) {
+#if 1
+ TEXT()->setCursorFromCoordinates(
+ view(), TEXT()->cursor.ix() + inset_x,
+ TEXT()->cursor.iy() -
+ TEXT()->cursor.irow()->baseline() +
+ TEXT()->cursor.irow()->height() + 1);
+ TEXT()->cursor.x_fix(TEXT()->cursor.x());
+#else
+ TEXT()->cursorDown(view());
+#endif
+ } else {
+ TEXT()->cursorRight(view());
+ }
moveCursorUpdate(true, false);
- owner->showState();
- return string();
- } else {
+ owner->view_state_changed();
+ goto exit_with_message;
+ }
+#warning I am not sure this is still right, please have a look! (Jug 20020417)
+ else { // result == UNDISPATCHED
//setMessage(N_("Text mode"));
switch (action) {
case LFUN_UNKNOWN_ACTION:
case LFUN_BREAKPARAGRAPH:
case LFUN_BREAKLINE:
- TEXT()->cursorRight(owner->view());
- owner->view()->setState();
- owner->showState();
+ TEXT()->cursorRight(view());
+ view()->switchKeyMap();
+ owner->view_state_changed();
break;
case LFUN_RIGHT:
if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
- TEXT()->cursorRight(owner->view());
+ TEXT()->cursorRight(view());
moveCursorUpdate(true, false);
- owner->showState();
+ owner->view_state_changed();
}
- return string();
- case LFUN_LEFT:
+ goto exit_with_message;
+ case LFUN_LEFT:
if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
- TEXT()->cursorRight(owner->view());
+ TEXT()->cursorRight(view());
moveCursorUpdate(true, false);
- owner->showState();
+ owner->view_state_changed();
}
- return string();
+ goto exit_with_message;
case LFUN_DOWN:
if (TEXT()->cursor.row()->next())
- TEXT()->cursorDown(owner->view());
+ TEXT()->cursorDown(view());
else
- TEXT()->cursorRight(owner->view());
+ TEXT()->cursorRight(view());
moveCursorUpdate(true, false);
- owner->showState();
- return string();
+ owner->view_state_changed();
+ goto exit_with_message;
default:
break;
}
}
switch (action) {
-
+
case LFUN_ESCAPE:
{
- if (!owner->view()->available()) break;
-
+ if (!view()->available()) break;
// this function should be used always [asierra060396]
UpdatableInset * tli =
- owner->view()->theLockingInset();
+ view()->theLockingInset();
if (tli) {
UpdatableInset * lock = tli->getLockingInset();
-
+
if (tli == lock) {
- owner->view()->unlockInset(tli);
- TEXT()->cursorRight(owner->view());
+ view()->unlockInset(tli);
+ TEXT()->cursorRight(view());
moveCursorUpdate(true, false);
- owner->showState();
+ owner->view_state_changed();
} else {
- tli->unlockInsetInInset(owner->view(),
+ tli->unlockInsetInInset(view(),
lock,
true);
}
+ finishUndo();
+ // Tell the paragraph dialog that we changed paragraph
+ owner->getDialogs().updateParagraph();
}
}
break;
-
+
// --- Misc -------------------------------------------
- case LFUN_WORDFINDFORWARD :
+ case LFUN_WORDFINDFORWARD :
case LFUN_WORDFINDBACKWARD : {
static string last_search;
string searched_string;
-
+
if (!argument.empty()) {
last_search = argument;
searched_string = argument;
}
bool fw = (action == LFUN_WORDFINDBACKWARD);
if (!searched_string.empty()) {
- LyXFind(owner->view(), searched_string, fw);
+ lyxfind::LyXFind(view(), searched_string, fw);
}
-// owner->view()->showCursor();
+// view()->showCursor();
}
break;
-
+
case LFUN_PREFIX:
{
- if (owner->view()->available() && !owner->view()->theLockingInset()) {
- owner->view()->update(TEXT(),
+ if (view()->available() && !view()->theLockingInset()) {
+ view()->update(TEXT(),
BufferView::SELECT|BufferView::FITCUR);
}
- owner->message(keyseq.print());
+ owner->message(keyseq.printOptions());
}
break;
// --- Misc -------------------------------------------
case LFUN_EXEC_COMMAND:
- {
- std::vector<string> allCmds;
- std::transform(lyxaction.func_begin(), lyxaction.func_end(),
- std::back_inserter(allCmds), lyx::firster());
- static std::vector<string> hist;
- owner->getMiniBuffer()->getString(MiniBuffer::spaces,
- allCmds, hist);
- }
- break;
-
+ owner->focus_command_buffer();
+ break;
+
case LFUN_CANCEL: // RVDK_PATCH_5
keyseq.reset();
- meta_fake_bit = 0;
- if (owner->view()->available())
+ meta_fake_bit = key_modifier::none;
+ if (view()->available())
// cancel any selection
dispatch(LFUN_MARK_OFF);
setMessage(N_("Cancel"));
case LFUN_META_FAKE: // RVDK_PATCH_5
{
- meta_fake_bit = Mod1Mask;
+ meta_fake_bit = key_modifier::alt;
setMessage(keyseq.print());
}
- break;
+ break;
case LFUN_READ_ONLY_TOGGLE:
if (owner->buffer()->lyxvc.inUse()) {
!owner->buffer()->isReadonly());
}
break;
-
+
case LFUN_CENTER: // this is center and redraw.
- owner->view()->center();
+ view()->center();
break;
-
+
// --- Menus -----------------------------------------------
case LFUN_MENUNEW:
- menuNew(false);
+ menuNew(argument, false);
break;
-
+
case LFUN_MENUNEWTMPLT:
- menuNew(true);
+ menuNew(argument, true);
break;
-
+
case LFUN_CLOSEBUFFER:
closeBuffer();
break;
-
+
case LFUN_MENUWRITE:
if (!owner->buffer()->isUnnamed()) {
ostringstream s1;
s1 << _("Saving document") << ' '
<< MakeDisplayPath(owner->buffer()->fileName() + "...");
owner->message(s1.str().c_str());
- MenuWrite(owner->view(), owner->buffer());
+ MenuWrite(view(), owner->buffer());
+ s1 << _(" done.");
+ owner->message(s1.str().c_str());
} else
- WriteAs(owner->view(), owner->buffer());
+ WriteAs(view(), owner->buffer());
break;
-
+
case LFUN_WRITEAS:
- WriteAs(owner->view(), owner->buffer(), argument);
+ WriteAs(view(), owner->buffer(), argument);
break;
-
+
case LFUN_MENURELOAD:
reloadBuffer();
break;
-
+
case LFUN_UPDATE:
Exporter::Export(owner->buffer(), argument, true);
break;
case LFUN_PREVIEW:
Exporter::Preview(owner->buffer(), argument);
break;
-
- case LFUN_BUILDPROG:
+
+ case LFUN_BUILDPROG:
Exporter::Export(owner->buffer(), "program", true);
- break;
-
- case LFUN_RUNCHKTEX:
+ break;
+
+ case LFUN_RUNCHKTEX:
MenuRunChktex(owner->buffer());
break;
-
+
case LFUN_MENUPRINT:
- owner->getDialogs()->showPrint();
+ owner->getDialogs().showPrint();
break;
case LFUN_EXPORT:
if (argument == "custom")
- MenuSendto();
+ owner->getDialogs().showSendto();
else
Exporter::Export(owner->buffer(), argument, false);
break;
case LFUN_IMPORT:
doImport(argument);
break;
-
+
case LFUN_QUIT:
QuitLyX();
break;
-
+
case LFUN_TOCVIEW:
#if 0
case LFUN_LOFVIEW:
#endif
p.setCmdName("tableofcontents");
#if 0
- else if (action == LFUN_LOAVIEW )
+ else if (action == LFUN_LOAVIEW)
p.setCmdName("listof{algorithm}{List of Algorithms}");
else if (action == LFUN_LOFVIEW)
p.setCmdName("listoffigures");
else
p.setCmdName("listoftables");
#endif
- owner->getDialogs()->createTOC(p.getAsString());
- break;
- }
-
- case LFUN_DIALOG_TABULAR_INSERT:
- owner->getDialogs()->showTabularCreate();
- break;
-
- case LFUN_FIGURE:
- Figure();
+ owner->getDialogs().createTOC(p.getAsString());
break;
+ }
case LFUN_AUTOSAVE:
- AutoSave(owner->view());
+ AutoSave(view());
break;
-
+
case LFUN_UNDO:
- owner->view()->menuUndo();
+ view()->menuUndo();
break;
-
+
case LFUN_REDO:
- owner->view()->menuRedo();
+ view()->menuRedo();
break;
-
+
case LFUN_MENUSEARCH:
- owner->getDialogs()->showSearch();
+ owner->getDialogs().showSearch();
break;
-
+
case LFUN_REMOVEERRORS:
- if (owner->view()->removeAutoInsets()) {
- owner->view()->redraw();
- owner->view()->fitCursor();
+ if (view()->removeAutoInsets()) {
+#warning repaint() or update() or nothing ?
+ view()->repaint();
+ view()->fitCursor();
}
break;
- case LFUN_DEPTH:
- changeDepth(owner->view(), TEXT(false), 0);
- break;
-
case LFUN_DEPTH_MIN:
- changeDepth(owner->view(), TEXT(false), -1);
+ changeDepth(view(), TEXT(false), -1);
break;
-
+
case LFUN_DEPTH_PLUS:
- changeDepth(owner->view(), TEXT(false), 1);
+ changeDepth(view(), TEXT(false), 1);
break;
-
+
case LFUN_FREE:
- owner->getDialogs()->setUserFreeFont();
+ owner->getDialogs().setUserFreeFont();
break;
case LFUN_RECONFIGURE:
- Reconfigure(owner->view());
+ Reconfigure(view());
break;
#if 0
case LFUN_FLOATSOPERATE:
if (argument == "openfoot")
- owner->view()->allFloats(1,0);
+ view()->allFloats(1,0);
else if (argument == "closefoot")
- owner->view()->allFloats(0,0);
+ view()->allFloats(0,0);
else if (argument == "openfig")
- owner->view()->allFloats(1,1);
+ view()->allFloats(1,1);
else if (argument == "closefig")
- owner->view()->allFloats(0,1);
+ view()->allFloats(0,1);
break;
#else
#ifdef WITH_WARNINGS
#endif
#endif
case LFUN_HELP_ABOUTLYX:
- owner->getDialogs()->showAboutlyx();
+ owner->getDialogs().showAboutlyx();
break;
case LFUN_HELP_TEXINFO:
- owner->getDialogs()->showTexinfo();
+ owner->getDialogs().showTexinfo();
break;
- case LFUN_HELP_OPEN:
+ case LFUN_HELP_OPEN:
{
string const arg = argument;
if (arg.empty()) {
str << _("Opening help file") << ' '
<< MakeDisplayPath(fname) << "...";
owner->message(str.str().c_str());
- owner->view()->buffer(bufferlist.loadLyXFile(fname, false));
+ view()->buffer(bufferlist.loadLyXFile(fname, false));
owner->allowInput();
break;
- }
+ }
// --- version control -------------------------------
case LFUN_VC_REGISTER:
owner->buffer()->lyxvc.registrer();
}
break;
-
+
case LFUN_VC_CHECKIN:
{
if (owner->buffer()->lyxvc.inUse()
owner->buffer()->lyxvc.checkIn();
}
break;
-
+
case LFUN_VC_CHECKOUT:
{
if (owner->buffer()->lyxvc.inUse()
owner->buffer()->lyxvc.checkOut();
}
break;
-
+
case LFUN_VC_REVERT:
{
owner->buffer()->lyxvc.revert();
}
break;
-
+
case LFUN_VC_UNDO:
{
owner->buffer()->lyxvc.undoLast();
}
break;
-
+
case LFUN_VC_HISTORY:
{
- owner->getDialogs()->showVCLogFile();
+ owner->getDialogs().showVCLogFile();
break;
}
-
+
// --- buffers ----------------------------------------
- case LFUN_SWITCHBUFFER:
- owner->view()->buffer(bufferlist.getBuffer(argument));
+ case LFUN_SWITCHBUFFER:
+ view()->buffer(bufferlist.getBuffer(argument));
break;
case LFUN_FILE_NEW:
{
// servercmd: argument must be <file>:<template>
- Buffer * tmpbuf = NewLyxFile(argument);
+ Buffer * tmpbuf = NewFile(argument);
if (tmpbuf)
- owner->view()->buffer(tmpbuf);
+ view()->buffer(tmpbuf);
}
break;
-
+
case LFUN_FILE_OPEN:
open(argument);
break;
case LFUN_LATEX_LOG:
- owner->getDialogs()->showLogFile();
+ owner->getDialogs().showLogFile();
break;
-
+
case LFUN_LAYOUT_DOCUMENT:
- owner->getDialogs()->showDocument();
+ owner->getDialogs().showDocument();
break;
-
+
case LFUN_LAYOUT_PARAGRAPH:
- owner->getDialogs()->showParagraph();
+ owner->getDialogs().showParagraph();
break;
-
+
case LFUN_LAYOUT_CHARACTER:
- owner->getDialogs()->showCharacter();
+ owner->getDialogs().showCharacter();
break;
case LFUN_LAYOUT_TABULAR:
- if (owner->view()->theLockingInset()) {
- if (owner->view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
+ if (view()->theLockingInset()) {
+ if (view()->theLockingInset()->lyxCode()==Inset::TABULAR_CODE) {
InsetTabular * inset = static_cast<InsetTabular *>
- (owner->view()->theLockingInset());
- inset->openLayoutDialog(owner->view());
- } else if (owner->view()->theLockingInset()->
+ (view()->theLockingInset());
+ inset->openLayoutDialog(view());
+ } else if (view()->theLockingInset()->
getFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) {
InsetTabular * inset = static_cast<InsetTabular *>(
- owner->view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
- inset->openLayoutDialog(owner->view());
+ view()->theLockingInset()->getFirstLockingInsetOfType(Inset::TABULAR_CODE));
+ inset->openLayoutDialog(view());
}
}
break;
case LFUN_LAYOUT_PREAMBLE:
- owner->getDialogs()->showPreamble();
+ owner->getDialogs().showPreamble();
break;
-
+
case LFUN_DROP_LAYOUTS_CHOICE:
- owner->getToolbar()->openLayoutList();
+ owner->getToolbar().openLayoutList();
break;
case LFUN_MENU_OPEN_BY_NAME:
- owner->getMenubar()->openByName(argument);
+ owner->getMenubar().openByName(argument);
break; // RVDK_PATCH_5
-
+
case LFUN_SPELLCHECK:
- if (lyxrc.isp_command != "none")
- owner->getDialogs()->showSpellchecker();
+ owner->getDialogs().showSpellchecker();
break;
-
+
// --- lyxserver commands ----------------------------
<< owner->buffer()->fileName()
<< "] " << endl;
break;
-
+
case LFUN_NOTIFY:
{
dispatch_buffer = keyseq.print();
// Either change buffer or load the file
if (bufferlist.exists(s)) {
- owner->view()->buffer(bufferlist.getBuffer(s));
+ view()->buffer(bufferlist.getBuffer(s));
} else {
- owner->view()->buffer(bufferlist.loadLyXFile(s));
+ view()->buffer(bufferlist.loadLyXFile(s));
}
-
- // Set the cursor
- owner->view()->setCursorFromRow(row);
- // Recenter screen
- owner->view()->center();
+ view()->setCursorFromRow(row);
+
+ view()->center();
+ // see BufferView_pimpl::center()
+ view()->updateScrollbar();
}
break;
case LFUN_GOTO_PARAGRAPH:
{
- istringstream istr(argument.c_str());
+ istringstream istr(argument.c_str());
int id;
istr >> id;
Paragraph * par = owner->buffer()->getParFromID(id);
if (par == 0) {
lyxerr[Debug::INFO] << "No matching paragraph found! ["
- << id << "]" << std::endl;
+ << id << "]" << endl;
break;
} else {
- lyxerr << "Paragraph " << par->id()
- << " found." << endl;
+ lyxerr[Debug::INFO] << "Paragraph " << par->id()
+ << " found." << endl;
}
+ if (view()->theLockingInset())
+ view()->unlockInset(view()->theLockingInset());
+ if (par->inInset()) {
+ par->inInset()->edit(view());
+ }
// Set the cursor
- owner->view()->text->setCursor(owner->view(), par, 0);
- owner->view()->setState();
- owner->showState();
+ view()->getLyXText()->setCursor(view(), par, 0);
+ view()->switchKeyMap();
+ owner->view_state_changed();
- // Recenter screen
- owner->view()->center();
+ view()->center();
+ // see BufferView_pimpl::center()
+ view()->updateScrollbar();
}
break;
}
break;
- // --- toolbar ----------------------------------
- case LFUN_PUSH_TOOLBAR:
- {
- int nth = strToInt(argument);
- if (nth <= 0) {
- setErrorMessage(N_("Push-toolbar needs argument > 0"));
- } else {
- owner->getToolbar()->push(nth);
- }
- }
- break;
-
- case LFUN_ADD_TO_TOOLBAR:
- {
- if (lyxerr.debugging(Debug::GUI)) {
- lyxerr << "LFUN_ADD_TO_TOOLBAR:"
- "argument = `" << argument << '\'' << endl;
- }
- string tmp(argument);
- //lyxerr <<string("Argument: ") + argument);
- //lyxerr <<string("Tmp : ") + tmp);
- if (tmp.empty()) {
- setErrorMessage(N_("Usage: toolbar-add-to <LyX command>"));
- } else {
- owner->getToolbar()->add(argument, false);
- owner->getToolbar()->set();
- }
- }
- break;
-
// --- insert characters ----------------------------------------
// --- Mathed stuff. If we are here, there is no locked inset yet.
case LFUN_MATH_NUMBER:
case LFUN_MATH_NONUMBER:
case LFUN_MATH_LIMITS:
- case LFUN_SUBSCRIPT:
- case LFUN_SUPERSCRIPT:
{
setErrorMessage(N_("This is only allowed in math mode!"));
}
break;
+ // passthrough hat and underscore outside mathed:
+ case LFUN_SUBSCRIPT:
+ dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
+ break;
+ case LFUN_SUPERSCRIPT:
+ dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
+ break;
+
case LFUN_MATH_PANEL:
- owner->getDialogs()->showMathPanel();
+ owner->getDialogs().showMathPanel();
break;
-
+
case LFUN_CITATION_CREATE:
{
- InsetCommandParams p( "cite" );
-
+ InsetCommandParams p("cite");
+
if (!argument.empty()) {
// This should be set at source, ie when typing
// "citation-insert foo" in the minibuffer.
// Question: would pybibliographer also need to be
// changed. Suspect so. Leave as-is therefore.
if (contains(argument, "|")) {
- p.setContents( token(argument, '|', 0) );
- p.setOptions( token(argument, '|', 1) );
+ p.setContents(token(argument, '|', 0));
+ p.setOptions(token(argument, '|', 1));
} else {
- p.setContents( argument );
+ p.setContents(argument);
}
- dispatch(LFUN_CITATION_INSERT, p.getAsString());
+ dispatch(FuncRequest(view(), LFUN_CITATION_INSERT, p.getAsString()));
} else
- owner->getDialogs()->createCitation( p.getAsString() );
+ owner->getDialogs().createCitation(p.getAsString());
}
break;
-
+
case LFUN_CHILDOPEN:
{
string const filename =
- MakeAbsPath(argument,
- OnlyPath(owner->buffer()->fileName()));
+ MakeAbsPath(argument,
+ owner->buffer()->filePath());
setMessage(N_("Opening child document ") +
MakeDisplayPath(filename) + "...");
- owner->view()->savePosition(0);
+ view()->savePosition(0);
if (bufferlist.exists(filename))
- owner->view()->buffer(bufferlist.getBuffer(filename));
+ view()->buffer(bufferlist.getBuffer(filename));
else
- owner->view()->buffer(bufferlist.loadLyXFile(filename));
+ view()->buffer(bufferlist.loadLyXFile(filename));
}
break;
case LFUN_TOGGLECURSORFOLLOW:
lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
break;
-
+
case LFUN_KMAP_OFF: // keymap off
- owner->getIntl()->KeyMapOn(false);
+ owner->getIntl().KeyMapOn(false);
break;
-
+
case LFUN_KMAP_PRIM: // primary keymap
- owner->getIntl()->KeyMapPrim();
+ owner->getIntl().KeyMapPrim();
break;
-
+
case LFUN_KMAP_SEC: // secondary keymap
- owner->getIntl()->KeyMapSec();
+ owner->getIntl().KeyMapSec();
break;
-
+
case LFUN_KMAP_TOGGLE: // toggle keymap
- owner->getIntl()->ToggleKeyMap();
+ owner->getIntl().ToggleKeyMap();
break;
- case LFUN_SEQUENCE:
+ case LFUN_SEQUENCE:
{
// argument contains ';'-terminated commands
- while (argument.find(';') != string::npos) {
+ while (!argument.empty()) {
string first;
argument = split(argument, first, ';');
dispatch(first);
break;
case LFUN_DIALOG_PREFERENCES:
- owner->getDialogs()->showPreferences();
+ owner->getDialogs().showPreferences();
break;
-
+
case LFUN_SAVEPREFERENCES:
{
Path p(user_lyxdir);
case LFUN_SCREEN_FONT_UPDATE:
{
// handle the screen font changes.
- //
lyxrc.set_font_norm_type();
- fontloader.update();
- // Of course we should only do the resize and the textcache.clear
- // if values really changed...but not very important right now. (Lgb)
- // All visible buffers will need resize
- owner->resize();
+ lyx_gui::update_fonts();
// We also need to empty the textcache so that
// the buffer will be formatted correctly after
// a zoom change.
textcache.clear();
+ // Of course we should only do the resize and the textcache.clear
+ // if values really changed...but not very important right now. (Lgb)
+ // All visible buffers will need resize
+ view()->resize();
+ view()->repaint();
}
break;
break;
}
+ bool const graphicsbg_changed =
+ (lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
+ x11_name != lcolor.getX11Name(LColor::graphicsbg));
+
if (!lcolor.setColor(lyx_name, x11_name)) {
static string const err1 (N_("Set-color \""));
static string const err2 (
setErrorMessage(_(err1) + lyx_name + _(err2));
break;
}
- lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
- owner->view()->redraw();
+
+ lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
+
+ if (graphicsbg_changed) {
+#ifdef WITH_WARNINGS
+#warning FIXME!! The graphics cache no longer has a changeDisplay method.
+#endif
+#if 0
+ grfx::GCache & gc = grfx::GCache::get();
+ gc.changeDisplay(true);
+#endif
+ }
+
+ view()->repaint();
break;
}
owner->message(argument);
break;
- case LFUN_MESSAGE_PUSH:
- owner->messagePush(argument);
+ case LFUN_FORKS_SHOW:
+ owner->getDialogs().showForks();
break;
- case LFUN_MESSAGE_POP:
- owner->messagePop();
+ case LFUN_FORKS_KILL:
+ {
+ if (!isStrInt(argument))
+ break;
+
+ pid_t const pid = strToInt(argument);
+ ForkedcallsController & fcc = ForkedcallsController::get();
+ fcc.kill(pid);
+ break;
+ }
+
+ case LFUN_TOOLTIPS_TOGGLE:
+ owner->getDialogs().toggleTooltips();
break;
default:
// Then if it was none of the above
- if (!owner->view()->Dispatch(action, argument))
+ // Trying the BufferView::pimpl dispatch:
+ if (!view()->dispatch(ev))
lyxerr << "A truly unknown func ["
- << lyxaction.getActionName(action) << "]!"
+ << lyxaction.getActionName(ev.action) << "]!"
<< endl;
break;
} // end of switch
exit_with_message:
+ sendDispatchMessage(getMessage(), ev, verbose);
+}
- commandshortcut.erase();
-
- if (lyxrc.display_shortcuts && show_sc) {
- if (action != LFUN_SELFINSERT) {
- // Put name of command and list of shortcuts
- // for it in minibuffer
- string comname = lyxaction.getActionName(action);
-
- kb_action pseudoaction = action;
- bool argsadded = false;
-
- if (!argument.empty()) {
- // If we have the command with argument,
- // this is better
- pseudoaction =
- lyxaction.searchActionArg(action,
- argument);
-
- if (pseudoaction == -1) {
- pseudoaction = action;
- } else {
- comname += " " + argument;
- argsadded = true;
- }
- }
- string const shortcuts =
- toplevel_keymap->findbinding(pseudoaction);
+void LyXFunc::sendDispatchMessage(string const & msg, FuncRequest const & ev, bool verbose)
+{
+ owner->updateMenubar();
+ owner->updateToolbar();
- if (!shortcuts.empty()) {
- comname += ": " + shortcuts;
- } else if (!argsadded && !argument.empty()) {
- comname += " " + argument;
- }
+ if (ev.action == LFUN_SELFINSERT || !verbose) {
+ lyxerr[Debug::ACTION] << "dispatch msg is " << msg << endl;
+ if (!msg.empty())
+ owner->message(msg);
+ return;
+ }
- if (!comname.empty()) {
- comname = strip(comname);
- commandshortcut = "(" + comname + ')';
+ string dispatch_msg = msg;
+ if (!dispatch_msg.empty())
+ dispatch_msg += " ";
- // Here we could even add a small pause,
- // to annoy the user and make him learn
- // the shortcuts.
- // No! That will just annoy, not teach
- // anything. The user will read the messages
- // if they are interested. (Asger)
- }
- }
- }
+ string comname = lyxaction.getActionName(ev.action);
- string const res = getMessage();
+ int pseudoaction = ev.action;
+ bool argsadded = false;
- if (res.empty()) {
- if (!commandshortcut.empty()) {
- owner->getMiniBuffer()->addSet(commandshortcut);
+ if (!ev.argument.empty()) {
+ // the pseudoaction is useful for the bindings
+ pseudoaction = lyxaction.searchActionArg(ev.action, ev.argument);
+
+ if (pseudoaction == LFUN_UNKNOWN_ACTION) {
+ pseudoaction = ev.action;
+ } else {
+ comname += " " + ev.argument;
+ argsadded = true;
}
- } else {
- string const msg(_(res) + ' ' + commandshortcut);
- owner->message(msg);
}
- return res;
+ string const shortcuts = toplevel_keymap->findbinding(pseudoaction);
+
+ if (!shortcuts.empty()) {
+ comname += ": " + shortcuts;
+ } else if (!argsadded && !ev.argument.empty()) {
+ comname += " " + ev.argument;
+ }
+
+ if (!comname.empty()) {
+ comname = rtrim(comname);
+ dispatch_msg += "(" + comname + ')';
+ }
+
+ lyxerr[Debug::ACTION] << "verbose dispatch msg " << dispatch_msg << endl;
+ if (!dispatch_msg.empty())
+ owner->message(dispatch_msg);
}
}
-void LyXFunc::menuNew(bool fromTemplate)
+void LyXFunc::menuNew(string const & name, bool fromTemplate)
{
string initpath = lyxrc.document_path;
+ string filename(name);
- if (owner->view()->available()) {
- string const trypath = owner->buffer()->filepath;
+ if (view()->available()) {
+ string const trypath = owner->buffer()->filePath();
// If directory is writeable, use this as default.
if (IsDirWriteable(trypath))
initpath = trypath;
}
static int newfile_number;
- string s;
-
- if (lyxrc.new_ask_filename) {
- FileDialog fileDlg(owner, _("Enter filename for new document"),
- LFUN_SELECT_FILE_SYNC,
- make_pair(string(_("Documents")),
- string(lyxrc.document_path)),
- make_pair(string(_("Templates")),
- string(lyxrc.template_path)));
- FileDialog::Result result =
- fileDlg.Select(initpath,
- _("*.lyx|LyX Documents (*.lyx)"),
- _("newfile"));
-
- if (result.second.empty()) {
- owner->message(_("Canceled."));
- lyxerr[Debug::INFO] << "New Document Cancelled." << endl;
- return;
- }
-
- // get absolute path of file and make sure the filename ends
- // with .lyx
- s = MakeAbsPath(result.second);
- if (!IsLyXFilename(s))
- s += ".lyx";
-
- // Check if the document already is open
- if (bufferlist.exists(s)) {
- switch (Alert::askConfirmation(_("Document is already open:"),
- MakeDisplayPath(s, 50),
- _("Do you want to close that document now?\n"
- "('No' will just switch to the open version)")))
- {
- case 1: // Yes: close the document
- if (!bufferlist.close(bufferlist.getBuffer(s)))
- // If close is canceled, we cancel here too.
- return;
- break;
- case 2: // No: switch to the open document
- owner->view()->buffer(bufferlist.getBuffer(s));
- return;
- case 3: // Cancel: Do nothing
- owner->message(_("Canceled."));
- return;
- }
- }
- // Check whether the file already exists
- FileInfo fi(s);
- if (fi.readable() &&
- Alert::askQuestion(_("File already exists:"),
- MakeDisplayPath(s, 50),
- _("Do you want to open the document?"))) {
- // loads document
- string const disp_fn(MakeDisplayPath(s));
-
- ostringstream str;
- str << _("Opening document") << ' '
- << disp_fn << "...";
-
- owner->message(str.str().c_str());
- //XFlush(fl_get_display());
- owner->view()->buffer(bufferlist.loadLyXFile(s));
- ostringstream str2;
- str2 << _("Document") << ' '
- << disp_fn << ' ' << _("opened.");
-
- owner->message(str2.str().c_str());
-
- return;
- }
- } else {
- s = AddName(lyxrc.document_path,
+ if (filename.empty()) {
+ filename = AddName(lyxrc.document_path,
"newfile" + tostr(++newfile_number) + ".lyx");
- FileInfo fi(s);
- while (bufferlist.exists(s) || fi.readable()) {
+ FileInfo fi(filename);
+ while (bufferlist.exists(filename) || fi.readable()) {
++newfile_number;
- s = AddName(lyxrc.document_path,
+ filename = AddName(lyxrc.document_path,
"newfile" + tostr(newfile_number) +
".lyx");
- fi.newFile(s);
+ fi.newFile(filename);
}
}
if (fromTemplate) {
FileDialog fileDlg(owner, _("Select template file"),
LFUN_SELECT_FILE_SYNC,
- make_pair(string(_("Documents")),
+ make_pair(string(_("Documents|#o#O")),
string(lyxrc.document_path)),
- make_pair(string(_("Templates")),
+ make_pair(string(_("Templates|#T#t")),
string(lyxrc.template_path)));
FileDialog::Result result =
fileDlg.Select(lyxrc.template_path,
_("*.lyx|LyX Documents (*.lyx)"));
-
+
if (result.first == FileDialog::Later)
return;
string const fname = result.second;
- if (fname.empty())
+ if (fname.empty())
return;
- templname = fname;
+ templname = fname;
}
-
- // find a free buffer
- lyxerr[Debug::INFO] << "Find a free buffer." << endl;
- owner->view()->buffer(bufferlist.newFile(s, templname));
+
+ view()->buffer(bufferlist.newFile(filename, templname, !name.empty()));
}
void LyXFunc::open(string const & fname)
{
string initpath = lyxrc.document_path;
-
- if (owner->view()->available()) {
- string const trypath = owner->buffer()->filepath;
+
+ if (view()->available()) {
+ string const trypath = owner->buffer()->filePath();
// If directory is writeable, use this as default.
if (IsDirWriteable(trypath))
initpath = trypath;
}
string filename;
-
+
if (fname.empty()) {
FileDialog fileDlg(owner, _("Select document to open"),
LFUN_FILE_OPEN,
- make_pair(string(_("Documents")),
+ make_pair(string(_("Documents|#o#O")),
string(lyxrc.document_path)),
- make_pair(string(_("Examples")),
+ make_pair(string(_("Examples|#E#e")),
string(AddPath(system_lyxdir, "examples"))));
FileDialog::Result result =
fileDlg.Select(initpath,
"*.lyx|LyX Documents (*.lyx)");
-
+
if (result.first == FileDialog::Later)
return;
filename = result.second;
-
+
// check selected filename
if (filename.empty()) {
owner->message(_("Canceled."));
// get absolute path of file and add ".lyx" to the filename if
// necessary
string const fullpath = FileSearch(string(), filename, "lyx");
- if (fullpath.empty()) {
- Alert::alert(_("Error"), _("Could not find file"), filename);
- return;
+ if (!fullpath.empty()) {
+ filename = fullpath;
}
- filename = fullpath;
-
- // loads document
string const disp_fn(MakeDisplayPath(filename));
+ // if the file doesn't exist, let the user create one
+ FileInfo const f(filename, true);
+ if (!f.exist()) {
+ if (!Alert::askQuestion(_("No such file"), disp_fn,
+ _("Start a new document with this filename ?"))) {
+ owner->message(_("Canceled"));
+ return;
+ }
+ // the user specifically chose this name. Believe them.
+ Buffer * buffer = bufferlist.newFile(filename, "", true);
+ view()->buffer(buffer);
+ return;
+ }
+
ostringstream str;
str << _("Opening document") << ' ' << disp_fn << "...";
-
+
owner->message(str.str().c_str());
Buffer * openbuf = bufferlist.loadLyXFile(filename);
if (openbuf) {
- owner->view()->buffer(openbuf);
+ view()->buffer(openbuf);
ostringstream str;
str << _("Document") << ' ' << disp_fn << ' ' << _("opened.");
owner->message(str.str().c_str());
}
-// checks for running without gui are missing.
void LyXFunc::doImport(string const & argument)
{
string format;
string filename = split(argument, format, ' ');
- lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
+
+ lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
<< " file: " << filename << endl;
- if (filename.empty()) { // need user interaction
+ // need user interaction
+ if (filename.empty()) {
string initpath = lyxrc.document_path;
-
- if (owner->view()->available()) {
- string const trypath = owner->buffer()->filepath;
+
+ if (view()->available()) {
+ string const trypath = owner->buffer()->filePath();
// If directory is writeable, use this as default.
if (IsDirWriteable(trypath))
initpath = trypath;
string const text = _("Select ") + formats.prettyName(format)
+ _(" file to import");
- FileDialog fileDlg(owner, text,
+ FileDialog fileDlg(owner, text,
LFUN_IMPORT,
- make_pair(string(_("Documents")),
+ make_pair(string(_("Documents|#o#O")),
string(lyxrc.document_path)),
- make_pair(string(_("Examples")),
+ make_pair(string(_("Examples|#E#e")),
string(AddPath(system_lyxdir, "examples"))));
-
+
string const extension = "*." + formats.extension(format)
+ "| " + formats.prettyName(format)
+ " (*." + formats.extension(format) + ")";
return;
filename = result.second;
-
+
// check selected filename
if (filename.empty())
owner->message(_("Canceled."));
}
- // still no filename? abort
- if (filename.empty())
+ if (filename.empty())
return;
// get absolute path of file
string const lyxfile = ChangeExtension(filename, ".lyx");
// Check if the document already is open
- if (bufferlist.exists(lyxfile)) {
- switch (Alert::askConfirmation(_("Document is already open:"),
+ if (lyxrc.use_gui && bufferlist.exists(lyxfile)) {
+ switch (Alert::askConfirmation(_("Document is already open:"),
MakeDisplayPath(lyxfile, 50),
_("Do you want to close that document now?\n"
"('No' will just switch to the open version)")))
{
- case 1: // Yes: close the document
- if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
+ case 1:
// If close is canceled, we cancel here too.
+ if (!bufferlist.close(bufferlist.getBuffer(lyxfile)))
return;
break;
- case 2: // No: switch to the open document
- owner->view()->buffer(bufferlist.getBuffer(lyxfile));
+ case 2:
+ view()->buffer(bufferlist.getBuffer(lyxfile));
return;
- case 3: // Cancel: Do nothing
+ case 3:
owner->message(_("Canceled."));
return;
}
}
- // Check if a LyX document by the same root exists in filesystem
- FileInfo const f(lyxfile, true);
- if (f.exist() && !Alert::askQuestion(_("A document by the name"),
- MakeDisplayPath(lyxfile),
- _("already exists. Overwrite?"))) {
- owner->message(_("Canceled"));
- return;
+ // if the file exists already, and we didn't do
+ // -i lyx thefile.lyx, warn
+ if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
+ if (!Alert::askQuestion(_("A document by the name"),
+ MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) {
+ owner->message(_("Canceled"));
+ return;
+ }
}
- // filename should be valid now
-
+
Importer::Import(owner, filename, format);
}
{
string const fn = owner->buffer()->fileName();
if (bufferlist.close(owner->buffer()))
- owner->view()->buffer(bufferlist.loadLyXFile(fn));
+ view()->buffer(bufferlist.loadLyXFile(fn));
}
// need this otherwise SEGV may occur while trying to
// set variables that don't exist
// since there's no current buffer
- owner->getDialogs()->hideBufferDependent();
+ owner->getDialogs().hideBufferDependent();
} else {
- owner->view()->buffer(bufferlist.first());
+ view()->buffer(bufferlist.first());
}
}
}
}
-void LyXFunc::setMessage(string const & m)
+void LyXFunc::setMessage(string const & m) const
{
dispatch_buffer = m;
}
-void LyXFunc::initMiniBuffer()
+void LyXFunc::setStatusMessage(string const & m) const
+{
+ status_buffer = m;
+}
+
+
+string const LyXFunc::view_status_message()
{
- string text = _("Welcome to LyX!");
-
// When meta-fake key is pressed, show the key sequence so far + "M-".
if (wasMetaKey()) {
- text = keyseq.print();
- text += "M-";
+ return keyseq.print() + "M-";
}
// Else, when a non-complete key sequence is pressed,
// show the available options.
if (keyseq.length() > 0 && !keyseq.deleted()) {
- text = keyseq.printOptions();
- }
-
- // Else, show the buffer state.
- else if (owner->view()->available()) {
- Buffer * tmpbuf = owner->buffer();
-
- string const nicename =
- MakeDisplayPath(tmpbuf->fileName());
- // Should we do this instead? (kindo like emacs)
- // leaves more room for other information
- text = "LyX: ";
- text += nicename;
- if (tmpbuf->lyxvc.inUse()) {
- text += " [";
- text += tmpbuf->lyxvc.versionString();
- text += ' ';
- text += tmpbuf->lyxvc.locker();
- if (tmpbuf->isReadonly())
- text += " (RO)";
- text += ']';
- } else if (tmpbuf->isReadonly())
- text += " [RO]";
- if (!tmpbuf->isLyxClean())
- text += _(" (Changed)");
- } else {
- if (text != _("Welcome to LyX!")) // this is a hack
- text = _("* No document open *");
+ return keyseq.printOptions();
}
-
- owner->message(text);
+
+ if (!view()->available())
+ return _("Welcome to LyX!");
+
+ return currentState(view());
}
+
+BufferView * LyXFunc::view() const
+{
+ lyx::Assert(owner);
+ return owner->view().get();
+}