2013-08-09 08:01:20 +08:00
|
|
|
/* Aseprite
|
2013-01-27 23:13:13 +08:00
|
|
|
* Copyright (C) 2001-2013 David Capello
|
2010-03-28 10:43:08 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-03-28 10:43:08 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2010-03-28 10:43:08 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/recent_files.h"
|
2010-03-28 10:43:08 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app_menus.h"
|
|
|
|
#include "app/ini_file.h"
|
2013-01-19 10:39:19 +08:00
|
|
|
#include "base/fs.h"
|
2012-02-12 06:04:52 +08:00
|
|
|
#include "base/path.h"
|
2011-06-30 09:51:46 +08:00
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2012-02-12 06:09:50 +08:00
|
|
|
#include <set>
|
2010-03-28 10:43:08 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2010-03-28 10:43:08 +08:00
|
|
|
RecentFiles::RecentFiles()
|
2012-02-12 06:04:52 +08:00
|
|
|
: m_files(16)
|
|
|
|
, m_paths(16)
|
2010-03-28 10:43:08 +08:00
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
|
2012-02-12 06:04:52 +08:00
|
|
|
for (int c=m_files.limit()-1; c>=0; c--) {
|
2010-03-28 10:43:08 +08:00
|
|
|
sprintf(buf, "Filename%02d", c);
|
|
|
|
|
2012-02-12 06:04:52 +08:00
|
|
|
const char* filename = get_config_string("RecentFiles", buf, NULL);
|
2014-04-18 04:12:55 +08:00
|
|
|
if (filename && *filename && base::is_file(filename))
|
2012-02-12 06:04:52 +08:00
|
|
|
m_files.addItem(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int c=m_paths.limit()-1; c>=0; c--) {
|
|
|
|
sprintf(buf, "Path%02d", c);
|
|
|
|
|
|
|
|
const char* path = get_config_string("RecentPaths", buf, NULL);
|
|
|
|
if (path && *path)
|
|
|
|
m_paths.addItem(path);
|
2010-03-28 10:43:08 +08:00
|
|
|
}
|
2012-02-12 06:09:50 +08:00
|
|
|
|
|
|
|
// Create recent list of paths from filenames (for backward
|
|
|
|
// compatibility with previous versions of ASEPRITE).
|
|
|
|
if (m_paths.empty()) {
|
|
|
|
std::set<std::string> included;
|
|
|
|
|
|
|
|
// For each recent file...
|
|
|
|
const_iterator it = files_begin();
|
|
|
|
const_iterator end = files_end();
|
|
|
|
for (; it != end; ++it) {
|
2014-04-21 06:53:27 +08:00
|
|
|
std::string path = base::get_file_path(*it);
|
2012-02-12 06:09:50 +08:00
|
|
|
|
|
|
|
// Check if the path was not already included in the list
|
|
|
|
if (included.find(path) == included.end()) {
|
|
|
|
included.insert(path);
|
|
|
|
m_paths.addItem(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-28 10:43:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RecentFiles::~RecentFiles()
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
|
2012-02-12 06:04:52 +08:00
|
|
|
int c = 0;
|
|
|
|
for (const_iterator it = files_begin(); it != files_end(); ++it) {
|
2010-03-28 10:43:08 +08:00
|
|
|
const char* filename = it->c_str();
|
|
|
|
sprintf(buf, "Filename%02d", c);
|
|
|
|
set_config_string("RecentFiles", buf, filename);
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
2012-02-12 06:04:52 +08:00
|
|
|
c = 0;
|
|
|
|
for (const_iterator it = paths_begin(); it != paths_end(); ++it) {
|
|
|
|
const char* path = it->c_str();
|
|
|
|
sprintf(buf, "Path%02d", c);
|
|
|
|
set_config_string("RecentPaths", buf, path);
|
|
|
|
c++;
|
|
|
|
}
|
2010-03-28 10:43:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RecentFiles::addRecentFile(const char* filename)
|
|
|
|
{
|
2012-02-12 06:04:52 +08:00
|
|
|
m_files.addItem(filename);
|
|
|
|
m_paths.addItem(base::get_file_path(filename));
|
2012-07-10 00:20:58 +08:00
|
|
|
|
|
|
|
AppMenus::instance()->rebuildRecentList();
|
2010-03-28 10:43:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RecentFiles::removeRecentFile(const char* filename)
|
|
|
|
{
|
2012-02-12 06:04:52 +08:00
|
|
|
m_files.removeItem(filename);
|
|
|
|
m_paths.removeItem(base::get_file_path(filename));
|
2012-07-10 00:20:58 +08:00
|
|
|
|
|
|
|
AppMenus::instance()->rebuildRecentList();
|
2010-03-28 10:43:08 +08:00
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|