1 /************************************************************************/
2 /* */
3 /* Ted: The list of bookmarks on the Bookmark and Hyperlink tools. */
4 /* */
5 /************************************************************************/
6
7 # include "tedConfig.h"
8
9 # include <stdlib.h>
10
11 # include "tedBookmarkList.h"
12 # include "tedAppFront.h"
13 # include <guiTextUtil.h>
14
15 # include <appDebugon.h>
16
17 /************************************************************************/
18
tedInitBookmarkList(BookmarkList * bl)19 void tedInitBookmarkList( BookmarkList * bl )
20 {
21 bl->blMarkLabelWidget= (APP_WIDGET)0;
22 bl->blMarkTextWidget= (APP_WIDGET)0;
23
24 bl->blMarkListWidget= (APP_WIDGET)0;
25
26 bl->blIsLocal= 0;
27 bl->blMarkChosenExists= 0;
28 }
29
30 /************************************************************************/
31 /* */
32 /* Fill a listbox with the bookmarks in a document. */
33 /* */
34 /* 1) Empty the list widget. */
35 /* 2) Collect bookmarks. */
36 /* 3) Sort them. */
37 /* 4) And insert them in the list. */
38 /* */
39 /************************************************************************/
40
tedFillBookmarkList(BookmarkList * bl,int includeTocMarks,const BufferDocument * bd)41 void tedFillBookmarkList( BookmarkList * bl,
42 int includeTocMarks,
43 const BufferDocument * bd )
44 {
45 int i;
46
47 int bookmarkCount= 0;
48 char ** bookmarks= (char **)0;
49 const DocumentFieldList * dfl= &(bd->bdFieldList);
50 const int fieldCount= dfl->dflPagedList.plItemCount;
51
52 APP_WIDGET list= bl->blMarkListWidget;
53
54 /* 1 */
55 appGuiEmptyListWidget( list );
56
57 if ( fieldCount == 0 )
58 { goto ready; }
59
60 /* 2,3 */
61 if ( docMakeBookmarkList( &bookmarks, &bookmarkCount,
62 includeTocMarks, &(bd->bdFieldList) ) )
63 { goto ready; }
64
65 /* 4 */
66 for ( i= 0; i < bookmarkCount; i++ )
67 { appGuiAddValueToListWidget( list, -1, bookmarks[i] ); }
68
69 ready:
70
71 if ( bookmarks )
72 {
73 for ( i= 0; i < bookmarkCount; i++ )
74 {
75 if ( bookmarks[i] )
76 { free( bookmarks[i] ); }
77 }
78
79 free( bookmarks );
80 }
81
82 return;
83 }
84
tedBookmarkUpdateSelectionInList(BookmarkList * bl,const MemoryBuffer * mbChosen)85 void tedBookmarkUpdateSelectionInList( BookmarkList * bl,
86 const MemoryBuffer * mbChosen )
87 {
88 if ( bl->blIsLocal && bl->blMarkChosenExists )
89 {
90 appGuiSelectValueInListWidget( bl->blMarkListWidget,
91 utilMemoryBufferGetString( mbChosen ) );
92 }
93 else{
94 appGuiRemoveSelectionFromListWidget( bl->blMarkListWidget );
95 }
96 }
97
tedBookmarkFindChosen(BookmarkList * bl,EditApplication * ea,const MemoryBuffer * mbChosen)98 void tedBookmarkFindChosen( BookmarkList * bl,
99 EditApplication * ea,
100 const MemoryBuffer * mbChosen )
101 {
102 if ( mbChosen && ! utilMemoryBufferIsEmpty( mbChosen ) )
103 {
104 DocumentField * df;
105
106 if ( tedAppFindBookmarkField( &df, ea, mbChosen ) < 0 )
107 { bl->blMarkChosenExists= 0; }
108 else{ bl->blMarkChosenExists= 1; }
109 }
110 else{ bl->blMarkChosenExists= 0; }
111
112 return;
113 }
114
115 /************************************************************************/
116 /* */
117 /* A Bookmark was chosen in the list. */
118 /* */
119 /************************************************************************/
120
tedBookmarkListToText(BookmarkList * bl,MemoryBuffer * mbChosen,void * voidlcs,APP_WIDGET w)121 void tedBookmarkListToText( BookmarkList * bl,
122 MemoryBuffer * mbChosen,
123 void * voidlcs,
124 APP_WIDGET w )
125 {
126 char * markName;
127
128 markName= appGuiGetStringFromListCallback( w, voidlcs );
129 if ( ! markName )
130 { XDEB(markName); return; }
131 appStringToTextWidget( bl->blMarkTextWidget, markName );
132
133 appFreeStringFromListCallback( markName );
134
135 if ( appBufferFromTextWidget( mbChosen, bl->blMarkTextWidget ) )
136 { LDEB(1); }
137 else{ bl->blMarkChosenExists= 1; }
138
139 return;
140 }
141
142