]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlExternal.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlExternal.C
index 69007ce0915b8b7d39dd87a0596126e5d8634193..556363ac50d1a6600b24391bb57a8275e2e4e98e 100644 (file)
 #include "insets/ExternalSupport.h"
 #include "insets/ExternalTemplate.h"
 
+#include "support/filefilterlist.h"
 #include "support/filetools.h"
-#include "support/tostr.h"
-
-namespace external = lyx::external;
-
-using lyx::support::MakeAbsPath;
-using lyx::support::readBB_from_PSFile;
+#include "support/convert.h"
 
+using std::advance;
 using std::vector;
 using std::string;
 
+namespace lyx {
+
+using support::FileFilterList;
+using support::MakeAbsPath;
+using support::readBB_from_PSFile;
+
+namespace frontend {
+
 
 ControlExternal::ControlExternal(Dialog & parent)
        : Dialog::Controller(parent),
@@ -64,7 +69,7 @@ void ControlExternal::dispatchParams()
        string const lfun = InsetExternalMailer::params2string(params(),
                                                               kernel().buffer());
 
-       kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
+       kernel().dispatch(FuncRequest(getLfun(), lfun));
 }
 
 
@@ -129,29 +134,33 @@ external::Template ControlExternal::getTemplate(int i) const
        external::TemplateManager::Templates::const_iterator i1
                = external::TemplateManager::get().getTemplates().begin();
 
-       std::advance(i1, i);
+       advance(i1, i);
 
        return i1->second;
 }
 
 
-string const ControlExternal::Browse(string const & input) const
+string const ControlExternal::browse(string const & input,
+                                    string const & template_name) const
 {
        string const title =  _("Select external file");
 
        string const bufpath = kernel().bufferFilepath();
 
        /// Determine the template file extension
-       string pattern = "*";
+       external::TemplateManager const & etm =
+               external::TemplateManager::get();
        external::Template const * const et_ptr =
-               external::getTemplatePtr(params());
-       if (et_ptr)
-               pattern = et_ptr->fileRegExp;
+               etm.getTemplateByName(template_name);
+
+       FileFilterList const filter = et_ptr ?
+               FileFilterList(et_ptr->fileRegExp) :
+               FileFilterList();
 
        std::pair<string, string> dir1(N_("Documents|#o#O"),
-                                 string(lyxrc.document_path));
+                                      string(lyxrc.document_path));
 
-       return browseRelFile(input, bufpath, title, pattern, false, dir1);
+       return browseRelFile(input, bufpath, title, filter, false, dir1);
 }
 
 
@@ -170,9 +179,9 @@ string const ControlExternal::readBB(string const & file)
        int width = 0;
        int height = 0;
 
-       lyx::graphics::Cache & gc = lyx::graphics::Cache::get();
+       graphics::Cache & gc = graphics::Cache::get();
        if (gc.inCache(abs_file)) {
-               lyx::graphics::Image const * image = gc.item(abs_file)->image();
+               graphics::Image const * image = gc.item(abs_file)->image();
 
                if (image) {
                        width  = image->getWidth();
@@ -180,30 +189,35 @@ string const ControlExternal::readBB(string const & file)
                }
        }
 
-       return ("0 0 " + tostr(width) + ' ' + tostr(height));
+       return ("0 0 " + convert<string>(width) + ' ' + convert<string>(height));
 }
 
+} // namespace frontend
+
+
+namespace external {
 
 namespace {
 
-external::RotationDataType origins_array[] = {
-       external::RotationData::DEFAULT,
-       external::RotationData::TOPLEFT,
-       external::RotationData::BOTTOMLEFT,
-       external::RotationData::BASELINELEFT,
-       external::RotationData::CENTER,
-       external::RotationData::TOPCENTER,
-       external::RotationData::BOTTOMCENTER,
-       external::RotationData::BASELINECENTER,
-       external::RotationData::TOPRIGHT,
-       external::RotationData::BOTTOMRIGHT,
-       external::RotationData::BASELINERIGHT
+RotationDataType origins_array[] = {
+       RotationData::DEFAULT,
+       RotationData::TOPLEFT,
+       RotationData::BOTTOMLEFT,
+       RotationData::BASELINELEFT,
+       RotationData::CENTER,
+       RotationData::TOPCENTER,
+       RotationData::BOTTOMCENTER,
+       RotationData::BASELINECENTER,
+       RotationData::TOPRIGHT,
+       RotationData::BOTTOMRIGHT,
+       RotationData::BASELINERIGHT
 };
 
-lyx::size_type const origins_array_size =
+
+size_type const origins_array_size =
 sizeof(origins_array) / sizeof(origins_array[0]);
 
-vector<external::RotationDataType> const
+vector<RotationDataType> const
 origins(origins_array, origins_array + origins_array_size);
 
 // These are the strings, corresponding to the above, that the GUI should
@@ -217,8 +231,6 @@ char const * const origin_gui_strs[] = {
 
 } // namespace anon
 
-namespace lyx {
-namespace external {
 
 vector<RotationDataType> const & all_origins()
 {
@@ -227,7 +239,7 @@ vector<RotationDataType> const & all_origins()
 
 string const origin_gui_str(size_type i)
 {
-       return origin_gui_strs[i];
+       return _(origin_gui_strs[i]);
 }
 
 } // namespace external