]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Small fixes
[lyx.git] / src / lyxfunc.C
index 893dc3b65217b0a7f9e8fb5e465e71f585abb346..242c756850c9da2d917b4c53fa1b3c6b23d19fcf 100644 (file)
@@ -91,7 +91,6 @@ using std::pair;
 using std::endl;
 using std::find_if;
 
-extern void InsertAsciiFile(BufferView *, string const &, bool);
 extern void math_insert_symbol(string const &);
 extern bool math_insert_greek(char);
 extern BufferList bufferlist;
@@ -101,14 +100,6 @@ 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
@@ -118,19 +109,7 @@ 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();
 
@@ -345,10 +324,12 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
                disable = !Exporter::IsExportable(buf, "ps")
                        || lyxrc.fax_command == "none";
                break;
-#endif
-       case LFUN_IMPORT:
-               disable = !Importer::IsImportable(argument);
+#else
+       case LFUN_EXPORT:
+               disable = argument == "fax" &&
+                       !Exporter::IsExportable(buf, argument);
                break;
+#endif
        case LFUN_UNDO:
                disable = buf->undostack.empty();
                break;
@@ -365,6 +346,17 @@ LyXFunc::func_status LyXFunc::getStatus(int ac) const
                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()->theLockingInset()) {
@@ -771,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()));
@@ -779,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:
@@ -1285,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:
@@ -1373,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:
@@ -2046,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;
@@ -2345,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;
@@ -2504,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));
                        }
@@ -2569,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";
@@ -2642,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;
                    
@@ -2658,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;
@@ -2705,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 ") +
@@ -2725,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;
                }
@@ -2771,7 +2763,7 @@ string const LyXFunc::Dispatch(int ac,
 
        case LFUN_SELFINSERT:
        {
-               LyXFont old_font(owner->view()->text->real_current_font);
+               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
@@ -2813,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);
@@ -2854,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 <lyx_name>"
@@ -2864,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));
@@ -2906,7 +2900,7 @@ string const LyXFunc::Dispatch(int ac,
                        }
                        
                        owner->view()->beforeChange();
-                       LyXFont old_font(owner->view()->text->real_current_font);
+                       LyXFont const old_font(owner->view()->text->real_current_font);
                        for (string::size_type i = 0;
                             i < argument.length(); ++i) {
                                if (greek_kb_flag) {
@@ -2943,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
                                                            + " " +
@@ -2978,7 +2973,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
        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;
@@ -2986,7 +2981,7 @@ 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);
@@ -3063,9 +3058,9 @@ void LyXFunc::MenuNew(bool fromTemplate)
        string templname;
        if (fromTemplate) {
                ProhibitInput(owner->view());
-               string fname = fileDlg.Select(_("Choose template"),
-                                      lyxrc.template_path,
-                                      "*.lyx");
+               string const fname = fileDlg.Select(_("Choose template"),
+                                                   lyxrc.template_path,
+                                                   "*.lyx");
                AllowInput(owner->view());
                if (fname.empty()) return;
                 templname = fname;
@@ -3083,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;
@@ -3125,6 +3120,7 @@ void LyXFunc::MenuOpen()
        }
 }
 
+
 // checks for running without gui are missing.
 void LyXFunc::doImport(string const & argument)
 {
@@ -3138,7 +3134,7 @@ void LyXFunc::doImport(string const & argument)
                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;
@@ -3149,10 +3145,9 @@ void LyXFunc::doImport(string const & argument)
                fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
                fileDlg.SetButton(1, _("Examples"), 
                                        AddPath(system_lyxdir, "examples"));
-               string text = _("Select ") + Formats::PrettyName(format)
+               string const text = _("Select ") + formats.PrettyName(format)
                        + _(" file to import");
-               string format2 = (format == "textparagraph") ? "text" : format;
-               string extension = "*." + Formats::Extension(format2);
+               string const extension = "*." + formats.Extension(format);
                filename = fileDlg.Select(text, initpath, extension);
                AllowInput(owner->view());
  
@@ -3168,7 +3163,7 @@ void LyXFunc::doImport(string const & argument)
        // 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)) {
@@ -3192,7 +3187,7 @@ void LyXFunc::doImport(string const & argument)
        }
 
        // 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?"))) {
@@ -3215,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;
@@ -3246,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),
@@ -3260,7 +3255,7 @@ void LyXFunc::MenuInsertLyXFile(string const & filen)
 
 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));
 }
@@ -3274,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());
                }
        }