]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetexternal.C
Applied John's FileDialog patch.
[lyx.git] / src / insets / insetexternal.C
index 77435740d298fe1637a8a0e3c6032ac762c04f3f..8bddd24839475b7739521ebcb7adee7f3aa7fe70 100644 (file)
 
 #include FORMS_H_LOCATION
 #include <cstdio>
+#include <utility> 
 
 #include "insetexternal.h"
 #include "ExternalTemplate.h"
 #include "lyx_gui_misc.h" // CancelCloseBoxCB
 #include "BufferView.h"
 #include "buffer.h"
-#include "filedlg.h"
+#include "frontends/FileDialog.h"
 #include "lyx_main.h"
 #include "LaTeXFeatures.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
 #include "support/path.h"
 #include "support/syscall.h"
+#include "frontends/Dialogs.h" // redrawGUI
 
-using std::endl;
+#ifdef SIGC_CXX_NAMESPACES
+using SigC::slot;
+#endif
 
+using std::endl;
+using std::pair;
+using std::make_pair; 
 
 InsetExternal::InsetExternal() 
        : form_external(0)
 {
-       tempname = lyx::tempName(); //TmpFileName();
+       tempname = lyx::tempName(string(), "lyxext");
+       r_ = Dialogs::redrawGUI.connect(slot(this, &InsetExternal::redraw));
 }
 
 
 InsetExternal::~InsetExternal()
 {
        lyx::unlink(tempname);
+       r_.disconnect();
+}
+
+
+void InsetExternal::redraw()
+{
+       if (form_external && form_external->form_external->visible)
+               fl_redraw_form(form_external->form_external);
 }
 
 
@@ -114,7 +130,6 @@ void InsetExternal::browseCB(FL_OBJECT * ob, long)
 
        static string current_path;
        static int once = 0;
-       LyXFileDlg fileDlg;
        
        string p = inset->filename;
        string buf = MakeAbsPath(holder->view->buffer()->fileName());
@@ -126,7 +141,11 @@ void InsetExternal::browseCB(FL_OBJECT * ob, long)
                buf = OnlyPath(holder->view->buffer()->fileName());
        }
        
-       fileDlg.SetButton(0, _("Document"), buf); 
+       FileDialog fileDlg(holder->view->owner(), _("Select external file"),
+               LFUN_SELECT_FILE_SYNC,
+               make_pair(string(_("Document")), string(buf)));
+       
+       // FIXME: should have "nice name" for file type e.g. "Xfig files"
 
        /// Determine the template file extension
        ExternalTemplate et = inset->getTemplate(inset->getCurrentTemplate());
@@ -135,18 +154,17 @@ void InsetExternal::browseCB(FL_OBJECT * ob, long)
                regexp = "*";
        }
 
+       regexp += "|";
+
        bool error = false;
        do {
-               if (once) {
-                       p = fileDlg.Select(_("External inset file"),
-                                          current_path,
-                                          regexp, string());
-               } else {
-                       p = fileDlg.Select(_("External inset file"), buf,
-                                          regexp, string());
-               }
+               string const path = (once) ? current_path : buf;
+               FileDialog::Result result = fileDlg.Select(path, regexp);
+
+               if (result.second.empty()) 
+                       return;
 
-               if (p.empty()) return;
+               string p = result.second;
 
                buf = MakeRelPath(p, buf2);
                current_path = OnlyPath(p);
@@ -319,7 +337,9 @@ void InsetExternal::Read(Buffer const *, LyXLex & lex)
        filename = format.substr(pos1 + 2, pos2 - (pos1 + 2));
        parameters = format.substr(pos2 + 3, format.length() - (pos2 + 4));
 
-       lyxerr << templatename << " " << filename << " " << parameters << endl;
+       lyxerr[Debug::INFO] << "InsetExternal::Read: " << templatename
+                           << " " << filename
+                           << " " << parameters << endl;
 }
 
 
@@ -406,7 +426,10 @@ string const InsetExternal::getScreenLabel() const
                return _("External");
        } else {
                ExternalTemplate const & et = getTemplate(templatename);
-               return doSubstitution(0, et.guiName);
+               if (et.guiName.empty())
+                       return "ext: ???";
+               else
+                       return doSubstitution(0, et.guiName);
        }
 }
 
@@ -536,7 +559,9 @@ int InsetExternal::getTemplateNumber(string const & name) const
                ++i;
        }
        // This should never happen
-       Assert(false);
+       ///  This can happen if someone sends you a lyx file that uses
+       ///  external templates that are defined only on his machine
+       //Assert(false);
        return 0;
 }