]> git.lyx.org Git - features.git/blobdiff - src/lyxfunc.C
fix call to Dispatch
[features.git] / src / lyxfunc.C
index c359d127f85d778c13fbf293c93d8ad0251cf28d..5c6eece450d21a820e797518a324d35a5c30c503 100644 (file)
 
 #include <config.h>
 
-#ifdef HAVE_SSTREAM
-#include <sstream>
-using std::istringstream;
-#else
-#include <strstream>
-#endif
+#include "Lsstream.h"
 
 #include <time.h>
 #include <locale.h>
@@ -86,12 +81,9 @@ using std::istringstream;
 #include "bufferview_funcs.h"
 #include "frontends/Dialogs.h"
 #include "frontends/Toolbar.h"
-#ifdef NEW_MENUBAR
 #include "frontends/Menubar.h"
-#else
-#include "menus.h"
-#endif
 #include "FloatList.h"
+#include "exporter.h"
 #include "FontLoader.h"
 #include "TextCache.h"
 
@@ -101,7 +93,7 @@ using std::endl;
 extern bool cursor_follows_scrollbar;
 
 extern void InsertAsciiFile(BufferView *, string const &, bool);
-extern void math_insert_symbol(char const *);
+extern void math_insert_symbol(string const &);
 extern bool math_insert_greek(char);
 extern BufferList bufferlist;
 extern LyXServer * lyxserver;
@@ -115,12 +107,16 @@ extern bool MenuWriteAs(Buffer *);
 extern int  MenuRunLaTeX(Buffer *);
 extern int  MenuBuildProg(Buffer *);
 extern int  MenuRunChktex(Buffer *);
+#ifndef NEW_EXPORT
 extern bool CreatePostscript(Buffer *, bool);
+#endif
 extern void MenuPrint(Buffer *);
 extern void MenuSendto();
 extern void QuitLyX();
 extern void MenuFax(Buffer *);
+#ifndef NEW_EXPORT
 extern void MenuExport(Buffer *, string const &);
+#endif
 extern void show_symbols_form(LyXFunc *);
 
 extern LyXAction lyxaction;
@@ -128,9 +124,11 @@ extern LyXAction lyxaction;
 extern tex_accent_struct get_accent(kb_action action);
 
 extern void AutoSave(BufferView *);
+#ifndef NEW_EXPORT
 extern bool PreviewDVI(Buffer *);
 extern bool PreviewPostscript(Buffer *);
-extern void MenuInsertLabel(char const *);
+#endif
+extern void MenuInsertLabel(string const &);
 extern void MenuLayoutCharacter();
 extern void MenuLayoutParagraph();
 extern void MenuLayoutDocument();
@@ -262,10 +260,6 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                lyxerr << "Key ["
                       << action << "]["
                       << buf << "]"
-#if 0
-                      << "["
-                      << num_bytes << "]"
-#endif
                       << endl;
        }
 
@@ -301,15 +295,10 @@ int LyXFunc::processKeySym(KeySym keysym, unsigned int state)
                        return 0;
                }
        }
-#if 0
-       else
-               if (action == LFUN_SELFINSERT) {
-                       argument = s_r[0];
-               }
-#endif
+
         bool tmp_sc = show_sc;
        show_sc = false;
-       Dispatch(action, argument.c_str());
+       Dispatch(action, argument);
        show_sc = tmp_sc;
        
        return 0;
@@ -443,7 +432,7 @@ int LyXFunc::processKeyEvent(XEvent * ev)
 
         bool tmp_sc = show_sc;
        show_sc = false;
-       Dispatch(action, argument.c_str());
+       Dispatch(action, argument);
        show_sc = tmp_sc;
        
        return 0;
