]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
Applied Angus patch to compile on DEC C++ and to avoid name clashes
[lyx.git] / src / lyxfunc.C
index b44f6c808c7018ab3ab15d9956222d65959bfbca..aad8925e1bf5b2c03e0eef4633378494096ab3f0 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <time.h>
 #include <locale.h>
+#include <utility> 
+#include <algorithm> 
 
 #include <cstdlib>
 #include <cctype>
@@ -60,7 +62,6 @@
 #include "minibuffer.h"
 #include "vspace.h"
 #include "LyXView.h"
-#include "filedlg.h"
 #include "lyx_gui_misc.h"
 #include "support/filetools.h"
 #include "support/FileInfo.h"
@@ -75,8 +76,8 @@
 #include "trans_mgr.h"
 #include "layout.h"
 #include "WorkArea.h"
-#include "lyxfr1.h"
 #include "bufferview_funcs.h"
+#include "frontends/FileDialog.h"
 #include "frontends/Dialogs.h"
 #include "frontends/Toolbar.h"
 #include "frontends/Menubar.h"
 #include "importer.h"
 #include "FontLoader.h"
 #include "TextCache.h"
+#include "lyxfind.h"
 
 using std::pair;
+using std::make_pair; 
 using std::endl;
 using std::find_if;
 
-extern void math_insert_symbol(BufferView *, string const &);
-extern bool math_insert_greek(BufferView *, char);
 extern BufferList bufferlist;
 extern LyXServer * lyxserver;
 extern int greek_kb_flag;
 extern bool selection_possible;
 extern void MenuSendto();
 
-extern kb_keymap * toplevel_keymap;
+extern boost::scoped_ptr<kb_keymap> toplevel_keymap;
 
 extern void show_symbols_form(LyXFunc *);
 
@@ -692,6 +693,8 @@ string const LyXFunc::Dispatch(int ac,
                }
        }
 
+       Assert(action != LFUN_SELECT_FILE_SYNC);
+
        switch (action) {
                // --- Misc -------------------------------------------
        case LFUN_WORDFINDFORWARD  : 
@@ -708,8 +711,8 @@ string const LyXFunc::Dispatch(int ac,
 
                if (!searched_string.empty() &&
                    ((action == LFUN_WORDFINDBACKWARD) ? 
-                    TEXT()->SearchBackward(owner->view(), searched_string) :
-                    TEXT()->SearchForward(owner->view(), searched_string))) {
+                    SearchBackward(owner->view(), searched_string) :
+                    SearchForward(owner->view(), searched_string))) {
 
                        // ??? What is that ???
                        owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR);
@@ -793,10 +796,6 @@ string const LyXFunc::Dispatch(int ac,
                MenuNew(true);
                break;
                
-       case LFUN_MENUOPEN:
-               MenuOpen();
-               break;
-               
        case LFUN_CLOSEBUFFER:
                CloseBuffer();
                break;
@@ -807,19 +806,12 @@ string const LyXFunc::Dispatch(int ac,
                                                    MakeDisplayPath(owner->buffer()->fileName()),
                                                    "...");
                        MenuWrite(owner->view(), owner->buffer());
-                       //owner->getMiniBuffer()-> {
-                       //      Set(_("Document saved as"),
-                       //          MakeDisplayPath(owner->buffer()->fileName()));
-                       //} else {
-                       //owner->getMiniBuffer()->Set(_("Save failed!"));
-                       //}
-               } else {
-                       MenuWriteAs(owner->view(), owner->buffer());
-               }
+               } else
+                       WriteAs(owner->view(), owner->buffer());
                break;
                
-       case LFUN_MENUWRITEAS:
-               MenuWriteAs(owner->view(), owner->buffer());
+       case LFUN_WRITEAS:
+               WriteAs(owner->view(), owner->buffer(), argument);
                break;
                
        case LFUN_MENURELOAD:
