mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-17 08:43:11 +00:00
Refactor: Use new base::paths type for list of filenames/extensions
This commit is contained in:
parent
d82bd89d4f
commit
dee6ff6c7e
2
laf
2
laf
@ -1 +1 @@
|
||||
Subproject commit de578c1e6cc636d00b806051d338bf196712885f
|
||||
Subproject commit b8af51a8294aeaaf15177516f7d44fad23f1fe62
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "app/app_brushes.h"
|
||||
#include "base/mutex.h"
|
||||
#include "base/paths.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/pixel_format.h"
|
||||
#include "obs/signal.h"
|
||||
@ -102,7 +103,6 @@ namespace app {
|
||||
obs::signal<void()> PaletteChange;
|
||||
|
||||
private:
|
||||
typedef std::vector<std::string> FileList;
|
||||
class CoreModules;
|
||||
class Modules;
|
||||
|
||||
@ -115,7 +115,7 @@ namespace app {
|
||||
bool m_isGui;
|
||||
bool m_isShell;
|
||||
base::UniquePtr<MainWindow> m_mainWindow;
|
||||
FileList m_files;
|
||||
base::paths m_files;
|
||||
base::UniquePtr<AppBrushes> m_brushes;
|
||||
BackupIndicator* m_backupIndicator;
|
||||
base::mutex m_backupIndicatorMutex;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2016-2017 David Capello
|
||||
// Copyright (C) 2016-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -139,7 +139,7 @@ void PreviewCliDelegate::saveFile(const CliOpenFile& cof)
|
||||
cof.filenameFormat));
|
||||
|
||||
if (fop) {
|
||||
std::vector<std::string> files;
|
||||
base::paths files;
|
||||
fop->getFilenameList(files);
|
||||
for (const auto& file : files) {
|
||||
if (base::is_file(file))
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -453,11 +453,10 @@ private:
|
||||
}
|
||||
|
||||
void onImageFilename() {
|
||||
std::string exts = get_writable_extensions();
|
||||
|
||||
FileSelectorFiles newFilename;
|
||||
base::paths newFilename;
|
||||
if (!app::show_file_selector(
|
||||
"Save Sprite Sheet", m_filename, exts,
|
||||
"Save Sprite Sheet", m_filename,
|
||||
get_writable_extensions(),
|
||||
FileSelectorType::Save, newFilename))
|
||||
return;
|
||||
|
||||
@ -478,9 +477,10 @@ private:
|
||||
|
||||
void onDataFilename() {
|
||||
// TODO hardcoded "json" extension
|
||||
FileSelectorFiles newFilename;
|
||||
base::paths exts = { "json" };
|
||||
base::paths newFilename;
|
||||
if (!app::show_file_selector(
|
||||
"Save JSON Data", m_dataFilename, "json",
|
||||
"Save JSON Data", m_dataFilename, exts,
|
||||
FileSelectorType::Save, newFilename))
|
||||
return;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -649,10 +649,10 @@ private:
|
||||
}
|
||||
|
||||
void onImport() {
|
||||
FileSelectorFiles filename;
|
||||
base::paths exts = { KEYBOARD_FILENAME_EXTENSION };
|
||||
base::paths filename;
|
||||
if (!app::show_file_selector(
|
||||
"Import Keyboard Shortcuts", "",
|
||||
KEYBOARD_FILENAME_EXTENSION,
|
||||
"Import Keyboard Shortcuts", "", exts,
|
||||
FileSelectorType::Open, filename))
|
||||
return;
|
||||
|
||||
@ -666,11 +666,11 @@ private:
|
||||
}
|
||||
|
||||
void onExport() {
|
||||
FileSelectorFiles filename;
|
||||
base::paths exts = { KEYBOARD_FILENAME_EXTENSION };
|
||||
base::paths filename;
|
||||
|
||||
if (!app::show_file_selector(
|
||||
"Export Keyboard Shortcuts", "",
|
||||
KEYBOARD_FILENAME_EXTENSION,
|
||||
"Export Keyboard Shortcuts", "", exts,
|
||||
FileSelectorType::Save, filename))
|
||||
return;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -58,9 +58,10 @@ void LoadMaskCommand::onExecute(Context* context)
|
||||
const ContextReader reader(context);
|
||||
|
||||
if (context->isUIAvailable()) {
|
||||
FileSelectorFiles selectedFilename;
|
||||
base::paths exts = { "msk" };
|
||||
base::paths selectedFilename;
|
||||
if (!app::show_file_selector(
|
||||
"Load .msk File", m_filename, "msk",
|
||||
"Load .msk File", m_filename, exts,
|
||||
FileSelectorType::Open, selectedFilename))
|
||||
return;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -64,11 +64,11 @@ void LoadPaletteCommand::onExecute(Context* context)
|
||||
filename = m_filename;
|
||||
}
|
||||
else {
|
||||
std::string exts = get_readable_palette_extensions();
|
||||
|
||||
FileSelectorFiles filenames;
|
||||
if (app::show_file_selector("Load Palette", "", exts,
|
||||
FileSelectorType::Open, filenames)) {
|
||||
base::paths exts = get_readable_palette_extensions();
|
||||
base::paths filenames;
|
||||
if (app::show_file_selector(
|
||||
"Load Palette", "", exts,
|
||||
FileSelectorType::Open, filenames)) {
|
||||
filename = filenames.front();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -104,11 +104,11 @@ void OpenFileCommand::onExecute(Context* context)
|
||||
|
||||
m_usedFiles.clear();
|
||||
|
||||
FileSelectorFiles filenames;
|
||||
base::paths filenames;
|
||||
|
||||
// interactive
|
||||
if (context->isUIAvailable() && m_filename.empty()) {
|
||||
std::string exts = get_readable_extensions();
|
||||
base::paths exts = get_readable_extensions();
|
||||
|
||||
// Add backslash as show_file_selector() expected a filename as
|
||||
// initial path (and the file part is removed from the path).
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2016 David Capello
|
||||
// Copyright (C) 2016-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -9,9 +9,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/commands/command.h"
|
||||
#include "base/paths.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -24,7 +24,7 @@ namespace app {
|
||||
OpenFileCommand();
|
||||
Command* clone() const override { return new OpenFileCommand(*this); }
|
||||
|
||||
const std::vector<std::string>& usedFiles() const {
|
||||
const base::paths& usedFiles() const {
|
||||
return m_usedFiles;
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ namespace app {
|
||||
std::string m_folder;
|
||||
bool m_repeatCheckbox;
|
||||
bool m_oneFrame;
|
||||
std::vector<std::string> m_usedFiles;
|
||||
base::paths m_usedFiles;
|
||||
SequenceDecision m_seqDecision;
|
||||
};
|
||||
|
||||
|
@ -878,9 +878,10 @@ private:
|
||||
}
|
||||
|
||||
void onAddExtension() {
|
||||
FileSelectorFiles filename;
|
||||
base::paths exts = { "zip" };
|
||||
base::paths filename;
|
||||
if (!app::show_file_selector(
|
||||
"Add Extension", "", "zip",
|
||||
"Add Extension", "", exts,
|
||||
FileSelectorType::Open, filename))
|
||||
return;
|
||||
|
||||
@ -1028,11 +1029,11 @@ private:
|
||||
return base::normalize_path(rf.defaultFilename());
|
||||
}
|
||||
|
||||
static std::vector<std::string> themeFolders() {
|
||||
static base::paths themeFolders() {
|
||||
ResourceFinder rf;
|
||||
rf.includeDataDir(skin::SkinTheme::kThemesFolderName);
|
||||
|
||||
std::vector<std::string> paths;
|
||||
base::paths paths;
|
||||
while (rf.next())
|
||||
paths.push_back(base::normalize_path(rf.filename()));
|
||||
return paths;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -90,11 +90,11 @@ private:
|
||||
}
|
||||
|
||||
void onSelectFontFile() {
|
||||
FileSelectorFiles face;
|
||||
base::paths exts = { "ttf", "ttc", "otf", "dfont" };
|
||||
base::paths face;
|
||||
if (!show_file_selector(
|
||||
"Select a TrueType Font",
|
||||
m_face,
|
||||
"ttf,ttc,otf,dfont",
|
||||
m_face, exts,
|
||||
FileSelectorType::Open, face))
|
||||
return;
|
||||
|
||||
|
@ -193,11 +193,11 @@ bool SaveFileBaseCommand::saveAsDialog(
|
||||
filename = m_filename;
|
||||
}
|
||||
else {
|
||||
std::string exts = get_writable_extensions();
|
||||
base::paths exts = get_writable_extensions();
|
||||
filename = document->filename();
|
||||
|
||||
again:;
|
||||
FileSelectorFiles newfilename;
|
||||
base::paths newfilename;
|
||||
if (!app::show_file_selector(
|
||||
dlgTitle, filename, exts,
|
||||
FileSelectorType::Save, newfilename,
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -46,9 +46,10 @@ void SaveMaskCommand::onExecute(Context* context)
|
||||
const ContextReader reader(context);
|
||||
const Document* document(reader.document());
|
||||
|
||||
FileSelectorFiles selFilename;
|
||||
base::paths exts = { "msk" };
|
||||
base::paths selFilename;
|
||||
if (!app::show_file_selector(
|
||||
"Save .msk File", "default.msk", "msk",
|
||||
"Save .msk File", "default.msk", exts,
|
||||
FileSelectorType::Save, selFilename))
|
||||
return;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -57,11 +57,11 @@ void SavePaletteCommand::onExecute(Context* context)
|
||||
filename = get_preset_palette_filename(m_preset, ".ase");
|
||||
}
|
||||
else {
|
||||
std::string exts = get_writable_palette_extensions();
|
||||
FileSelectorFiles selFilename;
|
||||
if (!app::show_file_selector("Save Palette", "", exts,
|
||||
FileSelectorType::Save,
|
||||
selFilename))
|
||||
base::paths exts = get_writable_palette_extensions();
|
||||
base::paths selFilename;
|
||||
if (!app::show_file_selector(
|
||||
"Save Palette", "", exts,
|
||||
FileSelectorType::Save, selFilename))
|
||||
return;
|
||||
|
||||
filename = selFilename.front();
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -48,7 +48,7 @@ using namespace doc;
|
||||
namespace {
|
||||
|
||||
static std::map<ObjectId, ObjVersionsMap> g_docVersions;
|
||||
static std::map<ObjectId, std::vector<std::string> > g_deleteFiles;
|
||||
static std::map<ObjectId, base::paths> g_deleteFiles;
|
||||
|
||||
class Writer {
|
||||
public:
|
||||
@ -302,7 +302,7 @@ private:
|
||||
std::string m_dir;
|
||||
app::Document* m_doc;
|
||||
ObjVersionsMap& m_objVersions;
|
||||
std::vector<std::string>& m_deleteFiles;
|
||||
base::paths& m_deleteFiles;
|
||||
doc::CancelIO* m_cancel;
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2017 David Capello
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -297,7 +297,7 @@ void Extension::uninstallFiles(const std::string& path)
|
||||
json11::Json json;
|
||||
read_json_file(infoFn, json);
|
||||
|
||||
std::vector<std::string> installedDirs;
|
||||
base::paths installedDirs;
|
||||
|
||||
for (const auto& value : json["installedFiles"].array_items()) {
|
||||
std::string fn = base::join_path(path, value.string_value());
|
||||
@ -545,7 +545,7 @@ ExtensionInfo Extensions::getCompressedExtensionInfo(const std::string& zipFn)
|
||||
Extension* Extensions::installCompressedExtension(const std::string& zipFn,
|
||||
const ExtensionInfo& info)
|
||||
{
|
||||
std::vector<std::string> installedFiles;
|
||||
base::paths installedFiles;
|
||||
|
||||
// Uncompress zipFn in info.dstPath
|
||||
{
|
||||
|
@ -142,9 +142,20 @@ private:
|
||||
};
|
||||
|
||||
class AseFormat : public FileFormat {
|
||||
const char* onGetName() const override { return "ase"; }
|
||||
const char* onGetExtensions() const override { return "ase,aseprite"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::ASE_ANIMATION; }
|
||||
|
||||
const char* onGetName() const override {
|
||||
return "ase";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("ase");
|
||||
exts.push_back("aseprite");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::ASE_ANIMATION;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -43,9 +43,18 @@ class BmpFormat : public FileFormat {
|
||||
uint32_t blue_mask; // Mask for blue channel.
|
||||
};
|
||||
|
||||
const char* onGetName() const override { return "bmp"; }
|
||||
const char* onGetExtensions() const override { return "bmp"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::BMP_IMAGE; }
|
||||
const char* onGetName() const override {
|
||||
return "bmp";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("bmp");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::BMP_IMAGE;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -45,34 +45,24 @@ namespace app {
|
||||
|
||||
using namespace base;
|
||||
|
||||
std::string get_readable_extensions()
|
||||
base::paths get_readable_extensions()
|
||||
{
|
||||
std::string buf;
|
||||
|
||||
base::paths paths;
|
||||
for (const FileFormat* format : *FileFormatsManager::instance()) {
|
||||
if (format->support(FILE_SUPPORT_LOAD)) {
|
||||
if (!buf.empty())
|
||||
buf.push_back(',');
|
||||
buf += format->extensions();
|
||||
}
|
||||
if (format->support(FILE_SUPPORT_LOAD))
|
||||
format->getExtensions(paths);
|
||||
}
|
||||
|
||||
return buf;
|
||||
return paths;
|
||||
}
|
||||
|
||||
std::string get_writable_extensions()
|
||||
base::paths get_writable_extensions()
|
||||
{
|
||||
std::string buf;
|
||||
|
||||
base::paths paths;
|
||||
for (const FileFormat* format : *FileFormatsManager::instance()) {
|
||||
if (format->support(FILE_SUPPORT_SAVE)) {
|
||||
if (!buf.empty())
|
||||
buf.push_back(',');
|
||||
buf += format->extensions();
|
||||
}
|
||||
if (format->support(FILE_SUPPORT_SAVE))
|
||||
format->getExtensions(paths);
|
||||
}
|
||||
|
||||
return buf;
|
||||
return paths;
|
||||
}
|
||||
|
||||
Document* load_document(Context* context, const std::string& filename)
|
||||
@ -268,7 +258,7 @@ FileOp* FileOp::createLoadDocumentOperation(Context* context, const std::string&
|
||||
|
||||
if (window.closer() == window.agree()) {
|
||||
// If the user replies "Agree", we load the selected files.
|
||||
std::vector<std::string> list;
|
||||
base::paths list;
|
||||
|
||||
auto it = window.files()->children().begin();
|
||||
auto end = window.files()->children().end();
|
||||
@ -991,7 +981,7 @@ void FileOp::setProgress(double progress)
|
||||
m_progressInterface->ackFileOpProgress(progress);
|
||||
}
|
||||
|
||||
void FileOp::getFilenameList(std::vector<std::string>& output) const
|
||||
void FileOp::getFilenameList(base::paths& output) const
|
||||
{
|
||||
if (isSequence()) {
|
||||
output = m_seq.filename_list;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/mutex.h"
|
||||
#include "base/paths.h"
|
||||
#include "base/shared_ptr.h"
|
||||
#include "doc/frame.h"
|
||||
#include "doc/image_ref.h"
|
||||
@ -17,7 +18,6 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Flags for FileOp::createLoadDocumentOperation()
|
||||
#define FILE_LOAD_SEQUENCE_NONE 0x00000001
|
||||
@ -112,7 +112,7 @@ namespace app {
|
||||
bool isOneFrame() const { return m_oneframe; }
|
||||
|
||||
const std::string& filename() const { return m_filename; }
|
||||
const std::vector<std::string>& filenames() const { return m_seq.filename_list; }
|
||||
const base::paths& filenames() const { return m_seq.filename_list; }
|
||||
Context* context() const { return m_context; }
|
||||
Document* document() const { return m_document; }
|
||||
Document* releaseDocument() {
|
||||
@ -165,7 +165,7 @@ namespace app {
|
||||
double progress() const;
|
||||
void setProgress(double progress);
|
||||
|
||||
void getFilenameList(std::vector<std::string>& output) const;
|
||||
void getFilenameList(base::paths& output) const;
|
||||
|
||||
private:
|
||||
FileOp(); // Undefined
|
||||
@ -196,7 +196,7 @@ namespace app {
|
||||
|
||||
// Data for sequences.
|
||||
struct {
|
||||
std::vector<std::string> filename_list; // All file names to load/save.
|
||||
base::paths filename_list; // All file names to load/save.
|
||||
Palette* palette; // Palette of the sequence.
|
||||
ImageRef image; // Image to be saved/loaded.
|
||||
// For the progress bar.
|
||||
@ -215,8 +215,8 @@ namespace app {
|
||||
};
|
||||
|
||||
// Available extensions for each load/save operation.
|
||||
std::string get_readable_extensions();
|
||||
std::string get_writable_extensions();
|
||||
base::paths get_readable_extensions();
|
||||
base::paths get_writable_extensions();
|
||||
|
||||
// High-level routines to load/save documents.
|
||||
app::Document* load_document(Context* context, const std::string& filename);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -28,9 +28,9 @@ const char* FileFormat::name() const
|
||||
return onGetName();
|
||||
}
|
||||
|
||||
const char* FileFormat::extensions() const
|
||||
void FileFormat::getExtensions(base::paths& exts) const
|
||||
{
|
||||
return onGetExtensions();
|
||||
onGetExtensions(exts);
|
||||
}
|
||||
|
||||
dio::FileFormat FileFormat::dioFormat() const
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -8,6 +8,7 @@
|
||||
#define APP_FILE_FILE_FORMAT_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/paths.h"
|
||||
#include "base/shared_ptr.h"
|
||||
#include "dio/file_format.h"
|
||||
|
||||
@ -44,7 +45,10 @@ namespace app {
|
||||
virtual ~FileFormat();
|
||||
|
||||
const char* name() const; // File format name
|
||||
const char* extensions() const; // Extensions (e.g. "jpeg,jpg")
|
||||
|
||||
// Fill "exts" variable with the supported extensions (e.g. "jpeg" and "jpg")
|
||||
void getExtensions(base::paths& exts) const;
|
||||
|
||||
dio::FileFormat dioFormat() const;
|
||||
|
||||
bool load(FileOp* fop);
|
||||
@ -72,7 +76,7 @@ namespace app {
|
||||
|
||||
protected:
|
||||
virtual const char* onGetName() const = 0;
|
||||
virtual const char* onGetExtensions() const = 0;
|
||||
virtual void onGetExtensions(base::paths& exts) const = 0;
|
||||
virtual dio::FileFormat onGetDioFormat() const = 0;
|
||||
virtual int onGetFlags() const = 0;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -25,9 +25,20 @@ namespace app {
|
||||
using namespace base;
|
||||
|
||||
class FliFormat : public FileFormat {
|
||||
const char* onGetName() const override { return "flc"; }
|
||||
const char* onGetExtensions() const override{ return "flc,fli"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::FLIC_ANIMATION; }
|
||||
|
||||
const char* onGetName() const override {
|
||||
return "flc";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("flc");
|
||||
exts.push_back("fli");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::FLIC_ANIMATION;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -61,9 +61,18 @@ enum class DisposalMethod {
|
||||
|
||||
class GifFormat : public FileFormat {
|
||||
|
||||
const char* onGetName() const override { return "gif"; }
|
||||
const char* onGetExtensions() const override { return "gif"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::GIF_ANIMATION; }
|
||||
const char* onGetName() const override {
|
||||
return "gif";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("gif");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::GIF_ANIMATION;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -24,9 +24,19 @@ namespace app {
|
||||
using namespace base;
|
||||
|
||||
class IcoFormat : public FileFormat {
|
||||
const char* onGetName() const override { return "ico"; }
|
||||
const char* onGetExtensions() const override { return "ico"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::ICO_IMAGES; }
|
||||
|
||||
const char* onGetName() const override {
|
||||
return "ico";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("ico");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::ICO_IMAGES;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -42,9 +42,19 @@ class JpegFormat : public FileFormat {
|
||||
float quality;
|
||||
};
|
||||
|
||||
const char* onGetName() const override { return "jpeg"; }
|
||||
const char* onGetExtensions() const override { return "jpeg,jpg"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::JPEG_IMAGE; }
|
||||
const char* onGetName() const override {
|
||||
return "jpeg";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("jpeg");
|
||||
exts.push_back("jpg");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::JPEG_IMAGE;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -32,18 +32,22 @@ namespace app {
|
||||
|
||||
using namespace doc;
|
||||
|
||||
std::string get_readable_palette_extensions()
|
||||
static const char* palExts[] = { "col", "gpl", "hex", "pal" };
|
||||
|
||||
base::paths get_readable_palette_extensions()
|
||||
{
|
||||
std::string buf = get_readable_extensions();
|
||||
buf += ",col,gpl,hex,pal";
|
||||
return buf;
|
||||
base::paths paths = get_readable_extensions();
|
||||
for (const char* s : palExts)
|
||||
paths.push_back(s);
|
||||
return paths;
|
||||
}
|
||||
|
||||
std::string get_writable_palette_extensions()
|
||||
base::paths get_writable_palette_extensions()
|
||||
{
|
||||
std::string buf = get_writable_extensions();
|
||||
buf += ",col,gpl,hex,pal";
|
||||
return buf;
|
||||
base::paths paths = get_writable_extensions();
|
||||
for (const char* s : palExts)
|
||||
paths.push_back(s);
|
||||
return paths;
|
||||
}
|
||||
|
||||
Palette* load_palette(const char* filename)
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -8,14 +8,16 @@
|
||||
#define APP_FILE_PALETTE_FILE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/paths.h"
|
||||
|
||||
namespace doc {
|
||||
class Palette;
|
||||
}
|
||||
|
||||
namespace app {
|
||||
|
||||
std::string get_readable_palette_extensions();
|
||||
std::string get_writable_palette_extensions();
|
||||
base::paths get_readable_palette_extensions();
|
||||
base::paths get_writable_palette_extensions();
|
||||
|
||||
doc::Palette* load_palette(const char *filename);
|
||||
bool save_palette(const char *filename, const doc::Palette* pal,
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -22,9 +22,20 @@ namespace app {
|
||||
using namespace base;
|
||||
|
||||
class PcxFormat : public FileFormat {
|
||||
const char* onGetName() const override { return "pcx"; }
|
||||
const char* onGetExtensions() const override { return "pcx,pcc"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::PCX_IMAGE; }
|
||||
|
||||
const char* onGetName() const override {
|
||||
return "pcx";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("pcx");
|
||||
exts.push_back("pcc");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::PCX_IMAGE;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -26,9 +26,18 @@ namespace app {
|
||||
using namespace base;
|
||||
|
||||
class PngFormat : public FileFormat {
|
||||
const char* onGetName() const override { return "png"; }
|
||||
const char* onGetExtensions() const override { return "png"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::PNG_IMAGE; }
|
||||
const char* onGetName() const override {
|
||||
return "png";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("png");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::PNG_IMAGE;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -23,9 +23,18 @@ namespace app {
|
||||
using namespace base;
|
||||
|
||||
class TgaFormat : public FileFormat {
|
||||
const char* onGetName() const override { return "tga"; }
|
||||
const char* onGetExtensions() const override { return "tga"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::TARGA_IMAGE; }
|
||||
const char* onGetName() const override {
|
||||
return "tga";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("tga");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::TARGA_IMAGE;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2015-2017 David Capello
|
||||
// Copyright (C) 2015-2018 David Capello
|
||||
// Copyright (C) 2015 Gabriel Rauter
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
@ -39,9 +39,18 @@ using namespace base;
|
||||
|
||||
class WebPFormat : public FileFormat {
|
||||
|
||||
const char* onGetName() const override { return "webp"; }
|
||||
const char* onGetExtensions() const override { return "webp"; }
|
||||
dio::FileFormat onGetDioFormat() const override { return dio::FileFormat::WEBP_ANIMATION; }
|
||||
const char* onGetName() const override {
|
||||
return "webp";
|
||||
}
|
||||
|
||||
void onGetExtensions(base::paths& exts) const override {
|
||||
exts.push_back("webp");
|
||||
}
|
||||
|
||||
dio::FileFormat onGetDioFormat() const override {
|
||||
return dio::FileFormat::WEBP_ANIMATION;
|
||||
}
|
||||
|
||||
int onGetFlags() const override {
|
||||
return
|
||||
FILE_SUPPORT_LOAD |
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -13,7 +13,6 @@
|
||||
#include "app/app.h"
|
||||
#include "app/pref/preferences.h"
|
||||
#include "app/ui/file_selector.h"
|
||||
#include "base/split_string.h"
|
||||
#include "she/display.h"
|
||||
#include "she/native_dialogs.h"
|
||||
#include "she/system.h"
|
||||
@ -23,9 +22,9 @@ namespace app {
|
||||
bool show_file_selector(
|
||||
const std::string& title,
|
||||
const std::string& initialPath,
|
||||
const std::string& showExtensions,
|
||||
const base::paths& extensions,
|
||||
FileSelectorType type,
|
||||
FileSelectorFiles& output,
|
||||
base::paths& output,
|
||||
FileSelectorDelegate* delegate)
|
||||
{
|
||||
if (Preferences::instance().experimental.useNativeFileDialog() &&
|
||||
@ -51,10 +50,8 @@ bool show_file_selector(
|
||||
}
|
||||
dlg->setType(nativeType);
|
||||
|
||||
std::vector<std::string> tokens;
|
||||
base::split_string(showExtensions, tokens, ",");
|
||||
for (const auto& tok : tokens)
|
||||
dlg->addFilter(tok, tok + " files (*." + tok + ")");
|
||||
for (const auto& ext : extensions)
|
||||
dlg->addFilter(ext, ext + " files (*." + ext + ")");
|
||||
|
||||
bool res = dlg->show(she::instance()->defaultDisplay());
|
||||
if (res) {
|
||||
@ -69,7 +66,7 @@ bool show_file_selector(
|
||||
}
|
||||
|
||||
FileSelector fileSelector(type, delegate);
|
||||
return fileSelector.show(title, initialPath, showExtensions, output);
|
||||
return fileSelector.show(title, initialPath, extensions, output);
|
||||
}
|
||||
|
||||
} // namespace app
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -8,10 +8,10 @@
|
||||
#define APP_FILE_SELECTOR_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/paths.h"
|
||||
#include "doc/pixel_ratio.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ui {
|
||||
class ComboBox;
|
||||
@ -21,8 +21,6 @@ namespace app {
|
||||
|
||||
enum class FileSelectorType { Open, OpenMultiple, Save };
|
||||
|
||||
typedef std::vector<std::string> FileSelectorFiles;
|
||||
|
||||
class FileSelectorDelegate {
|
||||
public:
|
||||
virtual ~FileSelectorDelegate() { }
|
||||
@ -47,9 +45,9 @@ namespace app {
|
||||
bool show_file_selector(
|
||||
const std::string& title,
|
||||
const std::string& initialPath,
|
||||
const std::string& showExtensions,
|
||||
const base::paths& extensions,
|
||||
FileSelectorType type,
|
||||
FileSelectorFiles& output,
|
||||
base::paths& output,
|
||||
FileSelectorDelegate* delegate = nullptr);
|
||||
|
||||
} // namespace app
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -92,7 +92,7 @@ public:
|
||||
const FileItemList& children();
|
||||
void createDirectory(const std::string& dirname);
|
||||
|
||||
bool hasExtension(const std::string& csv_extensions);
|
||||
bool hasExtension(const base::paths& extensions);
|
||||
|
||||
she::Surface* getThumbnail();
|
||||
void setThumbnail(she::Surface* thumbnail);
|
||||
@ -511,11 +511,11 @@ void FileItem::createDirectory(const std::string& dirname)
|
||||
m_version = 0;
|
||||
}
|
||||
|
||||
bool FileItem::hasExtension(const std::string& csv_extensions)
|
||||
bool FileItem::hasExtension(const base::paths& extensions)
|
||||
{
|
||||
ASSERT(m_filename != NOTINITIALIZED);
|
||||
|
||||
return base::has_file_extension(m_filename, csv_extensions);
|
||||
return base::has_file_extension(m_filename, extensions);
|
||||
}
|
||||
|
||||
she::Surface* FileItem::getThumbnail()
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/mutex.h"
|
||||
#include "base/paths.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -77,7 +78,7 @@ namespace app {
|
||||
virtual const FileItemList& children() = 0;
|
||||
virtual void createDirectory(const std::string& dirname) = 0;
|
||||
|
||||
virtual bool hasExtension(const std::string& csv_extensions) = 0;
|
||||
virtual bool hasExtension(const base::paths& extensions) = 0;
|
||||
|
||||
virtual she::Surface* getThumbnail() = 0;
|
||||
virtual void setThumbnail(she::Surface* thumbnail) = 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2017 David Capello
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -21,7 +21,7 @@ std::string find_font(const std::string& firstDir,
|
||||
if (base::is_file(fn))
|
||||
return fn;
|
||||
|
||||
std::vector<std::string> fontDirs;
|
||||
base::paths fontDirs;
|
||||
get_font_dirs(fontDirs);
|
||||
|
||||
for (const std::string& dir : fontDirs) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2017 David Capello
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -8,12 +8,13 @@
|
||||
#define APP_FONT_PATH_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/paths.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace app {
|
||||
|
||||
void get_font_dirs(std::vector<std::string>& fontDirs);
|
||||
void get_font_dirs(base::paths& fontDirs);
|
||||
std::string find_font(const std::string& firstDir,
|
||||
const std::string& filename);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2017 David Capello
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
namespace app {
|
||||
|
||||
void get_font_dirs(std::vector<std::string>& fontDirs)
|
||||
void get_font_dirs(base::paths& fontDirs)
|
||||
{
|
||||
// TODO use a Cocoa API to get the list of paths
|
||||
fontDirs.push_back("~/Library/Fonts");
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2017 David Capello
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -16,9 +16,9 @@
|
||||
|
||||
namespace app {
|
||||
|
||||
std::vector<std::string> g_cache;
|
||||
base::paths g_cache;
|
||||
|
||||
void get_font_dirs(std::vector<std::string>& fontDirs)
|
||||
void get_font_dirs(base::paths& fontDirs)
|
||||
{
|
||||
if (!g_cache.empty()) {
|
||||
fontDirs = g_cache;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2017 David Capello
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
namespace app {
|
||||
|
||||
void get_font_dirs(std::vector<std::string>& fontDirs)
|
||||
void get_font_dirs(base::paths& fontDirs)
|
||||
{
|
||||
std::vector<wchar_t> buf(MAX_PATH+1);
|
||||
HRESULT hr = SHGetFolderPath(
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -329,7 +329,7 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
||||
|
||||
case kDropFilesMessage:
|
||||
{
|
||||
DropFilesMessage::Files files = static_cast<DropFilesMessage*>(msg)->files();
|
||||
base::paths files = static_cast<DropFilesMessage*>(msg)->files();
|
||||
UIContext* ctx = UIContext::instance();
|
||||
OpenFileCommand cmd;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -9,9 +9,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/disable_copying.h"
|
||||
#include "base/paths.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace app {
|
||||
|
||||
@ -58,7 +58,7 @@ namespace app {
|
||||
|
||||
private:
|
||||
bool m_log;
|
||||
std::vector<std::string> m_paths;
|
||||
base::paths m_paths;
|
||||
int m_current;
|
||||
std::string m_default;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -63,7 +63,7 @@ FileList::~FileList()
|
||||
ThumbnailGenerator::instance()->stopAllWorkers();
|
||||
}
|
||||
|
||||
void FileList::setExtensions(const char* extensions)
|
||||
void FileList::setExtensions(const base::paths& extensions)
|
||||
{
|
||||
m_exts = extensions;
|
||||
|
||||
@ -591,7 +591,7 @@ void FileList::regenerateList()
|
||||
if (fileitem->isHidden())
|
||||
it = m_list.erase(it);
|
||||
else if (!fileitem->isFolder() &&
|
||||
!fileitem->hasExtension(m_exts.c_str())) {
|
||||
!fileitem->hasExtension(m_exts)) {
|
||||
it = m_list.erase(it);
|
||||
}
|
||||
else
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/file_system.h"
|
||||
#include "base/paths.h"
|
||||
#include "base/time.h"
|
||||
#include "obs/signal.h"
|
||||
#include "ui/timer.h"
|
||||
@ -28,8 +29,8 @@ namespace app {
|
||||
FileList();
|
||||
virtual ~FileList();
|
||||
|
||||
const std::string& extensions() const { return m_exts; }
|
||||
void setExtensions(const char* extensions);
|
||||
const base::paths& extensions() const { return m_exts; }
|
||||
void setExtensions(const base::paths& extensions);
|
||||
|
||||
IFileItem* currentFolder() const { return m_currentFolder; }
|
||||
void setCurrentFolder(IFileItem* folder);
|
||||
@ -76,7 +77,7 @@ namespace app {
|
||||
int m_req_w, m_req_h;
|
||||
IFileItem* m_selected;
|
||||
std::vector<bool> m_selectedItems;
|
||||
std::string m_exts;
|
||||
base::paths m_exts;
|
||||
|
||||
// Incremental-search
|
||||
std::string m_isearch;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -23,10 +23,9 @@
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
#include "app/widget_loader.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/bind.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/fs.h"
|
||||
#include "base/split_string.h"
|
||||
#include "base/paths.h"
|
||||
#include "base/string.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "fmt/format.h"
|
||||
@ -84,11 +83,23 @@ static FileItemList* navigation_history = NULL; // Set of FileItems navigated
|
||||
static NullableIterator<FileItemList> navigation_position; // Current position in the navigation history
|
||||
|
||||
// This map acts like a temporal customization by the user when he/she
|
||||
// wants to open files. The key (first) is the real "showExtensions"
|
||||
// parameter given to the FileSelector::show() function. The value
|
||||
// (second) is the selected extension by the user. It's used only in
|
||||
// FileSelector::Open type of dialogs.
|
||||
static std::map<std::string, std::string> preferred_open_extensions;
|
||||
// wants to open files. The key (first) is the real "allExtensions"
|
||||
// parameter given to the FileSelector::show() function where each
|
||||
// extension is concatenated with each other in one string separated
|
||||
// by ','. The value (second) is the selected/preferred extension by
|
||||
// the user. It's used only in FileSelector::Open type of dialogs.
|
||||
static std::map<std::string, base::paths> preferred_open_extensions;
|
||||
|
||||
static std::string merge_paths(const base::paths& paths)
|
||||
{
|
||||
std::string k;
|
||||
for (const auto& p : paths) {
|
||||
if (!k.empty())
|
||||
k.push_back(',');
|
||||
k += p;
|
||||
}
|
||||
return k;
|
||||
}
|
||||
|
||||
// Slot for App::Exit signal
|
||||
static void on_exit_delete_navigation_history()
|
||||
@ -170,6 +181,19 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class FileSelector::CustomFileExtensionItem : public ListItem {
|
||||
public:
|
||||
CustomFileExtensionItem(const std::string& text,
|
||||
const base::paths& exts)
|
||||
: ListItem(text)
|
||||
, m_exts(exts)
|
||||
{
|
||||
}
|
||||
const base::paths& extensions() const { return m_exts; }
|
||||
private:
|
||||
base::paths m_exts;
|
||||
};
|
||||
|
||||
// We have this dummy/hidden widget only to handle special navigation
|
||||
// with arrow keys. In the past this code was in the same FileSelector
|
||||
// itself, but there were problems adding that window as a message
|
||||
@ -393,8 +417,8 @@ void FileSelector::goInsideFolder()
|
||||
bool FileSelector::show(
|
||||
const std::string& title,
|
||||
const std::string& initialPath,
|
||||
const std::string& showExtensions,
|
||||
FileSelectorFiles& output)
|
||||
const base::paths& allExtensions,
|
||||
base::paths& output)
|
||||
{
|
||||
FileSystemModule* fs = FileSystemModule::instance();
|
||||
LockFS lock(fs);
|
||||
@ -437,22 +461,25 @@ bool FileSelector::show(
|
||||
|
||||
// Change the file formats/extensions to be shown
|
||||
std::string initialExtension = base::get_file_extension(initialPath);
|
||||
std::string exts = showExtensions;
|
||||
base::paths exts;
|
||||
if (m_type == FileSelectorType::Open ||
|
||||
m_type == FileSelectorType::OpenMultiple) {
|
||||
auto it = preferred_open_extensions.find(exts);
|
||||
std::string k = merge_paths(allExtensions);
|
||||
auto it = preferred_open_extensions.find(k);
|
||||
if (it == preferred_open_extensions.end())
|
||||
exts = showExtensions;
|
||||
exts = allExtensions;
|
||||
else
|
||||
exts = preferred_open_extensions[exts];
|
||||
exts = preferred_open_extensions[k];
|
||||
}
|
||||
else {
|
||||
ASSERT(m_type == FileSelectorType::Save);
|
||||
if (!initialExtension.empty())
|
||||
exts = initialExtension;
|
||||
exts = base::paths{ initialExtension };
|
||||
else
|
||||
exts = allExtensions;
|
||||
}
|
||||
m_fileList->setMultipleSelection(m_type == FileSelectorType::OpenMultiple);
|
||||
m_fileList->setExtensions(exts.c_str());
|
||||
m_fileList->setExtensions(exts);
|
||||
if (start_folder)
|
||||
m_fileList->setCurrentFolder(start_folder);
|
||||
|
||||
@ -471,34 +498,36 @@ bool FileSelector::show(
|
||||
m_defExtension = initialExtension;
|
||||
|
||||
// File type for all formats
|
||||
{
|
||||
ListItem* item = new ListItem("All formats");
|
||||
item->setValue(showExtensions);
|
||||
fileType()->addItem(item);
|
||||
}
|
||||
fileType()->addItem(
|
||||
new CustomFileExtensionItem("All formats", allExtensions));
|
||||
|
||||
// One file type for each supported image format
|
||||
std::vector<std::string> tokens;
|
||||
base::split_string(showExtensions, tokens, ",");
|
||||
for (const auto& tok : tokens) {
|
||||
for (const auto& e : allExtensions) {
|
||||
// If the default extension is empty, use the first filter
|
||||
if (m_defExtension.empty())
|
||||
m_defExtension = tok;
|
||||
m_defExtension = e;
|
||||
|
||||
ListItem* item = new ListItem(tok + " files");
|
||||
item->setValue(tok);
|
||||
fileType()->addItem(item);
|
||||
fileType()->addItem(
|
||||
new CustomFileExtensionItem(e + " files",
|
||||
base::paths{ e }));
|
||||
}
|
||||
// All files
|
||||
{
|
||||
ListItem* item = new ListItem("All files");
|
||||
item->setValue(""); // Empty extensions means "*.*"
|
||||
fileType()->addItem(item);
|
||||
}
|
||||
fileType()->addItem(
|
||||
new CustomFileExtensionItem("All files",
|
||||
base::paths())); // Empty extensions means "*.*"
|
||||
|
||||
// file name entry field
|
||||
m_fileName->setValue(base::get_file_name(initialPath).c_str());
|
||||
m_fileName->getEntryWidget()->selectText(0, -1);
|
||||
fileType()->setValue(exts);
|
||||
|
||||
for (Widget* wItem : *fileType()) {
|
||||
auto item = dynamic_cast<CustomFileExtensionItem*>(wItem);
|
||||
ASSERT(item);
|
||||
if (item && item->extensions() == exts) {
|
||||
fileType()->setSelectedItem(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// setup the title of the window
|
||||
setText(title.c_str());
|
||||
@ -899,17 +928,22 @@ void FileSelector::onLocationCloseListBox()
|
||||
// change the file-extension in the 'filename' entry widget
|
||||
void FileSelector::onFileTypeChange()
|
||||
{
|
||||
std::string exts = fileType()->getValue();
|
||||
base::paths exts;
|
||||
auto* selExtItem = dynamic_cast<CustomFileExtensionItem*>(fileType()->getSelectedItem());
|
||||
if (selExtItem)
|
||||
exts = selExtItem->extensions();
|
||||
|
||||
if (exts != m_fileList->extensions()) {
|
||||
m_navigationLocked = true;
|
||||
m_fileList->setExtensions(exts.c_str());
|
||||
m_fileList->setExtensions(exts);
|
||||
m_navigationLocked = false;
|
||||
|
||||
if (m_type == FileSelectorType::Open ||
|
||||
m_type == FileSelectorType::OpenMultiple) {
|
||||
std::string origShowExtensions =
|
||||
dynamic_cast<ListItem*>(fileType()->getItem(0))->getValue();
|
||||
preferred_open_extensions[origShowExtensions] = fileType()->getValue();
|
||||
const base::paths& allExtensions =
|
||||
dynamic_cast<CustomFileExtensionItem*>(fileType()->getItem(0))->extensions();
|
||||
std::string k = merge_paths(allExtensions);
|
||||
preferred_open_extensions[k] = exts;
|
||||
}
|
||||
}
|
||||
|
||||
@ -969,10 +1003,11 @@ void FileSelector::onExtraOptions()
|
||||
|
||||
std::string FileSelector::getSelectedExtension() const
|
||||
{
|
||||
std::string ext = fileType()->getValue();
|
||||
if (ext.empty() || ext.find(',') != std::string::npos)
|
||||
ext = m_defExtension;
|
||||
return ext;
|
||||
auto selExtItem = dynamic_cast<CustomFileExtensionItem*>(fileType()->getSelectedItem());
|
||||
if (selExtItem && selExtItem->extensions().size() == 1)
|
||||
return selExtItem->extensions().front();
|
||||
else
|
||||
return m_defExtension;
|
||||
}
|
||||
|
||||
void FileSelector::updateExtraLabel()
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -40,8 +40,8 @@ namespace app {
|
||||
// Shows the dialog to select a file in the program.
|
||||
bool show(const std::string& title,
|
||||
const std::string& initialPath,
|
||||
const std::string& showExtensions,
|
||||
FileSelectorFiles& output);
|
||||
const base::paths& extensions,
|
||||
base::paths& output);
|
||||
|
||||
private:
|
||||
void updateLocation();
|
||||
@ -64,6 +64,7 @@ namespace app {
|
||||
class CustomFileNameItem;
|
||||
class CustomFolderNameItem;
|
||||
class CustomFileNameEntry;
|
||||
class CustomFileExtensionItem;
|
||||
class ExtrasWindow;
|
||||
|
||||
FileSelectorType m_type;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2017 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This program is distributed under the terms of
|
||||
// the End-User License Agreement for Aseprite.
|
||||
@ -147,12 +147,12 @@ FontPopup::FontPopup()
|
||||
|
||||
m_popup->view()->attachToView(&m_listBox);
|
||||
|
||||
std::vector<std::string> fontDirs;
|
||||
base::paths fontDirs;
|
||||
get_font_dirs(fontDirs);
|
||||
|
||||
// Create a list of fullpaths to every font found in all font
|
||||
// directories (fontDirs)
|
||||
std::vector<std::string> files;
|
||||
base::paths files;
|
||||
for (const auto& fontDir : fontDirs) {
|
||||
for (const auto& file : base::list_files(fontDir)) {
|
||||
std::string fullpath = base::join_path(fontDir, file);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2012-2017 David Capello
|
||||
// Copyright (C) 2012-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "base/concurrent_queue.h"
|
||||
#include "base/exception.h"
|
||||
#include "base/paths.h"
|
||||
#include "base/string.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "she/alleg4/alleg_display.h"
|
||||
@ -101,7 +102,7 @@ static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
|
||||
|
||||
case WM_DROPFILES: {
|
||||
HDROP hdrop = (HDROP)(wparam);
|
||||
Event::Files files;
|
||||
base::paths files;
|
||||
|
||||
int count = DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
|
||||
for (int index=0; index<count; ++index) {
|
||||
|
@ -8,14 +8,12 @@
|
||||
#define SHE_EVENT_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/paths.h"
|
||||
#include "gfx/point.h"
|
||||
#include "gfx/size.h"
|
||||
#include "she/keys.h"
|
||||
#include "she/pointer_type.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#pragma push_macro("None")
|
||||
#undef None // Undefine the X11 None macro
|
||||
|
||||
@ -51,8 +49,6 @@ namespace she {
|
||||
X2Button,
|
||||
};
|
||||
|
||||
typedef std::vector<std::string> Files;
|
||||
|
||||
Event() : m_type(None),
|
||||
m_display(nullptr),
|
||||
m_scancode(kKeyNil),
|
||||
@ -69,7 +65,7 @@ namespace she {
|
||||
|
||||
Type type() const { return m_type; }
|
||||
Display* display() const { return m_display; }
|
||||
const Files& files() const { return m_files; }
|
||||
const base::paths& files() const { return m_files; }
|
||||
// TODO Rename this to virtualKey(), which is the real
|
||||
// meaning. Then we need another kind of "scan code" with the
|
||||
// position in the keyboard, which might be useful to identify
|
||||
@ -95,7 +91,7 @@ namespace she {
|
||||
|
||||
void setType(Type type) { m_type = type; }
|
||||
void setDisplay(Display* display) { m_display = display; }
|
||||
void setFiles(const Files& files) { m_files = files; }
|
||||
void setFiles(const base::paths& files) { m_files = files; }
|
||||
|
||||
void setScancode(KeyScancode scancode) { m_scancode = scancode; }
|
||||
void setModifiers(KeyModifiers modifiers) { m_modifiers = modifiers; }
|
||||
@ -113,7 +109,7 @@ namespace she {
|
||||
private:
|
||||
Type m_type;
|
||||
Display* m_display;
|
||||
Files m_files;
|
||||
base::paths m_files;
|
||||
KeyScancode m_scancode;
|
||||
KeyModifiers m_modifiers;
|
||||
int m_unicodeChar;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library - GTK dialogs
|
||||
// Copyright (C) 2017 David Capello
|
||||
// Copyright (C) 2017-2018 David Capello
|
||||
// Copyright (C) 2016 Gabriel Rauter
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -32,7 +32,7 @@ public:
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
void getMultipleFileNames(std::vector<std::string>& output) override {
|
||||
void getMultipleFileNames(base::paths& output) override {
|
||||
output = m_filenames;
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ private:
|
||||
|
||||
std::string m_filename;
|
||||
std::string m_initialDir;
|
||||
std::vector<std::string> m_filenames;
|
||||
base::paths m_filenames;
|
||||
GtkFileChooser* m_chooser;
|
||||
GtkWidget* m_preview;
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2015-2017 David Capello
|
||||
// Copyright (C) 2015-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -8,8 +8,9 @@
|
||||
#define SHE_NATIVE_DIALOGS_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/paths.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace she {
|
||||
class Display;
|
||||
@ -30,7 +31,7 @@ namespace she {
|
||||
virtual void setDefaultExtension(const std::string& extension) = 0;
|
||||
virtual void addFilter(const std::string& extension, const std::string& description) = 0;
|
||||
virtual std::string fileName() = 0;
|
||||
virtual void getMultipleFileNames(std::vector<std::string>& output) = 0;
|
||||
virtual void getMultipleFileNames(base::paths& output) = 0;
|
||||
virtual void setFileName(const std::string& filename) = 0;
|
||||
virtual bool show(Display* parent) = 0;
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2016 David Capello
|
||||
// Copyright (C) 2016-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
inline void generate_drop_files_from_nsarray(NSArray* filenames)
|
||||
{
|
||||
std::vector<std::string> files;
|
||||
base::paths files;
|
||||
for (int i=0; i<[filenames count]; ++i) {
|
||||
NSString* fn = [filenames objectAtIndex: i];
|
||||
files.push_back(base::normalize_path([fn UTF8String]));
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2012-2017 David Capello
|
||||
// Copyright (C) 2012-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -88,7 +88,7 @@ public:
|
||||
return m_filename;
|
||||
}
|
||||
|
||||
void getMultipleFileNames(std::vector<std::string>& output) override {
|
||||
void getMultipleFileNames(base::paths& output) override {
|
||||
output = m_filenames;
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ public:
|
||||
private:
|
||||
|
||||
std::string m_filename;
|
||||
std::vector<std::string> m_filenames;
|
||||
base::paths m_filenames;
|
||||
};
|
||||
|
||||
NativeDialogsOSX::NativeDialogsOSX()
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2015-2017 David Capello
|
||||
// Copyright (C) 2015-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -39,7 +39,7 @@ public:
|
||||
return base::to_utf8(&m_filename[0]);
|
||||
}
|
||||
|
||||
void getMultipleFileNames(std::vector<std::string>& output) override {
|
||||
void getMultipleFileNames(base::paths& output) override {
|
||||
output = m_filenames;
|
||||
}
|
||||
|
||||
@ -337,7 +337,7 @@ private:
|
||||
|
||||
int m_defFilter;
|
||||
std::vector<WCHAR> m_filename;
|
||||
std::vector<std::string> m_filenames;
|
||||
base::paths m_filenames;
|
||||
std::wstring m_initialDir;
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2012-2017 David Capello
|
||||
// Copyright (C) 2012-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -1025,7 +1025,7 @@ LRESULT WinWindow::wndProc(UINT msg, WPARAM wparam, LPARAM lparam)
|
||||
|
||||
case WM_DROPFILES: {
|
||||
HDROP hdrop = (HDROP)(wparam);
|
||||
Event::Files files;
|
||||
base::paths files;
|
||||
|
||||
int count = DragQueryFile(hdrop, 0xFFFFFFFF, NULL, 0);
|
||||
for (int index=0; index<count; ++index) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// SHE library
|
||||
// Copyright (C) 2016 David Capello
|
||||
// Copyright (C) 2016-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include "she/win/window_dde.h"
|
||||
|
||||
#include "base/paths.h"
|
||||
#include "base/string.h"
|
||||
#include "she/event.h"
|
||||
#include "she/event_queue.h"
|
||||
@ -57,7 +58,7 @@ bool parse_dde_command(const std::string& cmd)
|
||||
}
|
||||
|
||||
std::string cmdName = cmd.substr(i, j-i);
|
||||
std::vector<std::string> cmdParams;
|
||||
base::paths cmdParams;
|
||||
|
||||
for (i=j+1; i<cmd.size(); ) {
|
||||
if (cmd[i] == ')') {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
@ -8,6 +8,7 @@
|
||||
#define UI_MESSAGE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/paths.h"
|
||||
#include "gfx/point.h"
|
||||
#include "gfx/rect.h"
|
||||
#include "ui/base.h"
|
||||
@ -17,9 +18,6 @@
|
||||
#include "ui/pointer_type.h"
|
||||
#include "ui/widgets_list.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Timer;
|
||||
@ -177,16 +175,15 @@ namespace ui {
|
||||
|
||||
class DropFilesMessage : public Message {
|
||||
public:
|
||||
typedef std::vector<std::string> Files;
|
||||
|
||||
DropFilesMessage(const Files& files)
|
||||
: Message(kDropFilesMessage), m_files(files) {
|
||||
DropFilesMessage(const base::paths& files)
|
||||
: Message(kDropFilesMessage)
|
||||
, m_files(files) {
|
||||
}
|
||||
|
||||
const Files& files() const { return m_files; }
|
||||
const base::paths& files() const { return m_files; }
|
||||
|
||||
private:
|
||||
Files m_files;
|
||||
base::paths m_files;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
Loading…
x
Reference in New Issue
Block a user