]> git.lyx.org Git - lyx.git/blobdiff - src/LyX.cpp
cosmetics
[lyx.git] / src / LyX.cpp
index 3c2dd305d889fdc70663413ad869f376b419cbca..21f351bb4c3b153c3dbc6041a17563a36d175323 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "LyX.h"
 
+#include "Color.h"
 #include "ConverterCache.h"
 #include "Buffer.h"
 #include "buffer_funcs.h"
@@ -29,9 +30,9 @@
 #include "Format.h"
 #include "gettext.h"
 #include "KeyMap.h"
+#include "CmdDef.h"
 #include "Language.h"
 #include "Session.h"
-#include "Color.h"
 #include "LyXAction.h"
 #include "LyXFunc.h"
 #include "Lexer.h"
@@ -62,6 +63,7 @@
 #include "support/Systemcall.h"
 
 #include <boost/bind.hpp>
+#include <boost/scoped_ptr.hpp>
 
 #include <algorithm>
 #include <iostream>
@@ -89,9 +91,7 @@ using support::addName;
 using support::addPath;
 using support::bformat;
 using support::changeExtension;
-using support::createDirectory;
 using support::createLyXTmpDir;
-using support::destroyDir;
 using support::FileName;
 using support::fileSearch;
 using support::getEnv;
@@ -108,10 +108,9 @@ namespace os = support::os;
 
 
 
-/// are we using the GUI at all?
-/**
-* We default to true and this is changed to false when the export feature is used.
-*/
+// Are we using the GUI at all?  We default to true and this is changed
+// to false when the export feature is used.
+
 bool use_gui = true;
 
 bool quitting; // flag, that we are quitting the program
@@ -140,7 +139,7 @@ void reconfigureUserLyXDir()
        string const configure_command = package().configure_command();
 
        lyxerr << to_utf8(_("LyX: reconfiguring user directory")) << endl;
-       support::Path p(package().user_support());
+       support::PathChanger p(package().user_support());
        Systemcall one;
        one.startscript(Systemcall::Wait, configure_command);
        lyxerr << "LyX: " << to_utf8(_("Done!")) << endl;
@@ -166,6 +165,8 @@ struct LyX::Singletons
        ///
        boost::scoped_ptr<KeyMap> toplevel_keymap_;
        ///
+       boost::scoped_ptr<CmdDef> toplevel_cmddef_;
+       ///
        boost::scoped_ptr<Server> lyx_server_;
        ///
        boost::scoped_ptr<ServerSocket> lyx_socket_;
@@ -205,6 +206,7 @@ frontend::Application * theApp()
 
 LyX::~LyX()
 {
+       delete pimpl_;
 }
 
 
@@ -226,7 +228,7 @@ LyX::LyX()
        : first_start(false)
 {
        singleton_ = this;
-       pimpl_.reset(new Singletons);
+       pimpl_ = new Singletons;
 }
 
 
@@ -317,6 +319,13 @@ KeyMap & LyX::topLevelKeymap()
 }
 
 
