From d1f85c07e0059409b1b3212fbd2cb845067e2312 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sun, 12 Jan 2025 15:05:05 +0100 Subject: [PATCH] wip copy/delete/rename --- fm.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- function.c | 17 +++++++++++++++-- function.h | 8 ++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/fm.c b/fm.c index f446244..f6bda6f 100644 --- a/fm.c +++ b/fm.c @@ -305,8 +305,35 @@ int main (int argc, char *argv[]) switch (getch ()) { #endif /* PDCURSES */ case ALT_C: /* copy */ + for (i = 0; i < list[panel]->nb; i++) { + current = list[panel]->tab + i; + if (current->selected) { + char *src = strdupcat (dirname[panel], SEPARATOR, current->name); + char *dest = dirname[(panel + 1 ) % MAXPANELS]; + if (processcopy (dest, src) != 0) { + char *buf = strdupcat ("Can't copy '", src, "' to '", dest, "'", NULL); + msgwindow (buf, winscreen, 0); + getch (); + free (buf); + } + free (src); + } + } break; case ALT_D: /* delete */ + for (i = 0; i < list[panel]->nb; i++) { + current = list[panel]->tab + i; + if (current->selected) { + char *src = strdupcat (dirname[panel], SEPARATOR, current->name); + if (processdelete (src) != 0) { + char *buf = strdupcat ("Can't delete '", src, "'", NULL); + msgwindow (buf, winscreen, 0); + getch (); + free (buf); + } + free (src); + } + } break; case ALT_F: /* filter */ string = getwindow ("Set filter", winscreen, MAXFILTER / 2, MAXFILTER, NULL); @@ -322,6 +349,20 @@ int main (int argc, char *argv[]) } break; case ALT_M: /* move */ + for (i = 0; i < list[panel]->nb; i++) { + current = list[panel]->tab + i; + if (current->selected) { + char *src = strdupcat (dirname[panel], SEPARATOR, current->name); + char *dest = dirname[(panel + 1 ) % MAXPANELS]; + if (processmove (dest, src) != 0) { + char *buf = strdupcat ("Can't copy '", src, "' to '", dest, "'", NULL); + msgwindow (buf, winscreen, 0); + getch (); + free (buf); + } + free (src); + } + } break; case ALT_N: /* new dir */ string = getwindow ("New directory", winscreen, MAXFNAME / 2, MAXFNAME, NULL); @@ -363,7 +404,9 @@ int main (int argc, char *argv[]) break; case ALT_S: /* select */ current = list[panel]->tab + windir[panel]->index; - current->selected = (current->selected) ? 0 : 1; + if (strcmp (current->name, "..") != 0) { + current->selected = (current->selected) ? 0 : 1; + } break; case ALT_V: /* view */ break; diff --git a/function.c b/function.c index 5bf83e9..7258ca9 100644 --- a/function.c +++ b/function.c @@ -17,8 +17,6 @@ #include "function.h" -#define SEPARATOR "/" - int strmaxlen (char *str, char ch) { int len = 0; @@ -363,4 +361,19 @@ int filterlist (list_t *list, char *regex) return rc; } +int processcopy (char *dest, char *src) +{ + return 0; +} + +int processdelete (char *src) +{ + return 0; +} + +int processmove (char *dest, char *src) +{ + return 0; +} + /* vim: set ts=4 sw=4 et: */ diff --git a/function.h b/function.h index 838f0ce..ea8440a 100644 --- a/function.h +++ b/function.h @@ -11,6 +11,8 @@ } \ } while (0) +#define SEPARATOR "/" + #define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) #define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) @@ -37,6 +39,12 @@ void freewindow (window_t *win); int filterlist (list_t *list, char *regex); +int processcopy (char *dest, char *src); + +int processdelete (char *src); + +int processmove (char *dest, char *src); + #endif /* __FUNCTION_H__ */ /* vim: set ts=4 sw=4 et: */ -- 2.30.2