]> git.lyx.org Git - features.git/commitdiff
* BufferView:
authorAbdelrazak Younes <younes@lyx.org>
Sun, 2 Dec 2007 20:05:17 +0000 (20:05 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 2 Dec 2007 20:05:17 +0000 (20:05 +0000)
- dispatch(): transfer LFUN_FILE_INSERT_PLAINTEXT_* to GuiView::dispatch()
- insertPlaintextFile(): split in BufferView::insertPlaintextFile() and GuiView::insertPlaintextFile()

This patch get rid of FileDialog use in BufferView. Remains Buffer, Converters and LyXFunc.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21930 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/BufferView.h
src/frontends/qt4/GuiView.cpp
src/frontends/qt4/GuiView.h
src/insets/InsetTabular.cpp

index 6a7568b85676991e6fdebd70e3d3ae3364e9f89a..d050da8228110f8174528a6737e2c839fc84bd17 100644 (file)
@@ -59,7 +59,6 @@
 
 #include "frontends/alert.h"
 #include "frontends/Delegates.h"
-#include "frontends/FileDialog.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 #include "frontends/Selection.h"
@@ -894,16 +893,6 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd)
                }
                break;
 
-       case LFUN_FILE_INSERT_PLAINTEXT_PARA:
-               // FIXME UNICODE
-               insertPlaintextFile(FileName(to_utf8(cmd.argument())), true);
-               break;
-
-       case LFUN_FILE_INSERT_PLAINTEXT:
-               // FIXME UNICODE
-               insertPlaintextFile(FileName(to_utf8(cmd.argument())), false);
-               break;
-
        case LFUN_FONT_STATE:
                cur.message(cur.currentState());
                break;
@@ -1955,28 +1944,8 @@ void BufferView::setGuiDelegate(frontend::GuiBufferViewDelegate * gui)
 
 
 // FIXME: Move this out of BufferView again
-docstring BufferView::contentsOfPlaintextFile(FileName const & fname,
-       bool asParagraph)
+docstring BufferView::contentsOfPlaintextFile(FileName const & fname)
 {
-       if (fname.empty()) {
-               FileDialog dlg(_("Select file to insert"),
-                                  ( asParagraph
-                                    ? LFUN_FILE_INSERT_PLAINTEXT_PARA 
-                                    : LFUN_FILE_INSERT_PLAINTEXT) );
-
-               FileDialog::Result result =
-                       dlg.open(from_utf8(buffer().filePath()),
-                                    FileFilterList(), docstring());
-
-               if (result.first == FileDialog::Later)
-                       return docstring();
-
-               if (result.second.empty())
-                       return docstring();
-
-               return contentsOfPlaintextFile(FileName(to_utf8(result.second)), false);
-       }
-
        if (!fname.isReadableFile()) {
                docstring const error = from_ascii(strerror(errno));
                docstring const file = makeDisplayPath(fname.absFilename(), 50);
@@ -2013,7 +1982,7 @@ docstring BufferView::contentsOfPlaintextFile(FileName const & fname,
 
 void BufferView::insertPlaintextFile(FileName const & f, bool asParagraph)
 {
-       docstring const tmpstr = contentsOfPlaintextFile(f, asParagraph);
+       docstring const tmpstr = contentsOfPlaintextFile(f);
 
        if (tmpstr.empty())
                return;
@@ -2025,6 +1994,9 @@ void BufferView::insertPlaintextFile(FileName const & f, bool asParagraph)
                cur.innerText()->insertStringAsParagraphs(cur, tmpstr);
        else
                cur.innerText()->insertStringAsLines(cur, tmpstr);
+
+       updateMetrics();
+       buffer_.changed();
 }
 
 } // namespace lyx
index 4f6ee458d6d66202fb4d2fae838c315518f89c6d..31514e480800e2d064a6ab86962da646a0d24f21 100644 (file)
@@ -241,8 +241,7 @@ public:
        void setGuiDelegate(frontend::GuiBufferViewDelegate *);
 
        ///
-       docstring contentsOfPlaintextFile(support::FileName const & f,
-               bool asParagraph);
+       docstring contentsOfPlaintextFile(support::FileName const & f);
        // Insert plain text file (if filename is empty, prompt for one)
        void insertPlaintextFile(support::FileName const & f, bool asParagraph);
        ///
index c7f64a03ea8f3aefae45f619ae0250008d9aa156..0788bebcab55063b969c56bfc8d498860264fe0f 100644 (file)
@@ -1070,6 +1070,44 @@ void GuiView::insertLyXFile(docstring const & fname)
 }
 
 
+void GuiView::insertPlaintextFile(docstring const & fname,
+       bool asParagraph)
+{
+       BufferView * bv = view();
+       if (!bv)
+               return;
+
+       // FIXME UNICODE
+       FileName filename(to_utf8(fname));
+       
+       if (!filename.empty()) {
+               bv->insertPlaintextFile(filename, asParagraph);
+               return;
+       }
+
+       FileDialog dlg(_("Select file to insert"), (asParagraph ?
+               LFUN_FILE_INSERT_PLAINTEXT_PARA : LFUN_FILE_INSERT_PLAINTEXT));
+
+       FileDialog::Result result = dlg.open(from_utf8(bv->buffer().filePath()),
+               FileFilterList(), docstring());
+
+       if (result.first == FileDialog::Later)
+               return;
+
+       // FIXME UNICODE
+       filename.set(to_utf8(result.second));
+
+       // check selected filename
+       if (filename.empty()) {
+               // emit message signal.
+               message(_("Canceled."));
+               return;
+       }
+
+       bv->insertPlaintextFile(filename, asParagraph);
+}
+
+
 bool GuiView::dispatch(FuncRequest const & cmd)
 {
        BufferView * bv = view();       
@@ -1107,6 +1145,14 @@ bool GuiView::dispatch(FuncRequest const & cmd)
                case LFUN_FILE_INSERT:
                        insertLyXFile(cmd.argument());
                        break;
+               case LFUN_FILE_INSERT_PLAINTEXT_PARA:
+                       insertPlaintextFile(cmd.argument(), true);
+                       break;
+
+               case LFUN_FILE_INSERT_PLAINTEXT:
+                       insertPlaintextFile(cmd.argument(), false);
+                       break;
+
 
                case LFUN_TOOLBAR_TOGGLE: {
                        string const name = cmd.getArg(0);
index c57a129b70d94b34ff38812c98c990d2c7b6b470..91f6eab076ff2bb72aff53ba34646465b11965e3 100644 (file)
@@ -236,6 +236,9 @@ private:
        ///
        void insertLyXFile(docstring const & fname);
        ///
+       void insertPlaintextFile(docstring const & fname,
+               bool asParagraph);
+       ///
        Inset * getOpenInset(std::string const & name) const;
 
        /// Is the dialog currently visible?
index 76091c4e5d0ac52f11d0143e451d4f04e3cdb8a2..8904bfc0b26a48b3f5081e8b4fdbe06911d4d54f 100644 (file)
@@ -3411,7 +3411,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_FILE_INSERT_PLAINTEXT: {
                // FIXME UNICODE
                docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
-                       FileName(to_utf8(cmd.argument())), false);
+                       FileName(to_utf8(cmd.argument())));
                if (tmpstr.empty())
                        break;
                cur.recordUndoInset(INSERT_UNDO);