@@ -495,6 +484,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
         static bool noLaTeX = lyxrc.latex_command == "none";
         bool disable = false;
         switch (action) {
+#ifndef NEW_EXPORT
        case LFUN_PREVIEW:
                disable = noLaTeX || lyxrc.view_dvi_command == "none";
                break;
@@ -505,6 +495,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
        case LFUN_RUNDVIPS:
                disable = noLaTeX;
                break;
+#endif
        case LFUN_MENUPRINT:
                disable = noLaTeX || lyxrc.print_command == "none";
                break;
@@ -517,6 +508,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
                else if (argument == "linuxdoc")
                        disable = lyxrc.linuxdoc_to_lyx_command == "none";
                break;
+#ifndef NEW_EXPORT
        case LFUN_EXPORT:
                if (argument == "latex")
                        disable = (! buf->isLatex() && ! buf->isLiterate()) ;
@@ -536,6 +528,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
                else if (argument == "custom")
                        disable = (! buf->isLatex() && ! buf->isLiterate());
                break;
+#endif
        case LFUN_UNDO:
                disable = buf->undostack.empty();
                break;
@@ -569,7 +562,7 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
        case LFUN_TABULAR_FEATURE:
                disable = true;
                if (owner->view()->the_locking_inset) {
-                       int ret = 0;
+                       func_status ret = LyXFunc::Disabled;
                        if (owner->view()->the_locking_inset->LyxCode() == Inset::TABULAR_CODE) {
                                ret = static_cast<InsetTabular *>
                                        (owner->view()->the_locking_inset)->
@@ -580,21 +573,17 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
                                        GetFirstLockingInsetOfType(Inset::TABULAR_CODE))->
                                        getStatus(argument);
                        }
-                       switch(ret) {
-                       case 0:
-                               break;
-                       case 1:
-                               disable = false;
-                               break;
-                       case 2:
-                               disable = false;
-                               flag |= LyXFunc::ToggleOn;
-                               break;
-                       case 3:
-                               disable = false;
-                               flag |= LyXFunc::ToggleOff;
-                               break;
-                       }
+                       flag |= ret;
+                       disable = false;
+               } else {
+                   static InsetTabular inset(owner->buffer(), 1, 1);
+                   func_status ret;
+
+                   disable = true;
+                   ret = inset.getStatus(argument);
+                   if ((ret & LyXFunc::ToggleOn) ||
+                       (ret & LyXFunc::ToggleOff))
+                       flag |= LyXFunc::ToggleOff;
                }
                break;
 
@@ -612,6 +601,9 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
        case LFUN_VC_HISTORY:
                disable = !buf->lyxvc.inUse();
                break;
+       case LFUN_REF_BACK:
+               disable = owner->view()->NoSavedPositions();
+               break;
        default:
                break;
         }
@@ -655,18 +647,19 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
 }
 
 
-string LyXFunc::Dispatch(string const & s) 
+string const LyXFunc::Dispatch(string const & s) 
 {
        // Split command string into command and argument
-       string cmd, line = frontStrip(s);
+       string cmd;
+       string line = frontStrip(s);
        string arg = strip(frontStrip(split(line, cmd, ' ')));
 
-       return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
+       return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg);
 }
 
 
