mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-02 23:50:50 +00:00
file chooser
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@408 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -45,6 +45,14 @@ MWDECL void MwDirectoryFreeEntry(MwDirectoryEntry* entry);
|
|||||||
*/
|
*/
|
||||||
MWDECL char* MwDirectoryCurrent(void);
|
MWDECL char* MwDirectoryCurrent(void);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* %brief Joins 2 paths
|
||||||
|
* %param a Path
|
||||||
|
* %param b Path
|
||||||
|
* %return Path
|
||||||
|
*/
|
||||||
|
MWDECL char* MwDirectoryJoin(char* a, char* b);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -124,3 +124,85 @@ char* MwDirectoryCurrent(void) {
|
|||||||
return getcwd(NULL, 0);
|
return getcwd(NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define DIRSEP '\\'
|
||||||
|
#else
|
||||||
|
#define DIRSEP '/'
|
||||||
|
#endif
|
||||||
|
static void MwDirectoryJoinSingle(char* target, char* p) {
|
||||||
|
int i;
|
||||||
|
if(strcmp(p, ".") == 0) return;
|
||||||
|
|
||||||
|
for(i = strlen(target) - 1; i >= 0; i--) {
|
||||||
|
if(target[i] == DIRSEP) {
|
||||||
|
target[i] = 0;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strcmp(p, "..") == 0) {
|
||||||
|
for(i = strlen(target) - 1; i >= 0; i--) {
|
||||||
|
if(target[i] != DIRSEP) {
|
||||||
|
target[i] = 0;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
char b[2];
|
||||||
|
b[0] = DIRSEP;
|
||||||
|
b[1] = 0;
|
||||||
|
|
||||||
|
strcat(target, b);
|
||||||
|
strcat(target, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = strlen(target) - 1; i >= 0; i--) {
|
||||||
|
if(target[i] == DIRSEP) {
|
||||||
|
target[i] = 0;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strchr(target, DIRSEP) == NULL) {
|
||||||
|
char b[2];
|
||||||
|
b[0] = DIRSEP;
|
||||||
|
b[1] = 0;
|
||||||
|
|
||||||
|
strcat(target, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* MwDirectoryJoin(char* a, char* b) {
|
||||||
|
char* p = malloc(strlen(a) + 1 + strlen(b) + 1);
|
||||||
|
char* bdup = MwStringDupliacte(b);
|
||||||
|
char* b2 = bdup;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
strcpy(p, a);
|
||||||
|
for(i = strlen(p) - 1; i >= 0; i--) {
|
||||||
|
if(p[i] == DIRSEP) {
|
||||||
|
p[i] = 0;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while(b2 != NULL) {
|
||||||
|
char* current = b2;
|
||||||
|
|
||||||
|
b2 = strchr(b2, DIRSEP);
|
||||||
|
if(b2 != NULL) {
|
||||||
|
b2[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MwDirectoryJoinSingle(p, current);
|
||||||
|
|
||||||
|
if(b2 != NULL) b2++;
|
||||||
|
}
|
||||||
|
free(bdup);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,7 +75,27 @@ static void files_activate(MwWidget handle, void* user, void* call) {
|
|||||||
|
|
||||||
(void)user;
|
(void)user;
|
||||||
|
|
||||||
scan(handle->parent, fc->sorted_entries[index - 1]->name);
|
if(fc->sorted_entries[index - 1]->type == MwDIRECTORY_DIRECTORY) {
|
||||||
|
char* p = MwDirectoryJoin(fc->path, fc->sorted_entries[index - 1]->name);
|
||||||
|
|
||||||
|
scan(handle->parent, p);
|
||||||
|
|
||||||
|
free(p);
|
||||||
|
} else {
|
||||||
|
okay(fc->okay, NULL, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void addr_up_activate(MwWidget handle, void* user, void* call) {
|
||||||
|
filechooser_t* fc = handle->parent->opaque;
|
||||||
|
char* p = MwDirectoryJoin(fc->path, "..");
|
||||||
|
|
||||||
|
(void)user;
|
||||||
|
(void)call;
|
||||||
|
|
||||||
|
scan(handle->parent, p);
|
||||||
|
|
||||||
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void layout(MwWidget handle) {
|
static void layout(MwWidget handle) {
|
||||||
@@ -178,6 +198,7 @@ static void layout(MwWidget handle) {
|
|||||||
fc->addr_up = MwVaCreateWidget(MwButtonClass, "addr_up", handle, wx, wy, ww, wh,
|
fc->addr_up = MwVaCreateWidget(MwButtonClass, "addr_up", handle, wx, wy, ww, wh,
|
||||||
MwNpixmap, fc->up,
|
MwNpixmap, fc->up,
|
||||||
NULL);
|
NULL);
|
||||||
|
MwAddUserHandler(fc->addr_up, MwNactivateHandler, addr_up_activate, NULL);
|
||||||
} else {
|
} else {
|
||||||
MwVaApply(fc->addr_up,
|
MwVaApply(fc->addr_up,
|
||||||
MwNx, wx,
|
MwNx, wx,
|
||||||
|
|||||||
Reference in New Issue
Block a user