]> git.lyx.org Git - lyx.git/commitdiff
make browsing for lyxdir files DTRT
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 8 Aug 2004 15:23:43 +0000 (15:23 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 8 Aug 2004 15:23:43 +0000 (15:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8872 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlPrefs.C
src/frontends/controllers/helper_funcs.C
src/frontends/controllers/helper_funcs.h

index 5a21f20d312482b1cc7224c37f636c8918c20d46..cc33e685cc795af9953a2bb254de0564c1700b15 100644 (file)
@@ -1,3 +1,11 @@
+2004-08-08  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * helper_funcs.C (browseLibFile): new function. Tries to do the
+       right thing to look for a file in lyxdir
+
+       * ControlPrefs.C (browsebind, browseUI, browsekbmap): use
+       browseLibFile
+
 2004-08-07  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * ControlBibtex.C (browseBst): new method, specialized to lookup
index 8236af8c56296f46e25455b2c7bb7efea89db7b9..8f1a3775caff7722b38eb2b1d43bed894b7dcbf4 100644 (file)
@@ -20,9 +20,7 @@
 #include "funcrequest.h"
 #include "LColor.h"
 
-#include "support/filetools.h"
 #include "support/globbing.h"
-#include "support/path_defines.h"
 
 #include <sstream>
 
@@ -36,10 +34,7 @@ extern BufferList bufferlist;
 
 namespace lyx {
 
-using support::AddName;
 using support::FileFilterList;
-using support::system_lyxdir;
-using support::user_lyxdir;
 
 namespace frontend {
 
@@ -123,37 +118,22 @@ void ControlPrefs::updateScreenFonts()
 
 string const ControlPrefs::browsebind(string const & file) const
 {
-       pair<string,string> dir1(_("System Bind|#S#s"),
-                                AddName(system_lyxdir(), "bind"));
-
-       pair<string,string> dir2(_("User Bind|#U#u"),
-                                AddName(user_lyxdir(), "bind"));
-
-       return browseFile(file, _("Choose bind file"),
-                         FileFilterList("*.bind"), false, dir1, dir2);
+       return browseLibFile("bind", file, "bind", _("Choose bind file"),
+                         FileFilterList("LyX bind files (*.bind)"));
 }
 
 
 string const ControlPrefs::browseUI(string const & file) const
 {
-       pair<string,string> const dir1(_("Sys UI|#S#s"),
-                                      AddName(system_lyxdir(), "ui"));
-
-       pair<string,string> const dir2(_("User UI|#U#u"),
-                                      AddName(user_lyxdir(), "ui"));
-
-       return browseFile(file, _("Choose UI file"),
-                         FileFilterList("*.ui"), false, dir1, dir2);
+       return browseLibFile("ui", file, "ui", _("Choose UI file"),
+                         FileFilterList("LyX UI files (*.ui)"));
 }
 
 
 string const ControlPrefs::browsekbmap(string const & file) const
 {
-       pair<string, string> dir(_("Key maps|#K#k"),
-                                AddName(system_lyxdir(), "kbd"));
-
-       return browseFile(file, _("Choose keyboard map"),
-                         FileFilterList("*.kmap"), false, dir);
+       return browseLibFile("kbd", file, "kmap", _("Choose keyboard map"),
+                         FileFilterList("LyX keyboard maps (*.kmap)"));
 }
 
 
index a817db0a1d9e1542b0da89d5746278893c1d0d56..abead0256952a9675bcb9679e5d297254d0b8579 100644 (file)
@@ -3,6 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
+ * \author Jean-Marc Lasgouttes
  * \author Angus Leeming
  *
  * Full author contact details are available in file CREDITS.
@@ -18,7 +19,8 @@
 #include "frontends/Alert.h"
 #include "frontends/FileDialog.h"
 
-#include "support/filetools.h" // OnlyPath, OnlyFilename
+#include "support/filetools.h"
+#include "support/path_defines.h"
 #include "support/globbing.h"
 
 using std::pair;
@@ -30,12 +32,18 @@ extern const char * stringFromUnit(int);
 
 namespace lyx {
 
+using support::AddName;
+using support::ChangeExtension;
 using support::FileFilterList;
+using support::GetExtension;
+using support::LibFileSearch;
 using support::MakeAbsPath;
 using support::MakeRelPath;
 using support::OnlyFilename;
 using support::OnlyPath;
 using support::prefixIs;
+using support::system_lyxdir;
+using support::user_lyxdir;
 
 namespace frontend {
 
@@ -101,6 +109,38 @@ string const browseRelFile(string const & filename,
 }
 
 
+
+string const browseLibFile(string const & dir,
+                          string const & name,
+                          string const & ext,
+                          string const & title,
+                          FileFilterList const & filters)
+{
+       pair<string,string> const dir1(_("System files|#S#s"),
+                                      AddName(system_lyxdir(), dir));
+       
+       pair<string,string> const dir2(_("User files|#U#u"),
+                                      AddName(user_lyxdir(), dir));
+       
+       string const result = browseFile(LibFileSearch(dir, name, ext), title,
+                                  filters, false, dir1, dir2);
+
+       // remove the extension if it is the default one
+       string noextresult;
+       if (GetExtension(result) == ext)
+               noextresult = ChangeExtension(result, string());
+       else
+               noextresult = result;
+
+       // remove the directory, if it is the default one
+       string const file = OnlyFilename(noextresult);
+       if (LibFileSearch(dir, file, ext) == result)
+               return file;
+       else
+               return noextresult;
+}
+
+
 string const browseDir(string const & pathname,
                        string const & title,
                        pair<string,string> const & dir1,
index aa9313f04c1d47da19c26a226291e36bac2b023e..36def74d207e43bc6f45c97b371d475ea7fc4304 100644 (file)
@@ -44,11 +44,11 @@ browseFile(std::string const & filename,
           std::make_pair(std::string(), std::string()));
 
 
-/* Wrapper around browseFile which tries to provide a filename
-   relative to relpath.  If the relative path is of the form "foo.txt"
-   or "bar/foo.txt", then it is returned as relative. OTOH, if it is
-   of the form "../baz/foo.txt", an absolute path is returned. This is
-   intended to be useful for insets which encapsulate files/
+/** Wrapper around browseFile which tries to provide a filename
+    relative to relpath.  If the relative path is of the form "foo.txt"
+    or "bar/foo.txt", then it is returned as relative. OTOH, if it is
+    of the form "../baz/foo.txt", an absolute path is returned. This is
+    intended to be useful for insets which encapsulate files/
 */
 std::string const
 browseRelFile(std::string const & filename,
@@ -62,6 +62,19 @@ browseRelFile(std::string const & filename,
              std::make_pair(std::string(), std::string()));
 
 
+/** Wrapper around browseFile which tries to provide a filename
+ *  relative to the user or system directory. The dir, name and ext
+ *  parameters have the same meaning as in the
+ *  lyx::support::LibFileSearch function.
+ */
+std::string const
+browseLibFile(std::string const & dir,
+             std::string const & name,
+             std::string const & ext,
+             std::string const & title,
+             support::FileFilterList const & filters);
+
+
 /** Launch a file dialog and return the chosen directory.
     pathname: a suggested pathname.
     title: the title of the dialog.