mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-07 18:09:44 +00:00
working history
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@413 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
typedef struct filechooser {
|
typedef struct filechooser {
|
||||||
char* path;
|
char* path;
|
||||||
|
char** history;
|
||||||
|
int history_seek;
|
||||||
|
|
||||||
MwDirectoryEntry** entries;
|
MwDirectoryEntry** entries;
|
||||||
MwDirectoryEntry** sorted_entries;
|
MwDirectoryEntry** sorted_entries;
|
||||||
@@ -28,12 +30,15 @@ typedef struct filechooser {
|
|||||||
MwLLPixmap computer;
|
MwLLPixmap computer;
|
||||||
} filechooser_t;
|
} filechooser_t;
|
||||||
|
|
||||||
static void scan(MwWidget handle, const char* path);
|
static void scan(MwWidget handle, const char* path, int record);
|
||||||
|
|
||||||
static void destroy(MwWidget handle) {
|
static void destroy(MwWidget handle) {
|
||||||
filechooser_t* fc = handle->opaque;
|
filechooser_t* fc = handle->opaque;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
for(i = 0; i < arrlen(fc->history); i++) free(fc->history[i]);
|
||||||
|
arrfree(fc->history);
|
||||||
|
|
||||||
arrfree(fc->sorted_entries);
|
arrfree(fc->sorted_entries);
|
||||||
for(i = 0; i < arrlen(fc->entries); i++) MwDirectoryFreeEntry(fc->entries[i]);
|
for(i = 0; i < arrlen(fc->entries); i++) MwDirectoryFreeEntry(fc->entries[i]);
|
||||||
arrfree(fc->entries);
|
arrfree(fc->entries);
|
||||||
@@ -85,7 +90,7 @@ static void files_activate(MwWidget handle, void* user, void* call) {
|
|||||||
if(fc->sorted_entries[index - 1]->type == MwDIRECTORY_DIRECTORY) {
|
if(fc->sorted_entries[index - 1]->type == MwDIRECTORY_DIRECTORY) {
|
||||||
char* p = MwDirectoryJoin(fc->path, fc->sorted_entries[index - 1]->name);
|
char* p = MwDirectoryJoin(fc->path, fc->sorted_entries[index - 1]->name);
|
||||||
|
|
||||||
scan(handle->parent, p);
|
scan(handle->parent, p, 1);
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
} else {
|
} else {
|
||||||
@@ -104,7 +109,7 @@ static void nav_activate(MwWidget handle, void* user, void* call) {
|
|||||||
#else
|
#else
|
||||||
struct passwd* p = getpwuid(getuid());
|
struct passwd* p = getpwuid(getuid());
|
||||||
|
|
||||||
scan(handle->parent, p->pw_dir);
|
scan(handle->parent, p->pw_dir, 1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,16 +121,40 @@ static void addr_up_activate(MwWidget handle, void* user, void* call) {
|
|||||||
(void)user;
|
(void)user;
|
||||||
(void)call;
|
(void)call;
|
||||||
|
|
||||||
scan(handle->parent, p);
|
scan(handle->parent, p, 1);
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addr_back_activate(MwWidget handle, void* user, void* call) {
|
||||||
|
filechooser_t* fc = handle->parent->opaque;
|
||||||
|
|
||||||
|
(void)user;
|
||||||
|
(void)call;
|
||||||
|
|
||||||
|
if(fc->history_seek > 1) {
|
||||||
|
fc->history_seek -= 2;
|
||||||
|
scan(handle->parent, fc->history[fc->history_seek], 0);
|
||||||
|
fc->history_seek++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void addr_fwd_activate(MwWidget handle, void* user, void* call) {
|
||||||
|
filechooser_t* fc = handle->parent->opaque;
|
||||||
|
|
||||||
|
(void)user;
|
||||||
|
(void)call;
|
||||||
|
|
||||||
|
if(fc->history_seek < arrlen(fc->history)) {
|
||||||
|
scan(handle->parent, fc->history[fc->history_seek++], 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void addr_activate(MwWidget handle, void* user, void* call) {
|
static void addr_activate(MwWidget handle, void* user, void* call) {
|
||||||
(void)user;
|
(void)user;
|
||||||
(void)call;
|
(void)call;
|
||||||
|
|
||||||
scan(handle->parent, MwGetText(handle, MwNtext));
|
scan(handle->parent, MwGetText(handle, MwNtext), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void layout(MwWidget handle) {
|
static void layout(MwWidget handle) {
|
||||||
@@ -196,6 +225,7 @@ static void layout(MwWidget handle) {
|
|||||||
fc->addr_back = MwVaCreateWidget(MwButtonClass, "addr_back", handle, wx, wy, ww, wh,
|
fc->addr_back = MwVaCreateWidget(MwButtonClass, "addr_back", handle, wx, wy, ww, wh,
|
||||||
MwNpixmap, fc->back,
|
MwNpixmap, fc->back,
|
||||||
NULL);
|
NULL);
|
||||||
|
MwAddUserHandler(fc->addr_back, MwNactivateHandler, addr_back_activate, NULL);
|
||||||
} else {
|
} else {
|
||||||
MwVaApply(fc->addr_back,
|
MwVaApply(fc->addr_back,
|
||||||
MwNx, wx,
|
MwNx, wx,
|
||||||
@@ -213,6 +243,7 @@ static void layout(MwWidget handle) {
|
|||||||
fc->addr_fwd = MwVaCreateWidget(MwButtonClass, "addr_fwd", handle, wx, wy, ww, wh,
|
fc->addr_fwd = MwVaCreateWidget(MwButtonClass, "addr_fwd", handle, wx, wy, ww, wh,
|
||||||
MwNpixmap, fc->forward,
|
MwNpixmap, fc->forward,
|
||||||
NULL);
|
NULL);
|
||||||
|
MwAddUserHandler(fc->addr_fwd, MwNactivateHandler, addr_fwd_activate, NULL);
|
||||||
} else {
|
} else {
|
||||||
MwVaApply(fc->addr_fwd,
|
MwVaApply(fc->addr_fwd,
|
||||||
MwNx, wx,
|
MwNx, wx,
|
||||||
@@ -325,7 +356,7 @@ static int qsort_files(const void* a, const void* b) {
|
|||||||
return strcmp(aent->name, bent->name);
|
return strcmp(aent->name, bent->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scan(MwWidget handle, const char* path) {
|
static void scan(MwWidget handle, const char* path, int record) {
|
||||||
filechooser_t* fc = handle->opaque;
|
filechooser_t* fc = handle->opaque;
|
||||||
void* dir = MwDirectoryOpen(path);
|
void* dir = MwDirectoryOpen(path);
|
||||||
int i;
|
int i;
|
||||||
@@ -345,6 +376,19 @@ static void scan(MwWidget handle, const char* path) {
|
|||||||
MwDirectoryClose(dir);
|
MwDirectoryClose(dir);
|
||||||
|
|
||||||
qsort(fc->entries, arrlen(fc->entries), sizeof(MwDirectoryEntry*), qsort_files);
|
qsort(fc->entries, arrlen(fc->entries), sizeof(MwDirectoryEntry*), qsort_files);
|
||||||
|
|
||||||
|
if(record) {
|
||||||
|
char* str = MwStringDupliacte(path);
|
||||||
|
|
||||||
|
while(arrlen(fc->history) > fc->history_seek) {
|
||||||
|
free(fc->history[fc->history_seek]);
|
||||||
|
arrdel(fc->history, fc->history_seek);
|
||||||
|
}
|
||||||
|
|
||||||
|
arrins(fc->history, fc->history_seek, str);
|
||||||
|
|
||||||
|
fc->history_seek++;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
MwWidget msgbox = MwMessageBox(handle, "Directory does not exist!", "Error", MwMB_ICONERROR | MwMB_BUTTONOK);
|
MwWidget msgbox = MwMessageBox(handle, "Directory does not exist!", "Error", MwMB_ICONERROR | MwMB_BUTTONOK);
|
||||||
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, msgbox_okay, NULL);
|
MwAddUserHandler(MwMessageBoxGetChild(msgbox, MwMB_BUTTONOK), MwNactivateHandler, msgbox_okay, NULL);
|
||||||
@@ -433,6 +477,8 @@ MwWidget MwFileChooser(MwWidget handle, const char* title) {
|
|||||||
MwNtitle, title,
|
MwNtitle, title,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
fc->history_seek = 0;
|
||||||
|
|
||||||
fc->dir = MwLoadXPM(window, MwIconDirectory);
|
fc->dir = MwLoadXPM(window, MwIconDirectory);
|
||||||
fc->file = MwLoadXPM(window, MwIconFile);
|
fc->file = MwLoadXPM(window, MwIconFile);
|
||||||
fc->back = MwLoadXPM(window, MwIconBack);
|
fc->back = MwLoadXPM(window, MwIconBack);
|
||||||
@@ -452,7 +498,7 @@ MwWidget MwFileChooser(MwWidget handle, const char* title) {
|
|||||||
MwAddUserHandler(window, MwNcloseHandler, cancel_window, NULL);
|
MwAddUserHandler(window, MwNcloseHandler, cancel_window, NULL);
|
||||||
|
|
||||||
path = MwDirectoryCurrent();
|
path = MwDirectoryCurrent();
|
||||||
scan(window, path);
|
scan(window, path, 1);
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
MwLLDetach(window->lowlevel, &p);
|
MwLLDetach(window->lowlevel, &p);
|
||||||
|
|||||||
@@ -76,10 +76,11 @@ static void frame_mouse_down(MwWidget handle, void* user, void* call) {
|
|||||||
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth * 2) / MwTextHeight(handle, "M"); i++) {
|
for(i = 0; (st + i) < arrlen(lb->list) && i < (h - MwDefaultBorderWidth * 2) / MwTextHeight(handle, "M"); i++) {
|
||||||
if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, "M"))) {
|
if(y <= m->point.y && m->point.y <= (y + MwTextHeight(handle, "M"))) {
|
||||||
unsigned long t;
|
unsigned long t;
|
||||||
|
int old = lb->selected;
|
||||||
|
|
||||||
lb->selected = st + i;
|
lb->selected = st + i;
|
||||||
|
|
||||||
if(((t = MwLLGetTick()) - lb->click_time) < 250 && lb->selected == st + i) {
|
if(((t = MwLLGetTick()) - lb->click_time) < 250 && old == st + i) {
|
||||||
MwDispatchUserHandler(handle->parent, MwNactivateHandler, &lb->selected);
|
MwDispatchUserHandler(handle->parent, MwNactivateHandler, &lb->selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user