]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/helper_funcs.C
port the graphics dialog to the new scheme and get rid of the ControlInset
[lyx.git] / src / frontends / controllers / helper_funcs.C
index 91b07996c204ae6683dde9a947eb8d10606c27bc..34ac0f1207a9a156061d489d7cd1f5c9a26cc61d 100644 (file)
@@ -1,21 +1,15 @@
-/* This file is part of
- * ====================================================== 
- *
- *           LyX, The Document Processor
- *
- *           Copyright 2001 The LyX Team.
+/**
+ * \file helper_funcs.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * ======================================================
+ * \author Angus Leeming
  *
- * \file helper_funcs.C
- * \author Angus Leeming <a.leeming@ic.ac.uk>
+ * Full author contact details are available in file CREDITS
  */
 
 #include <vector>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include <config.h>
 #include "LString.h"
 #include "support/filetools.h" // OnlyPath, OnlyFilename
 #include "support/lstrings.h"
 #include "gettext.h" // _()
-#include "lyx_gui_misc.h" // WriteAlert
+#include "frontends/Alert.h"
 
 using std::pair;
 using std::vector;
 using std::make_pair;
 
 
-string const getStringFromVector(vector<string> const & vec,
-                                string const & delim)
+string const browseFile(string const & filename,
+                       string const & title,
+                       string const & pattern,
+                       bool save,
+                       pair<string,string> const & dir1,
+                       pair<string,string> const & dir2)
 {
-       string str;
-       int i = 0;
-       for (vector<string>::const_iterator it = vec.begin();
-            it != vec.end(); ++it) {
-               string item = strip(frontStrip(*it));
-               if (item.empty()) continue;
-
-               if (i++ > 0) str += delim;
-               str += item;
-       }
-       return str;
-}
+       string lastPath(".");
+       if (!filename.empty())
+               lastPath = OnlyPath(filename);
 
-vector<string> const getVectorFromString(string const & str,
-                                        string const & delim)
-{
-       vector<string> vec;
-       if (str.empty())
-               return vec;
+       FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
 
-       string keys(strip(str));
+       FileDialog::Result result;
 
-       for(;;) {
-               string::size_type const idx = keys.find(delim);
-               if (idx == string::npos) {
-                       vec.push_back(frontStrip(keys));
-                       break;
-               }
+       while (true) {
+               if (save)
+                       result = fileDlg.save(lastPath, pattern,
+                               OnlyFilename(filename));
+               else
+                       result = fileDlg.open(lastPath, pattern,
+                               OnlyFilename(filename));
+
+               if (result.second.empty())
+                       return result.second;
+
+               lastPath = OnlyPath(result.second);
 
-               string const key = strip(frontStrip(keys.substr(0, idx)));
-               if (!key.empty())
-                       vec.push_back(key);
+               if (result.second.find_first_of("#~$% ") == string::npos)
+                       break;
 
-               string::size_type const start = idx + delim.size();
-               keys = keys.substr(start);
+               Alert::alert(_("Filename can't contain any "
+                       "of these characters:"),
+                       _("space, '#', '~', '$' or '%'."));
        }
 
-       return vec;
+       return result.second;
+}
+
+
+string const browseRelFile(string const & filename,
+                       string const & refpath,
+                       string const & title,
+                       string const & pattern,
+                       bool save,
+                       pair<string,string> const & dir1,
+                       pair<string,string> const & dir2)
+{
+       string const fname = MakeAbsPath(filename, refpath);
+
+       string const outname = browseFile(fname, title, pattern, save,
+                                         dir1, dir2);
+       string const reloutname = MakeRelPath(outname, refpath);
+       if (prefixIs(reloutname, "../"))
+               return outname;
+       else
+               return reloutname;
 }
 
-string const browseFile(LyXView * lv, string const & filename,
+
+string const browseDir(string const & pathname,
                        string const & title,
-                       string const & pattern, 
                        pair<string,string> const & dir1,
                        pair<string,string> const & dir2)
 {
-       string lastPath = ".";
-       if (!filename.empty()) lastPath = OnlyPath(filename);
+       string lastPath(".");
+       if (!pathname.empty())
+               lastPath = OnlyPath(pathname);
 
-       FileDialog fileDlg(lv, title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
+       FileDialog fileDlg(title, LFUN_SELECT_FILE_SYNC, dir1, dir2);
 
        FileDialog::Result result;
-       while (1) {
-               result = fileDlg.Select(lastPath, pattern, OnlyFilename(filename));
 
-               if (result.second.empty()) 
+       while (true) {
+               result = fileDlg.opendir(lastPath,
+                               OnlyFilename(pathname));
+
+               if (result.second.empty())
                        return result.second;
 
                lastPath = OnlyPath(result.second);
 
                if (result.second.find_first_of("#~$% ") == string::npos)
-                       break; 
-               WriteAlert(_("Filename can't contain any "
+                       break;
+
+               Alert::alert(_("directory name can't contain any "
                        "of these characters:"),
                        _("space, '#', '~', '$' or '%'."));
        }
@@ -114,8 +126,8 @@ extern const char * stringFromUnit(int);
 vector<string> const getLatexUnits()
 {
        vector<string> units;
-       const char * str;
-       for(int i=0; (str = stringFromUnit(i)); ++i)
+       char const * str;
+       for (int i = 0; (str = stringFromUnit(i)); ++i)
            units.push_back(str);
 
        return units;