]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfunc.C
some more changes
[lyx.git] / src / lyxfunc.C
index d1d920895f6c30ff25165657037550bbfdb3a041..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 "layout.h"
 #include "bufferview_funcs.h"
 #include "frontends/MiniBuffer.h"
-#include "vspace.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 =========================================================== */
 
 
@@ -880,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()) {
@@ -1069,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:
@@ -1578,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.
@@ -1613,7 +1575,7 @@ 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
@@ -1690,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();
@@ -1702,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);
                }
        }
 
@@ -1809,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()));
 }