-string LyXFunc::Dispatch(int ac,
-                        char const * do_not_use_this_arg)
+string const LyXFunc::Dispatch(int ac,
+                        string const & do_not_use_this_arg)
 {
        string argument;
        kb_action action;
@@ -684,7 +677,7 @@ string LyXFunc::Dispatch(int ac,
                        argument = tmparg;
        } else {
                action = static_cast<kb_action>(ac);
-               if (do_not_use_this_arg)
+               if (!do_not_use_this_arg.empty())
                        argument = do_not_use_this_arg; // except here
        }
     
@@ -976,6 +969,15 @@ string LyXFunc::Dispatch(int ac,
                reloadBuffer();
                break;
                
+#ifdef NEW_EXPORT
+       case LFUN_UPDATE:
+               Exporter::Export(owner->buffer(), argument, true);
+               break;
+
+       case LFUN_PREVIEW:
+               Exporter::Preview(owner->buffer(), argument);
+               break;
+#else
        case LFUN_PREVIEW:
                PreviewDVI(owner->buffer());
                break;
@@ -987,6 +989,11 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_RUNLATEX:
                MenuRunLaTeX(owner->buffer());
                break;
+
+       case LFUN_RUNDVIPS:
+               CreatePostscript(owner->buffer(), false);
+               break;
+#endif
                
         case LFUN_BUILDPROG:
                 MenuBuildProg(owner->buffer());
@@ -995,11 +1002,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_RUNCHKTEX:
                MenuRunChktex(owner->buffer());
                break;
-               
-       case LFUN_RUNDVIPS:
-               CreatePostscript(owner->buffer(), false);
-               break;
-               
+                               
        case LFUN_MENUPRINT:
                owner->getDialogs()->showPrint();
                break;
@@ -1009,7 +1012,11 @@ string LyXFunc::Dispatch(int ac,
                break;
                        
        case LFUN_EXPORT:
+#ifdef NEW_EXPORT
+               Exporter::Export(owner->buffer(), argument, false);
+#else
                MenuExport(owner->buffer(), argument);
+#endif
                break;
 
        case LFUN_IMPORT:
@@ -1062,7 +1069,7 @@ string LyXFunc::Dispatch(int ac,
                break;
        }
                
-       case LFUN_TABLE:
+       case LFUN_DIALOG_TABULAR_INSERT:
 #ifndef NEW_TABULAR
                Table();
 #else
@@ -1382,7 +1389,7 @@ string LyXFunc::Dispatch(int ac,
                Dispatch(int(LFUN_LAYOUT), 
                         textclasslist.NameOfLayout(owner->view()
                                                    ->buffer()->params.textclass,
-                                                   sel).c_str());
+                                                   sel));
                return string();
        }
                
@@ -1428,7 +1435,7 @@ string LyXFunc::Dispatch(int ac,
        break;
 
        case LFUN_LAYOUT_DOCUMENT:
-#ifdef USE_OLD_LAYOUT
+#ifdef USE_OLD_DOCUMENT_LAYOUT
                MenuLayoutDocument();
 #else
                owner->getDialogs()->showLayoutDocument();
@@ -1467,11 +1474,15 @@ string LyXFunc::Dispatch(int ac,
            break;
 
        case LFUN_LAYOUT_PAPER:
+#ifdef USE_OLD_DOCUMENT_LAYOUT
                MenuLayoutPaper();
+#endif
                break;
                
        case LFUN_LAYOUT_QUOTES:
+#ifdef USE_OLD_DOCUMENT_LAYOUT
                MenuLayoutQuotes();
+#endif
                break;
                
        case LFUN_LAYOUT_PREAMBLE:
@@ -1566,26 +1577,22 @@ string LyXFunc::Dispatch(int ac,
                MenuInsertLabel(argument.c_str());
                break;
                
-       case LFUN_REF_CREATE:
-       {
-               InsetCommandParams p( "ref" );
-               owner->getDialogs()->createRef( p.getAsString() );
-       }
-       break;
-               
        case LFUN_REF_INSERT:
-       {
-               InsetCommandParams p;
-               p.setFromString( argument );
+               if (argument.empty()) {
+                       InsetCommandParams p("ref");
+               owner->getDialogs()->createRef(p.getAsString());
+               } else {
+                       InsetCommandParams p;
+                       p.setFromString(argument);
+
+                       InsetRef * inset = new InsetRef(p);
+                       if (!owner->view()->insertInset(inset))
+                               delete inset;
+                       else
+                               owner->view()->updateInset(inset, true);
+               }
+               break;
 
-               InsetRef * inset = new InsetRef( p );
-               if (!owner->view()->insertInset(inset))
-                       delete inset;
-               else
-                       owner->view()->updateInset( inset, true );
-       }
-       break;
-                   
        case LFUN_REF_BACK:
        {
                owner->view()->restorePosition();
@@ -1613,11 +1620,7 @@ string LyXFunc::Dispatch(int ac,
        break;
                
        case LFUN_MENU_OPEN_BY_NAME:
-#ifdef NEW_MENUBAR
                owner->getMenubar()->openByName(argument);
-#else
-               owner->getMenus()->openByName(argument);
-#endif
                break; // RVDK_PATCH_5
                
        case LFUN_SPELLCHECK:
@@ -2215,11 +2218,8 @@ string LyXFunc::Dispatch(int ac,
                        cur_value = par->spacing.getValue();
                }
                
-#ifdef HAVE_SSTREAM
                istringstream istr(argument);
-#else
-               istrstream istr(argument.c_str());
-#endif
+
                string tmp;
                istr >> tmp;
                Spacing::Space new_spacing = cur_spacing;
@@ -2515,6 +2515,24 @@ string LyXFunc::Dispatch(int ac,
        }
        break;
 
+       case LFUN_GOTO_PARAGRAPH:
+       {
+                istringstream istr(argument);
+
+               int id;
+               istr >> id;
+               LyXParagraph * par = owner->view()->text->GetParFromID(id);
+
+               // Set the cursor
+               owner->view()->text->SetCursor(owner->view(), par, 0);
+               owner->view()->setState();
+               owner->showState();
+
+               // Recenter screen
+               owner->view()->center();
+       }
+       break;
+
        case LFUN_APROPOS:
        case LFUN_GETTIP:
        {
@@ -3189,12 +3207,13 @@ void LyXFunc::MenuNew(bool fromTemplate)
                        }
                }
        } else {
-               s = lyxrc.document_path + "newfile" + tostr(++newfile_number);
+               s = AddPath(lyxrc.document_path,
+                           "newfile" + tostr(++newfile_number));
                FileInfo fi(s);
                while (bufferlist.exists(s) || fi.readable()) {
                        ++newfile_number;
-                       s = lyxrc.document_path + "newfile" +
-                               tostr(newfile_number);
+                       s = AddPath(lyxrc.document_path,
+                                   "newfile" + tostr(newfile_number));
                        fi.newFile(s);
                }
        }