]> git.lyx.org Git - lyx.git/blob - src/insets/insetindex.C
the merge from branch debugstream
[lyx.git] / src / insets / insetindex.C
1 #include <config.h>
2
3 #include <stdlib.h>
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
9 #include FORMS_H_LOCATION  
10 #include "insetindex.h"
11 #include "buffer.h"
12 #include "debug.h"
13 #include "LaTeXFeatures.h"
14 #include "gettext.h"
15 #include "LString.h"
16 #include "lyx_gui_misc.h" // WarnReadonly()
17  
18 extern BufferView *current_view;
19 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
20
21 FD_index_form *index_form = 0;
22
23 static
24 void index_cb(FL_OBJECT *, long data)
25 {
26         InsetIndex *inset = (InsetIndex*)index_form->vdata;
27         
28         switch (data) {
29 // -       case 0: fl_hide_form(index_form->index_form); break;
30 // -       case 1: 
31 // -       {
32 // -               inset->setContents(fl_get_input(index_form->key));
33 // -               fl_hide_form(index_form->index_form);
34 // -               UpdateInset(inset);
35 // -               break;
36 // -       }
37         case 1: // OK
38                 if(!current_view->currentBuffer()->isReadonly()) {
39                         string tmp = fl_get_input(index_form->key);
40                         if(tmp != inset->getContents()) {
41                                 inset->setContents(tmp);
42                                 fl_hide_form(index_form->index_form);
43                                 UpdateInset(inset);
44                                 break;
45                         }
46                 } // fall through to Cancel on RO
47         case 0: // Cancel
48                 fl_hide_form(index_form->index_form); break;
49         }
50 }
51
52
53 static
54 FD_index_form *create_form_index_form()
55 {
56         FL_OBJECT *obj;
57         FD_index_form *fdui = (FD_index_form *) fl_calloc(1, sizeof(FD_index_form));
58
59         fdui->index_form = fl_bgn_form(FL_NO_BOX, 258, 196);
60         obj = fl_add_box(FL_UP_BOX,0,0,258,196,"");
61         fdui->key = obj = fl_add_input(FL_NORMAL_INPUT,93,26,130,30,
62                                        idex(_("Keyword:|#K")));
63           fl_set_object_shortcut(obj,scex(_("Keyword:|#K")),1);
64           fl_set_object_lsize(obj,FL_NORMAL_SIZE);
65         obj = fl_add_button(FL_RETURN_BUTTON,50,140,80,30,_("OK"));
66           obj->u_vdata = index_form;
67           fl_set_object_callback(obj,index_cb,1);
68         obj = fl_add_button(FL_NORMAL_BUTTON,150,140,80,30,
69                             idex(_("Cancel|^[")));
70           fl_set_object_shortcut(obj,scex(_("Cancel|^[")),1);
71           obj->u_vdata = index_form;
72           fl_set_object_callback(obj,index_cb,0);
73         fl_end_form();
74
75         return fdui;
76 }
77
78
79
80 /*---------------------------------------*/
81
82
83 InsetIndex::InsetIndex(string const & key)
84         : InsetCommand("index", key) 
85 {
86 }
87
88
89 InsetIndex::~InsetIndex()
90 {
91         if(index_form && index_form->index_form
92            && index_form->index_form->visible
93            && index_form->vdata == this)
94                 fl_hide_form(index_form->index_form);
95 }
96
97
98 void InsetIndex::Edit(int, int)
99 {
100         if(current_view->currentBuffer()->isReadonly())
101                 WarnReadonly();
102
103         if (!index_form)
104                 index_form = create_form_index_form();
105         
106         index_form->vdata = this;
107         fl_set_input(index_form->key, getContents().c_str());
108         if (index_form->index_form->visible) {
109                 fl_raise_form(index_form->index_form);
110         } else {
111                 fl_show_form(index_form->index_form,
112                              FL_PLACE_MOUSE, FL_FULLBORDER,
113                              _("Index"));
114         }
115 }
116
117
118 string InsetIndex::getScreenLabel() const
119 {
120         return _("Idx");
121 }
122
123
124 //
125 // InsetPrintIndex
126 //
127
128 InsetPrintIndex::InsetPrintIndex()
129         : InsetCommand("printindex")
130 {
131         owner = 0;
132 }
133
134
135 InsetPrintIndex::InsetPrintIndex(Buffer *o)
136         : InsetCommand("printindex"), owner(o)
137 {
138 }
139
140
141 InsetPrintIndex::~InsetPrintIndex()
142 {
143 }
144
145
146 string InsetPrintIndex::getScreenLabel() const
147 {
148         return _("PrintIndex");
149 }
150
151
152 void InsetPrintIndex::Validate(LaTeXFeatures &features) const
153 {
154         features.makeidx = true;
155 }
156
157
158 Inset::Code InsetPrintIndex::LyxCode() const
159 {
160         return Inset::INDEX_CODE;
161 }