mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 12:39:57 +00:00
Added jstring. The file-selector now uses jstrings.
This commit is contained in:
parent
17dee030f5
commit
9bf40439d4
@ -1,5 +1,10 @@
|
|||||||
2008-10-11 David A. Capello <davidcapello@gmail.com>
|
2008-10-11 David A. Capello <davidcapello@gmail.com>
|
||||||
|
|
||||||
|
* src/dialogs/filesel.cpp (ase_file_selector): Now it uses
|
||||||
|
"jstring" instead of "char*".
|
||||||
|
|
||||||
|
* src/jinete/jstring.h (jstring): Added.
|
||||||
|
|
||||||
* src/raster/undoable.cpp (Undoable::set_constant_frame_rate): Added.
|
* src/raster/undoable.cpp (Undoable::set_constant_frame_rate): Added.
|
||||||
(Undoable::set_frame_length): Renamed to set_frame_duration.
|
(Undoable::set_frame_length): Renamed to set_frame_duration.
|
||||||
|
|
||||||
|
2
config.h
2
config.h
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
/* general information */
|
/* general information */
|
||||||
#define PACKAGE "ASE"
|
#define PACKAGE "ASE"
|
||||||
#define VERSION "0.6b2"
|
#define VERSION "0.6"
|
||||||
#define WEBSITE "http://www.aseprite.org/"
|
#define WEBSITE "http://www.aseprite.org/"
|
||||||
#define COPYRIGHT "Copyright (C) 2001-2008 David A. Capello"
|
#define COPYRIGHT "Copyright (C) 2001-2008 David A. Capello"
|
||||||
|
|
||||||
|
@ -147,6 +147,7 @@ COMMON_SOURCES = \
|
|||||||
src/jinete/jsep.cpp \
|
src/jinete/jsep.cpp \
|
||||||
src/jinete/jslider.cpp \
|
src/jinete/jslider.cpp \
|
||||||
src/jinete/jstream.cpp \
|
src/jinete/jstream.cpp \
|
||||||
|
src/jinete/jstring.cpp \
|
||||||
src/jinete/jsystem.cpp \
|
src/jinete/jsystem.cpp \
|
||||||
src/jinete/jtextbox.cpp \
|
src/jinete/jtextbox.cpp \
|
||||||
src/jinete/jtheme.cpp \
|
src/jinete/jtheme.cpp \
|
||||||
|
@ -38,15 +38,13 @@ static void cmd_load_mask_execute(const char *argument)
|
|||||||
{
|
{
|
||||||
/* get current sprite */
|
/* get current sprite */
|
||||||
Sprite *sprite = current_sprite;
|
Sprite *sprite = current_sprite;
|
||||||
char *filename = ase_file_selector(_("Load .msk File"), "", "msk");
|
jstring filename = ase_file_selector(_("Load .msk File"), "", "msk");
|
||||||
if (filename) {
|
if (!filename.empty()) {
|
||||||
Mask *mask = load_msk_file(filename);
|
Mask *mask = load_msk_file(filename.c_str());
|
||||||
if (!mask) {
|
if (!mask) {
|
||||||
jalert("%s<<%s<<%s||%s",
|
jalert("%s<<%s<<%s||%s",
|
||||||
_("Error"), _("Error loading .msk file"),
|
_("Error"), _("Error loading .msk file"),
|
||||||
filename, _("&Close"));
|
filename.c_str(), _("&Close"));
|
||||||
|
|
||||||
jfree(filename);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +59,6 @@ static void cmd_load_mask_execute(const char *argument)
|
|||||||
|
|
||||||
sprite_generate_mask_boundaries(sprite);
|
sprite_generate_mask_boundaries(sprite);
|
||||||
update_screen_for_sprite(sprite);
|
update_screen_for_sprite(sprite);
|
||||||
jfree(filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ static void monitor_free(void *_data)
|
|||||||
*/
|
*/
|
||||||
static void cmd_open_file_execute(const char *argument)
|
static void cmd_open_file_execute(const char *argument)
|
||||||
{
|
{
|
||||||
char *filename;
|
jstring filename;
|
||||||
|
|
||||||
/* interactive */
|
/* interactive */
|
||||||
if (!argument) {
|
if (!argument) {
|
||||||
@ -152,11 +152,11 @@ static void cmd_open_file_execute(const char *argument)
|
|||||||
}
|
}
|
||||||
/* load the file specified in the argument */
|
/* load the file specified in the argument */
|
||||||
else {
|
else {
|
||||||
filename = (char *)argument;
|
filename = argument;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename) {
|
if (!filename.empty()) {
|
||||||
FileOp *fop = fop_to_load_sprite(filename, FILE_LOAD_SEQUENCE_ASK);
|
FileOp *fop = fop_to_load_sprite(filename.c_str(), FILE_LOAD_SEQUENCE_ASK);
|
||||||
|
|
||||||
if (fop) {
|
if (fop) {
|
||||||
if (fop->error) {
|
if (fop->error) {
|
||||||
@ -173,7 +173,7 @@ static void cmd_open_file_execute(const char *argument)
|
|||||||
data->thread = thread;
|
data->thread = thread;
|
||||||
data->alert_window = jalert_new(PACKAGE
|
data->alert_window = jalert_new(PACKAGE
|
||||||
"<<Loading file:<<%s||&Cancel",
|
"<<Loading file:<<%s||&Cancel",
|
||||||
get_filename(filename));
|
get_filename(filename.c_str()));
|
||||||
|
|
||||||
/* add a monitor to check the loading (FileOp) progress */
|
/* add a monitor to check the loading (FileOp) progress */
|
||||||
data->monitor = add_gui_monitor(monitor_openfile_bg,
|
data->monitor = add_gui_monitor(monitor_openfile_bg,
|
||||||
@ -224,9 +224,6 @@ static void cmd_open_file_execute(const char *argument)
|
|||||||
else {
|
else {
|
||||||
/* do nothing (the user cancelled or something like that) */
|
/* do nothing (the user cancelled or something like that) */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename != argument)
|
|
||||||
jfree(filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,11 +284,9 @@ static void select_all_command(JWidget widget)
|
|||||||
static void load_command(JWidget widget)
|
static void load_command(JWidget widget)
|
||||||
{
|
{
|
||||||
Palette *palette;
|
Palette *palette;
|
||||||
char *filename;
|
jstring filename = ase_file_selector(_("Load Palette"), "", "pcx,bmp,tga,lbm,col");
|
||||||
|
if (!filename.empty()) {
|
||||||
filename = ase_file_selector(_("Load Palette"), "", "pcx,bmp,tga,lbm,col");
|
palette = palette_load(filename.c_str());
|
||||||
if (filename) {
|
|
||||||
palette = palette_load(filename);
|
|
||||||
if (!palette) {
|
if (!palette) {
|
||||||
jalert(_("Error<<Loading palette file||&Close"));
|
jalert(_("Error<<Loading palette file||&Close"));
|
||||||
}
|
}
|
||||||
@ -296,39 +294,33 @@ static void load_command(JWidget widget)
|
|||||||
set_new_palette(palette);
|
set_new_palette(palette);
|
||||||
jfree(palette);
|
jfree(palette);
|
||||||
}
|
}
|
||||||
jfree(filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void save_command(JWidget widget)
|
static void save_command(JWidget widget)
|
||||||
{
|
{
|
||||||
char *filename;
|
jstring filename;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
filename = ase_file_selector(_("Save Palette"), "", "pcx,bmp,tga,col");
|
filename = ase_file_selector(_("Save Palette"), "", "pcx,bmp,tga,col");
|
||||||
if (filename) {
|
if (!filename.empty()) {
|
||||||
if (exists(filename)) {
|
if (exists(filename.c_str())) {
|
||||||
ret = jalert("%s<<%s<<%s||%s",
|
ret = jalert("%s<<%s<<%s||%s",
|
||||||
_("Warning"),
|
_("Warning"),
|
||||||
_("File exists, overwrite it?"),
|
_("File exists, overwrite it?"),
|
||||||
get_filename(filename),
|
get_filename(filename.c_str()),
|
||||||
_("&Yes||&No||&Cancel"));
|
_("&Yes||&No||&Cancel"));
|
||||||
|
|
||||||
if (ret == 2) {
|
if (ret == 2)
|
||||||
jfree(filename);
|
|
||||||
goto again;
|
goto again;
|
||||||
}
|
else if (ret != 1)
|
||||||
else if (ret != 1) {
|
|
||||||
jfree(filename);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (palette_save(paledit_get_palette(palette_editor), filename))
|
if (palette_save(paledit_get_palette(palette_editor),
|
||||||
|
filename.c_str()))
|
||||||
jalert(_("Error<<Saving palette file||&Close"));
|
jalert(_("Error<<Saving palette file||&Close"));
|
||||||
|
|
||||||
jfree(filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,28 +187,28 @@ static bool cmd_save_file_as_enabled(const char *argument)
|
|||||||
static void cmd_save_file_as_execute(const char *argument)
|
static void cmd_save_file_as_execute(const char *argument)
|
||||||
{
|
{
|
||||||
Sprite *sprite = current_sprite;
|
Sprite *sprite = current_sprite;
|
||||||
char filename[4096];
|
|
||||||
char exts[4096];
|
char exts[4096];
|
||||||
char *newfilename;
|
jstring filename;
|
||||||
|
jstring newfilename;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ustrcpy(filename, sprite->filename);
|
filename = sprite->filename;
|
||||||
get_writable_extensions(exts, sizeof(exts));
|
get_writable_extensions(exts, sizeof(exts));
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
newfilename = ase_file_selector(_("Save Sprite"), filename, exts);
|
newfilename = ase_file_selector(_("Save Sprite"), filename, exts);
|
||||||
if (!newfilename)
|
if (newfilename.empty())
|
||||||
return;
|
return;
|
||||||
ustrcpy(filename, newfilename);
|
|
||||||
jfree(newfilename);
|
filename = newfilename;
|
||||||
|
|
||||||
/* does the file exist? */
|
/* does the file exist? */
|
||||||
if (exists(filename)) {
|
if (exists(filename.c_str())) {
|
||||||
/* ask if the user wants overwrite the file? */
|
/* ask if the user wants overwrite the file? */
|
||||||
ret = jalert("%s<<%s<<%s||%s||%s||%s",
|
ret = jalert("%s<<%s<<%s||%s||%s||%s",
|
||||||
_("Warning"),
|
_("Warning"),
|
||||||
_("File exists, overwrite it?"),
|
_("File exists, overwrite it?"),
|
||||||
get_filename(filename),
|
get_filename(filename.c_str()),
|
||||||
_("&Yes"), _("&No"), _("&Cancel"));
|
_("&Yes"), _("&No"), _("&Cancel"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -224,7 +224,7 @@ static void cmd_save_file_as_execute(const char *argument)
|
|||||||
/* "no": we must back to select other file-name */
|
/* "no": we must back to select other file-name */
|
||||||
}
|
}
|
||||||
|
|
||||||
sprite_set_filename(sprite, filename);
|
sprite_set_filename(sprite, filename.c_str());
|
||||||
app_realloc_sprite_list();
|
app_realloc_sprite_list();
|
||||||
|
|
||||||
save_sprite_in_background(sprite);
|
save_sprite_in_background(sprite);
|
||||||
|
@ -42,20 +42,20 @@ static void cmd_save_mask_execute(const char *argument)
|
|||||||
{
|
{
|
||||||
/* get current sprite */
|
/* get current sprite */
|
||||||
Sprite *sprite = current_sprite;
|
Sprite *sprite = current_sprite;
|
||||||
char *filename = "default.msk";
|
jstring filename = "default.msk";
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
filename = ase_file_selector(_("Save .msk File"), filename, "msk");
|
filename = ase_file_selector(_("Save .msk File"), filename, "msk");
|
||||||
if (!filename)
|
if (filename.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* does the file exist? */
|
/* does the file exist? */
|
||||||
if (exists(filename)) {
|
if (exists(filename.c_str())) {
|
||||||
/* ask if the user wants overwrite the file? */
|
/* ask if the user wants overwrite the file? */
|
||||||
ret = jalert("%s<<%s<<%s||%s||%s||%s",
|
ret = jalert("%s<<%s<<%s||%s||%s||%s",
|
||||||
_("Warning"), _("File exists, overwrite it?"),
|
_("Warning"), _("File exists, overwrite it?"),
|
||||||
get_filename(filename),
|
get_filename(filename.c_str()),
|
||||||
_("&Yes"), _("&No"), _("&Cancel"));
|
_("&Yes"), _("&No"), _("&Cancel"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -71,10 +71,10 @@ static void cmd_save_mask_execute(const char *argument)
|
|||||||
/* "no": we must back to select other file-name */
|
/* "no": we must back to select other file-name */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (save_msk_file(sprite->mask, filename) != 0)
|
if (save_msk_file(sprite->mask, filename.c_str()) != 0)
|
||||||
jalert("%s<<%s<<%s||%s",
|
jalert("%s<<%s<<%s||%s",
|
||||||
_("Error"), _("Error saving .msk file"),
|
_("Error"), _("Error saving .msk file"),
|
||||||
filename, _("&Close"));
|
filename.c_str(), _("&Close"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Command cmd_save_mask = {
|
Command cmd_save_mask = {
|
||||||
|
@ -43,7 +43,7 @@ static void cmd_sprite_properties_execute(const char *argument)
|
|||||||
{
|
{
|
||||||
JWidget window, killer, name, type, size, frames, speed, ok;
|
JWidget window, killer, name, type, size, frames, speed, ok;
|
||||||
Sprite *sprite = current_sprite;
|
Sprite *sprite = current_sprite;
|
||||||
char *imgtype_text;
|
jstring imgtype_text;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
/* load the window widget */
|
/* load the window widget */
|
||||||
@ -82,7 +82,7 @@ static void cmd_sprite_properties_execute(const char *argument)
|
|||||||
jwidget_set_text(name, sprite->filename);
|
jwidget_set_text(name, sprite->filename);
|
||||||
|
|
||||||
/* color mode */
|
/* color mode */
|
||||||
jwidget_set_text(type, imgtype_text);
|
jwidget_set_text(type, imgtype_text.c_str());
|
||||||
|
|
||||||
/* sprite size (width and height) */
|
/* sprite size (width and height) */
|
||||||
usprintf(buf, "%dx%d (", sprite->w, sprite->h);
|
usprintf(buf, "%dx%d (", sprite->w, sprite->h);
|
||||||
|
@ -108,7 +108,7 @@ struct FileItem
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* the root of the file-system */
|
// the root of the file-system
|
||||||
static FileItem *rootitem = NULL;
|
static FileItem *rootitem = NULL;
|
||||||
static HashTable *hash_fileitems = NULL;
|
static HashTable *hash_fileitems = NULL;
|
||||||
static unsigned int current_file_system_version = 0;
|
static unsigned int current_file_system_version = 0;
|
||||||
|
@ -278,15 +278,14 @@ static FONT *my_load_font(const char *filename)
|
|||||||
|
|
||||||
static void button_font_command(JWidget widget)
|
static void button_font_command(JWidget widget)
|
||||||
{
|
{
|
||||||
char *filename;
|
jstring filename =
|
||||||
|
ase_file_selector(_("Open Font (TTF or Allegro bitmap format)"),
|
||||||
|
get_config_string ("DrawText", "Font", ""),
|
||||||
|
"pcx,bmp,tga,lbm,ttf");
|
||||||
|
|
||||||
filename = ase_file_selector(_("Open Font (TTF or Allegro bitmap format)"),
|
if (!filename.empty()) {
|
||||||
get_config_string ("DrawText", "Font", ""),
|
set_config_string("DrawText", "Font", filename.c_str());
|
||||||
"pcx,bmp,tga,lbm,ttf");
|
|
||||||
if (filename) {
|
|
||||||
set_config_string("DrawText", "Font", filename);
|
|
||||||
update_button_text();
|
update_button_text();
|
||||||
jfree(filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <cassert>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <allegro.h>
|
#include <allegro.h>
|
||||||
#include <allegro/internal/aintern.h>
|
#include <allegro/internal/aintern.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -69,9 +71,9 @@ static bool filetype_msg_proc(JWidget widget, JMessage msg);
|
|||||||
* - the 'core/file_system' routines.
|
* - the 'core/file_system' routines.
|
||||||
* - the 'widgets/fileview' widget.
|
* - the 'widgets/fileview' widget.
|
||||||
*/
|
*/
|
||||||
char *ase_file_selector(const char *message,
|
jstring ase_file_selector(const jstring& message,
|
||||||
const char *init_path,
|
const jstring& init_path,
|
||||||
const char *exts)
|
const jstring& exts)
|
||||||
{
|
{
|
||||||
static JWidget window = NULL;
|
static JWidget window = NULL;
|
||||||
FileItem *start_folder = NULL;
|
FileItem *start_folder = NULL;
|
||||||
@ -79,9 +81,7 @@ char *ase_file_selector(const char *message,
|
|||||||
JWidget goback, goforward, goup;
|
JWidget goback, goforward, goup;
|
||||||
JWidget filename_entry;
|
JWidget filename_entry;
|
||||||
JWidget filetype;
|
JWidget filetype;
|
||||||
char buf[512];
|
jstring result;
|
||||||
char *result = NULL;
|
|
||||||
char *tok;
|
|
||||||
|
|
||||||
file_system_refresh();
|
file_system_refresh();
|
||||||
|
|
||||||
@ -92,45 +92,42 @@ char *ase_file_selector(const char *message,
|
|||||||
navigation_history);
|
navigation_history);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 'buf' will contain the start folder path */
|
// use the current path
|
||||||
ustrcpy(buf, init_path);
|
jstring start_folder_path;
|
||||||
|
|
||||||
/* use the current path */
|
// if init_path doesn't contain a path...
|
||||||
if (get_filename(buf) == buf) {
|
if (init_path.filepath().empty()) {
|
||||||
char path[512];
|
// get the saved `path' in the configuration file
|
||||||
|
jstring path = get_config_string("FileSelect", "CurrentDirectory", "");
|
||||||
|
start_folder = get_fileitem_from_path(path.c_str());
|
||||||
|
|
||||||
/* get saved `path' */
|
// is the folder find?
|
||||||
ustrcpy(path, get_config_string("FileSelect", "CurrentDirectory", ""));
|
|
||||||
start_folder = get_fileitem_from_path(path);
|
|
||||||
if (!start_folder) {
|
if (!start_folder) {
|
||||||
/* if the `path' doesn't exist */
|
// if the `path' doesn't exist...
|
||||||
if ((!ugetat(path, 0)) || (!ji_dir_exists(path))) {
|
if (path.empty() || (!ji_dir_exists(path.c_str()))) {
|
||||||
/* try to get current `path' */
|
// we can get the current `path' from the system
|
||||||
#ifdef HAVE_DRIVES
|
#ifdef HAVE_DRIVES
|
||||||
int drive = _al_getdrive();
|
int drive = _al_getdrive();
|
||||||
#else
|
#else
|
||||||
int drive = 0;
|
int drive = 0;
|
||||||
#endif
|
#endif
|
||||||
|
char tmp[1024];
|
||||||
_al_getdcwd(drive, path, sizeof(path) - ucwidth(OTHER_PATH_SEPARATOR));
|
_al_getdcwd(drive, tmp, sizeof(tmp) - ucwidth(OTHER_PATH_SEPARATOR));
|
||||||
|
path = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
fix_filename_case(path);
|
start_folder_path = path / init_path;
|
||||||
fix_filename_slashes(path);
|
|
||||||
put_backslash(path);
|
|
||||||
|
|
||||||
ustrcat(path, buf);
|
|
||||||
ustrcpy(buf, path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* remove the filename */
|
// remove the filename
|
||||||
*get_filename(buf) = 0;
|
start_folder_path = init_path.filepath() / "";
|
||||||
}
|
}
|
||||||
|
start_folder_path.fix_separators();
|
||||||
|
|
||||||
if (!start_folder)
|
if (!start_folder)
|
||||||
start_folder = get_fileitem_from_path(buf);
|
start_folder = get_fileitem_from_path(start_folder_path.c_str());
|
||||||
|
|
||||||
if (!window) {
|
if (!window) {
|
||||||
JWidget view, location;
|
JWidget view, location;
|
||||||
|
|
||||||
@ -159,7 +156,7 @@ char *ase_file_selector(const char *message,
|
|||||||
jbutton_add_command(goup, goup_command);
|
jbutton_add_command(goup, goup_command);
|
||||||
|
|
||||||
view = jview_new();
|
view = jview_new();
|
||||||
fileview = fileview_new(start_folder, exts);
|
fileview = fileview_new(start_folder, exts.c_str());
|
||||||
|
|
||||||
jwidget_add_hook(fileview, -1, fileview_msg_proc, NULL);
|
jwidget_add_hook(fileview, -1, fileview_msg_proc, NULL);
|
||||||
jwidget_add_hook(location, -1, location_msg_proc, NULL);
|
jwidget_add_hook(location, -1, location_msg_proc, NULL);
|
||||||
@ -196,20 +193,21 @@ char *ase_file_selector(const char *message,
|
|||||||
|
|
||||||
/* fill file-type combo-box */
|
/* fill file-type combo-box */
|
||||||
jcombobox_clear(filetype);
|
jcombobox_clear(filetype);
|
||||||
ustrcpy(buf, exts);
|
|
||||||
for (tok = ustrtok(buf, ",");
|
std::vector<jstring> tokens;
|
||||||
tok != NULL;
|
std::vector<jstring>::iterator tok;
|
||||||
tok = ustrtok(NULL, ",")) {
|
|
||||||
jcombobox_add_string(filetype, tok, NULL);
|
exts.split(',', tokens);
|
||||||
}
|
for (tok=tokens.begin(); tok!=tokens.end(); ++tok)
|
||||||
|
jcombobox_add_string(filetype, tok->c_str(), NULL);
|
||||||
|
|
||||||
/* file name entry field */
|
/* file name entry field */
|
||||||
filename_entry = jwidget_find_name(window, "filename");
|
filename_entry = jwidget_find_name(window, "filename");
|
||||||
jwidget_set_text(filename_entry, get_filename(init_path));
|
jwidget_set_text(filename_entry, init_path.filename().c_str());
|
||||||
select_filetype_from_filename(window);
|
select_filetype_from_filename(window);
|
||||||
|
|
||||||
/* setup the title of the window */
|
/* setup the title of the window */
|
||||||
jwidget_set_text(window, message);
|
jwidget_set_text(window, message.c_str());
|
||||||
|
|
||||||
/* get the ok-button */
|
/* get the ok-button */
|
||||||
ok = jwidget_find_name(window, "ok");
|
ok = jwidget_find_name(window, "ok");
|
||||||
@ -221,26 +219,22 @@ char *ase_file_selector(const char *message,
|
|||||||
jwindow_open_fg(window);
|
jwindow_open_fg(window);
|
||||||
if (jwindow_get_killer(window) == ok ||
|
if (jwindow_get_killer(window) == ok ||
|
||||||
jwindow_get_killer(window) == fileview) {
|
jwindow_get_killer(window) == fileview) {
|
||||||
char *p;
|
|
||||||
|
|
||||||
/* open the selected file */
|
/* open the selected file */
|
||||||
FileItem *folder = fileview_get_current_folder(fileview);
|
FileItem *folder = fileview_get_current_folder(fileview);
|
||||||
assert(folder != NULL);
|
assert(folder != NULL);
|
||||||
|
|
||||||
ustrcpy(buf, fileitem_get_filename(folder));
|
jstring buf = fileitem_get_filename(folder);
|
||||||
put_backslash(buf);
|
buf /= jwidget_get_text(filename_entry);
|
||||||
ustrcat(buf, jwidget_get_text(filename_entry));
|
|
||||||
|
|
||||||
/* does it not have extension? ...we should add the extension
|
/* does it not have extension? ...we should add the extension
|
||||||
selected in the filetype combo-box */
|
selected in the filetype combo-box */
|
||||||
p = get_extension(buf);
|
if (buf.extension().empty()) {
|
||||||
if (!p || *p == 0) {
|
buf += '.';
|
||||||
ustrcat(buf, ".");
|
buf += jcombobox_get_selected_string(filetype);
|
||||||
ustrcat(buf, jcombobox_get_selected_string(filetype));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* duplicate the buffer to return a new string */
|
/* duplicate the buffer to return a new string */
|
||||||
result = jstrdup(buf);
|
result = buf;
|
||||||
|
|
||||||
/* save the path in the configuration file */
|
/* save the path in the configuration file */
|
||||||
set_config_string("FileSelect", "CurrentDirectory",
|
set_config_string("FileSelect", "CurrentDirectory",
|
||||||
|
@ -19,9 +19,11 @@
|
|||||||
#ifndef DIALOGS_FILESEL_H
|
#ifndef DIALOGS_FILESEL_H
|
||||||
#define DIALOGS_FILESEL_H
|
#define DIALOGS_FILESEL_H
|
||||||
|
|
||||||
char *ase_file_selector(const char *message,
|
#include "jinete/jstring.h"
|
||||||
const char *init_path,
|
|
||||||
const char *exts);
|
jstring ase_file_selector(const jstring& message,
|
||||||
|
const jstring& init_path,
|
||||||
|
const jstring& exts);
|
||||||
|
|
||||||
#endif /* DIALOGS_FILESEL_H */
|
#endif /* DIALOGS_FILESEL_H */
|
||||||
|
|
||||||
|
@ -62,6 +62,7 @@
|
|||||||
#include "jinete/jsep.h"
|
#include "jinete/jsep.h"
|
||||||
#include "jinete/jslider.h"
|
#include "jinete/jslider.h"
|
||||||
#include "jinete/jstream.h"
|
#include "jinete/jstream.h"
|
||||||
|
#include "jinete/jstring.h"
|
||||||
#include "jinete/jsystem.h"
|
#include "jinete/jsystem.h"
|
||||||
#include "jinete/jtextbox.h"
|
#include "jinete/jtextbox.h"
|
||||||
#include "jinete/jtheme.h"
|
#include "jinete/jtheme.h"
|
||||||
|
142
src/jinete/jstring.cpp
Normal file
142
src/jinete/jstring.cpp
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/* Jinete - a GUI library
|
||||||
|
* Copyright (C) 2003-2008 David A. Capello.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of the Jinete nor the names of its contributors may
|
||||||
|
* be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "jinete/jstring.h"
|
||||||
|
|
||||||
|
#if defined ALLEGRO_WINDOWS
|
||||||
|
const char jstring::separator = '\\';
|
||||||
|
#else
|
||||||
|
const char jstring::separator = '/';
|
||||||
|
#endif
|
||||||
|
|
||||||
|
jstring jstring::filepath() const
|
||||||
|
{
|
||||||
|
const_reverse_iterator rit;
|
||||||
|
jstring res;
|
||||||
|
|
||||||
|
for (rit=rbegin(); rit!=rend(); ++rit)
|
||||||
|
if (is_separator(*rit))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (rit != rend()) {
|
||||||
|
++rit;
|
||||||
|
std::copy(begin(), const_iterator(rit.base()),
|
||||||
|
std::back_inserter(res));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring jstring::filename() const
|
||||||
|
{
|
||||||
|
const_reverse_iterator rit;
|
||||||
|
jstring res;
|
||||||
|
|
||||||
|
for (rit=rbegin(); rit!=rend(); ++rit)
|
||||||
|
if (is_separator(*rit))
|
||||||
|
break;
|
||||||
|
|
||||||
|
std::copy(const_iterator(rit.base()), end(),
|
||||||
|
std::back_inserter(res));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring jstring::extension() const
|
||||||
|
{
|
||||||
|
const_reverse_iterator rit;
|
||||||
|
jstring res;
|
||||||
|
|
||||||
|
// search for the first dot from the end of the string
|
||||||
|
for (rit=rbegin(); rit!=rend(); ++rit) {
|
||||||
|
if (is_separator(*rit))
|
||||||
|
return res;
|
||||||
|
else if (*rit == '.')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rit != rend()) {
|
||||||
|
std::copy(const_iterator(rit.base()), end(),
|
||||||
|
std::back_inserter(res));
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring jstring::filetitle() const
|
||||||
|
{
|
||||||
|
const_reverse_iterator rit;
|
||||||
|
const_iterator last_dot = end();
|
||||||
|
jstring res;
|
||||||
|
|
||||||
|
for (rit=rbegin(); rit!=rend(); ++rit) {
|
||||||
|
if (is_separator(*rit))
|
||||||
|
break;
|
||||||
|
else if (*rit == '.' && last_dot == end())
|
||||||
|
last_dot = rit.base()-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const_iterator it(rit.base()); it!=end(); ++it) {
|
||||||
|
if (it == last_dot)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
res.push_back(*it);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring jstring::operator/(const jstring& component) const
|
||||||
|
{
|
||||||
|
jstring res(*this);
|
||||||
|
res /= component;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a the file name @a component in the path (this string)
|
||||||
|
* separated with a slash.
|
||||||
|
*/
|
||||||
|
jstring& jstring::operator/=(const jstring& component)
|
||||||
|
{
|
||||||
|
if (!empty() && !is_separator(*(end()-1)))
|
||||||
|
push_back(jstring::separator);
|
||||||
|
|
||||||
|
operator+=(component);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void jstring::fix_separators()
|
||||||
|
{
|
||||||
|
std::replace_if(begin(), end(), jstring::is_separator, jstring::separator);
|
||||||
|
}
|
119
src/jinete/jstring.h
Normal file
119
src/jinete/jstring.h
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/* Jinete - a GUI library
|
||||||
|
* Copyright (C) 2003-2008 David A. Capello.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of the Jinete nor the names of its contributors may
|
||||||
|
* be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef JINETE_STRING_H
|
||||||
|
#define JINETE_STRING_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string of characters.
|
||||||
|
*/
|
||||||
|
class jstring : public std::basic_string<char>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const char separator;
|
||||||
|
|
||||||
|
jstring() {
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit jstring(int length)
|
||||||
|
: std::string(length, static_cast<char>(0))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring(const jstring& str)
|
||||||
|
: std::string(str)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring(const std::string& str)
|
||||||
|
: std::string(str)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring(const char* str)
|
||||||
|
: std::string(str)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring(const char* str, int length)
|
||||||
|
: std::string(str, length)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_separator(char c) {
|
||||||
|
return (c == '\\' || c == '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
jstring filepath() const;
|
||||||
|
jstring filename() const;
|
||||||
|
jstring extension() const;
|
||||||
|
jstring filetitle() const;
|
||||||
|
|
||||||
|
jstring operator/(const jstring& component) const;
|
||||||
|
jstring& operator/=(const jstring& component);
|
||||||
|
void fix_separators();
|
||||||
|
|
||||||
|
template<typename List>
|
||||||
|
void split(value_type separator, List& result) const
|
||||||
|
{
|
||||||
|
jstring tok;
|
||||||
|
|
||||||
|
tok.reserve(size());
|
||||||
|
|
||||||
|
for (const_iterator it=begin(); it!=end(); ++it) {
|
||||||
|
if (*it == separator) {
|
||||||
|
result.push_back(tok);
|
||||||
|
tok.clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tok.push_back(*it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
inline jstring operator+(const jstring& _s1, const char* _s2)
|
||||||
|
{
|
||||||
|
jstring _res(_s1);
|
||||||
|
_res.append(jstring(_s2));
|
||||||
|
return _res;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline jstring operator+(const char* _s1, const jstring& _s2)
|
||||||
|
{
|
||||||
|
jstring _res(_s1);
|
||||||
|
_res.append(_s2);
|
||||||
|
return _res;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* JINETE_STRING_H */
|
Loading…
x
Reference in New Issue
Block a user