+CmdDef & LyX::topLevelCmdDef()
+{
+       BOOST_ASSERT(pimpl_->toplevel_cmddef_.get());
+       return *pimpl_->toplevel_cmddef_.get();
+}
+
+
 Converters & LyX::converters()
 {
        return pimpl_->converters_;
@@ -439,7 +448,7 @@ int LyX::exec(int & argc, char * argv[])
                bool final_success = false;
                for (BufferList::iterator I = begin; I != pimpl_->buffer_list_.end(); ++I) {
                        Buffer * buf = *I;
-                       if (buf != buf->getMasterBuffer())
+                       if (buf != buf->masterBuffer())
                                continue;
                        bool success = false;
                        buf->dispatch(batch_command, &success);
@@ -505,7 +514,7 @@ void LyX::prepareExit()
                LYXERR(Debug::INFO) << "Deleting tmp dir "
                                    << package().temp_dir().absFilename() << endl;
 
-               if (!destroyDir(package().temp_dir())) {
+               if (!package().temp_dir().destroyDirectory()) {
                        docstring const msg =
                                bformat(_("Unable to remove the temporary directory %1$s"),
                                from_utf8(package().temp_dir().absFilename()));
@@ -594,7 +603,7 @@ void LyX::loadFiles()
                        continue;
 
                Buffer * buf = pimpl_->buffer_list_.newBuffer(it->absFilename(), false);
-               if (loadLyXFile(buf, *it)) {
+               if (buf->loadLyXFile(*it)) {
                        ErrorList const & el = buf->errorList("Parse");
                        if (!el.empty())
                                for_each(el.begin(), el.end(),
@@ -684,7 +693,7 @@ void LyX::restoreGuiSession()
        BufferList::iterator end = pimpl_->buffer_list_.end();
        for (; I != end; ++I) {
                Buffer * buf = *I;
-               if (buf != buf->getMasterBuffer())
+               if (buf != buf->masterBuffer())
                        continue;
                updateLabels(*buf);
        }
@@ -963,10 +972,16 @@ bool LyX::init()
        // Set the language defined by the user.
        //setGuiLanguage(lyxrc.gui_language);
 
+       // Set up command definitions
+       pimpl_->toplevel_cmddef_.reset(new CmdDef);
+       pimpl_->toplevel_cmddef_->read(lyxrc.def_file);
+
        // Set up bindings
        pimpl_->toplevel_keymap_.reset(new KeyMap);
-       defaultKeyBindings(pimpl_->toplevel_keymap_.get());
+       pimpl_->toplevel_keymap_->read("site");
        pimpl_->toplevel_keymap_->read(lyxrc.bind_file);
+       // load user bind file user.bind
+       pimpl_->toplevel_keymap_->read("user");
 
        pimpl_->lyxfunc_.initKeySequences(pimpl_->toplevel_keymap_.get());
 
@@ -1015,58 +1030,6 @@ bool LyX::init()
 }
 
 
-void LyX::defaultKeyBindings(KeyMap  * kbmap)
-{
-       kbmap->bind("Right", FuncRequest(LFUN_CHAR_FORWARD));
-       kbmap->bind("Left", FuncRequest(LFUN_CHAR_BACKWARD));
-       kbmap->bind("Up", FuncRequest(LFUN_UP));
-       kbmap->bind("Down", FuncRequest(LFUN_DOWN));
-
-       kbmap->bind("Tab", FuncRequest(LFUN_CELL_FORWARD));
-       kbmap->bind("C-Tab", FuncRequest(LFUN_CELL_SPLIT));
-       kbmap->bind("~S-ISO_Left_Tab", FuncRequest(LFUN_CELL_BACKWARD));
-       kbmap->bind("~S-BackTab", FuncRequest(LFUN_CELL_BACKWARD));
-
-       kbmap->bind("Home", FuncRequest(LFUN_LINE_BEGIN));
-       kbmap->bind("End", FuncRequest(LFUN_LINE_END));
-       kbmap->bind("Prior", FuncRequest(LFUN_SCREEN_UP));
-       kbmap->bind("Next", FuncRequest(LFUN_SCREEN_DOWN));
-
-       kbmap->bind("Return", FuncRequest(LFUN_BREAK_PARAGRAPH));
-       //kbmap->bind("~C-~S-~M-nobreakspace", FuncRequest(LFUN_PROTECTEDSPACE));
-
-       kbmap->bind("Delete", FuncRequest(LFUN_CHAR_DELETE_FORWARD));
-       kbmap->bind("BackSpace", FuncRequest(LFUN_CHAR_DELETE_BACKWARD));
-
-       // kbmap->bindings to enable the use of the numeric keypad
-       // e.g. Num Lock set
-       //kbmap->bind("KP_0", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_Decimal", FuncRequest(LFUN_SELF_INSERT));
-       kbmap->bind("KP_Enter", FuncRequest(LFUN_BREAK_PARAGRAPH));
-       //kbmap->bind("KP_1", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_2", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_3", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_4", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_5", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_6", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_Add", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_7", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_8", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_9", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_Divide", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_Multiply", FuncRequest(LFUN_SELF_INSERT));
-       //kbmap->bind("KP_Subtract", FuncRequest(LFUN_SELF_INSERT));
-       kbmap->bind("KP_Right", FuncRequest(LFUN_CHAR_FORWARD));
-       kbmap->bind("KP_Left", FuncRequest(LFUN_CHAR_BACKWARD));
-       kbmap->bind("KP_Up", FuncRequest(LFUN_UP));
-       kbmap->bind("KP_Down", FuncRequest(LFUN_DOWN));
-       kbmap->bind("KP_Home", FuncRequest(LFUN_LINE_BEGIN));
-       kbmap->bind("KP_End", FuncRequest(LFUN_LINE_END));
-       kbmap->bind("KP_Prior", FuncRequest(LFUN_SCREEN_UP));
-       kbmap->bind("KP_Next", FuncRequest(LFUN_SCREEN_DOWN));
-}
-
-
 void LyX::emergencyCleanup() const
 {
        // what to do about tmpfiles is non-obvious. we would
@@ -1165,7 +1128,7 @@ bool LyX::queryUserLyXDir(bool explicit_userdir)
        lyxerr << to_utf8(bformat(_("LyX: Creating directory %1$s"),
                          from_utf8(sup.absFilename()))) << endl;
 
-       if (!createDirectory(sup, 0755)) {
+       if (!sup.createDirectory(0755)) {
                // Failed, so let's exit.
                lyxerr << to_utf8(_("Failed to create directory. Exiting."))
                       << endl;
@@ -1377,6 +1340,7 @@ int parse_help(string const &, string const &)
        return 0;
 }
 
+
 int parse_version(string const &, string const &)
 {
        lyxerr << "LyX " << lyx_version
@@ -1388,6 +1352,7 @@ int parse_version(string const &, string const &)
        return 0;
 }
 
+
 int parse_sysdir(string const & arg, string const &)
 {
        if (arg.empty()) {
@@ -1399,6 +1364,7 @@ int parse_sysdir(string const & arg, string const &)
        return 1;
 }
 
+
 int parse_userdir(string const & arg, string const &)
 {
        if (arg.empty()) {
@@ -1410,6 +1376,7 @@ int parse_userdir(string const & arg, string const &)
        return 1;
 }
 
+
 int parse_execute(string const & arg, string const &)
 {
        if (arg.empty()) {
@@ -1421,6 +1388,7 @@ int parse_execute(string const & arg, string const &)
        return 1;
 }
 
+
 int parse_export(string const & type, string const &)
 {
        if (type.empty()) {
@@ -1433,6 +1401,7 @@ int parse_export(string const & type, string const &)
        return 1;
 }
 
+
 int parse_import(string const & type, string const & file)
 {
        if (type.empty()) {
@@ -1449,6 +1418,7 @@ int parse_import(string const & type, string const & file)
        return 2;
 }
 
+
 int parse_geometry(string const & arg1, string const &)
 {
        geometryArg = arg1;
@@ -1492,8 +1462,10 @@ void LyX::easyParse(int & argc, char * argv[])
                if (it == cmdmap.end())
                        continue;
 
-               string const arg((i + 1 < argc) ? to_utf8(from_local8bit(argv[i + 1])) : string());
-               string const arg2((i + 2 < argc) ? to_utf8(from_local8bit(argv[i + 2])) : string());
+               string const arg =
+                       (i + 1 < argc) ? to_utf8(from_local8bit(argv[i + 1])) : string();
+               string const arg2 =
+                       (i + 2 < argc) ? to_utf8(from_local8bit(argv[i + 2])) : string();
 
                int const remove = 1 + it->second(arg, arg2);