]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
more cursor dispatch
[lyx.git] / src / lyx_cb.C
index 54d331314569b9a4791023ac4fe44ca17edab87c..48ac377406df0ff2497807cf0c895cde8df6fd44 100644 (file)
 #include <config.h>
 
 #include "lyx_cb.h"
-#include "lyx_main.h"
+
 #include "buffer.h"
 #include "bufferlist.h"
+#include "BufferView.h"
+#include "cursor.h"
 #include "debug.h"
+#include "gettext.h"
 #include "lastfiles.h"
+#include "lyx_main.h"
+#include "lyxlayout.h"
 #include "lyxrc.h"
 #include "lyxtext.h"
-#include "gettext.h"
-#include "BufferView.h"
+#include "paragraph.h"
 
-
-#include "frontends/lyx_gui.h"
-#include "frontends/LyXView.h"
 #include "frontends/Alert.h"
 #include "frontends/FileDialog.h"
+#include "frontends/lyx_gui.h"
+#include "frontends/LyXView.h"
 
 #include "support/FileInfo.h"
 #include "support/filetools.h"
 #include "support/forkedcall.h"
+#include "support/globbing.h"
 #include "support/lyxlib.h"
+#include "support/os.h"
 #include "support/path.h"
 #include "support/path_defines.h"
-#include "support/os.h"
 #include "support/systemcall.h"
 
 #include <cerrno>
 #include <fstream>
 
-using namespace lyx::support;
-
-using std::vector;
-using std::ifstream;
+using lyx::support::AddName;
+using lyx::support::bformat;
+using lyx::support::destroyDir;
+using lyx::support::FileFilterList;
+using lyx::support::FileInfo;
+using lyx::support::ForkedProcess;
+using lyx::support::IsLyXFilename;
+using lyx::support::LibFileSearch;
+using lyx::support::MakeAbsPath;
+using lyx::support::MakeDisplayPath;
+using lyx::support::OnlyFilename;
+using lyx::support::OnlyPath;
+using lyx::support::Path;
+using lyx::support::removeAutosaveFile;
+using lyx::support::rename;
+using lyx::support::split;
+using lyx::support::system_lyxdir;
+using lyx::support::Systemcall;
+using lyx::support::tempName;
+using lyx::support::unlink;
+using lyx::support::user_lyxdir;
+
+namespace os = lyx::support::os;
+
+using std::auto_ptr;
+using std::back_inserter;
 using std::copy;
 using std::endl;
+using std::make_pair;
+using std::string;
+using std::ifstream;
 using std::ios;
-using std::back_inserter;
 using std::istream_iterator;
-using std::pair;
-using std::make_pair;
+
 
 extern BufferList bufferlist;
 // this should be static, but I need it in buffer.C
@@ -67,7 +94,7 @@ bool quitting;        // flag, that we are quitting the program
 bool MenuWrite(Buffer * buffer)
 {
        if (buffer->save()) {
-               lastfiles->newFile(buffer->fileName());
+               LyX::ref().lastfiles().newFile(buffer->fileName());
                return true;
        }
 
@@ -104,10 +131,12 @@ bool WriteAs(Buffer * buffer, string const & filename)
                if (!IsLyXFilename(fname))
                        fname += ".lyx";
 
+               FileFilterList const filter (_("LyX Documents (*.lyx)"));
+
                FileDialog::Result result =
                        fileDlg.save(OnlyPath(fname),
-                                      _("*.lyx| LyX Documents (*.lyx)"),
-                                      OnlyFilename(fname));
+                                    filter,
+                                    OnlyFilename(fname));
 
                if (result.first == FileDialog::Later)
                        return false;
@@ -161,7 +190,7 @@ void QuitLyX()
                if (!bufferlist.quitWriteAll())
                        return;
 
-               lastfiles->writeFile(lyxrc.lastfiles);
+               LyX::cref().lastfiles().writeFile(lyxrc.lastfiles);
        }
 
        // Set a flag that we do quitting from the program,
@@ -192,8 +221,8 @@ public:
        AutoSaveBuffer(BufferView & bv, string const & fname)
                : bv_(bv), fname_(fname) {}
        ///
-       virtual ForkedProcess * clone() const {
-               return new AutoSaveBuffer(*this);
+       virtual auto_ptr<ForkedProcess> clone() const {
+               return auto_ptr<ForkedProcess>(new AutoSaveBuffer(*this));
        }
        ///
        int start();
@@ -329,13 +358,12 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
                return;
 
        // clear the selection
-       bool flag = (bv->text == bv->getLyXText());
-       if (flag)
-               bv->beforeChange(bv->text);
-       if (!asParagraph)
-               bv->getLyXText()->insertStringAsLines(tmpstr);
-       else
+       if (bv->text() == bv->getLyXText())
+               bv->cursor().clearSelection();
+       if (asParagraph)
                bv->getLyXText()->insertStringAsParagraphs(tmpstr);
+       else
+               bv->getLyXText()->insertStringAsLines(tmpstr);
        bv->update();
 }
 
@@ -349,7 +377,9 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
                FileDialog fileDlg(_("Select file to insert"),
                        (asParagraph) ? LFUN_FILE_INSERT_ASCII_PARA : LFUN_FILE_INSERT_ASCII);
 
-               FileDialog::Result result = fileDlg.open(bv->owner()->buffer()->filePath());
+               FileDialog::Result result =
+                       fileDlg.open(bv->owner()->buffer()->filePath(),
+                                    FileFilterList(), string());
 
                if (result.first == FileDialog::Later)
                        return string();
@@ -386,7 +416,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
        istream_iterator<char> end;
 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
        // We use this until the compilers get better...
-       vector<char> tmp;
+       std::vector<char> tmp;
        copy(ii, end, back_inserter(tmp));
        string const tmpstr(tmp.begin(), tmp.end());
 #else
@@ -404,8 +434,8 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap
 
 string const getPossibleLabel(BufferView const & bv)
 {
-       ParagraphList::iterator pit = bv.getLyXText()->cursor.par();
-       ParagraphList & plist = bv.getLyXText()->ownerParagraphs();
+       ParagraphList::iterator pit = bv.getLyXText()->cursorPar();
+       ParagraphList & plist = bv.getLyXText()->paragraphs();
 
        LyXLayout_ptr layout = pit->layout();
 
@@ -435,9 +465,9 @@ string const getPossibleLabel(BufferView const & bv)
                        break;
                string head;
                par_text = split(par_text, head, ' ');
+               // Is it legal to use spaces in labels ?
                if (i > 0)
-                       text += '-'; // Is it legal to use spaces in
-               // labels ?
+                       text += '-';
                text += head;
        }