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