Skip to content

Commit

Permalink
GUI: workaround for loading data files with single quote (') in the path
Browse files Browse the repository at this point in the history
(this problem was reported by Ranjit)
  • Loading branch information
wojdyr committed Mar 20, 2015
1 parent 7526000 commit 86111b2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
18 changes: 14 additions & 4 deletions wxgui/dload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ void DLoadDlg::exec_command(bool replace)
int x = browser_->x_column->GetValue();
int y = browser_->y_column->GetValue();
bool has_s = browser_->std_dev_cb->GetValue();
int sig = browser_->s_column->GetValue();
int b = browser_->block_ch->GetSelection();
// default parameter values are not passed explicitely
if (x != 1 || y != 2 || has_s || b != 0) {
cols = ":" + S(x) + ":" + S(y) + ":";
if (has_s)
cols += S(browser_->s_column->GetValue());
cols += S(sig);
cols += ":";
if (b != 0)
cols += S(b);
Expand All @@ -103,11 +104,20 @@ void DLoadDlg::exec_command(bool replace)
wxArrayString paths;
browser_->filectrl->GetPaths(paths);
string trailer;
if (browser_->comma_cb->GetValue())
string lua_trailer;
if (browser_->comma_cb->GetValue()) {
trailer = " _ decimal_comma";
lua_trailer = ", '', 'decimal_comma'";
}
for (size_t i = 0; i < paths.GetCount(); ++i) {
exec(cmd + "@" + (replace ? S(data_idx_) : S("+")) +
" < '" + wx2s(paths[i]) + cols + "'" + trailer);
if (paths[i].Find('\'') == wxNOT_FOUND)
cmd += "@" + (replace ? S(data_idx_) : S("+")) +
" < '" + wx2s(paths[i]) + cols + "'" + trailer;
else // very special case
cmd += "lua F:load(" + S(replace ? data_idx_ : -1) +
", [[" + wx2s(paths[i]) + "]], " + S(b) + ", " +
S(x) + ", " + S(y) + ", " + S(sig) + lua_trailer + ")";
exec(cmd);
if (browser_->title_tc->IsEnabled()) {
wxString t = browser_->title_tc->GetValue().Trim();
if (!t.IsEmpty()) {
Expand Down
31 changes: 24 additions & 7 deletions wxgui/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,12 +1015,23 @@ void FFrame::OnDataQLoad (wxCommandEvent&)
} // ignore the exception here, it'll be thrown later
}

bool has_single_quote = false;
for (size_t i = 0; i < paths.size(); ++i) {
if (i != 0)
cmd += " ; ";
cmd += "@+ <'" + wx2s(paths[i]) + "'";
if (!options.empty())
cmd += " _ " + options;
if (!has_single_quote)
if (paths[i].Find('\'') != wxNOT_FOUND) {
has_single_quote = true;
cmd += "lua ";
}
if (has_single_quote) { // very special case
cmd += "F:load(-1, [[" + wx2s(paths[i]) + "]], 0, 1, 2, 0, '', '"
+ options + "')";
} else {
cmd += "@+ <'" + wx2s(paths[i]) + "'";
if (!options.empty())
cmd += " _ " + options;
}
recent_data_->add(paths[i], options.empty() ? "" : "_ "+options);
}

Expand All @@ -1042,10 +1053,16 @@ void FFrame::OnDataXLoad (wxCommandEvent&)
void FFrame::OnDataRecent (wxCommandEvent& event)
{
const RecentFiles::Item& item = recent_data_->pull(event.GetId());
string cmd = "@+ <'" + wx2s(item.fn.GetFullPath()) + "'";
if (!item.options.empty())
cmd += " " + item.options;
exec(cmd);
wxString path = item.fn.GetFullPath();
if (path.Find('\'') == wxNOT_FOUND) {
string cmd = "@+ <'" + wx2s(path) + "'";
if (!item.options.empty())
cmd += " " + item.options;
exec(cmd);
} else { // very special case
// ignoring options
exec("lua F:load(-1, [[" + wx2s(path) + "]])");
}
}

void FFrame::OnDataRevertUpdate (wxUpdateUIEvent& event)
Expand Down

0 comments on commit 86111b2

Please sign in to comment.