]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlInclude.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlInclude.C
index f8f8061ff9aec3daa76c3186eaf3cc2b7d9ab8b1..92e5e50a2d74b277a6f54d6689f9316bd7f10828 100644 (file)
 #include "Kernel.h"
 
 #include "buffer.h"
+#include "format.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "lyxrc.h"
 
 #include "insets/insetinclude.h"
 
+#include "support/filefilterlist.h"
 #include "support/filetools.h"
 
 #include <utility>
 
-using lyx::support::IsFileReadable;
-using lyx::support::MakeAbsPath;
-using lyx::support::OnlyPath;
-
 using std::pair;
 using std::string;
 
+namespace lyx {
+
+using support::FileFilterList;
+using support::IsFileReadable;
+using support::MakeAbsPath;
+using support::OnlyPath;
+
+namespace frontend {
 
 ControlInclude::ControlInclude(Dialog & parent)
        : Dialog::Controller(parent)
@@ -56,7 +62,7 @@ void ControlInclude::clearParams()
 void ControlInclude::dispatchParams()
 {
        string const lfun = InsetIncludeMailer::params2string(params_);
-       kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
+       kernel().dispatch(FuncRequest(getLfun(), lfun));
 }
 
 
@@ -66,23 +72,18 @@ void ControlInclude::setParams(InsetCommandParams const & params)
 }
 
 
-string const ControlInclude::Browse(string const & in_name, Type in_type)
+string const ControlInclude::browse(string const & in_name, Type in_type) const
 {
        string const title = _("Select document to include");
 
        // input TeX, verbatim, or LyX file ?
-       string pattern;
+       FileFilterList filters;
        switch (in_type) {
+       case INCLUDE:
        case INPUT:
-           pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
+           filters = FileFilterList(_("LaTeX/LyX Documents (*.tex *.lyx)"));
            break;
-
        case VERBATIM:
-           pattern = _("*| All files (*)");
-           break;
-
-       case INCLUDE:
-           pattern = _("*.(tex|lyx)| LaTeX/LyX Documents (*.tex *.lyx)");
            break;
        }
 
@@ -91,13 +92,19 @@ string const ControlInclude::Browse(string const & in_name, Type in_type)
 
        string const docpath = OnlyPath(kernel().buffer().fileName());
 
-       return browseRelFile(in_name, docpath, title, pattern, false, dir1);
+       return browseRelFile(in_name, docpath, title,
+                            filters, false, dir1);
 }
 
 
 void ControlInclude::load(string const & file)
 {
-       kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
+       string const ext = support::GetExtension(file);
+       if (ext == "lyx")
+               kernel().dispatch(FuncRequest(LFUN_CHILDOPEN, file));
+       else
+               // tex file or other text file in verbatim mode
+               formats.edit(kernel().buffer(), file, "text");
 }
 
 
@@ -112,3 +119,6 @@ bool ControlInclude::fileExists(string const & file)
 
        return false;
 }
+
+} // namespace frontend
+} // namespace lyx