]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
some more changes
[lyx.git] / src / lyxfunc.C
index fe5c9056a3b255b46d100f083bceedfd217a5cbb..19bfb7dba377d1d9682eceea5895ec61e1497999 100644 (file)
@@ -20,7 +20,6 @@
 #include "lyxrow.h"
 #include "bufferlist.h"
 #include "BufferView.h"
-#include "frontends/xforms/ColorHandler.h"
 #include "lyxserver.h"
 #include "intl.h"
 #include "lyx_main.h"
 #include "trans_mgr.h"
 #include "layout.h"
 #include "bufferview_funcs.h"
-#include "minibuffer.h"
-#include "vspace.h"
+#include "frontends/MiniBuffer.h"
 #include "frontends/LyXView.h"
+#include "frontends/lyx_gui.h"
+#include "vspace.h"
 #include "FloatList.h"
 #include "converter.h"
 #include "exporter.h"
 #include "importer.h"
-#include "frontends/font_loader.h"
 #include "TextCache.h"
 #include "lyxfind.h"
 #include "undo_funcs.h"
 #include <utility>
 #include <algorithm>
 
-
 using std::pair;
 using std::make_pair;
 using std::endl;
@@ -124,39 +122,6 @@ extern tex_accent_struct get_accent(kb_action action);
 extern void ShowLatexLog();
 
 
-#if 0
-
-///
-class MiniBufferController : public SigC::Object {
-public:
-       ///
-       MiniBufferController() {
-               minibuffer
-                       .cmdReady
-                       .connect(slot(this,
-                                     &MiniBufferController::receiveCommand));
-               minibuffer
-                       .argReady
-                       .connect(slot(this,
-                                     &MiniBufferController::receiveArg));
-       }
-       ///
-       void receiveCmd(string const & cmd) {}
-       ///
-       void receiveArg(string const & arg) {}
-
-
-private:
-};
-
-namespace {
-
-MiniBufferController mb_ctrl;
-
-}
-#endif
-
-
 /* === globals =========================================================== */
 
 
@@ -471,7 +436,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
        }
        case LFUN_MATH_VALIGN:
-               if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
+               if (mathcursor && mathcursor->formula()->hullType() != "simple") {
                        char align = mathcursor->valign();
                        if (align == '\0') {
                                disable = true;
@@ -491,7 +456,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
 
        case LFUN_MATH_HALIGN:
-               if (mathcursor && mathcursor->formula()->getType() != LM_OT_SIMPLE) {
+               if (mathcursor && mathcursor->formula()->hullType() != "simple") {
                        char align = mathcursor->halign();
                        if (align == '\0') {
                                disable = true;
@@ -511,22 +476,9 @@ FuncStatus LyXFunc::getStatus(kb_action action,
                break;
 
        case LFUN_MATH_MUTATE:
-               if (tli && (tli->lyxCode() == Inset::MATH_CODE)) {
-                       MathInsetTypes type = mathcursor->formula()->getType();
-                       if (argument == "inline") {
-                               flag.setOnOff(type == LM_OT_SIMPLE);
-                       } else if (argument == "display") {
-                               flag.setOnOff(type == LM_OT_EQUATION);
-                       } else if (argument == "eqnarray") {
-                               flag.setOnOff(type == LM_OT_EQNARRAY);
-                       } else if (argument == "align") {
-                               flag.setOnOff(type == LM_OT_ALIGN);
-                       } else if (argument == "none") {
-                               flag.setOnOff(type == LM_OT_NONE);
-                       } else {
-                               disable = true;
-                       }
-               } else
+               if (tli && (tli->lyxCode() == Inset::MATH_CODE))
+                       flag.setOnOff(mathcursor->formula()->hullType() == argument);
+               else
                        disable = true;
                break;
 
@@ -546,7 +498,7 @@ FuncStatus LyXFunc::getStatus(kb_action action,
        case LFUN_MATH_COLUMN_INSERT:
        case LFUN_MATH_COLUMN_DELETE:
                disable = !mathcursor || !mathcursor->halign() ||
-                       mathcursor->formula()->getType() == LM_OT_SIMPLE;
+                       mathcursor->formula()->hullType() == "simple";
                break;
 
        default:
@@ -785,42 +737,40 @@ void LyXFunc::verboseDispatch(kb_action action,
 
        commandshortcut.erase();
 
-       if (lyxrc.display_shortcuts && show_sc) {
-               if (action != LFUN_SELFINSERT) {
-                       // Put name of command and list of shortcuts
-                       // for it in minibuffer
-                       string comname = lyxaction.getActionName(action);
+       if (show_sc && action != LFUN_SELFINSERT) {
+               // Put name of command and list of shortcuts
+               // for it in minibuffer
+               string comname = lyxaction.getActionName(action);
 
-                       int pseudoaction = action;
-                       bool argsadded = false;
+               int pseudoaction = action;
+               bool argsadded = false;
 
-                       if (!argument.empty()) {
-                               // the pseudoaction is useful for the bindings
-                               pseudoaction =
-                                       lyxaction.searchActionArg(action,
-                                                                 argument);
+               if (!argument.empty()) {
+                       // the pseudoaction is useful for the bindings
+                       pseudoaction =
+                               lyxaction.searchActionArg(action,
+                                                         argument);
 
-                               if (pseudoaction == LFUN_UNKNOWN_ACTION) {
-                                       pseudoaction = action;
-                               } else {
-                                       comname += " " + argument;
-                                       argsadded = true;
-                               }
+                       if (pseudoaction == LFUN_UNKNOWN_ACTION) {
+                               pseudoaction = action;
+                       } else {
+                               comname += " " + argument;
+                               argsadded = true;
                        }
+               }
 
-                       string const shortcuts =
-                               toplevel_keymap->findbinding(pseudoaction);
+               string const shortcuts =
+                       toplevel_keymap->findbinding(pseudoaction);
 
-                       if (!shortcuts.empty()) {
-                               comname += ": " + shortcuts;
-                       } else if (!argsadded && !argument.empty()) {
-                               comname += " " + argument;
-                       }
+               if (!shortcuts.empty()) {
+                       comname += ": " + shortcuts;
+               } else if (!argsadded && !argument.empty()) {
+                       comname += " " + argument;
+               }
 
-                       if (!comname.empty()) {
-                               comname = strip(comname);
-                               commandshortcut = "(" + comname + ')';
-                       }
+               if (!comname.empty()) {
+                       comname = strip(comname);
+                       commandshortcut = "(" + comname + ')';
                }
        }
 
@@ -895,18 +845,14 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                                goto exit_with_message;
                                        // If UNDISPATCHED, just soldier on
                        else if (result == UpdatableInset::FINISHED) {
-                                       if (TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
-                                               TEXT()->cursorRight(owner->view());
-                                               moveCursorUpdate(true, false);
-                                               owner->showState();
-                                       }
-                                       goto exit_with_message;
+                               goto exit_with_message;
+                               // We do not need special RTL handling here:
+                               // FINISHED means that the cursor should be
+                               // one position after the inset.
                        } else if (result == UpdatableInset::FINISHED_RIGHT) {
-                               if (!TEXT()->cursor.par()->isRightToLeftPar(owner->buffer()->params)) {
-                                       TEXT()->cursorRight(owner->view());
-                                       moveCursorUpdate(true, false);
-                                       owner->showState();
-                               }
+                               TEXT()->cursorRight(owner->view());
+                               moveCursorUpdate(true, false);
+                               owner->showState();
                                goto exit_with_message;
                        } else if (result == UpdatableInset::FINISHED_UP) {
                                if (TEXT()->cursor.irow()->previous()) {
@@ -1049,8 +995,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                transform(lyxaction.func_begin(), lyxaction.func_end(),
                          back_inserter(allCmds), lyx::firster());
                static vector<string> hist;
-               owner->getMiniBuffer()->getString(MiniBuffer::spaces,
-                                                 allCmds, hist);
+               owner->getMiniBuffer()->prepareForInput(allCmds, hist);
        }
        break;
 
@@ -1085,11 +1030,11 @@ string const LyXFunc::dispatch(kb_action action, string argument)
 
                // --- Menus -----------------------------------------------
        case LFUN_MENUNEW:
-               menuNew(false);
+               menuNew(argument, false);
                break;
 
        case LFUN_MENUNEWTMPLT:
-               menuNew(true);
+               menuNew(argument, true);
                break;
 
        case LFUN_CLOSEBUFFER:
@@ -1409,11 +1354,11 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                        owner->view()->buffer(bufferlist.loadLyXFile(s));
                }
 
-               // Set the cursor
                owner->view()->setCursorFromRow(row);
 
-               // Recenter screen
                owner->view()->center();
+               // see BufferView_pimpl::center() 
+               owner->view()->updateScrollbar();
        }
        break;
 
@@ -1443,8 +1388,9 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                owner->view()->setState();
                owner->showState();
 
-               // Recenter screen
                owner->view()->center();
+               // see BufferView_pimpl::center() 
+               owner->view()->updateScrollbar();
        }
        break;
 
@@ -1569,7 +1515,7 @@ string const LyXFunc::dispatch(kb_action action, string argument)
        case LFUN_SEQUENCE:
        {
                // argument contains ';'-terminated commands
-               while (argument.find(';') != string::npos) {
+               while (!argument.empty()) {
                        string first;
                        argument = split(argument, first, ';');
                        verboseDispatch(first, false);
@@ -1593,11 +1539,12 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                // handle the screen font changes.
                //
                lyxrc.set_font_norm_type();
-               fontloader.update();
+               lyx_gui::update_fonts();
                // Of course we should only do the resize and the textcache.clear
                // if values really changed...but not very important right now. (Lgb)
                // All visible buffers will need resize
                owner->view()->resize();
+               owner->view()->repaint();
                // We also need to empty the textcache so that
                // the buffer will be formatted correctly after
                // a zoom change.
@@ -1628,11 +1575,16 @@ string const LyXFunc::dispatch(kb_action action, string argument)
                        break;
                }
 
-               lyxColorHandler->updateColor(lcolor.getFromLyXName(lyx_name));
+               lyx_gui::update_color(lcolor.getFromLyXName(lyx_name));
 
                if (graphicsbg_changed) {
+#ifdef WITH_WARNINGS
+#warning FIXME!! The graphics cache no longer has a changeDisplay method.
+#endif
+#if 0
                        grfx::GCache & gc = grfx::GCache::get();
                        gc.changeDisplay(true);
+#endif
                }
 
                owner->view()->repaint();
@@ -1700,9 +1652,10 @@ void LyXFunc::setupLocalKeymap()
 }
 
 
-void LyXFunc::menuNew(bool fromTemplate)
+void LyXFunc::menuNew(string const & name, bool fromTemplate)
 {
        string initpath = lyxrc.document_path;
+       string filename(name);
 
        if (owner->view()->available()) {
                string const trypath = owner->buffer()->filePath();
@@ -1712,86 +1665,17 @@ void LyXFunc::menuNew(bool fromTemplate)
        }
 
        static int newfile_number;
-       string s;
-
-       if (lyxrc.new_ask_filename) {
-               FileDialog fileDlg(owner, _("Enter filename for new document"),
-                                  LFUN_SELECT_FILE_SYNC,
-                       make_pair(string(_("Documents|#o#O")),
-                                 string(lyxrc.document_path)),
-                       make_pair(string(_("Templates|#T#t")),
-                                 string(lyxrc.template_path)));
-
-               FileDialog::Result result =
-                       fileDlg.Select(initpath,
-                                      _("*.lyx|LyX Documents (*.lyx)"),
-                                      _("newfile"));
-
-               if (result.second.empty()) {
-                       owner->message(_("Canceled."));
-                       lyxerr[Debug::INFO] << "New Document Cancelled." << endl;
-                       return;
-               }
-
-               // get absolute path of file and make sure the filename ends
-               // with .lyx
-               s = MakeAbsPath(result.second);
-               if (!IsLyXFilename(s))
-                       s += ".lyx";
-
-               // Check if the document already is open
-               if (bufferlist.exists(s)) {
-                       switch (Alert::askConfirmation(_("Document is already open:"),
-                                               MakeDisplayPath(s, 50),
-                                               _("Do you want to close that document now?\n"
-                                                 "('No' will just switch to the open version)")))
-                       {
-                       case 1: // Yes: close the document
-                               if (!bufferlist.close(bufferlist.getBuffer(s)))
-                               // If close is canceled, we cancel here too.
-                                       return;
-                               break;
-                       case 2: // No: switch to the open document
-                               owner->view()->buffer(bufferlist.getBuffer(s));
-                               return;
-                       case 3: // Cancel: Do nothing
-                               owner->message(_("Canceled."));
-                               return;
-                       }
-               }
-               // Check whether the file already exists
-               FileInfo fi(s);
-               if (fi.readable() &&
-                   Alert::askQuestion(_("File already exists:"),
-                               MakeDisplayPath(s, 50),
-                               _("Do you want to open the document?"))) {
-                               // loads document
-                       string const disp_fn(MakeDisplayPath(s));
-
-                       ostringstream str;
-                       str << _("Opening  document") << ' '
-                           << disp_fn << "...";
-
-                       owner->message(str.str().c_str());
-                       owner->view()->buffer(bufferlist.loadLyXFile(s));
-                       ostringstream str2;
-                       str2 << _("Document") << ' '
-                            << disp_fn << ' ' << _("opened.");
-
-                       owner->message(str2.str().c_str());
 
-                       return;
-               }
-       } else {
-               s = AddName(lyxrc.document_path,
+       if (filename.empty()) {
+               filename = AddName(lyxrc.document_path,
                            "newfile" + tostr(++newfile_number) + ".lyx");
-               FileInfo fi(s);
-               while (bufferlist.exists(s) || fi.readable()) {
+               FileInfo fi(filename);
+               while (bufferlist.exists(filename) || fi.readable()) {
                        ++newfile_number;
-                       s = AddName(lyxrc.document_path,
+                       filename = AddName(lyxrc.document_path,
                                    "newfile" + tostr(newfile_number) +
                                    ".lyx");
-                       fi.newFile(s);
+                       fi.newFile(filename);
                }
        }
 
@@ -1819,9 +1703,7 @@ void LyXFunc::menuNew(bool fromTemplate)
                templname = fname;
        }
 
-       // find a free buffer
-       lyxerr[Debug::INFO] << "Find a free buffer." << endl;
-       owner->view()->buffer(bufferlist.newFile(s, templname));
+       owner->view()->buffer(bufferlist.newFile(filename, templname, !name.empty()));
 }
 
 
@@ -1902,7 +1784,7 @@ void LyXFunc::doImport(string const & argument)
 
        lyxerr[Debug::INFO] << "LyXFunc::doImport: " << format
                            << " file: " << filename << endl;
+
        // need user interaction
        if (filename.empty()) {
                string initpath = lyxrc.document_path;
@@ -1970,7 +1852,7 @@ void LyXFunc::doImport(string const & argument)
                        }
        }
 
-       // if the file exists already, and we didn't do 
+       // if the file exists already, and we didn't do
        // -i lyx thefile.lyx, warn
        if (FileInfo(lyxfile, true).exist() && filename != lyxfile) {
                if (!Alert::askQuestion(_("A document by the name"),