summaryrefslogtreecommitdiff
path: root/fluid/app/history.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'fluid/app/history.cxx')
-rw-r--r--fluid/app/history.cxx62
1 files changed, 36 insertions, 26 deletions
diff --git a/fluid/app/history.cxx b/fluid/app/history.cxx
index 7eadb5469..91b2f0b99 100644
--- a/fluid/app/history.cxx
+++ b/fluid/app/history.cxx
@@ -17,11 +17,20 @@
#include "app/history.h"
#include "Fluid.h"
+#include "tools/filename.h"
#include "../src/flstring.h"
-using namespace fld;
-using namespace fld::app;
+
+fld::app::History::History() {
+ int i, j;
+ for (i = 0; i < 10; i++) {
+ for (j = 0; j < FL_PATH_MAX; j++) {
+ abspath[i][j] = '\0';
+ relpath[i][j] = '\0';
+ }
+ }
+}
/**
@@ -31,25 +40,23 @@ using namespace fld::app;
It also computes and stores the relative filepaths for display in
the main menu.
*/
-void History::load() {
- int i; // Looping var
- int max_files;
+void fld::app::History::load() {
+ int i;
+ int max_files;
Fluid.preferences.get("recent_files", max_files, 5);
if (max_files > 10) max_files = 10;
- for (i = 0; i < max_files; i ++) {
- Fluid.preferences.get( Fl_Preferences::Name("file%d", i), abspath[i], "", sizeof(abspath[i]));
+ for (i = 0; i < max_files; i++) {
+ Fluid.preferences.get(Fl_Preferences::Name("file%d", i), abspath[i], "", sizeof(abspath[i]));
if (abspath[i][0]) {
- // Make a shortened version of the filename for the menu...
- std::string fn = fl_filename_shortened(abspath[i], 48);
- strncpy(relpath[i], fn.c_str(), sizeof(relpath[i]) - 1);
+ fl_filename_shortened(relpath[i], sizeof(relpath[i]), abspath[i], 48);
if (i == 9) Fluid.history_item[i].flags = FL_MENU_DIVIDER;
else Fluid.history_item[i].flags = 0;
} else break;
}
- for (; i < 10; i ++) {
+ for (; i < 10; i++) {
if (i) Fluid.history_item[i-1].flags |= FL_MENU_DIVIDER;
Fluid.history_item[i].hide();
}
@@ -64,19 +71,24 @@ void History::load() {
\param[in] project_file path and filename of .fl project file, will be
converted into an absolute file path based on the current working directory.
*/
-void History::update(std::string project_file) {
- int i; // Looping var
- int max_files;
+void fld::app::History::update(const char *project_file) {
+ int i;
+ int max_files;
+
+ if (!project_file || !project_file[0]) return;
Fluid.preferences.get("recent_files", max_files, 5);
if (max_files > 10) max_files = 10;
- std::string absolute = fld::fix_separators(fl_filename_absolute_str(project_file));
- for (i = 0; i < max_files; i ++)
+ char absolute[FL_PATH_MAX];
+ fl_filename_absolute(absolute, FL_PATH_MAX, project_file);
+ fld_fix_separators(absolute);
+
+ for (i = 0; i < max_files; i++)
#if defined(_WIN32) || defined(__APPLE__)
- if (!strcasecmp(absolute.c_str(), abspath[i])) break;
+ if (!strcasecmp(absolute, abspath[i])) break;
#else
- if (!strcmp(absolute.c_str(), abspath[i])) break;
+ if (!strcmp(absolute, abspath[i])) break;
#endif // _WIN32 || __APPLE__
// Does the first entry match?
@@ -92,24 +104,22 @@ void History::update(std::string project_file) {
memmove(relpath + 1, relpath, i * sizeof(relpath[0]));
// Put the new file at the top...
- strlcpy(abspath[0], absolute.c_str(), sizeof(abspath[0]));
- std::string fn = fl_filename_shortened(absolute, 48);
- strncpy(relpath[0], fn.c_str(), sizeof(relpath[0]) - 1);
+ strlcpy(abspath[0], absolute, sizeof(abspath[0]));
+ fl_filename_shortened(relpath[0], sizeof(relpath[0]), absolute, 48);
// Update the menu items as needed...
- for (i = 0; i < max_files; i ++) {
- Fluid.preferences.set( Fl_Preferences::Name("file%d", i), abspath[i]);
+ for (i = 0; i < max_files; i++) {
+ Fluid.preferences.set(Fl_Preferences::Name("file%d", i), abspath[i]);
if (abspath[i][0]) {
if (i == 9) Fluid.history_item[i].flags = FL_MENU_DIVIDER;
else Fluid.history_item[i].flags = 0;
} else break;
}
- for (; i < 10; i ++) {
- Fluid.preferences.set( Fl_Preferences::Name("file%d", i), "");
+ for (; i < 10; i++) {
+ Fluid.preferences.set(Fl_Preferences::Name("file%d", i), "");
if (i) Fluid.history_item[i-1].flags |= FL_MENU_DIVIDER;
Fluid.history_item[i].hide();
}
Fluid.preferences.flush();
}
-