]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
removed a warning from screen and added CFLAGS in lyx.spec.in.
[lyx.git] / src / lyxfunc.C
index 3b9897713f86dec957bfd541d38b4cccc979ab6f..24a0a3406fdc1c701fa79d26ae19b236a6fa1249 100644 (file)
@@ -58,6 +58,8 @@
 #include "trans_mgr.h"
 #include "ImportLaTeX.h"
 #include "ImportNoweb.h"
+#include "support/syscall.h"
+#include "support/lstrings.h"
 
 extern bool cursor_follows_scrollbar;
 
@@ -157,19 +159,6 @@ LyXFunc::~LyXFunc()
 }
 
 
-string LyXFunc::argAsString(char const * const argument)
-{
-       string tmp(argument);
-
-       if (tmp.empty()) {
-               // get the arg from somewhere else, a popup, or ask for
-               // it in the minibuffer.
-       }
-       lyxerr.debug() << "argAsString: <" << tmp << '>' << endl;
-       return tmp;
-}
-
-
 // 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
@@ -200,7 +189,7 @@ int LyXFunc::processKeyEvent(XEvent *ev)
        s_r[9] = '\0';
        int num_bytes;
        int action; 
-       char *argument = 0;
+       string argument;
        XKeyEvent *keyevent = &ev->xkey;
        KeySym keysym_return;
 
@@ -296,11 +285,9 @@ int LyXFunc::processKeyEvent(XEvent *ev)
                if (!(keyevent->state&ControlMask) &&
                    !(keyevent->state&Mod1Mask) &&
                    (isochar && keysym_return < 0xF000)) {
-                       argument = &s_r[0]; // shall this be here
-                       argument[0] = isochar;
-                       argument[1] = 0;
+                       argument += isochar;
                }
-               if (!argument) {
+               if (argument.empty()) {
                        lyxerr.debug() << "Empty argument!" << endl;
                        // This can`t possibly be of any use
                        // so we`ll skip the dispatch.
@@ -308,21 +295,14 @@ int LyXFunc::processKeyEvent(XEvent *ev)
                }
        } else
                if (action==LFUN_SELFINSERT) {
-                       argument = &s_r[0];
-                       argument[1] = 0;
+                       argument = s_r[0];
                }
     
         bool tmp_sc = show_sc;
        show_sc = false;
-       Dispatch(action, argument);
+       Dispatch(action, argument.c_str());
        show_sc = tmp_sc;
        
-       // Need this for deadkeys (alkis)
-       //keyseq.length=0;
-       // ...but that breaks the minibuffer's display of "M-"...
-#ifdef WITH_WARNINGS
-#warning How does the deadkeys react to this?
-#endif
        return 0;
 } 
 
