From ba5279276f4ded1c3fb2e246f362e3e3357f637d Mon Sep 17 00:00:00 2001 From: id Date: Thu, 3 Jun 1999 00:24:03 +0000 Subject: [PATCH] Delete button in file panel. --- WINGs/WINGsP.h | 3 ++ WINGs/wfilepanel.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ WINGs/widgets.c | 16 +++++++++++ 3 files changed, 90 insertions(+) diff --git a/WINGs/WINGsP.h b/WINGs/WINGsP.h index 8bc4eb27..776e86eb 100644 --- a/WINGs/WINGsP.h +++ b/WINGs/WINGsP.h @@ -196,6 +196,9 @@ typedef struct W_Screen { struct W_Pixmap *homeIcon; struct W_Pixmap *altHomeIcon; + struct W_Pixmap *trashcanIcon; + struct W_Pixmap *altTrashcanIcon; + struct W_Pixmap *magnifyIcon; /* struct W_Pixmap *altMagnifyIcon;*/ struct W_Pixmap *wheelIcon; diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index f4ca89e6..4c5970dd 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -26,6 +26,7 @@ typedef struct W_FilePanel { WMButton *cancelButton; WMButton *homeButton; + WMButton *trashcanButton; WMView *accessoryView; @@ -63,6 +64,8 @@ static void browserDClick(); static void fillColumn(WMBrowserDelegate *self, WMBrowser *bPtr, int column, WMList *list); +static void deleteFile(); + static void goHome(); static void buttonClick(); @@ -244,6 +247,16 @@ makeFilePanel(WMScreen *scrPtr, char *name, char *title) WMSetButtonAltImage(fPtr->homeButton, scrPtr->altHomeIcon); WMSetButtonAction(fPtr->homeButton, goHome, fPtr); + fPtr->trashcanButton = WMCreateCommandButton(fPtr->win); + WMMoveWidget(fPtr->trashcanButton, 25, 325); + WMResizeWidget(fPtr->trashcanButton, 28, 28); + WMSetButtonImagePosition(fPtr->trashcanButton, WIPImageOnly); + WMSetButtonImage(fPtr->trashcanButton, scrPtr->trashcanIcon); + WMSetButtonAltImage(fPtr->trashcanButton, scrPtr->altTrashcanIcon); + + WMSetButtonAction(fPtr->trashcanButton, deleteFile, fPtr); + /*xxxxxxxxxxxx***/ + WMRealizeWidget(fPtr->win); WMMapSubwidgets(fPtr->win); @@ -569,6 +582,63 @@ browserClick(WMBrowser *bPtr, WMFilePanel *panel) } } +#define ERROR_PANEL(s) err_str = wmalloc(strlen(file)+strlen(s)); \ + sprintf(err_str, s, file); \ + WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win, \ + "Error", err_str, "OK", NULL, NULL); + +static void +deleteFile(WMButton *bPre, WMFilePanel *panel) +{ + char *file; + char *buffer; + char *err_str; + + WMFilePanel *deletePanel; + + file = getCurrentFileName(panel); + if (file[strlen(file)-1] == '/') { + ERROR_PANEL("%s is a directory."); + free(err_str); + free(file); + return; + } + buffer = wmalloc(strlen(file)+15); + sprintf(buffer,"Delete file %s ?\x0",file); + if (!WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win, + "Warning", buffer, "OK", "Cancel", NULL)) { + int rem_stat; + if (rem_stat = remove(file)) { + switch (errno) { + case EISDIR: + ERROR_PANEL("%s is a directory."); + break; + case ENOENT: + ERROR_PANEL("%s does not exist."); + break; + case EACCES: + ERROR_PANEL("Has no right to access %s."); + break; + case ENOMEM: + ERROR_PANEL("Insufficient kernel memory was available."); + break; + case EROFS: + ERROR_PANEL("%s refers to a file on a read-only filesystem."); + break; + default: + ERROR_PANEL("Can not delete %s."); + } + free(err_str); + } + else { + char *s = strrchr(file,'/'); + if (s) s[1] = 0; + WMSetFilePanelDirectory(panel, file); + } + } + free(buffer); + free(file); +} static void goHome(WMButton *bPtr, WMFilePanel *panel) @@ -609,6 +679,7 @@ handleEvents(XEvent *event, void *data) WMMoveWidget(pPtr->cancelButton, newWidth-(PWIDTH-140), newHeight-(PHEIGHT-325)); WMMoveWidget(pPtr->homeButton, 55, newHeight-(PHEIGHT-325)); + WMMoveWidget(pPtr->trashcanButton, 25, newHeight-(PHEIGHT-325)); newColumnCount = (newWidth - 14) / 140; WMSetBrowserMaxVisibleColumns(pPtr->browser, newColumnCount); diff --git a/WINGs/widgets.c b/WINGs/widgets.c index 950f39fb..a230947c 100644 --- a/WINGs/widgets.c +++ b/WINGs/widgets.c @@ -426,6 +426,22 @@ loadPixmaps(WMScreen *scr) scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128); RDestroyImage(tmp); + /* trash can */ + tmp = RGetSubImage(image, 105, 0, 24, 24); + RCombineImageWithColor(tmp, &white); + scr->trashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128); + RDestroyImage(tmp); + tmp = RGetSubImage(image, 105, 0, 24, 24); + RCombineImageWithColor(tmp, &white); + scr->altTrashcanIcon = WMCreatePixmapFromRImage(scr, tmp, 128); + RDestroyImage(tmp); + + + tmp = RGetSubImage(image, 0, 0, 24, 24); + RCombineImageWithColor(tmp, &white); + scr->altHomeIcon = WMCreatePixmapFromRImage(scr, tmp, 128); + RDestroyImage(tmp); + /* Magnifying Glass Icon for ColorPanel */ tmp = RGetSubImage(image, 24, 0, 40, 32); RCombineImageWithColor(tmp, &gray);