From 98fabee0868d4eb01eb28759cffc3af9a318e903 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 11 Feb 2012 19:09:50 -0300 Subject: [PATCH] Add compatibility to load the recent list of paths from the recent list of files from old aseprite.ini files. --- src/base/recent_items.h | 1 + src/recent_files.cpp | 20 ++++++++++++++++++++ src/recent_files.h | 5 ++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/base/recent_items.h b/src/base/recent_items.h index daac81d93..442f65b82 100644 --- a/src/base/recent_items.h +++ b/src/base/recent_items.h @@ -24,6 +24,7 @@ public: const_iterator begin() { return m_items.begin(); } const_iterator end() { return m_items.end(); } + bool empty() const { return m_items.empty(); } size_t size() const { return m_items.size(); } size_t limit() const { return m_limit; } diff --git a/src/recent_files.cpp b/src/recent_files.cpp index c02b57482..1f196df3d 100644 --- a/src/recent_files.cpp +++ b/src/recent_files.cpp @@ -26,6 +26,7 @@ #include #include +#include RecentFiles::RecentFiles() : m_files(16) @@ -48,6 +49,25 @@ RecentFiles::RecentFiles() if (path && *path) m_paths.addItem(path); } + + // Create recent list of paths from filenames (for backward + // compatibility with previous versions of ASEPRITE). + if (m_paths.empty()) { + std::set included; + + // For each recent file... + const_iterator it = files_begin(); + const_iterator end = files_end(); + for (; it != end; ++it) { + base::string path = base::get_file_path(*it); + + // Check if the path was not already included in the list + if (included.find(path) == included.end()) { + included.insert(path); + m_paths.addItem(path); + } + } + } } RecentFiles::~RecentFiles() diff --git a/src/recent_files.h b/src/recent_files.h index b1c5655c0..b3715609f 100644 --- a/src/recent_files.h +++ b/src/recent_files.h @@ -20,13 +20,12 @@ #define RECENT_FILES_H_INCLUDED #include "base/recent_items.h" - -#include +#include "base/string.h" class RecentFiles { public: - typedef base::RecentItems List; + typedef base::RecentItems List; typedef List::iterator iterator; typedef List::const_iterator const_iterator;