2010-03-28 02:43:08 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2011-01-18 23:49:53 +00:00
|
|
|
* Copyright (C) 2001-2011 David Capello
|
2010-03-28 02:43:08 +00: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
#include "core/cfg.h"
|
|
|
|
#include "modules/gui.h"
|
|
|
|
#include "recent_files.h"
|
|
|
|
|
|
|
|
RecentFiles::RecentFiles()
|
2010-09-18 03:28:24 +00:00
|
|
|
: m_limit(16)
|
2010-03-28 02:43:08 +00:00
|
|
|
{
|
2010-09-18 03:28:24 +00:00
|
|
|
const char* filename;
|
2010-03-28 02:43:08 +00:00
|
|
|
char buf[512];
|
|
|
|
int c;
|
|
|
|
|
2010-09-18 03:28:24 +00:00
|
|
|
for (c=m_limit-1; c>=0; c--) {
|
2010-03-28 02:43:08 +00:00
|
|
|
sprintf(buf, "Filename%02d", c);
|
|
|
|
|
|
|
|
filename = get_config_string("RecentFiles", buf, NULL);
|
|
|
|
if ((filename) && (*filename))
|
|
|
|
addRecentFile(filename);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RecentFiles::~RecentFiles()
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
for (const_iterator it = begin(); it != end(); ++it) {
|
|
|
|
const char* filename = it->c_str();
|
|
|
|
sprintf(buf, "Filename%02d", c);
|
|
|
|
set_config_string("RecentFiles", buf, filename);
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
|
2010-09-18 03:28:24 +00:00
|
|
|
m_files.clear();
|
2010-03-28 02:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RecentFiles::const_iterator RecentFiles::begin()
|
|
|
|
{
|
2010-09-18 03:28:24 +00:00
|
|
|
return m_files.begin();
|
2010-03-28 02:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RecentFiles::const_iterator RecentFiles::end()
|
|
|
|
{
|
2010-09-18 03:28:24 +00:00
|
|
|
return m_files.end();
|
2010-03-28 02:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RecentFiles::addRecentFile(const char* filename)
|
|
|
|
{
|
2010-09-18 03:28:24 +00:00
|
|
|
iterator it = std::find(m_files.begin(), m_files.end(), filename);
|
2010-03-28 02:43:08 +00:00
|
|
|
|
|
|
|
// If the filename already exist in the list...
|
2010-09-18 03:28:24 +00:00
|
|
|
if (it != m_files.end()) {
|
2010-03-28 02:43:08 +00:00
|
|
|
// Move it to the first position
|
2010-09-18 03:28:24 +00:00
|
|
|
m_files.erase(it);
|
|
|
|
m_files.insert(m_files.begin(), filename);
|
2010-03-28 02:43:08 +00:00
|
|
|
schedule_rebuild_recent_list();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the filename does not exist...
|
|
|
|
|
|
|
|
// Does the list is full?
|
2010-09-18 03:28:24 +00:00
|
|
|
if ((int)m_files.size() == m_limit) {
|
2010-03-28 02:43:08 +00:00
|
|
|
// Remove the last entry
|
2010-09-18 03:28:24 +00:00
|
|
|
m_files.erase(--m_files.end());
|
2010-03-28 02:43:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-18 03:28:24 +00:00
|
|
|
m_files.insert(m_files.begin(), filename);
|
2010-03-28 02:43:08 +00:00
|
|
|
schedule_rebuild_recent_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecentFiles::removeRecentFile(const char* filename)
|
|
|
|
{
|
2010-09-18 03:28:24 +00:00
|
|
|
iterator it = std::find(m_files.begin(), m_files.end(), filename);
|
2010-03-28 02:43:08 +00:00
|
|
|
|
2010-09-18 03:28:24 +00:00
|
|
|
if (it != m_files.end()) {
|
|
|
|
m_files.erase(it);
|
2010-03-28 02:43:08 +00:00
|
|
|
|
|
|
|
schedule_rebuild_recent_list();
|
|
|
|
}
|
|
|
|
}
|