📄 defaultsedit.c
字号:
} /* * Initialize panel items for program names panel subwindow, progpanel * This panel contains all names of programs which have been specified * in the master defaults file * Also set initial value of cur_progitem to an appropriate value * "SunView" is selected if present, otherwise the first one. */static intprog_swinit(){ char full_name[DE_FULLNAME_MAX_LENGTH]; /* Full name of node */ int i; char *attrs[DE_MAX_SCREENS]; cur_progvalue = NULL; deflt_get_fullchild("/", full_name); attrs[0] = (char *)PANEL_CHOICE_STRINGS; i = 1; while (full_name !=NULL && strlen(full_name) != 0) { prog_names[i] = (caddr_t) strcpy(getchars(strlen(full_name)), full_name); attrs[i] = &prog_names[i][1]; /* strip leading / */ if (strequal(full_name,"/SunView")) cur_progvalue = i; deflt_get_fullsibling("/", full_name, full_name); i++; } attrs[i++] = 0; attrs[i] = 0; (void)panel_create_item(menupanel, PANEL_CYCLE, ATTR_LIST, attrs, PANEL_VALUE, cur_progvalue ? cur_progvalue-1 : 0, PANEL_LABEL_STRING, "Category", PANEL_NOTIFY_PROC, prog_notifyproc, 0);}/* * Initialize panel items for tree panel subwindow, treepanel. * This subwindow displays part of the defaults database pertaining to * any selected program which have entry in the master defaults database. * The treepanel actually displays the text and choice items to which the * user inputs his parameters. * Also initialize the 2-line help window with a message */static inttree_swinit(height) int height;{ treepanel = panel_begin(tool, PANEL_VERTICAL_SCROLLBAR, scrollbar_build((caddr_t)0), PANEL_HEIGHT, height, 0); if (treepanel == NULL) deferror("Can't create tree panel", True); cur_ylinenr = 0; if (get_cur_progname()==NULL) { show_message((char *)NULL, "No entries in master defaults database directory (/usr/lib/defaults)", ""); } else { subtree_show(); show_message((char *)NULL, "Get HELP by clicking the left button on the appropriate label or string", "" ); } return (int)panel_get(treepanel, PANEL_HEIGHT);}/* * Initialize a text subwindow of height pixels */static inttext_swinit(height) int height;{ textwindow=textsw_build(tool, TEXTSW_HEIGHT, height, 0); return height;} /* * Initilize panel help subwindow helppanel * The help subwindow contains essentially one text item, which labels and * values (= helpmessages or other messages) */static inthelp_swinit(){ char dummyname[DE_FULLNAME_MAX_LENGTH]; int i; Defobj defobjptr; helppanel = panel_begin(tool, PANEL_HEIGHT, PANEL_CU(2)+2, 0); if (helppanel == NULL) deferror("Can't create tree panel", True); /* Create a dummy node name of length DE_FULLNAME_MAX_LENGTH-1 */ for(i=0;i<DE_FULLNAME_MAX_LENGTH-1;i++){ dummyname[i]=' '; } dummyname[DE_FULLNAME_MAX_LENGTH-1]='\0'; defobjptr = create_defobj(dummyname, Helpstring); (void)strcpy(defobjptr->nodename, ""); helpdisplayitem = panel_create_item(helppanel, PANEL_TEXT, PANEL_LABEL_STRING, "Helplabel", PANEL_LABEL_BOLD, True, PANEL_VALUE_STORED_LENGTH, DE_HELP_TEXT_ALLOC_LENGTH-1, PANEL_VALUE_DISPLAY_LENGTH, DE_HELP_TEXT_ALLOC_LENGTH-1, PANEL_VALUE, "", PANEL_LAYOUT, PANEL_VERTICAL, PANEL_EVENT_PROC, help_text_eventproc, PANEL_CLIENT_DATA, defobjptr, 0); defobjptr->ilabel = helpdisplayitem; defobjptr->ivalue = helpdisplayitem; return (int)panel_get(helppanel, PANEL_HEIGHT); }/* * Return the defaults database full name (like "/Scrollbar") from the * currently selected button item in the progpanel. */static char*get_cur_progname(){ return (prog_names[cur_progvalue]);}static charconfirm_category_switch_msg[] ="You have not saved your changes. If you switch categories without \saving your changes, the changes will be lost. Press the left \mouse button to switch categories and discard the changes you \have made. Press the right button to remain in this category.";Debug( Bool t_prog_notifyproc = False; )#define NUMWINDOWS 5static Cursor oldcursor[NUMWINDOWS];static char *window[NUMWINDOWS];/* * This event proc is called whenever one of the program name buttons * in the progpanel are clicked on. *//* ARGSUSED */static voidprog_notifyproc(item, value, event) Panel_item item; struct inputevent *event;{ Bool any_change; int fd, i, result; static first; Event alert_event; if (first == 0) { window[0] = menupanel; window[1] = treepanel; window[2] = textwindow; window[3] = helppanel; window[4] = (char *)tool; first = 1; for (i = 0; i < NUMWINDOWS; i++) oldcursor[i] = cursor_create((char *)0); } for (i = 0; i < NUMWINDOWS; i++) { fd = win_get_fd(window[i]); win_getcursor(fd, oldcursor[i]); win_setcursor(fd, &defaultsedit_hourglass_cursor); } tool_set_attributes(tool, WIN_LABEL, "wait...", 0); any_change = subtree_extractinfo((Bool)FALSE); /* * pass False to subtree_extractinfo() to that * it will onnly check for changed values and * not actually read those changed values from * the panel into memory. */ Debug(if (t_prog_notifyproc) printf("<prog_notifyproc: any_change=%d> ", any_change);) if (!any_change) { result = 1; } else { result = alert_prompt( (Frame)0, &alert_event, ALERT_MESSAGE_STRINGS, "You have not saved your changes.", "If you switch categories without saving", "your changes, the changes will be discarded.", "Please confirm.", 0, ALERT_BUTTON_YES, "Confirm, discard changes", ALERT_BUTTON_NO, "Cancel", 0); if (result == ALERT_YES) { result = 1; } else result = 0; } if (result == 0) { (void)panel_set(item, PANEL_VALUE, cur_progvalue-1, 0); } else { subtree_clearitems(); /* values are 1 base, not zero based */ cur_progvalue = value + 1; subtree_show(); } /* Remember to reset cursor and namestripe */ for (i = 0; i < NUMWINDOWS; i++) { fd = win_get_fd(window[i]); win_setcursor(fd, oldcursor[i]); } tool_set_attributes(tool, WIN_LABEL, "defaultsedit", 0);}/* * Run a specialized setup program like Scrolldemo or Indenttool * in order to set parameters for the currently selected program. * The setup program name is stored under the node "/$Setup_program" */static voidrun_setup_prog(){ int pid; /* Process identification for child demo */ char childforkname[DE_FULLNAME_MAX_LENGTH]; char namenode[DE_FULLNAME_MAX_LENGTH]; int result; Event alert_event; (void)strcpy(namenode, get_cur_progname()); (void)strcat(namenode, "/$Setup_program"); if (defaults_exists(namenode, (int *)NULL)) { (void)strcpy(childforkname, defaults_get_string(namenode, "", (int *)NULL)); result = alert_prompt( (Frame)0, &alert_event, ALERT_MESSAGE_STRINGS, "Attempting to run Demo/Setup program.", "All changes done to default values will be", "saved before starting Demo program.", "Please confirm startup.", 0, ALERT_BUTTON_YES, "Confirm, start Demo", ALERT_BUTTON_NO, "Cancel", 0); switch (result) { case ALERT_YES: result = 1; break; case ALERT_NO: return; default: /* alert_failed */ return; } show_message((char *)NULL, "Saving defaults parameters before calling demo program", ""); sleep(1); (void) subtree_extractinfo(True); dump_default_trees(); show_message((char *)NULL, "Starting child process with demo program, wait...", childforkname); /* start child process to run setup in */ pid = start_child_proc(childforkname, False, False, (union wait *)NULL); /* demo_child_wait3 is called when demo_child finish processing */ (void)notify_set_wait3_func(menupanel, demo_child_wait3, pid); } else show_message((char *)NULL, "Could not find any demo program name in defaults database, program: ", namenode);}/* * Called when clicked on the Save button in the menu window * Save current defaults *//* ARGSUSED */static voidmenu_save_notifyproc(item, event) Panel_item item; Event event;{ (void) subtree_extractinfo(True); dump_default_trees();}static charconfirm_quit_with_changes_msg[] ="Press the left mouse button to Quit without saving changes. \Press the right mouse button to cancel.";static char confirm_quit_msg[] ="Press the left mouse button to confirm Quit. \Press the right mouse button now to cancel.";/* * Called when clicked on the Quit button in the menu window * Quits the program without saving anyting *//* ARGSUSED */static voidmenu_quit_notifyproc(item, event) Panel_item item; Event event;{ Bool any_change; int result; Event alert_event; any_change = subtree_extractinfo((Bool)FALSE); /* * pass False to subtree_extractinfo() to that * it will onnly check for changed values and * not actually read those changed values from * the panel into memory. */ if (any_change) { result = alert_prompt( (Frame)0, &alert_event, ALERT_MESSAGE_STRINGS, "Quiting will discard unsaved changes.", "Please confirm.", 0, ALERT_BUTTON_YES, "Confirm, discard changes", ALERT_BUTTON_NO, "Cancel", 0); if (result == ALERT_YES) /* confirmed */ exit(0); } else { result = alert_prompt( (Frame)0, &alert_event, ALERT_MESSAGE_STRINGS, "Are you sure you want to Quit?", 0, ALERT_BUTTON_YES, "Confirm", ALERT_BUTTON_NO, "Cancel", ALERT_OPTIONAL, 1, ALERT_NO_BEEPING, 1, 0); if (result == ALERT_YES) /* confirmed */ exit(0); }} /* * Called when clicked on the Reset button in the menu subwindow * Resets the current panel to its state when it was opened. *//* ARGSUSED */static voidmenu_reset_notifyproc(item, event) Panel_item item; Event event;{ subtree_clearitems(); subtree_show(); show_message((char *)NULL, "", "");}/* * Check if user has previously clicked on a valid text object item */static Boolcheck_clicked_defobj(allowenumflg) Bool allowenumflg;{ if (last_clicked_defobj==NULL) { show_message((char *)NULL, "First click on an item which may contain text or numeric data!", ""); return False; } allowenumflg = (Bool) (allowenumflg && (last_clicked_defobj->nodetype==Enumerate || last_clicked_defobj->nodetype==Editenumerate)); if (! (allowenumflg || last_clicked_defobj->nodetype==String || last_clicked_defobj->nodetype==Editstring || last_clicked_defobj->nodetype==Helpstring)) { show_message((char *)NULL, "Last clicked object does not contain textdata or numeric data!", ""); return False; } return True;}/* * Edit the label on the item last clicked *//* ARGSUSED */static voidmenu_labeledit_notifyproc(it, event) Panel_item it; Event event;{ Defobj defobjptr; Panel_item old; if (!check_clicked_defobj(True)) return; if (last_clicked_defobj->nodetype==Helpstring) { show_message((char *)NULL, "Click on an item first!", ""); return; } defobjptr = last_clicked_defobj; if (defobjptr->nodetype==Editstring || defobjptr->nodetype==Editenumerate) { /* Label is already in an editable state */ return; } old = defobjptr->ilabel; if (defobjptr->nodetype==Enumerate) { defobjptr->nodetype=Editenumerate; defobjptr->ilabel=panel_create_item(treepanel, PANEL_TEXT, PANEL_ITEM_X, PANEL_CU(0), PANEL_ITEM_Y, (int)panel_get(old, PANEL_ITEM_Y),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -