From 46cb6110b77adc9c1f7f41741328945757fc3310 Mon Sep 17 00:00:00 2001 From: Sanel Zukan Date: Fri, 21 Oct 2011 15:41:30 +0000 Subject: [PATCH] Correctly write/read user supplied programs. --- ede-preferred-applications/AppChoice.cpp | 13 ++++++++++++- .../ede-preferred-applications.cpp | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ede-preferred-applications/AppChoice.cpp b/ede-preferred-applications/AppChoice.cpp index 5adceb8..188a211 100644 --- a/ede-preferred-applications/AppChoice.cpp +++ b/ede-preferred-applications/AppChoice.cpp @@ -60,6 +60,7 @@ void AppChoice::add_if_user_program(const char *cmd) { if(found) return; + user_val = cmd; replace(size() - 2, get_basename(cmd)); add(_("Browse...")); } @@ -70,6 +71,16 @@ void AppChoice::select_by_cmd(const char *cmd) { int pos; + if(!user_val.empty()) { + const char *b = get_basename(user_val.c_str()); + pos = find_index(b); + if(pos >= 0) { + value(pos); + pvalue = pos; + return; + } + } + for(int i = 0; known_apps[i].name; i++) { if(STR_CMP(cmd, known_apps[i].cmd)) { /* now find menu entry with this name */ @@ -94,7 +105,7 @@ const char *AppChoice::selected(void) { const char *n = text(); /* first check if user one was selected */ - if(!user_val.empty() && STR_CMP(get_basename(user_val.c_str()), n)); + if(!user_val.empty() && STR_CMP(get_basename(user_val.c_str()), n)) return user_val.c_str(); for(int i = 0; known_apps[i].name; i++) { diff --git a/ede-preferred-applications/ede-preferred-applications.cpp b/ede-preferred-applications/ede-preferred-applications.cpp index 2e598d4..991a35c 100644 --- a/ede-preferred-applications/ede-preferred-applications.cpp +++ b/ede-preferred-applications/ede-preferred-applications.cpp @@ -16,6 +16,8 @@ #include "AppChoice.h" +#define EMPTY_STR(s) (s[0] == '\0' || (strlen(s) == 0)) + EDELIB_NS_USING_AS(Window, EdeWindow) EDELIB_NS_USING(Resource) @@ -33,7 +35,7 @@ static void check_and_store(AppChoice *c, const char *n, Resource &rc) { /* load separate item */ static void check_and_load(AppChoice *c, const char *n, Resource &rc) { static char buf[128]; - if(rc.get("Preferred", n, buf, sizeof(buf)) && strlen(buf) > 0) { + if(rc.get("Preferred", n, buf, sizeof(buf)) && !EMPTY_STR(buf)) { c->add_if_user_program(buf); c->select_by_cmd(buf); }