@@ -902,14 +894,8 @@ string const LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_MENUSEARCH:
-       {
-               // Ok this is one _very_ bad solution, but I think that some
-               // of this will be rewritten as part of GUI indep anyway.
-               // Lgb
-               static LyXFindReplace FR_;
-               FR_.StartSearch(owner->view());
-       }
-       break;
+               owner->getDialogs()->showSearch();
+               break;
                
        case LFUN_REMOVEERRORS:
                if (owner->view()->removeAutoInsets()) {
@@ -1117,7 +1103,7 @@ string const LyXFunc::Dispatch(int ac,
        break;
                        
        case LFUN_FILE_OPEN:
-               owner->view()->buffer(bufferlist.loadLyXFile(argument));
+               Open(argument);
                break;
 
        case LFUN_LATEX_LOG:
@@ -1149,11 +1135,7 @@ string const LyXFunc::Dispatch(int ac,
                break;
                
        case LFUN_LAYOUT_PARAGRAPH:
-#ifdef USE_OLD_PARAGRAPH_LAYOUT
-               MenuLayoutParagraph();
-#else
                owner->getDialogs()->showLayoutParagraph();
-#endif
                break;
                
        case LFUN_LAYOUT_CHARACTER:
@@ -1330,10 +1312,8 @@ string const LyXFunc::Dispatch(int ac,
        break;
 
        case LFUN_MATH_PANEL:
-       {
-               show_symbols_form(this);
-       }
-       break;
+               owner->getDialogs()->showMathPanel();
+               break;
        
        case LFUN_CITATION_CREATE:
        {
@@ -1356,22 +1336,6 @@ string const LyXFunc::Dispatch(int ac,
        }
        break;
                    
-       case LFUN_CHILD_CREATE:
-       {
-               InsetCommandParams p("include");
-               if (!argument.empty()) {
-                       if (contains(argument, "|")) {
-                               p.setContents(token(argument, '|', 0));
-                               p.setOptions(token(argument, '|', 1));
-                       } else
-                               p.setContents(argument);
-                       Dispatch(LFUN_CHILD_INSERT, p.getAsString());
-               } else
-                       owner->getDialogs()->createInclude(p.getAsString());
-       }
-       break;
-
        case LFUN_CHILDOPEN:
        {
                string const filename =
@@ -1532,15 +1496,14 @@ exit_with_message:
 
 void LyXFunc::setupLocalKeymap()
 {
-       keyseq.stdmap = keyseq.curmap = toplevel_keymap;
-       cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap;
+       keyseq.stdmap = keyseq.curmap = toplevel_keymap.get();
+       cancel_meta_seq.stdmap = cancel_meta_seq.curmap = toplevel_keymap.get();
 }
 
 
 void LyXFunc::MenuNew(bool fromTemplate)
 {
        string initpath = lyxrc.document_path;
-       LyXFileDlg fileDlg;
 
        if (owner->view()->available()) {
                string const trypath = owner->buffer()->filepath;
@@ -1553,14 +1516,14 @@ void LyXFunc::MenuNew(bool fromTemplate)
        string s;
        
        if (lyxrc.new_ask_filename) {
-               ProhibitInput(owner->view());
-               fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
-               fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
-               string fname = fileDlg.Select(_("Enter Filename for new document"), 
-                                      initpath, "*.lyx", _("newfile"));
-               AllowInput(owner->view());
+               FileDialog fileDlg(owner, _("Enter filename for new document"),
+                       LFUN_SELECT_FILE_SYNC,
+                       make_pair(string(_("Documents")), string(lyxrc.document_path)),
+                       make_pair(string(_("Templates")), string(lyxrc.template_path)));
+
+               FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx|LyX Documents (*.lyx)"), _("newfile"));
        
-               if (fname.empty()) {
+               if (result.second.empty()) {
                        owner->getMiniBuffer()->Set(_("Canceled."));
                        lyxerr.debug() << "New Document Cancelled." << endl;
                        return;
@@ -1568,7 +1531,7 @@ void LyXFunc::MenuNew(bool fromTemplate)
        
                // get absolute path of file and make sure the filename ends
                // with .lyx
-               s = MakeAbsPath(fname);
+               s = MakeAbsPath(result.second);
                if (!IsLyXFilename(s))
                        s += ".lyx";
 
@@ -1627,12 +1590,20 @@ void LyXFunc::MenuNew(bool fromTemplate)
        // The template stuff
        string templname;
        if (fromTemplate) {
-               ProhibitInput(owner->view());
-               string const fname = fileDlg.Select(_("Choose template"),
-                                                   lyxrc.template_path,
-                                                   "*.lyx");
-               AllowInput(owner->view());
-               if (fname.empty()) return;
+               FileDialog fileDlg(owner, _("Select template file"),
+                       LFUN_SELECT_FILE_SYNC,
+                       make_pair(string(_("Documents")), string(lyxrc.document_path)),
+                       make_pair(string(_("Templates")), string(lyxrc.template_path)));
+
+               FileDialog::Result result = fileDlg.Select(initpath, _("*.lyx|LyX Documents (*.lyx)"));
+       
+               if (result.first == FileDialog::Later)
+                       return;
+
+               string const fname = result.second;
+
+               if (fname.empty()) 
+                       return;
                 templname = fname;
        }
   
@@ -1642,10 +1613,9 @@ void LyXFunc::MenuNew(bool fromTemplate)
 }
 
 
-void LyXFunc::MenuOpen()
+void LyXFunc::Open(string const & fname)
 {
        string initpath = lyxrc.document_path;
-       LyXFileDlg fileDlg;
   
        if (owner->view()->available()) {
                string const trypath = owner->buffer()->filepath;
@@ -1654,20 +1624,28 @@ void LyXFunc::MenuOpen()
                        initpath = trypath;
        }
 
-       // launches dialog
-       ProhibitInput(owner->view());
-       fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
-       fileDlg.SetButton(1, _("Examples"), 
-                         AddPath(system_lyxdir, "examples"));
-       string filename = fileDlg.Select(_("Select Document to Open"),
-                                        initpath, "*.lyx");
-       AllowInput(owner->view());
+       string filename;
  
-       // check selected filename
-       if (filename.empty()) {
-               owner->getMiniBuffer()->Set(_("Canceled."));
-               return;
-       }
+       if (fname.empty()) {
+               FileDialog fileDlg(owner, _("Select document to open"),
+                       LFUN_FILE_OPEN,
+                       make_pair(string(_("Documents")), string(lyxrc.document_path)),
+                       make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
+
+               FileDialog::Result result = fileDlg.Select(initpath, "*.lyx|LyX Documents (*.lyx)");
+       
+               if (result.first == FileDialog::Later)
+                       return;
+
+               filename = result.second;
+               // check selected filename
+               if (filename.empty()) {
+                       owner->getMiniBuffer()->Set(_("Canceled."));
+                       return;
+               }
+       } else
+               filename = fname;
 
        // get absolute path of file and make sure the filename ends
        // with .lyx
@@ -1701,7 +1679,6 @@ void LyXFunc::doImport(string const & argument)
 
        if (filename.empty()) { // need user interaction
                string initpath = lyxrc.document_path;
-               LyXFileDlg fileDlg;
                
                if (owner->view()->available()) {
                        string const trypath = owner->buffer()->filepath;
@@ -1710,16 +1687,23 @@ void LyXFunc::doImport(string const & argument)
                                initpath = trypath;
                }
 
-               // launches dialog
-               ProhibitInput(owner->view());
-               fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
-               fileDlg.SetButton(1, _("Examples"), 
-                                       AddPath(system_lyxdir, "examples"));
                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());
+
+               FileDialog fileDlg(owner, text, 
+                       LFUN_IMPORT,
+                       make_pair(string(_("Documents")), string(lyxrc.document_path)),
+                       make_pair(string(_("Examples")), string(AddPath(system_lyxdir, "examples"))));
+                       
+               string const extension = "*." + formats.Extension(format) + "| " +
+                       formats.PrettyName(format) + " (*." + formats.Extension(format) + ")";
+
+               FileDialog::Result result = fileDlg.Select(initpath, extension);
+
+               if (result.first == FileDialog::Later)
+                       return;
+
+               filename = result.second;
  
                // check selected filename
                if (filename.empty())