static Bool shouldRemoveItem(struct WEditMenuDelegate *delegate, WEditMenu * menu, WEditMenuItem * item) { _Panel *panel = (_Panel *) delegate->data; if (panel->dontAsk) return True; if (WGetEditMenuSubmenu(item)) { int res; res = WMRunAlertPanel(WMWidgetScreen(menu), NULL, _("Remove Submenu"), _("Removing this item will destroy all items inside\n" "the submenu. Do you really want to do that?"), _("Yes"), _("No"), _("Yes, don't ask again")); switch (res) { case WAPRDefault: return True; case WAPRAlternate: return False; case WAPROther: panel->dontAsk = True; return True; } } return True; }
static WMPropList* getDefaultMenu(_Panel *panel) { WMPropList *menu; char *menuPath, *gspath; gspath = wusergnusteppath(); menuPath = wmalloc(strlen(gspath)+128); sprintf(menuPath, "%s/Library/WindowMaker/plmenu", gspath); menu = WMReadPropListFromFile(menuPath); if (!menu) { char *buffer, *msg; msg = _("Could not open default menu from '%s'"); buffer = wmalloc(strlen(msg) + strlen(menuPath) + 10); sprintf(buffer, msg, menuPath); WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Error"), buffer, _("OK"), NULL, NULL); wfree(buffer); } wfree(menuPath); return menu; }
static void speedChange(WMWidget * w, void *data) { _Panel *panel = (_Panel *) data; int i; char buffer[64]; int threshold; char *tmp; if (w == NULL) { float accel; tmp = WMGetTextFieldText(panel->acceT); if (sscanf(tmp, "%f", &accel) != 1 || accel < 0) { WMRunAlertPanel(WMWidgetScreen(panel->acceT), GetWindow(), _("Error"), _("Invalid mouse acceleration value. Must be a positive real value."), _("OK"), NULL, NULL); wfree(tmp); return; } panel->acceleration = accel; wfree(tmp); } else { i = (int)WMGetSliderValue(panel->speedS); panel->acceleration = 0.25 + (i * 0.25); sprintf(buffer, "%.2f", 0.25 + (i * 0.25)); WMSetTextFieldText(panel->acceT, buffer); } tmp = WMGetTextFieldText(panel->threT); if (sscanf(tmp, "%i", &threshold) != 1 || threshold < 0 || threshold > panel->maxThreshold) { WMRunAlertPanel(WMWidgetScreen(panel->parent), GetWindow(), _("Error"), _ ("Invalid mouse acceleration threshold value. Must be the number of pixels to travel before accelerating."), _("OK"), NULL, NULL); } else { setMouseAccel(WMWidgetScreen(panel->parent), panel->acceleration, threshold); } wfree(tmp); }
static void showData(_Panel *panel) { char *gspath; char *menuPath; WMPropList *pmenu; gspath = wusergnusteppath(); menuPath = wmalloc(strlen(gspath)+32); strcpy(menuPath, gspath); strcat(menuPath, "/Defaults/WMRootMenu"); pmenu = WMReadPropListFromFile(menuPath); if (!pmenu || !WMIsPLArray(pmenu)) { int res; res = WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Warning"), _("The menu file format currently in use is not supported\n" "by this tool. Do you want to discard the current menu\n" "to use this tool?"), _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL); if (res == WAPRDefault) { pmenu = getDefaultMenu(panel); if (!pmenu) { pmenu = WMCreatePLArray(WMCreatePLString("Applications"), NULL); } } else { panel->dontSave = True; return; } } panel->menuPath = menuPath; buildMenuFromPL(panel, pmenu); WMReleasePropList(pmenu); }
static WMPropList *getDefaultMenu(_Panel * panel) { WMPropList *menu; static const char menuPath[] = WMAKER_RESOURCE_PATH "/plmenu"; menu = WMReadPropListFromFile(menuPath); if (!menu) { char *buffer, *msg; msg = _("Could not open default menu from '%s'"); buffer = wmalloc(strlen(msg) + strlen(menuPath) + 10); sprintf(buffer, msg, menuPath); WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Error"), buffer, _("OK"), NULL, NULL); wfree(buffer); } return menu; }
void buttonClick(WMWidget *w, void *ptr) { char buffer[300]; if (SlideButton((int)ptr)) { MoveCount++; if (CheckWin()) { sprintf(buffer, "You finished the game in %i moves.", MoveCount); if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer, "Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) { exit(0); } ResetGame(); } } }
static pid_t downloadFile(WMScreen * scr, _Panel * panel, const char *file) { pid_t pid; pid = fork(); if (pid < 0) { werror("could not fork() process"); WMRunAlertPanel(scr, GetWindow(panel), _("Error"), "Could not start download. fork() failed", _("OK"), NULL, NULL); return -1; } if (pid != 0) { return pid; } close(ConnectionNumber(WMScreenDisplay(scr))); exit(1); }
static void showData(_Panel * panel) { const char *gspath; char *menuPath, *labelText; char buf[1024]; WMPropList *pmenu; gspath = wusergnusteppath(); menuPath = wmalloc(strlen(gspath) + 32); strcpy(menuPath, gspath); strcat(menuPath, "/Defaults/WMRootMenu"); pmenu = WMReadPropListFromFile(menuPath); /* check if WMRootMenu references another file, and if so, if that file is in proplist format */ while (WMIsPLString(pmenu)) { char *path = NULL; path = wexpandpath(WMGetFromPLString(pmenu)); if (access(path, F_OK) < 0) path = wfindfile(DEF_CONFIG_PATHS, path); /* TODO: if needed, concatenate locale suffix to path. See getLocalizedMenuFile() in src/rootmenu.c. */ if (!path) break; if (access(path, W_OK) < 0) { snprintf(buf, 1024, _("The menu file \"%s\" referenced by " "WMRootMenu is read-only.\n" "You cannot use WPrefs to modify it."), path); WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Warning"), buf, _("OK"), NULL, NULL); panel->dontSave = True; wfree(path); return; } pmenu = WMReadPropListFromFile(path); menuPath = path; } if (!pmenu || !WMIsPLArray(pmenu)) { int res; res = WMRunAlertPanel(WMWidgetScreen(panel->parent), panel->parent, _("Warning"), _("The menu file format currently in use is not supported\n" "by this tool. Do you want to discard the current menu\n" "to use this tool?"), _("Yes, Discard and Update"), _("No, Keep Current Menu"), NULL); if (res == WAPRDefault) { pmenu = getDefaultMenu(panel); if (!pmenu) { pmenu = WMCreatePLArray(WMCreatePLString("Applications"), NULL); } } else { panel->dontSave = True; return; } } panel->menuPath = menuPath; snprintf(buf, 1024, _("\n\nWhen saved, the menu will be written to the file\n\"%s\"."), menuPath); labelText = WMGetLabelText(panel->sections[NoInfo][0]); labelText = wstrconcat(labelText, buf); WMSetLabelText(panel->sections[NoInfo][0], labelText); wfree(labelText); buildMenuFromPL(panel, pmenu); WMReleasePropList(pmenu); }
static WEditMenu *buildSubmenu(_Panel * panel, WMPropList * pl) { WMScreen *scr = WMWidgetScreen(panel->parent); WEditMenu *menu; WEditMenuItem *item; char *title; WMPropList *tp, *bp; int i; tp = WMGetFromPLArray(pl, 0); title = WMGetFromPLString(tp); menu = WCreateEditMenu(scr, title); for (i = 1; i < WMGetPropListItemCount(pl); i++) { WMPropList *pi; pi = WMGetFromPLArray(pl, i); tp = WMGetFromPLArray(pi, 0); bp = WMGetFromPLArray(pi, 1); title = WMGetFromPLString(tp); if (!bp || WMIsPLArray(bp)) { /* it's a submenu */ WEditMenu *submenu; submenu = buildSubmenu(panel, pi); item = WAddMenuItemWithTitle(menu, title); WSetEditMenuSubmenu(menu, item, submenu); } else { ItemData *data; data = parseCommand(pi); if (data != NULL) { item = WAddMenuItemWithTitle(menu, title); if (panel->markerPix[data->type]) WSetEditMenuItemImage(item, panel->markerPix[data->type]); WSetEditMenuItemData(item, data, (WMCallback *) freeItemData); } else { char *buf = wmalloc(1024); snprintf(buf, 1024, _("Invalid menu command \"%s\" with label \"%s\" cleared"), WMGetFromPLString(WMGetFromPLArray(pi, 1)), WMGetFromPLString(WMGetFromPLArray(pi, 0))); WMRunAlertPanel(scr, panel->parent, _("Warning"), buf, _("OK"), NULL, NULL); wfree(buf); } } } WSetEditMenuAcceptsDrop(menu, True); WSetEditMenuDelegate(menu, &menuDelegate); WMRealizeWidget(menu); return menu; }