#include "support/lstrings.h" // frontStrip, strip
#include "gettext.h"
#include "support/LAssert.h"
+#include "lyxlength.h"
+#include "lyxgluelength.h"
using std::ofstream;
using std::pair;
{
// Find '|' in the sc and return the string after that.
register char const * sd = sc;
- while(sd[0]!= 0 && sd[0] != '|') ++sd;
+ while (sd[0]!= 0 && sd[0] != '|') ++sd;
if (sd[0] == '|') {
++sd;
char const * flyx_ident_extract(char const * sc)
{
register char const * se = sc;
- while(se[0]!= 0 && se[0] != '|') ++se;
+ while (se[0]!= 0 && se[0] != '|') ++se;
if (se[0] == 0) return sc;
}
+/// Given an fl_input, return its contents.
+string const getStringFromInput(FL_OBJECT * ob)
+{
+ if (!ob || ob->objclass != FL_INPUT)
+ return string();
+
+ char const * tmp = fl_get_input(ob);
+ return (tmp) ? tmp : string();
+}
+
+
+// Given an fl_browser, return the contents of line
+string const getStringFromBrowser(FL_OBJECT * ob, int line)
+{
+ if (!ob || ob->objclass != FL_BROWSER ||
+ line < 1 || line > fl_get_browser_maxline(ob))
+ return string();
+
+ char const * tmp = fl_get_browser_line(ob, line);
+ return (tmp) ? tmp : string();
+}
+
+// Given an fl_browser, return the contents of the currently
+// highlighted line.
+// If nothing is selected, return an empty string
+string const getSelectedStringFromBrowser(FL_OBJECT * ob)
+{
+ if (!ob || ob->objclass != FL_BROWSER)
+ return string();
+
+ int const line = fl_get_browser(ob);
+ if (line < 1 || line > fl_get_browser_maxline(ob))
+ return string();
+
+ if (!fl_isselected_browser_line(ob, line))
+ return string();
+
+ char const * tmp = fl_get_browser_line(ob, line);
+ return (tmp) ? tmp : string();
+}
+
+
// Given an fl_browser, create a vector of its entries
vector<string> const getVectorFromBrowser(FL_OBJECT * ob)
{
if (length.empty())
return string();
+ //don't return unit-from-choice if the input(field) contains a unit
+ if (isValidGlueLength(length))
+ return length;
+
string unit = strip(frontStrip(fl_get_choice_text(choice)));
unit = subst(unit, "%%", "%");
}
+#if 1
+// this should definitely be the other way around!!!
+void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
+ LyXLength const & len,
+ string const & default_unit)
+{
+ if (len.zero())
+ updateWidgetsFromLengthString(input, choice,
+ string(), default_unit);
+ else
+ updateWidgetsFromLengthString(input, choice,
+ len.asString(), default_unit);
+
+}
+
+
+// Most of the code here is a poor duplication of the parser code
+// which is in LyXLength. Use that instead
void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
string const & str,
string const & default_unit)
fl_set_input(input, len.c_str());
fl_set_choice(choice, unitpos);
}
-
+#else
+void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
+ string const & str,
+ string const & default_unit)
+{
+ updateWidgetsFromLength(input, choice,
+ LyXLength(str), default_unit);
+}
+
+
+void updateWidgetsFromLength(FL_OBJECT * input, FL_OBJECT * choice,
+ LyXLength const & len,
+ string const & default_unit)
+{
+ // Paranoia check
+ lyx::Assert(input && input->objclass == FL_INPUT &&
+ choice && choice->objclass == FL_CHOICE);
+
+ if (len.zero()) {
+ fl_set_input(input, "");
+ fl_set_choice_text(choice, default_unit.c_str());
+ } else {
+ ostringstream buffer;
+ buffer << len.value();
+ fl_set_input(input, buffer.str().c_str());
+ fl_set_choice_text(choice, stringFromUnit(len.unit()));
+ }
+}
+#endif
+
+
// Take a string and add breaks so that it fits into a desired label width, w
string formatted(string const & sin, int w, int size, int style)
{
}
FileInfo const tp(name);
- if (!tp.isDir()) {
+ if (!tp.isOK() || !tp.isDir()) {
error_message = N_("Directory does not exist.");
return false;
}
}
FileInfo const tp(name);
- if (!tp.isDir()) {
+ if (!tp.isOK() || !tp.isDir()) {
error_message = N_("Directory does not exist.");
return false;
}
}
FileInfo d(name);
- if (!d.isDir()) {
+
+ if (!d.isOK() || !d.isDir()) {
d.newFile(dir);
}
- if (!d.isDir()) {
+ if (!d.isOK() || !d.isDir()) {
error_message = N_("Directory does not exist.");
return false;
}
}
FileInfo f(name);
- if (dir == name || f.isDir()) {
+ if (dir == name || (f.isOK() && f.isDir())) {
error_message = N_("A file is required, not a directory.");
return false;
}
- if (f.exist() && !f.writable()) {
+ if (f.isOK() && f.exist() && !f.writable()) {
error_message = N_("Cannot write to this file.");
return false;
}
}
FileInfo d(name);
- if (!d.isDir()) {
+
+ if (!d.isOK() && !d.isDir()) {
d.newFile(dir);
}
- if (!d.isDir()) {
+ if (!d.isOK() || !d.isDir()) {
error_message = N_("Directory does not exist.");
return false;
}
}
FileInfo f(name);
- if (dir == name || f.isDir()) {
+ if (dir == name || (f.isOK() && f.isDir())) {
error_message = N_("A file is required, not a directory.");
return false;
}