hi, attached is the patch implementing forward search.
i didn't add gui combo for the rc variable because the ui needs to be reworked first. i will address this in a different thread. pavel
diff --git a/src/FuncCode.h b/src/FuncCode.h index 20434e5..c545fee 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -445,6 +445,7 @@ enum FuncCode LFUN_SPELLING_IGNORE, // spitz 20100118 // 345 LFUN_PREVIEW_INSERT, // vfr, 20100328 + LFUN_FORWARD_SEARCH, LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 053680a..32a2604 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2825,6 +2825,23 @@ void LyXAction::init() */ { LFUN_SERVER_GOTO_FILE_ROW, "server-goto-file-row", ReadOnly | NoBuffer, System }, /*! + * \var lyx::FuncCode lyx::LFUN_FORWARD_SEARCH + * \li Action: Sets the cursor position in the previewed (e.g. dvi) file based on the row + number in LyX window. + * \li Notion: The external program used for forward search call can be specified in + \\forward_search RC setting. By default its value is\n + "xdvi -sourceposition $$n:$$t $$o"\n + The values replaced in the call: $$n for row number, $$t for + exported temporary .tex file, $$o exported output file, either + dvi or pdf, depending on the argument of #LFUN_FORWARD_SEARCH. + * \li Syntax: forward-search [dvi|pdf] + * \li Params: By default dvi route is taken. + * \li Origin: sanda, 14 Apr 2010 + * \endvar + */ + { LFUN_FORWARD_SEARCH, "forward-search", ReadOnly, System }, + +/*! * \var lyx::FuncCode lyx::LFUN_SERVER_NOTIFY * \li Action: Sends notify message about the last key-sequence to client. * \li Notion: This can be used to grab last key-sequence used inside the LyX window. diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index 3b363fd..7402484 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -94,6 +94,7 @@ LexerKeyword lyxrcTags[] = { { "\\example_path", LyXRC::RC_EXAMPLEPATH }, { "\\font_encoding", LyXRC::RC_FONT_ENCODING }, { "\\format", LyXRC::RC_FORMAT }, + { "\\forward_search", LyXRC::RC_FORWARD_SEARCH }, { "\\fullscreen_limit", LyXRC::RC_FULL_SCREEN_LIMIT }, { "\\fullscreen_menubar", LyXRC::RC_FULL_SCREEN_MENUBAR }, { "\\fullscreen_scrollbar", LyXRC::RC_FULL_SCREEN_SCROLLBAR }, @@ -326,6 +327,7 @@ void LyXRC::setDefaults() user_email = to_utf8(support::user_email()); open_buffers_in_tabs = true; single_close_tab_button = false; + forward_search = "xdvi -sourceposition $$n:$$t $$o"; // Fullscreen settings full_screen_limit = false; @@ -1156,6 +1158,9 @@ int LyXRC::read(Lexer & lexrc) case RC_SINGLE_CLOSE_TAB_BUTTON: lexrc >> single_close_tab_button; break; + case RC_FORWARD_SEARCH: + lexrc >> forward_search; + break; // Obsoteted in 1.4.0 case RC_USETEMPDIR: @@ -1840,6 +1845,8 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c << convert<string>(open_buffers_in_tabs) << '\n'; } + if (tag != RC_LAST) + break; case RC_SINGLE_CLOSE_TAB_BUTTON: if (ignore_system_lyxrc || single_close_tab_button != system_lyxrc.single_close_tab_button) { @@ -1849,6 +1856,13 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c } if (tag != RC_LAST) break; + case RC_FORWARD_SEARCH: + if (ignore_system_lyxrc || + forward_search != system_lyxrc.forward_search) { + os << "\\forward_search " << forward_search << '\n'; + } + if (tag != RC_LAST) + break; os << "\n#\n" << "# COLOR SECTION ###################################\n" @@ -2801,6 +2815,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new) case LyXRC::RC_VISUAL_CURSOR: case LyXRC::RC_VIEWER: case LyXRC::RC_VIEWER_ALTERNATIVES: + case LyXRC::RC_FORWARD_SEARCH: case LyXRC::RC_LAST: break; } diff --git a/src/LyXRC.h b/src/LyXRC.h index c68e83c..2eccbc5 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -78,6 +78,7 @@ public: RC_EXAMPLEPATH, RC_FONT_ENCODING, RC_FORMAT, + RC_FORWARD_SEARCH, RC_FULL_SCREEN_LIMIT, RC_FULL_SCREEN_SCROLLBAR, RC_FULL_SCREEN_TABBAR, @@ -490,6 +491,8 @@ public: bool open_buffers_in_tabs; /// bool single_close_tab_button; + /// + std::string forward_search; }; diff --git a/src/TexRow.cpp b/src/TexRow.cpp index f019c25..ac3c7c7 100644 --- a/src/TexRow.cpp +++ b/src/TexRow.cpp @@ -68,6 +68,9 @@ bool TexRow::getIdFromRow(int row, int & id, int & pos) const int TexRow::getRowFromIdPos(int id, int pos) const { bool foundid = false; + //lyxerr<<"Table:"; + //for (unsigned int i=0; i<rowlist.size(); i++) + //lyxerr<<i<<" (id,pos):\t"<<rowlist[i].id()<<" "<<rowlist[i].pos()<<"\n"; // this loop finds the last *nonempty* row with the same id // and position <= pos diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 1d8142c..722c81f 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -57,6 +57,7 @@ #include "LyXVC.h" #include "Paragraph.h" #include "SpellChecker.h" +#include "TexRow.h" #include "TextClass.h" #include "Text.h" #include "Toolbars.h" @@ -1656,6 +1657,7 @@ bool GuiView::getStatus(FuncRequest const & cmd, FuncStatus & flag) break; case LFUN_SERVER_GOTO_FILE_ROW: + case LFUN_FORWARD_SEARCH: break; default: @@ -3221,6 +3223,28 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr) goToFileRow(to_utf8(cmd.argument())); break; + case LFUN_FORWARD_SEARCH: { + string out_type="dvi"; + if (argument == "pdf") + out_type = "pdf"; + + FileName const path(doc_buffer->temppath()); + string const texname = addName(path.absFilename(), doc_buffer->latexName()); + string const outname = addName(path.absFilename(), support::changeExtension(doc_buffer->latexName(), out_type)); + int row = doc_buffer->texrow().getRowFromIdPos(bv->cursor().paragraph().id(), bv->cursor().pos()); + if (!row) + break; + string texrow = convert<string>(row); + + string command = lyxrc.forward_search; + command = subst(command, "$$n", texrow); + command = subst(command, "$$t", texname); + command = subst(command, "$$o", outname); + + Systemcall one; + one.startscript(Systemcall::Wait, command); + break; + } default: dr.dispatched(false); break;