X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfunc.C;h=242c756850c9da2d917b4c53fa1b3c6b23d19fcf;hb=f676dacf9c69d8c906653f54d00342c01de6facf;hp=22369a0ac47dd71ce8401234ae19f37ae4fd9608;hpb=197273f84066b66369dfd6b2972850223ccbc9f5;p=lyx.git diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 22369a0ac4..242c756850 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -24,7 +24,6 @@ #endif #include "version.h" -#include "lyxlookup.h" #include "kbmap.h" #include "lyxfunc.h" #include "bufferlist.h" @@ -68,13 +67,12 @@ #include "support/syscall.h" #include "support/lstrings.h" #include "support/path.h" +#include "support/lyxfunctional.h" #include "debug.h" #include "lyxrc.h" #include "lyxtext.h" #include "gettext.h" #include "trans_mgr.h" -#include "ImportLaTeX.h" -#include "ImportNoweb.h" #include "layout.h" #include "WorkArea.h" #include "lyxfr1.h" @@ -83,16 +81,16 @@ #include "frontends/Toolbar.h" #include "frontends/Menubar.h" #include "FloatList.h" +#include "converter.h" #include "exporter.h" +#include "importer.h" #include "FontLoader.h" #include "TextCache.h" using std::pair; using std::endl; +using std::find_if; -extern bool cursor_follows_scrollbar; - -extern void InsertAsciiFile(BufferView *, string const &, bool); extern void math_insert_symbol(string const &); extern bool math_insert_greek(char); extern BufferList bufferlist; @@ -102,34 +100,16 @@ extern bool selection_possible; extern kb_keymap * toplevel_keymap; -extern bool MenuWrite(Buffer *); -extern bool MenuWriteAs(Buffer *); -extern int MenuRunLaTeX(Buffer *); -extern int MenuBuildProg(Buffer *); -extern int MenuRunChktex(Buffer *); -extern void MenuPrint(Buffer *); -extern void MenuSendto(); -extern void QuitLyX(); +#if 0 extern void MenuFax(Buffer *); +#endif extern void show_symbols_form(LyXFunc *); extern LyXAction lyxaction; // (alkis) extern tex_accent_struct get_accent(kb_action action); -extern void AutoSave(BufferView *); -extern void MenuInsertLabel(string const &); -extern void MenuLayoutCharacter(); -extern void MenuLayoutParagraph(); -extern void MenuLayoutPreamble(); -extern void MenuLayoutSave(); - -extern Buffer * NewLyxFile(string const &); -extern void LoadLyXFile(string const &); -extern void Reconfigure(BufferView *); - extern LyXTextClass::size_type current_layout; -extern int getISOCodeFromLaTeX(char *); extern void ShowLatexLog(); @@ -190,28 +170,30 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state) //return 0; return FL_PREEMPT; } - - // this function should be used always [asierra060396] - UpdatableInset * tli = owner->view()->the_locking_inset; - if (owner->view()->available() && tli && (keysym == XK_Escape)) { - if (tli == tli->GetLockingInset()) { - owner->view()->unlockInset(tli); - owner->view()->text->CursorRight(owner->view()); - moveCursorUpdate(false); - owner->showState(); - } else { - tli->UnlockInsetInInset(owner->view(), - tli->GetLockingInset(),true); + + if (owner->view()->available()) { + // this function should be used always [asierra060396] + UpdatableInset * tli = owner->view()->theLockingInset(); + if (tli && (keysym == XK_Escape)) { + if (tli == tli->GetLockingInset()) { + owner->view()->unlockInset(tli); + owner->view()->text->CursorRight(owner->view()); + moveCursorUpdate(false); + owner->showState(); + } else { + tli->UnlockInsetInInset(owner->view(), + tli->GetLockingInset(),true); + } + //return 0; + return FL_PREEMPT; } - //return 0; - return FL_PREEMPT; } - + // Can we be sure that this will work for all X-Windows // 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) + if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R) || keysym == XK_Mode_switch || keysym == 0x0) return 0; @@ -226,7 +208,7 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state) // 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. - if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) { + if ((action != LFUN_CANCEL) && (action != LFUN_META_FAKE)) { // remove Caps Lock and Mod2 as a modifiers action = keyseq.addkey(keysym, @@ -252,7 +234,7 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state) // why not return already here if action == -1 and // num_bytes == 0? (Lgb) - if(keyseq.length > 1 || keyseq.length < -1) { + if (keyseq.length > 1 || keyseq.length < -1) { string buf; keyseq.print(buf); owner->getMiniBuffer()->Set(buf); @@ -290,141 +272,6 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state) } -#if 0 -int LyXFunc::processKeyEvent(XEvent * ev) -{ - char s_r[10]; - KeySym keysym_return = 0; - string argument; - XKeyEvent * keyevent = &ev->xkey; - int num_bytes = LyXLookupString(ev, s_r, 10, &keysym_return); - s_r[num_bytes] = '\0'; - - if (lyxerr.debugging(Debug::KEY)) { - char * tmp = XKeysymToString(keysym_return); - string stm = (tmp ? tmp : ""); - lyxerr << "KeySym is " - << stm - << "[" - << keysym_return << "]" - << " and num_bytes is " - << num_bytes - << " the string returned is \"" - << s_r << '\"' - << endl; - } - // Do nothing if we have nothing (JMarc) - if (num_bytes == 0 && keysym_return == NoSymbol) { - lyxerr[Debug::KEY] << "Empty kbd action (probably composing)" - << endl; - return 0; - } - - // this function should be used always [asierra060396] - UpdatableInset * tli = owner->view()->the_locking_inset; - if (owner->view()->available() && tli && (keysym_return==XK_Escape)) { - if (tli == tli->GetLockingInset()) { - owner->view()->unlockInset(tli); - owner->view()->text->CursorRight(owner->view()); - moveCursorUpdate(false); - owner->showState(); - } else { - tli->UnlockInsetInInset(owner->view(), - tli->GetLockingInset(),true); - } - return 0; - } - - // Can we be sure that this will work for all X-Windows - // implementations? (Lgb) - // This code snippet makes lyx ignore some keys. Perhaps - // all of them should be explictly mentioned? - if((keysym_return >= XK_Shift_L && keysym_return <= XK_Hyper_R) - || keysym_return == XK_Mode_switch || keysym_return == 0x0) - return 0; - - // 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_return, keyevent->state - &(ShiftMask|ControlMask - |Mod1Mask)); - - // 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. - if ( (action != LFUN_CANCEL) && (action != LFUN_META_FAKE) ) { - - // remove Caps Lock and Mod2 as a modifiers - action = keyseq.addkey(keysym_return, - (keyevent->state | meta_fake_bit) - &(ShiftMask|ControlMask - |Mod1Mask)); - } - // Dont remove this unless you know what you are doing. - meta_fake_bit = 0; - - if (action == 0) action = LFUN_PREFIX; - - if (lyxerr.debugging(Debug::KEY)) { - string buf; - keyseq.print(buf); - lyxerr << "Key [" - << action << "][" - << buf << "]" - << "[" - << num_bytes << "]" - << 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) - - if(keyseq.length > 1 || keyseq.length < -1) { - string buf; - keyseq.print(buf); - owner->getMiniBuffer()->Set(buf); - } - - if (action == -1) { - if (keyseq.length < -1) { // unknown key sequence... - string buf; - LyXBell(); - keyseq.print(buf); - owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf); - return 0; - } - - char isochar = keyseq.getiso(); - if (!(keyevent->state&ControlMask) && - !(keyevent->state&Mod1Mask) && - (isochar && keysym_return < 0xF000)) { - argument += isochar; - } - if (argument.empty()) { - lyxerr.debug() << "Empty argument!" << endl; - // This can`t possibly be of any use - // so we`ll skip the dispatch. - return 0; - } - } - else - if (action == LFUN_SELFINSERT) { - argument = s_r[0]; - } - - bool tmp_sc = show_sc; - show_sc = false; - Dispatch(action, argument); - show_sc = tmp_sc; - - return 0; -} -#endif - - LyXFunc::func_status LyXFunc::getStatus(int ac) const { kb_action action; @@ -472,16 +319,17 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const disable = !Exporter::IsExportable(buf, "dvi") || lyxrc.print_command == "none"; break; +#if 0 case LFUN_FAX: disable = !Exporter::IsExportable(buf, "ps") || lyxrc.fax_command == "none"; break; - case LFUN_IMPORT: - if (argument == "latex" || argument == "noweb") - disable = lyxrc.relyx_command == "none"; - else if (argument == "linuxdoc") - disable = lyxrc.linuxdoc_to_lyx_command == "none"; +#else + case LFUN_EXPORT: + disable = argument == "fax" && + !Exporter::IsExportable(buf, argument); break; +#endif case LFUN_UNDO: disable = buf->undostack.empty(); break; @@ -495,35 +343,46 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const disable = lyxrc.chktex_command == "none"; break; case LFUN_BUILDPROG: - disable = !Exporter::IsExportable(buf, "Program"); + disable = !Exporter::IsExportable(buf, "program"); + break; + + case LFUN_INSERTFOOTNOTE: + case LFUN_FOOTMELT: + case LFUN_MARGINMELT: + // Disable insertion of floats in a tabular. + disable = false; + if (owner->view()->theLockingInset()) { + disable = (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) || + owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE); + } break; case LFUN_LAYOUT_TABULAR: disable = true; - if (owner->view()->the_locking_inset) { - disable = (owner->view()->the_locking_inset->LyxCode() != Inset::TABULAR_CODE) && - !owner->view()->the_locking_inset->GetFirstLockingInsetOfType(Inset::TABULAR_CODE); + if (owner->view()->theLockingInset()) { + disable = (owner->view()->theLockingInset()->LyxCode() != Inset::TABULAR_CODE) && + !owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE); } break; case LFUN_TABULAR_FEATURE: disable = true; - if (owner->view()->the_locking_inset) { + if (owner->view()->theLockingInset()) { func_status ret = LyXFunc::Disabled; - if (owner->view()->the_locking_inset->LyxCode() == Inset::TABULAR_CODE) { + if (owner->view()->theLockingInset()->LyxCode() == Inset::TABULAR_CODE) { ret = static_cast - (owner->view()->the_locking_inset)-> + (owner->view()->theLockingInset())-> getStatus(argument); - } else if (owner->view()->the_locking_inset->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) { + } else if (owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)) { ret = static_cast - (owner->view()->the_locking_inset-> + (owner->view()->theLockingInset()-> GetFirstLockingInsetOfType(Inset::TABULAR_CODE))-> getStatus(argument); } flag |= ret; disable = false; } else { - static InsetTabular inset(owner->buffer(), 1, 1); + static InsetTabular inset(*owner->buffer(), 1, 1); func_status ret; disable = true; @@ -560,9 +419,9 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const if (buf) { func_status box = LyXFunc::ToggleOff; LyXFont font; - if (owner->view()->the_locking_inset && - owner->view()->the_locking_inset->getLyXText(owner->view())) - font = owner->view()->the_locking_inset-> + if (owner->view()->theLockingInset() && + owner->view()->theLockingInset()->getLyXText(owner->view())) + font = owner->view()->theLockingInset()-> getLyXText(owner->view())->real_current_font; else font = owner->view()->text->real_current_font; @@ -608,6 +467,9 @@ string const LyXFunc::Dispatch(string const & s) string const LyXFunc::Dispatch(int ac, string const & do_not_use_this_arg) { + lyxerr[Debug::ACTION] << "LyXFunc::Dispatch: action[" << ac + <<"] arg[" << do_not_use_this_arg << "]" << endl; + string argument; kb_action action; LyXText * text = 0; @@ -686,8 +548,7 @@ string const LyXFunc::Dispatch(int ac, } } - if (owner->view()->available() && owner->view()->the_locking_inset) { - text = owner->view()->the_locking_inset->getLyXText(owner->view()); + if (owner->view()->available() && owner->view()->theLockingInset()) { UpdatableInset::RESULT result; if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) && (keyseq.length >= -1))) @@ -700,7 +561,7 @@ string const LyXFunc::Dispatch(int ac, int slx; int sly; UpdatableInset * inset = - owner->view()->the_locking_inset; + owner->view()->theLockingInset(); inset->GetCursorPos(owner->view(), slx, sly); owner->view()->unlockInset(inset); owner->view()->menuUndo(); @@ -720,7 +581,7 @@ string const LyXFunc::Dispatch(int ac, int slx; int sly; UpdatableInset * inset = owner->view()-> - the_locking_inset; + theLockingInset(); inset->GetCursorPos(owner->view(), slx, sly); owner->view()->unlockInset(inset); owner->view()->menuRedo(); @@ -731,7 +592,7 @@ string const LyXFunc::Dispatch(int ac, if (inset) inset->Edit(owner->view(),slx,sly,0); return string(); - } else if (((result=owner->view()->the_locking_inset-> + } else if (((result=owner->view()->theLockingInset()-> LocalDispatch(owner->view(), action, argument)) == UpdatableInset::DISPATCHED) || @@ -739,7 +600,7 @@ string const LyXFunc::Dispatch(int ac, return string(); else { setMessage(N_("Text mode")); - switch(action) { + switch (action) { case LFUN_UNKNOWN_ACTION: case LFUN_BREAKPARAGRAPH: case LFUN_BREAKLINE: @@ -771,12 +632,15 @@ string const LyXFunc::Dispatch(int ac, } } } + if (owner->view()->theLockingInset()) + text = owner->view()->theLockingInset()-> + getLyXText(owner->view()); } if (!text) text = owner->view()->text; - switch(action) { + switch (action) { // --- Misc ------------------------------------------- case LFUN_WORDFINDFORWARD : case LFUN_WORDFINDBACKWARD : { @@ -806,7 +670,7 @@ string const LyXFunc::Dispatch(int ac, owner->view()->text->ClearSelection(); // Move cursor so that successive C-s 's will not stand in place. - if( action == LFUN_WORDFINDFORWARD ) + if (action == LFUN_WORDFINDFORWARD ) owner->view()->text->CursorRightOneWord(owner->view()); owner->view()->text->FinishUndo(); moveCursorUpdate(false); @@ -836,13 +700,13 @@ string const LyXFunc::Dispatch(int ac, // --- Misc ------------------------------------------- case LFUN_EXEC_COMMAND: - owner->getMiniBuffer()->ExecCommand(); + owner->getMiniBuffer()->PrepareForCommand(); break; case LFUN_CANCEL: // RVDK_PATCH_5 keyseq.reset(); meta_fake_bit = 0; - if(owner->view()->available()) + if (owner->view()->available()) // cancel any selection Dispatch(LFUN_MARK_OFF); setMessage(N_("Cancel")); @@ -853,7 +717,6 @@ string const LyXFunc::Dispatch(int ac, meta_fake_bit = Mod1Mask; string buf; keyseq.print(buf, true); - string res = string("M-") + buf; setMessage(buf); // RVDK_PATCH_5 } break; @@ -900,7 +763,7 @@ string const LyXFunc::Dispatch(int ac, owner->getMiniBuffer()->Set(_("Saving document"), MakeDisplayPath(owner->buffer()->fileName()), "..."); - MenuWrite(owner->buffer()); + MenuWrite(owner->view(), owner->buffer()); //owner->getMiniBuffer()-> { // Set(_("Document saved as"), // MakeDisplayPath(owner->buffer()->fileName())); @@ -908,12 +771,12 @@ string const LyXFunc::Dispatch(int ac, //owner->getMiniBuffer()->Set(_("Save failed!")); //} } else { - MenuWriteAs(owner->buffer()); + MenuWriteAs(owner->view(), owner->buffer()); } break; case LFUN_MENUWRITEAS: - MenuWriteAs(owner->buffer()); + MenuWriteAs(owner->view(), owner->buffer()); break; case LFUN_MENURELOAD: @@ -929,7 +792,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_BUILDPROG: - Exporter::Export(owner->buffer(), "Program", true); + Exporter::Export(owner->buffer(), "program", true); break; case LFUN_RUNCHKTEX: @@ -940,10 +803,12 @@ string const LyXFunc::Dispatch(int ac, owner->getDialogs()->showPrint(); break; +#if 0 case LFUN_FAX: MenuFax(owner->buffer()); break; - +#endif + case LFUN_EXPORT: Exporter::Export(owner->buffer(), argument, false); break; @@ -963,11 +828,11 @@ string const LyXFunc::Dispatch(int ac, { InsetCommandParams p; - if( action == LFUN_TOCVIEW ) + if (action == LFUN_TOCVIEW ) p.setCmdName( "tableofcontents" ); - else if( action == LFUN_LOAVIEW ) + else if (action == LFUN_LOAVIEW ) p.setCmdName( "listofalgorithms" ); - else if( action == LFUN_LOFVIEW ) + else if (action == LFUN_LOFVIEW ) p.setCmdName( "listoffigures" ); else p.setCmdName( "listoftables" ); @@ -983,17 +848,17 @@ string const LyXFunc::Dispatch(int ac, { InsetCommandParams p; - if( action == LFUN_TOC_INSERT ) + if (action == LFUN_TOC_INSERT ) p.setCmdName( "tableofcontents" ); - else if( action == LFUN_LOA_INSERT ) + else if (action == LFUN_LOA_INSERT ) p.setCmdName( "listofalgorithms" ); - else if( action == LFUN_LOF_INSERT ) + else if (action == LFUN_LOF_INSERT ) p.setCmdName( "listoffigures" ); else p.setCmdName( "listoftables" ); Inset * inset = new InsetTOC( p ); - if( !owner->view()->insertInset( inset, "Standard", true ) ) + if (!owner->view()->insertInset( inset, "Standard", true ) ) delete inset; break; } @@ -1157,7 +1022,7 @@ string const LyXFunc::Dispatch(int ac, && owner->view()->text->cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) { // only melt footnotes with FOOTMELT, not margins etc - if(owner->view()->text->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE) + if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::FOOTNOTE) Melt(owner->view()); } else @@ -1171,12 +1036,26 @@ string const LyXFunc::Dispatch(int ac, && owner->view()->text->cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE) { // only melt margins - if(owner->view()->text->cursor.par()->footnotekind == LyXParagraph::MARGIN) + if (owner->view()->text->cursor.par()->footnotekind == LyXParagraph::MARGIN) Melt(owner->view()); } else Margin(owner->view()); owner->view()->setState(); break; +#endif +#ifndef NEW_INSETS + case LFUN_FLOATSOPERATE: + if (argument == "openfoot") + owner->view()->allFloats(1,0); + else if (argument == "closefoot") + owner->view()->allFloats(0,0); + else if (argument == "openfig") + owner->view()->allFloats(1,1); + else if (argument == "closefig") + owner->view()->allFloats(0,1); + break; +#else +#warning Find another implementation here (or another lyxfunc)! #endif case LFUN_HELP_COPYRIGHT: owner->getDialogs()->showCopyright(); @@ -1207,17 +1086,21 @@ string const LyXFunc::Dispatch(int ac, break; } - case LFUN_HELP_VERSION: + case LFUN_HELP_VERSION: { ProhibitInput(owner->view()); - fl_show_message((string(_("LyX Version ")) + LYX_VERSION - + _(" of ") + LYX_RELEASE).c_str(), + string msg(_("LyX Version ")); + msg += LYX_VERSION; + msg += " of "; + msg += LYX_RELEASE; + fl_show_message(msg.c_str(), (_("Library directory: ") + MakeDisplayPath(system_lyxdir)).c_str(), (_("User directory: ") + MakeDisplayPath(user_lyxdir)).c_str()); AllowInput(owner->view()); break; - + } + // --- version control ------------------------------- case LFUN_VC_REGISTER: { @@ -1375,15 +1258,15 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_LAYOUT_TABULAR: - if (owner->view()->the_locking_inset) { - if (owner->view()->the_locking_inset->LyxCode()==Inset::TABULAR_CODE) { + if (owner->view()->theLockingInset()) { + if (owner->view()->theLockingInset()->LyxCode()==Inset::TABULAR_CODE) { InsetTabular * inset = static_cast - (owner->view()->the_locking_inset); + (owner->view()->theLockingInset()); inset->OpenLayoutDialog(owner->view()); - } else if (owner->view()->the_locking_inset-> + } else if (owner->view()->theLockingInset()-> GetFirstLockingInsetOfType(Inset::TABULAR_CODE)!=0) { InsetTabular * inset = static_cast( - owner->view()->the_locking_inset->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)); + owner->view()->theLockingInset()->GetFirstLockingInsetOfType(Inset::TABULAR_CODE)); inset->OpenLayoutDialog(owner->view()); } } @@ -1394,7 +1277,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_LAYOUT_SAVE_DEFAULT: - MenuLayoutSave(); + MenuLayoutSave(owner->view()); break; case LFUN_DROP_LAYOUTS_CHOICE: @@ -1482,7 +1365,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_INSERT_LABEL: - MenuInsertLabel(argument); + MenuInsertLabel(owner->view(), argument); break; case LFUN_REF_INSERT: @@ -1493,7 +1376,7 @@ string const LyXFunc::Dispatch(int ac, InsetCommandParams p; p.setFromString(argument); - InsetRef * inset = new InsetRef(p); + InsetRef * inset = new InsetRef(p, *owner->buffer()); if (!owner->view()->insertInset(inset)) delete inset; else @@ -1541,7 +1424,7 @@ string const LyXFunc::Dispatch(int ac, { LyXText * tmptext = owner->view()->text; bool is_rtl = tmptext->cursor.par()->isRightToLeftPar(owner->buffer()->params); - if(!tmptext->mark_set) + if (!tmptext->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); if (is_rtl) @@ -1570,7 +1453,7 @@ string const LyXFunc::Dispatch(int ac, // it simpler? (Lgb) LyXText * txt = owner->view()->text; bool is_rtl = txt->cursor.par()->isRightToLeftPar(owner->buffer()->params); - if(!txt->mark_set) owner->view()->beforeChange(); + if (!txt->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); LyXCursor cur = txt->cursor; if (!is_rtl) @@ -1605,7 +1488,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_UP: - if(!owner->view()->text->mark_set) owner->view()->beforeChange(); + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::UPDATE); owner->view()->text->CursorUp(owner->view()); owner->view()->text->FinishUndo(); @@ -1614,7 +1497,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_DOWN: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::UPDATE); owner->view()->text->CursorDown(owner->view()); @@ -1624,7 +1507,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_UP_PARAGRAPH: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::UPDATE); owner->view()->text->CursorUpParagraph(owner->view()); @@ -1634,7 +1517,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_DOWN_PARAGRAPH: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::UPDATE); owner->view()->text->CursorDownParagraph(owner->view()); @@ -1644,27 +1527,33 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_PRIOR: - if(!owner->view()->text->mark_set) - owner->view()->beforeChange(); + if (!text->mark_set) + owner->view()->beforeChange(); owner->view()->update(BufferView::UPDATE); - owner->view()->cursorPrevious(); + owner->view()->cursorPrevious(text); owner->view()->text->FinishUndo(); - moveCursorUpdate(false); + if (text->inset_owner) + owner->view()->updateInset(text->inset_owner, false); + else + moveCursorUpdate(false); owner->showState(); break; case LFUN_NEXT: - if(!owner->view()->text->mark_set) + if (!text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::UPDATE); - owner->view()->cursorNext(); + owner->view()->cursorNext(text); owner->view()->text->FinishUndo(); - moveCursorUpdate(false); + if (text->inset_owner) + owner->view()->updateInset(text->inset_owner, false); + else + moveCursorUpdate(false); owner->showState(); break; case LFUN_HOME: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); owner->view()->text->CursorHome(owner->view()); @@ -1674,7 +1563,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_END: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); owner->view()->text->CursorEnd(owner->view()); @@ -1685,7 +1574,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_SHIFT_TAB: case LFUN_TAB: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); owner->view()->text->CursorTab(owner->view()); @@ -1695,7 +1584,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_WORDRIGHT: - if(!text->mark_set) + if (!text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) @@ -1710,7 +1599,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_WORDLEFT: - if(!text->mark_set) + if (!text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); if (text->cursor.par()->isRightToLeftPar(owner->buffer()->params)) @@ -1725,7 +1614,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_BEGINNINGBUF: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); owner->view()->text->CursorTop(owner->view()); @@ -1735,7 +1624,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_ENDBUF: - if(!owner->view()->text->mark_set) + if (!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); owner->view()->text->CursorBottom(owner->view()); @@ -1802,17 +1691,23 @@ string const LyXFunc::Dispatch(int ac, case LFUN_PRIORSEL: owner->view()->update(BufferView::SELECT|BufferView::FITCUR); - owner->view()->cursorPrevious(); + owner->view()->cursorPrevious(text); owner->view()->text->FinishUndo(); - moveCursorUpdate(true); + if (text->inset_owner) + owner->view()->updateInset(text->inset_owner, false); + else + moveCursorUpdate(true); owner->showState(); break; case LFUN_NEXTSEL: owner->view()->update(BufferView::SELECT|BufferView::FITCUR); - owner->view()->cursorNext(); + owner->view()->cursorNext(text); owner->view()->text->FinishUndo(); - moveCursorUpdate(true); + if (text->inset_owner) + owner->view()->updateInset(text->inset_owner, false); + else + moveCursorUpdate(true); owner->showState(); break; @@ -1895,7 +1790,7 @@ string const LyXFunc::Dispatch(int ac, break; case LFUN_SETMARK: - if(text->mark_set) { + if (text->mark_set) { owner->view()->beforeChange(); owner->view()->update(BufferView::SELECT|BufferView::FITCUR); setMessage(N_("Mark removed")); @@ -2143,7 +2038,7 @@ string const LyXFunc::Dispatch(int ac, cur_value = par->spacing.getValue(); } - istringstream istr(argument); + istringstream istr(argument.c_str()); string tmp; istr >> tmp; @@ -2311,11 +2206,11 @@ string const LyXFunc::Dispatch(int ac, case LFUN_INSET_CAPTION: { // Do we have a locking inset... - if (owner->view()->the_locking_inset) { + if (owner->view()->theLockingInset()) { lyxerr << "Locking inset code: " - << static_cast(owner->view()->the_locking_inset->LyxCode()); + << static_cast(owner->view()->theLockingInset()->LyxCode()); InsetCaption * new_inset = new InsetCaption; - new_inset->setOwner(owner->view()->the_locking_inset); + new_inset->setOwner(owner->view()->theLockingInset()); new_inset->SetAutoBreakRows(true); new_inset->SetDrawFrame(0, InsetText::LOCKED); new_inset->SetFrameColor(0, LColor::footnoteframe); @@ -2333,7 +2228,7 @@ string const LyXFunc::Dispatch(int ac, if (!argument.empty()) ::sscanf(argument.c_str(),"%d%d", &r, &c); InsetTabular * new_inset = - new InsetTabular(owner->buffer(), r, c); + new InsetTabular(*owner->buffer(), r, c); if (owner->view()->insertInset(new_inset)) new_inset->Edit(owner->view(), 0, 0, 0); else @@ -2347,7 +2242,7 @@ string const LyXFunc::Dispatch(int ac, { LyXParagraph::size_type pos = owner->view()->text->cursor.pos(); - if(pos < owner->view()->text->cursor.par()->size()) + if (pos < owner->view()->text->cursor.par()->size()) //dispatch_buffer = owner->view()->text-> // cursor.par()->text[pos]; dispatch_buffer = @@ -2381,9 +2276,9 @@ string const LyXFunc::Dispatch(int ac, case LFUN_GETFONT: { LyXFont & font = owner->view()->text->current_font; - if(font.shape() == LyXFont::ITALIC_SHAPE) + if (font.shape() == LyXFont::ITALIC_SHAPE) dispatch_buffer = 'E'; - else if(font.shape() == LyXFont::SMALLCAPS_SHAPE) + else if (font.shape() == LyXFont::SMALLCAPS_SHAPE) dispatch_buffer = 'N'; else dispatch_buffer = '0'; @@ -2394,7 +2289,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_GETLATEX: { LyXFont & font = owner->view()->text->current_font; - if(font.latex() == LyXFont::ON) + if (font.latex() == LyXFont::ON) dispatch_buffer = 'L'; else dispatch_buffer = '0'; @@ -2420,7 +2315,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_GOTOFILEROW: { char file_name[100]; - int row; + int row; ::sscanf(argument.c_str(), " %s %d", file_name, &row); // Must replace extension of the file to be .lyx and get full path @@ -2442,7 +2337,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_GOTO_PARAGRAPH: { - istringstream istr(argument); + istringstream istr(argument.c_str()); int id; istr >> id; @@ -2569,13 +2464,14 @@ string const LyXFunc::Dispatch(int ac, case LFUN_INSERT_MATRIX: { if (owner->view()->available()) { - owner->view()-> - open_new_inset(new InsetFormula(false)); - owner->view() - ->the_locking_inset - ->LocalDispatch(owner->view(), - action, - argument); + if (owner->view()-> + open_new_inset(new InsetFormula(false))) + { + owner->view()->theLockingInset() + ->LocalDispatch(owner->view(), + action, + argument); + } } } break; @@ -2600,8 +2496,8 @@ string const LyXFunc::Dispatch(int ac, if (s.empty()) setErrorMessage(N_("Missing argument")); else { - string s1 = token(s, ' ', 1); - int na = s1.empty() ? 0 : lyx::atoi(s1); + string const s1 = token(s, ' ', 1); + int const na = s1.empty() ? 0 : lyx::atoi(s1); owner->view()-> open_new_inset(new InsetFormulaMacro(token(s, ' ', 0), na)); } @@ -2665,7 +2561,7 @@ string const LyXFunc::Dispatch(int ac, // ale970405+lasgoutt970425 // The argument can be up to two tokens separated // by a space. The first one is the bibstyle. - string db = token(argument, ' ', 0); + string const db = token(argument, ' ', 0); string bibstyle = token(argument, ' ', 1); if (bibstyle.empty()) bibstyle = "plain"; @@ -2716,13 +2612,13 @@ string const LyXFunc::Dispatch(int ac, { InsetCommandParams p( "index" ); - if( argument.empty() ) { + if (argument.empty()) { // Get the word immediately preceding the cursor LyXParagraph::size_type curpos = owner->view()->text->cursor.pos() - 1; string curstring; - if( curpos >= 0 ) + if (curpos >= 0 ) curstring = owner->view()->text ->cursor.par()->GetWord(curpos); @@ -2738,13 +2634,13 @@ string const LyXFunc::Dispatch(int ac, case LFUN_INDEX_INSERT: { InsetCommandParams p; - p.setFromString( argument ); - InsetIndex * inset = new InsetIndex( p ); + p.setFromString(argument); + InsetIndex * inset = new InsetIndex(p); if (!owner->view()->insertInset(inset)) delete inset; else - owner->view()->updateInset( inset, true ); + owner->view()->updateInset(inset, true); } break; @@ -2754,24 +2650,24 @@ string const LyXFunc::Dispatch(int ac, LyXParagraph::size_type curpos = owner->view()->text->cursor.pos() - 1; // Can't do that at the beginning of a paragraph - if( curpos < 0 ) break; + if (curpos < 0) break; - string curstring( owner->view()->text - ->cursor.par()->GetWord(curpos) ); + string const curstring(owner->view()->text + ->cursor.par()->GetWord(curpos)); - InsetCommandParams p( "index", curstring ); - InsetIndex * inset = new InsetIndex( p ); + InsetCommandParams p("index", curstring); + InsetIndex * inset = new InsetIndex(p); if (!owner->view()->insertInset(inset)) delete inset; else - owner->view()->updateInset( inset, true ); + owner->view()->updateInset(inset, true); } break; case LFUN_INDEX_PRINT: { - InsetCommandParams p( "printindex" ); + InsetCommandParams p("printindex"); Inset * inset = new InsetPrintIndex(p); if (!owner->view()->insertInset(inset, "Standard", true)) delete inset; @@ -2782,7 +2678,7 @@ string const LyXFunc::Dispatch(int ac, { lyxerr << "arg " << argument << endl; InsetCommandParams p( "lyxparent", argument ); - Inset * inset = new InsetParent(p, owner->buffer()); + Inset * inset = new InsetParent(p, *owner->buffer()); if (!owner->view()->insertInset(inset, "Standard", true)) delete inset; } @@ -2791,7 +2687,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_CHILDINSERT: { InsetCommandParams p( "Include", argument ); - Inset * inset = new InsetInclude(p, owner->buffer()); + Inset * inset = new InsetInclude(p, *owner->buffer()); if (owner->view()->insertInset(inset, "Standard", true)) inset->Edit(owner->view(), 0, 0, 0); else @@ -2801,7 +2697,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_CHILDOPEN: { - string filename = + string const filename = MakeAbsPath(argument, OnlyPath(owner->buffer()->fileName())); setMessage(N_("Opening child document ") + @@ -2821,21 +2717,21 @@ string const LyXFunc::Dispatch(int ac, case LFUN_INSERTFOOTNOTE: { LyXParagraph::footnote_kind kind; - if (argument == "footnote") - { kind = LyXParagraph::FOOTNOTE; } - else if (argument == "margin") - { kind = LyXParagraph::MARGIN; } - else if (argument == "figure") - { kind = LyXParagraph::FIG; } - else if (argument == "table") - { kind = LyXParagraph::TAB; } - else if (argument == "wide-fig") - { kind = LyXParagraph::WIDE_FIG; } - else if (argument == "wide-tab") - { kind = LyXParagraph::WIDE_TAB; } - else if (argument == "algorithm") - { kind = LyXParagraph::ALGORITHM; } - else { + if (argument == "footnote") { + kind = LyXParagraph::FOOTNOTE; + } else if (argument == "margin") { + kind = LyXParagraph::MARGIN; + } else if (argument == "figure") { + kind = LyXParagraph::FIG; + } else if (argument == "table") { + kind = LyXParagraph::TAB; + } else if (argument == "wide-fig") { + kind = LyXParagraph::WIDE_FIG; + } else if (argument == "wide-tab") { + kind = LyXParagraph::WIDE_TAB; + } else if (argument == "algorithm") { + kind = LyXParagraph::ALGORITHM; + } else { setErrorMessage(N_("Unknown kind of footnote")); break; } @@ -2846,7 +2742,7 @@ string const LyXFunc::Dispatch(int ac, break; #endif case LFUN_TOGGLECURSORFOLLOW: - cursor_follows_scrollbar = !cursor_follows_scrollbar; + lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar; break; case LFUN_KMAP_OFF: // keymap off @@ -2867,6 +2763,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_SELFINSERT: { + LyXFont const old_font(owner->view()->text->real_current_font); for (string::size_type i = 0; i < argument.length(); ++i) { owner->view()->text->InsertChar(owner->view(), argument[i]); // This needs to be in the loop, or else we @@ -2876,6 +2773,11 @@ string const LyXFunc::Dispatch(int ac, owner->view()->text->sel_cursor = owner->view()->text->cursor; moveCursorUpdate(false); + + // real_current_font.number can change so we need to + // update the minibuffer + if (old_font != owner->view()->text->real_current_font) + owner->showState(); } break; @@ -2903,7 +2805,8 @@ string const LyXFunc::Dispatch(int ac, else arg = lyxrc.date_insert_format; char datetmp[32]; - int datetmp_len = ::strftime(datetmp, 32, arg.c_str(), now_tm); + int const datetmp_len = + ::strftime(datetmp, 32, arg.c_str(), now_tm); for (int i = 0; i < datetmp_len; i++) { owner->view()->text->InsertChar(owner->view(), datetmp[i]); owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); @@ -2944,8 +2847,8 @@ string const LyXFunc::Dispatch(int ac, case LFUN_SET_COLOR: { - string lyx_name, x11_name; - x11_name = split(argument, lyx_name, ' '); + string lyx_name; + string const x11_name = split(argument, lyx_name, ' '); if (lyx_name.empty() || x11_name.empty()) { LyXBell(); setErrorMessage(N_("Syntax: set-color " @@ -2954,11 +2857,12 @@ string const LyXFunc::Dispatch(int ac, } if (!lcolor.setColor(lyx_name, x11_name)) { - static string err1 (N_("Set-color \"")); - static string err2 (N_("\" failed - color is undefined " - "or may not be redefined")); + static string const err1 (N_("Set-color \"")); + static string const err2 ( + N_("\" failed - color is undefined " + "or may not be redefined")); LyXBell(); - setErrorMessage(err1 + lyx_name + err2); + setErrorMessage(_(err1) + lyx_name + _(err2)); break; } lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name)); @@ -2968,7 +2872,7 @@ string const LyXFunc::Dispatch(int ac, case LFUN_UNKNOWN_ACTION: { - if(!owner->buffer()) { + if (!owner->buffer()) { LyXBell(); setErrorMessage(N_("No document open")); break; @@ -2988,7 +2892,7 @@ string const LyXFunc::Dispatch(int ac, * "auto_region_delete", which defaults to * true (on). */ - if ( lyxrc.auto_region_delete ) { + if (lyxrc.auto_region_delete) { if (owner->view()->text->selection){ owner->view()->text->CutSelection(owner->view(), false); owner->view()->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); @@ -2996,7 +2900,7 @@ string const LyXFunc::Dispatch(int ac, } owner->view()->beforeChange(); - + LyXFont const old_font(owner->view()->text->real_current_font); for (string::size_type i = 0; i < argument.length(); ++i) { if (greek_kb_flag) { @@ -3011,6 +2915,11 @@ string const LyXFunc::Dispatch(int ac, owner->view()->text->sel_cursor = owner->view()->text->cursor; moveCursorUpdate(false); + + // real_current_font.number can change so we need to + // update the minibuffer + if (old_font != owner->view()->text->real_current_font) + owner->showState(); return string(); } else { // why is an "Unknown action" with empty @@ -3028,11 +2937,12 @@ string const LyXFunc::Dispatch(int ac, } // end of switch exit_with_message: - string res = getMessage(); + string const res = getMessage(); if (res.empty()) { if (!commandshortcut.empty()) { - string newbuf = owner->getMiniBuffer()->GetText(); + string const newbuf = + owner->getMiniBuffer()->GetText(); if (newbuf != commandshortcut) { owner->getMiniBuffer()->Set(newbuf + " " + @@ -3040,8 +2950,10 @@ string const LyXFunc::Dispatch(int ac, } } } else { - owner->getMiniBuffer()->Set(string(_(res.c_str())) - + " " + commandshortcut); + string msg(_(res)); + msg += " "; + msg += commandshortcut; + owner->getMiniBuffer()->Set(msg); } return res; @@ -3057,11 +2969,11 @@ void LyXFunc::setupLocalKeymap() void LyXFunc::MenuNew(bool fromTemplate) { - string fname, initpath = lyxrc.document_path; + string initpath = lyxrc.document_path; LyXFileDlg fileDlg; if (owner->view()->available()) { - string trypath = owner->buffer()->filepath; + string const trypath = owner->buffer()->filepath; // If directory is writeable, use this as default. if (IsDirWriteable(trypath) == 1) initpath = trypath; @@ -3069,12 +2981,12 @@ void LyXFunc::MenuNew(bool fromTemplate) static int newfile_number = 0; string s; - + if (lyxrc.new_ask_filename) { ProhibitInput(owner->view()); fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); fileDlg.SetButton(1, _("Templates"), lyxrc.template_path); - fname = fileDlg.Select(_("Enter Filename for new document"), + string fname = fileDlg.Select(_("Enter Filename for new document"), initpath, "*.lyx", _("newfile")); AllowInput(owner->view()); @@ -3092,7 +3004,7 @@ void LyXFunc::MenuNew(bool fromTemplate) // Check if the document already is open if (bufferlist.exists(s)) { - switch(AskConfirmation(_("Document is already open:"), + switch (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)"))) @@ -3120,7 +3032,7 @@ void LyXFunc::MenuNew(bool fromTemplate) // loads document owner->getMiniBuffer()->Set(_("Opening document"), MakeDisplayPath(s), "..."); - XFlush(fl_display); + XFlush(fl_get_display()); owner->view()->buffer( bufferlist.loadLyXFile(s)); owner->getMiniBuffer()->Set(_("Document"), @@ -3146,11 +3058,12 @@ void LyXFunc::MenuNew(bool fromTemplate) string templname; if (fromTemplate) { ProhibitInput(owner->view()); - fname = fileDlg.Select(_("Choose template"), - lyxrc.template_path, - "*.lyx"); - templname = fname; + string const fname = fileDlg.Select(_("Choose template"), + lyxrc.template_path, + "*.lyx"); AllowInput(owner->view()); + if (fname.empty()) return; + templname = fname; } // find a free buffer @@ -3165,7 +3078,7 @@ void LyXFunc::MenuOpen() LyXFileDlg fileDlg; if (owner->view()->available()) { - string trypath = owner->buffer()->filepath; + string const trypath = owner->buffer()->filepath; // If directory is writeable, use this as default. if (IsDirWriteable(trypath) == 1) initpath = trypath; @@ -3207,25 +3120,21 @@ void LyXFunc::MenuOpen() } } -// returns filename if file must be imported, -// empty string if either file not found or already loaded -// checks for running without gui are missing. -void LyXFunc::doImportHelper( - string const & file, // filename (possibly empty) - string const & text, // info when asking for filename - string const & pattern, // filetype - bool func(BufferView *, string const &) // the real import function -) +// checks for running without gui are missing. +void LyXFunc::doImport(string const & argument) { - string filename = file; + string format; + string filename = split(argument, format, ' '); + lyxerr.debug() << "LyXFunc::doImport: " << format + << " file: " << filename << endl; if (filename.empty()) { // need user interaction string initpath = lyxrc.document_path; LyXFileDlg fileDlg; if (owner->view()->available()) { - string trypath = owner->buffer()->filepath; + string const trypath = owner->buffer()->filepath; // If directory is writeable, use this as default. if (IsDirWriteable(trypath) == 1) initpath = trypath; @@ -3236,7 +3145,10 @@ void LyXFunc::doImportHelper( fileDlg.SetButton(0, _("Documents"), lyxrc.document_path); fileDlg.SetButton(1, _("Examples"), AddPath(system_lyxdir, "examples")); - filename = fileDlg.Select(text, initpath, pattern); + string const text = _("Select ") + formats.PrettyName(format) + + _(" file to import"); + string const extension = "*." + formats.Extension(format); + filename = fileDlg.Select(text, initpath, extension); AllowInput(owner->view()); // check selected filename @@ -3251,11 +3163,11 @@ void LyXFunc::doImportHelper( // get absolute path of file filename = MakeAbsPath(filename); - string lyxfile = ChangeExtension(filename, ".lyx"); + string const lyxfile = ChangeExtension(filename, ".lyx"); // Check if the document already is open if (bufferlist.exists(lyxfile)) { - switch(AskConfirmation(_("Document is already open:"), + switch (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)"))) @@ -3275,7 +3187,7 @@ void LyXFunc::doImportHelper( } // Check if a LyX document by the same root exists in filesystem - FileInfo f(lyxfile, true); + FileInfo const f(lyxfile, true); if (f.exist() && !AskQuestion(_("A document by the name"), MakeDisplayPath(lyxfile), _("already exists. Overwrite?"))) { @@ -3284,78 +3196,7 @@ void LyXFunc::doImportHelper( } // filename should be valid now - // notify user of import ahead - string displaypath = MakeDisplayPath(filename); - owner->getMiniBuffer()->Set(_("Importing"), displaypath, "..."); - - // call real importer - bool result = func(owner->view(), filename); - - // we are done - if (result) - owner->getMiniBuffer()->Set(displaypath, _("imported.")); - else - owner->getMiniBuffer()->Set(displaypath, _(": import failed.")); -} - -static -bool doImportASCIIasLines(BufferView * view, string const & filename) -{ - view->buffer(bufferlist.newFile(filename, string())); - InsertAsciiFile(view, filename, false); - return true; -} - -static -bool doImportASCIIasParagraphs(BufferView * view, string const & filename) -{ - view->buffer(bufferlist.newFile(filename, string())); - InsertAsciiFile(view, filename, true); - return true; -} - -static -bool doImportLaTeX(BufferView * view, string const & filename) -{ - ImportLaTeX myImport(filename); - Buffer * openbuf = myImport.run(); - if (openbuf) { - view->buffer(openbuf); - return true; - } - else - return false; -} - -static -bool doImportNoweb(BufferView * view, string const & filename) -{ - ImportNoweb myImport(filename); - Buffer * openbuf = myImport.run(); - if (openbuf) { - view->buffer(openbuf); - return true; - } - else - return false; -} - -static -bool doImportLinuxDoc(BufferView *, string const & filename) -{ - // run sgml2lyx - string tmp = lyxrc.linuxdoc_to_lyx_command + filename; - Systemcalls one; - Buffer * buf = 0; - - int result = one.startscript(Systemcalls::System, tmp); - if (result == 0) { - string filename = ChangeExtension(filename, ".lyx"); - // File was generated without problems. Load it. - buf = bufferlist.loadLyXFile(filename); - } - - return result == 0; + Importer::Import(owner, filename, format); } @@ -3369,7 +3210,7 @@ void LyXFunc::MenuInsertLyXFile(string const & filen) LyXFileDlg fileDlg; if (owner->view()->available()) { - string trypath = owner->buffer()->filepath; + string const trypath = owner->buffer()->filepath; // If directory is writeable, use this as default. if (IsDirWriteable(trypath) == 1) initpath = trypath; @@ -3400,7 +3241,7 @@ void LyXFunc::MenuInsertLyXFile(string const & filen) // Inserts document owner->getMiniBuffer()->Set(_("Inserting document"), MakeDisplayPath(filename), "..."); - bool res = owner->view()->insertLyXFile(filename); + bool const res = owner->view()->insertLyXFile(filename); if (res) { owner->getMiniBuffer()->Set(_("Document"), MakeDisplayPath(filename), @@ -3411,40 +3252,10 @@ void LyXFunc::MenuInsertLyXFile(string const & filen) } } -void LyXFunc::doImport(string const & argument) -{ - string type; - string filename = split(argument, type, ' '); - lyxerr.debug() << "LyXFunc::doImport: " << type - << " file: " << filename << endl; - - if (type == "latex") - doImportHelper(filename, - _("Select LaTeX file to import"), "*.tex", - doImportLaTeX); - else if (type == "ascii") - doImportHelper(filename, - _("Select ASCII file to import"), "*.txt", - doImportASCIIasLines); - else if (type == "asciiparagraph") - doImportHelper(filename, - _("Select ASCII file to import"), "*.txt", - doImportASCIIasParagraphs); - else if (type == "noweb") - doImportHelper(filename, - _("Select NoWeb file to import"), "*.nw", - doImportNoweb); - else if (type == "linuxdoc") - doImportHelper(filename, - _("Select LinuxDoc file to import"), "*.doc", - doImportLinuxDoc); - else - setErrorMessage(string(N_("Unknown import type: ")) + type); -} void LyXFunc::reloadBuffer() { - string fn = owner->buffer()->fileName(); + string const fn = owner->buffer()->fileName(); if (bufferlist.close(owner->buffer())) owner->view()->buffer(bufferlist.loadLyXFile(fn)); } @@ -3458,8 +3269,7 @@ void LyXFunc::CloseBuffer() // set variables that don't exist // since there's no current buffer owner->getDialogs()->hideBufferDependent(); - } - else { + } else { owner->view()->buffer(bufferlist.first()); } } @@ -3470,13 +3280,12 @@ Inset * LyXFunc::getInsetByCode(Inset::Code code) { LyXCursor cursor = owner->view()->text->cursor; Buffer * buffer = owner->view()->buffer(); - for (Buffer::inset_iterator it = Buffer::inset_iterator(cursor.par(), - cursor.pos()); - it != buffer->inset_iterator_end(); ++it) { - if ((*it)->LyxCode() == code) - return *it; - } - return 0; + Buffer::inset_iterator it = + find_if(Buffer::inset_iterator(cursor.par(), + cursor.pos()), + buffer->inset_iterator_end(), + compare_memfun(&Inset::LyxCode, code)); + return it != buffer->inset_iterator_end() ? (*it) : 0; }