@@ -337,7 +317,7 @@ string LyXFunc::Dispatch(string const &cmd, string const &arg)
 string LyXFunc::Dispatch(int ac,
                          char const *do_not_use_this_arg)
 {
-       char const * argument = 0;
+       string argument;
        kb_action action;
         
 
@@ -355,7 +335,8 @@ string LyXFunc::Dispatch(int ac,
                        argument = tmparg;
        } else {
                action = (kb_action)ac;
-               argument = do_not_use_this_arg; // except here
+               if (do_not_use_this_arg)
+                       argument = do_not_use_this_arg; // except here
        }
     
        selection_possible = false;
@@ -408,19 +389,17 @@ string LyXFunc::Dispatch(int ac,
                        int pseudoaction = action;
                        bool argsadded = false;
 
-                       string argu;
-                       if (argument) {
-                               argu = argument;
+                       if (!argument.empty()) {
                                // If we have the command with argument, 
                                // this is better
                                pseudoaction = 
                                        lyxaction.searchActionArg(action,
-                                                                 argument);
+                                                                 argument.c_str());
 
                                if (pseudoaction == -1) {
                                        pseudoaction = action;
                                } else {
-                                       comname += " " + argu;
+                                       comname += " " + argument;
                                        argsadded = true;
                                }
                        }
@@ -430,7 +409,7 @@ string LyXFunc::Dispatch(int ac,
                        if (!shortcuts.empty()) {
                                comname += ": " + shortcuts;
                        } else if (!argsadded) {
-                               comname += " " + argu;
+                               comname += " " + argument;
                        }
 
                        if (!comname.empty()) {
@@ -462,10 +441,8 @@ string LyXFunc::Dispatch(int ac,
        if (owner->currentView()->available() &&
            owner->currentBuffer()->the_locking_inset) {
                if (action>1 || (action==LFUN_UNKNOWN_ACTION && keyseq.length>=-1)) {
-                       char s[8]="";
-                       if (action==LFUN_UNKNOWN_ACTION && !argument) {
-                               sprintf(s, "%c", keyseq.getiso());
-                               argument = &s[0];
+                       if (action==LFUN_UNKNOWN_ACTION && argument.empty()) {
+                               argument = keyseq.getiso();
                        }
                        // Undo/Redo pre 0.13 is a bit tricky for insets.                   
                        if (action==LFUN_UNDO) {
@@ -491,7 +468,7 @@ string LyXFunc::Dispatch(int ac,
                                                inset->Edit(slx, sly);
                                        return string();
                                } else
-                                       if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument))
+                                       if (owner->currentBuffer()->the_locking_inset->LocalDispatch(action, argument.c_str()))
                                                return string();
                                        else {
                                                setMessage(N_("Text mode"));
@@ -511,11 +488,9 @@ string LyXFunc::Dispatch(int ac,
                static string last_search;
                string searched_string;
            
-               string arg = argAsString(argument);
-                       
-               if (!arg.empty()) {
-                       last_search = arg;
-                       searched_string = arg;
+               if (!argument.empty()) {
+                       last_search = argument;
+                       searched_string = argument;
                } else {
                        searched_string = last_search;
                }
@@ -685,7 +660,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_EXPORT:
        {
                //needs argument as string
-               string extyp=argAsString(argument);
+               string extyp=argument;
                
                // latex
                if (extyp == "latex") {
@@ -730,8 +705,29 @@ string LyXFunc::Dispatch(int ac,
                        MenuSendto();
                        break;
                }
+               // HTML
+               else if (extyp == "html") {
+                       // First, create LaTeX file
+                       MenuMakeLaTeX(owner->currentBuffer());
+
+                       // And now, run tth
+                       string file = owner->currentBuffer()->getFileName();
+                       file = ChangeExtension(file, ".tex", false);
+                       string result = ChangeExtension(file, ".html", false);
+                       string tmp = lyxrc->tth_command + " < " + file 
+                           + " > " + result ;
+                       Systemcalls one;
+                       int res = one.startscript(Systemcalls::System, tmp);
+                       if (res == 0) {
+                               setMessage(string(
+                                 _("Document exported as HTML to file: ")) + result);
+                       } else {
+                               setErrorMessage(string(
+                                 _("An unexpected error occured while converting document to HTML in file:")) + result);
+                       }
+               }
                else {
-                       setErrorMessage(string(N_("Unknown export type: "))
+                       setErrorMessage(string(_("Unknown export type: "))
                                        + extyp);
                }
        }
@@ -740,7 +736,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_IMPORT:
        {
                //needs argument as string
-               string imtyp=argAsString(argument);
+               string imtyp=argument;
                
                // latex
                if (imtyp == "latex") {
@@ -770,10 +766,16 @@ string LyXFunc::Dispatch(int ac,
                if (fd_form_toc->form_toc->visible) {
                        fl_raise_form(fd_form_toc->form_toc);
                } else {
+                       static int ow = -1, oh;
                        fl_show_form(fd_form_toc->form_toc,
                                     FL_PLACE_MOUSE |
                                     FL_FREE_SIZE, FL_FULLBORDER,
                                     _("Table of Contents"));
+                       if (ow < 0) {
+                               ow = fd_form_toc->form_toc->w;
+                               oh = fd_form_toc->form_toc->h;
+                       }
+                       fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
                }
                break;
                
@@ -1020,9 +1022,7 @@ string LyXFunc::Dispatch(int ac,
                        
        case LFUN_FILE_INSERT:
        {
-               // needs argument as string
-               string fil = argAsString(argument);
-               MenuInsertLyXFile(fil);
+               MenuInsertLyXFile(argument);
        }
        break;
        
@@ -1056,7 +1056,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_LAYOUTNO:
        {
                lyxerr.debug() << "LFUN_LAYOUTNO: (arg) " << argument << endl;
-               int sel = atoi(argument);
+               int sel = strToInt(argument);
                lyxerr.debug() << "LFUN_LAYOUTNO: (sel) "<< sel << endl;
                
                // Should this give a setMessage instead?
@@ -1216,7 +1216,7 @@ string LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_INSERT_LABEL:
-               MenuInsertLabel(argument);
+               MenuInsertLabel(argument.c_str());
                break;
                
        case LFUN_INSERT_REF:
@@ -1857,7 +1857,7 @@ string LyXFunc::Dispatch(int ac,
        {
                int  x;
                long y;
-               sscanf(argument, " %d %ld", &x, &y);
+               sscanf(argument.c_str(), " %d %ld", &x, &y);
                owner->currentBuffer()->text->SetCursorFromCoordinates(x, y);
        }
        break;
@@ -1910,7 +1910,7 @@ string LyXFunc::Dispatch(int ac,
        {
                char file_name[100];
                int  row;
-               sscanf(argument, " %s %d", file_name, &row);
+               sscanf(argument.c_str(), " %s %d", file_name, &row);
 
                // Must replace extension of the file to be .lyx and get full path
                string s = ChangeExtension(string(file_name), ".lyx", false);
@@ -1943,7 +1943,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_APROPOS:
        case LFUN_GETTIP:
        {
-               int qa = lyxaction.LookupFunc((const char*)argument);
+               int qa = lyxaction.LookupFunc(argument.c_str());
                setMessage(lyxaction.helpText((kb_action)qa));
        }
        break;
@@ -1995,7 +1995,7 @@ string LyXFunc::Dispatch(int ac,
        // --- toolbar ----------------------------------
        case LFUN_PUSH_TOOLBAR:
        {
-               int nth = atoi(argument);
+               int nth = strToInt(argument);
                if (lyxerr.debugging(Debug::TOOLBAR)) {
                        lyxerr << "LFUN_PUSH_TOOLBAR: argument = `"
                               << argument << "'\n"
@@ -2072,14 +2072,14 @@ string LyXFunc::Dispatch(int ac,
                        owner->currentBuffer()->
                                open_new_inset(new InsetFormula(false));
                        owner->currentBuffer()->
-                               the_locking_inset->LocalDispatch(action, argument);
+                               the_locking_inset->LocalDispatch(action, argument.c_str());
                }
        }          
        break;
               
        case LFUN_INSERT_MATH:
        {
-               math_insert_symbol(argument);
+               math_insert_symbol(argument.c_str());
        }
        break;
        
@@ -2128,7 +2128,7 @@ string LyXFunc::Dispatch(int ac,
                // ale970405
                // The note, if any, must be after the key, delimited
                // by a | so both key and remark can have spaces.
-               if (argument) {
+               if (!argument.empty()) {
                        string lsarg(argument);
                        if (contains(lsarg, "|")) {
                                new_inset->setContents(token(lsarg, '|', 0));
@@ -2199,7 +2199,7 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_INDEX_INSERT_LAST:
        {
                InsetIndex *new_inset = new InsetIndex();
-               if (argument) {
+               if (!argument.empty()) {
                        string lsarg(argument);
                        new_inset->setContents(lsarg);
                        owner->currentBuffer()->insertInset(new_inset);
@@ -2290,20 +2290,19 @@ string LyXFunc::Dispatch(int ac,
        case LFUN_INSERTFOOTNOTE: 
        {
                LyXParagraph::footnote_kind kind;
-               string arg = argument;
-               if (arg == "footnote")
+               if (argument == "footnote")
                        { kind = LyXParagraph::FOOTNOTE; }
-               else if (arg == "margin")
+               else if (argument == "margin")
                        { kind = LyXParagraph::MARGIN; }
-               else if (arg == "figure")
+               else if (argument == "figure")
                        { kind = LyXParagraph::FIG; }
-               else if (arg == "table")
+               else if (argument == "table")
                        { kind = LyXParagraph::TAB; }
-               else if (arg == "wide-fig")
+               else if (argument == "wide-fig")
                        { kind = LyXParagraph::WIDE_FIG; }
-               else if (arg == "wide-tab")
+               else if (argument == "wide-tab")
                        { kind = LyXParagraph::WIDE_TAB; }
-               else if (arg == "algorithm")
+               else if (argument == "algorithm")
                        { kind = LyXParagraph::ALGORITHM; }
                else {
                        setErrorMessage(N_("Unknown kind of footnote"));
@@ -2340,9 +2339,8 @@ string LyXFunc::Dispatch(int ac,
 
        case LFUN_SELFINSERT:
        {
-               string const text = argument;
-               for (string::size_type i = 0; i < text.length(); ++i) {
-                       owner->currentBuffer()->text->InsertChar(text[i]);
+               for (string::size_type i = 0; i < argument.length(); ++i) {
+                       owner->currentBuffer()->text->InsertChar(argument[i]);
                        // This needs to be in the loop, or else we
                        // won't break lines correctly. (Asger)
                        SmallUpdate(1);
@@ -2362,7 +2360,7 @@ string LyXFunc::Dispatch(int ac,
                        break;
                }
                         
-               if (argument) {
+               if (!argument.empty()) {
                        
                        /* Automatically delete the currently selected
                         * text and replace it with what is being
@@ -2378,12 +2376,12 @@ string LyXFunc::Dispatch(int ac,
                        }
                        
                        BeforeChange();
-                       for(char const *p = argument; *p; p++) {
+                       for (string::size_type i = 0; i < argument.length(); ++i) {
                                if (greek_kb_flag) {
-                                       if (!math_insert_greek(*p))
-                                               owner->getIntl()->getTrans()->TranslateAndInsert(*p, owner->currentBuffer()->text);
+                                       if (!math_insert_greek(argument[i]))
+                                               owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
                                } else
-                                       owner->getIntl()->getTrans()->TranslateAndInsert(*p, owner->currentBuffer()->text);
+                                       owner->getIntl()->getTrans()->TranslateAndInsert(argument[i], owner->currentBuffer()->text);
                        }
                        
                        SmallUpdate(1);