3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "$Id: m_tags.c,v 8.1 1996/12/11 19:34:33 bostic Exp $ (Berkeley) $Date: 1996/12/11 19:34:33 $";
16 /* This module implements a dialog for navigating the tag stack
19 * void __vi_show_tags_dialog( Widget parent, String title )
20 * Pops up a Tags dialog. We allow one per session. It is not modal.
22 * void __vi_push_tag( String text )
24 * void __vi_clear_tag()
25 * When core changes the tag stack we will change our representation
26 * of it. When this dialog appears, we need core to send a slew of
27 * messages so we can display the current tag stack.
29 * void __vi_set_tag_text( String text )
30 * the text field in the dialog is set to the string. ideally,
31 * this should be kept in sync with the word following the caret
32 * in the current editor window
35 * The push-buttons should activate and deactivate according to
36 * the state of the tag stack and the text field.
38 * Need to send VI commands rather than strings
40 * Need IPO command to start/stop asking for the current tag stack
46 #include <X11/Intrinsic.h>
47 #include <Xm/DialogS.h>
49 #include <Xm/LabelG.h>
52 #include <Xm/RowColumn.h>
53 #include <Xm/PushBG.h>
55 #if ! defined(SelfTest)
57 #include <bitstring.h>
58 #include <sys/types.h>
59 #include <sys/queue.h>
61 #include "../common/common.h"
62 #include "../ip_vi/ip.h"
68 static Widget db_tabs
= NULL
,
72 static Boolean active
= False
;
80 static void go_to_tag();
81 static void split_to_tag();
82 static void pop_tag();
84 static ButtonData button_data
[] = {
85 { "Go To Tag", True
, go_to_tag
},
86 { "Split To Tag", False
, split_to_tag
},
87 { "Pop Tag", False
, pop_tag
},
91 /* manage the tags stack list */
95 if ( ! active
) return;
97 XmListDeletePos( db_list
, 1 );
101 void __vi_clear_tag()
103 if ( ! active
) return;
105 XmListDeleteAllItems( db_list
);
109 void __vi_push_tag( text
)
114 if ( ! active
) return;
116 str
= XmStringCreateSimple( text
);
117 XmListAddItem( db_list
, str
, 1 );
122 /* create a set of push buttons */
124 #define SpacingRatio 4 /* 3:1 button to spaces */
126 #if defined(__STDC__)
127 static Widget
create_push_buttons( Widget parent
,
132 static Widget
create_push_buttons( parent
, data
, count
)
141 base
= SpacingRatio
*count
+ 1;
142 form
= XtVaCreateManagedWidget( "buttons",
145 XmNleftAttachment
, XmATTACH_FORM
,
146 XmNrightAttachment
, XmATTACH_FORM
,
147 XmNfractionBase
, base
,
148 XmNshadowType
, XmSHADOW_ETCHED_IN
,
149 XmNshadowThickness
, 2,
150 XmNverticalSpacing
, 4,
154 while ( count
-- > 0 ) {
155 w
= XtVaCreateManagedWidget(data
->name
,
156 xmPushButtonGadgetClass
,
158 XmNtopAttachment
, XmATTACH_FORM
,
159 XmNbottomAttachment
,XmATTACH_FORM
,
160 XmNleftAttachment
, XmATTACH_POSITION
,
161 XmNleftPosition
, pos
,
162 XmNshowAsDefault
, data
->is_default
,
163 XmNdefaultButtonShadowThickness
, data
->is_default
,
164 XmNrightAttachment
, XmATTACH_POSITION
,
165 XmNrightPosition
, pos
+SpacingRatio
-1,
168 if ( data
->is_default
)
169 XtVaSetValues( form
, XmNdefaultButton
, w
, 0 );
170 XtAddCallback( w
, XmNactivateCallback
, data
->cb
, 0 );
183 #if defined(SelfTest)
190 static void set_text_field( w
, ptr
, cbs
)
193 XmListCallbackStruct
*cbs
;
197 XmStringGetLtoR( cbs
->item
, XmSTRING_DEFAULT_CHARSET
, &str
);
198 XmTextFieldSetString( db_text
, str
);
203 void __vi_set_tag_text( text
)
206 if ( active
) XmTextFieldSetString( db_text
, text
);
210 static void destroyed()
212 #if defined(SelfTest)
216 /* some window managers destroy us upon popdown */
222 #if defined(__STDC__)
223 static void pop_tag( Widget w
)
225 static void pop_tag( w
)
229 static String buffer
= ":tagpop";
231 #if defined(SelfTest)
232 printf( "sending command <<%s>>\n", buffer
);
235 __vi_send_command_string( buffer
);
240 #if defined(__STDC__)
241 static void split_to_tag( Widget w
)
243 static void split_to_tag( w
)
250 str
= XmTextFieldGetString( db_text
);
252 #if defined(SelfTest)
253 printf( "sending command <<:Tag %s>>\n", str
);
257 * This is REALLY sleazy. We pass the nul along with the
258 * string so that the core editor doesn't have to copy the
259 * string to get a nul termination. This should be fixed
260 * as part of making the editor fully 8-bit clean.
262 ipb
.code
= VI_TAGSPLIT
;
264 ipb
.len
= strlen(str
) + 1;
265 __vi_send("s", &ipb
);
272 #if defined(__STDC__)
273 static void go_to_tag( Widget w
)
275 static void go_to_tag( w
)
282 str
= XmTextFieldGetString( db_text
);
284 #if defined(SelfTest)
285 printf( "sending command <<:tag %s>>\n", str
);
289 * This is REALLY sleazy. We pass the nul along with the
290 * string so that the core editor doesn't have to copy the
291 * string to get a nul termination. This should be fixed
292 * as part of making the editor fully 8-bit clean.
296 ipb
.len
= strlen(str
) + 1;
297 __vi_send("s", &ipb
);
305 /* Draw and display a dialog the describes nvi options */
307 #if defined(__STDC__)
308 static Widget
create_tags_dialog( Widget parent
, String title
)
310 static Widget
create_tags_dialog( parent
, title
)
315 Widget box
, form
, form2
, form3
, buttons
;
318 if ( db_tabs
!= NULL
) return db_tabs
;
320 box
= XtVaCreatePopupShell( title
,
321 xmDialogShellWidgetClass
,
324 XmNallowShellResize
, False
,
327 XtAddCallback( box
, XmNpopdownCallback
, cancel_cb
, 0 );
328 XtAddCallback( box
, XmNdestroyCallback
, destroyed
, 0 );
330 form
= XtVaCreateWidget( "Tags",
336 buttons
= create_push_buttons( form
, button_data
, XtNumber(button_data
) );
337 XtVaSetValues( buttons
,
338 XmNbottomAttachment
, XmATTACH_FORM
,
342 form3
= XtVaCreateWidget( "form",
345 XmNleftAttachment
, XmATTACH_FORM
,
346 XmNrightAttachment
, XmATTACH_FORM
,
347 XmNbottomAttachment
, XmATTACH_WIDGET
,
348 XmNbottomWidget
, buttons
,
352 form2
= XtVaCreateWidget( "form",
355 XmNtopAttachment
, XmATTACH_FORM
,
356 XmNleftAttachment
, XmATTACH_FORM
,
357 XmNrightAttachment
, XmATTACH_FORM
,
358 XmNbottomAttachment
, XmATTACH_WIDGET
,
359 XmNbottomWidget
, form3
,
363 db_list
= XtVaCreateManagedWidget( "list",
366 XmNtopAttachment
, XmATTACH_FORM
,
367 XmNleftAttachment
, XmATTACH_POSITION
,
369 XmNrightAttachment
, XmATTACH_FORM
,
370 XmNbottomAttachment
, XmATTACH_FORM
,
371 #if defined(SelfTest)
372 XmNvisibleItemCount
, 5,
374 XmNselectionPolicy
, XmSINGLE_SELECT
,
377 XtAddCallback( db_list
, XmNsingleSelectionCallback
, set_text_field
, 0 );
378 XtAddCallback( db_list
, XmNdefaultActionCallback
, go_to_tag
, 0 );
380 XtVaCreateManagedWidget( "Tag Stack",
383 XmNtopAttachment
, XmATTACH_FORM
,
384 XmNbottomAttachment
, XmATTACH_FORM
,
385 XmNleftAttachment
, XmATTACH_FORM
,
386 XmNrightAttachment
, XmATTACH_POSITION
,
387 XmNrightPosition
, 20,
388 XmNalignment
, XmALIGNMENT_END
,
392 XtVaCreateManagedWidget( "Tag",
395 XmNtopAttachment
, XmATTACH_FORM
,
396 XmNbottomAttachment
, XmATTACH_FORM
,
397 XmNleftAttachment
, XmATTACH_FORM
,
398 XmNrightAttachment
, XmATTACH_POSITION
,
399 XmNrightPosition
, 20,
400 XmNalignment
, XmALIGNMENT_END
,
404 db_text
= XtVaCreateManagedWidget( "text",
405 xmTextFieldWidgetClass
,
407 XmNtopAttachment
, XmATTACH_FORM
,
408 XmNbottomAttachment
, XmATTACH_FORM
,
409 XmNrightAttachment
, XmATTACH_FORM
,
410 XmNleftAttachment
, XmATTACH_POSITION
,
414 XtAddCallback( db_text
, XmNactivateCallback
, go_to_tag
, 0 );
416 /* keep this global, we might destroy it later */
420 XtManageChild( form3
);
421 XtManageChild( form2
);
427 /* module entry point
428 * __vi_show_tags_dialog( parent, title )
431 #if defined(__STDC__)
432 void __vi_show_tags_dialog( Widget parent
, String title
)
434 void __vi_show_tags_dialog( parent
, title
)
439 Widget db
= create_tags_dialog( parent
, title
),
440 shell
= XtParent(db
);
444 /* get the current window's text */
445 __vi_set_tag_text( (String
) __vi_get_word_at_caret( NULL
) );
447 /* TODO: ask vi core for the current tag stack now */
449 /* leave this guy up (or just raise it) */
450 XtPopup( shell
, XtGrabNone
);
451 XMapRaised( XtDisplay( shell
), XtWindow( shell
) );
458 #if defined(SelfTest)
460 #if XtSpecificationRelease == 4
461 #define ArgcType Cardinal *
463 #define ArgcType int *
466 static void add_a_tag( Widget w
)
468 static String tags
[] = { "first", "second", "this is the third" };
471 __vi_push_tag( tags
[i
] );
472 i
= (i
+1) % XtNumber(tags
);
475 #if defined(__STDC__)
476 static void show_tags( Widget w
, XtPointer data
, XtPointer cbs
)
478 static void show_tags( w
, data
, cbs
)
484 __vi_show_tags_dialog( data
, "Tags" );
487 main( int argc
, char *argv
[] )
490 Widget top_level
, rc
, button
;
493 /* create a top-level shell for the window manager */
494 top_level
= XtVaAppInitialize( &ctx
,
496 NULL
, 0, /* options */
498 argv
, /* might get modified */
503 rc
= XtVaCreateManagedWidget( "rc",
504 xmRowColumnWidgetClass
,
509 button
= XtVaCreateManagedWidget( "Pop up tags dialog",
510 xmPushButtonGadgetClass
,
514 XtAddCallback( button
, XmNactivateCallback
, show_tags
, rc
);
516 button
= XtVaCreateManagedWidget( "Add a tag",
517 xmPushButtonGadgetClass
,
521 XtAddCallback( button
, XmNactivateCallback
, add_a_tag
, rc
);
523 button
= XtVaCreateManagedWidget( "Quit",
524 xmPushButtonGadgetClass
,
528 XtAddCallback( button
, XmNactivateCallback
, exit
, 0 );
530 XtRealizeWidget(top_level
);