rem: W_Screen	*scr = WMWidgetScreen(panel->win); char		*toName = NULL; char		*fromName; char		*toPath, *fromPath; int		item; int		index;  item = WMGetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn); fromName = WMGetPopUpButtonItem(panel->customPaletteHistoryBtn, item);  toName = WMRunInputPanel(scr, panel->win, "Rename", "Rename palette to:", fromName, "OK", "Cancel");  if (toName) {   if (strcmp(toName, fromName) == 0) { free(toName); return; }   fromPath = wstrappend(panel->configurationPath, fromName); toPath   = wstrappend(panel->configurationPath, toName);  if (access (toPath, F_OK) == 0)	{	 if (WMRunAlertPanel(scr, panel->win, "Warning", "Palette already exists !\n\nOverwrite ?", "No", "Yes", NULL) == 1) {   remove(toPath);        } else { free(fromPath); free(toName); free(toPath);  return; } }  if ( rename(fromPath, toPath) != 0) wwarning("Couldn't rename palette %s to %s\n", fromName, toName); else { WMRemovePopUpButtonItem(panel->customPaletteHistoryBtn, item); WMInsertPopUpButtonItem(panel->customPaletteHistoryBtn, item, toName);  WMSetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn, item); } free(fromPath); free(toPath); free(toName); }
add: W_Screen    *scr = WMWidgetScreen(panel->win); char        *toName = NULL; char        *fromName; char        *toPath, *fromPath; int            item; int            index;  item = WMGetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn); fromName = WMGetPopUpButtonItem(panel->customPaletteHistoryBtn, item);  toName = WMRunInputPanel(scr, panel->win, "Rename", "Rename palette to:", fromName, "OK", "Cancel");  if (toName) {   if (strcmp(toName, fromName) == 0) { free(toName); return; }   fromPath = wstrappend(panel->configurationPath, fromName); toPath   = wstrappend(panel->configurationPath, toName);  if (access (toPath, F_OK) == 0)    {     if (WMRunAlertPanel(scr, panel->win, "Warning", "Palette already exists !\n\nOverwrite ?", "No", "Yes", NULL) == 1) {  int items = WMGetPopUpButtonNumberOfItems(panel->customPaletteHistoryBtn);  remove(toPath);   index = 1; while ((index < items) && (strcmp(WMGetPopUpButtonItem(panel->customPaletteHistoryBtn, index), toName) != 0 )) index++;  if (index < items) { WMRemovePopUpButtonItem(panel->customPaletteHistoryBtn, index); if (index < item) item--; }  } else { free(fromPath); free(toName); free(toPath);  return; } }  if ( rename(fromPath, toPath) != 0) wsyserror("Couldn't rename palette %s to %s\n", fromName, toName); else { WMRemovePopUpButtonItem(panel->customPaletteHistoryBtn, item); WMInsertPopUpButtonItem(panel->customPaletteHistoryBtn, item, toName);  WMSetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn, item); } free(fromPath); free(toPath); free(toName); }
context: customPaletteMenuRename(W_ColorPanel *panel){	W_Screen	*scr = WMWidgetScreen(panel->win);	char		*toName = NULL;	char		*fromName;	char		*toPath, *fromPath;	int		item;	int		index;	item = WMGetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn);	fromName = WMGetPopUpButtonItem(panel->customPaletteHistoryBtn, item);	toName = WMRunInputPanel(scr, panel->win, "Rename", "Rename palette to:", 		fromName, "OK", "Cancel");	if (toName) {		/* As some people do certain stupid things... */		if (strcmp(toName, fromName) == 0) {			free(toName);			return;		}		/* For normal people */		fromPath = wstrappend(panel->configurationPath, fromName);		toPath   = wstrappend(panel->configurationPath, toName);		if (access (toPath, F_OK) == 0)	{	/* Careful, this palette exists already */			if (WMRunAlertPanel(scr, panel->win, "Warning", 					"Palette already exists !\n\nOverwrite ?", "No", "Yes", NULL) == 1) {				/* "No" = 0, "Yes" = 1 */				remove(toPath);				/* Remove from History list too */				/*				 * XXX This code is not functional yet !!! (And not really necessary)				 */				/*				index = 1;				while ((index < WMGetPopUpButtonNumberOfItems(panel->customPaletteHistoryBtn)) &&						 (strcmp(WMGetPopUpButtonItem(panel->customPaletteHistoryBtn, index), toName) != 0 ))					index++;				if (index < WMGetPopUpButtonNumberOfItems(panel->customPaletteHistoryBtn)) {					WMRemovePopUpButtonItem(panel->customPaletteHistoryBtn, index);					if (index < item)						item--;				}				*/			} else {				free(fromPath);				free(toName);				free(toPath);				return;			}		}		if ( rename(fromPath, toPath) != 0)			wwarning("Couldn't rename palette %s to %s\n", fromName, toName);		else {			WMRemovePopUpButtonItem(panel->customPaletteHistoryBtn, item);			WMInsertPopUpButtonItem(panel->customPaletteHistoryBtn, item, toName);			WMSetPopUpButtonSelectedItem(panel->customPaletteHistoryBtn, item);		}		free(fromPath);		free(toPath);		free(toName);	}}