Hello,

I am new to nedit. It is an excellent editor. I have been using my own Motif editor for over 10 years. I was attracted nedit's syntax highlighting and tags support. Nedit is a very intuitive editor.

I would like to make a suggestion. I would like to change the background colors on the popup menu pushbuttons that I created. Unfortunately, they are all named "cmd". A small change to userCmds.c will give each widget its own name, which will allow setting colors via a X resource file.

The code is below. Basically, it uses the argument 'name' to createUserMenuItem() to create a name for XtVaCreateWidget(). The new function, create_widget_name(), will filter non-alpha/non-digit characters which may cause trouble in a resource file.

Opinions?

-David



/*
* Create a widget name by taking alpha and digit characters
* from name.
*/
static char *
create_widget_name(char *buffer, int size, const char *name)
{
   char *b = buffer;
while (*name && (b - buffer) < size)
   {
       if (isalnum((int)*name) || *name == '_')
       {
           *b++ = *name;
       }
       name++;
   }
*b = '\0'; /* In case nothing is copied to buffer... */
   if (b == buffer)
   {
       strncpy(buffer, "cmd", size);
       buffer[size - 1] = '\0';
   }
return buffer;
}

static Widget createUserMenuItem(Widget menuPane, char *name, menuItemRec *f,
   int index, XtCallbackProc cbRtn, XtPointer cbArg)
{
   XmString st1, st2;
   char accText[MAX_ACCEL_LEN];
   Widget btn;
   char name_buf[128];
generateAcceleratorString(accText, f->modifiers, f->keysym);
   st1=XmStringCreateSimple(name);
   st2=XmStringCreateSimple(accText);
   btn = XtVaCreateWidget(
           create_widget_name(name_buf, sizeof(name_buf), name),
           xmPushButtonWidgetClass, menuPane,
           XmNlabelString, st1,
           XmNacceleratorText, st2,
           XmNmnemonic, f->mnemonic,
           XmNuserData, index+10, NULL);
   XtAddCallback(btn, XmNactivateCallback, cbRtn, cbArg);
   XmStringFree(st1);
   XmStringFree(st2);
   return btn;
}





--
NEdit Develop mailing list - [email protected]
http://www.nedit.org/mailman/listinfo/develop

Reply via email to