doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / editors / space_info / info_report.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): Campbell Barton
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <limits.h>
28
29 #include "MEM_guardedalloc.h"
30
31 #include "BLI_blenlib.h"
32 #include "BLI_dynstr.h"
33 #include "BLI_utildefines.h"
34
35 #include "BKE_context.h"
36
37 #include "WM_api.h"
38 #include "WM_types.h"
39
40 #include "ED_screen.h"
41 #include "ED_types.h"
42
43 #include "RNA_access.h"
44 #include "RNA_define.h"
45
46 #include "info_intern.h"
47
48 int info_report_mask(SpaceInfo *UNUSED(sinfo))
49 {
50 #if 0
51         int report_mask = 0;
52
53         if(sinfo->rpt_mask & INFO_RPT_DEBUG)    report_mask |= RPT_DEBUG_ALL;
54         if(sinfo->rpt_mask & INFO_RPT_INFO)             report_mask |= RPT_INFO_ALL;
55         if(sinfo->rpt_mask & INFO_RPT_OP)               report_mask |= RPT_OPERATOR_ALL;
56         if(sinfo->rpt_mask & INFO_RPT_WARN)             report_mask |= RPT_WARNING_ALL;
57         if(sinfo->rpt_mask & INFO_RPT_ERR)              report_mask |= RPT_ERROR_ALL;
58
59         return report_mask;
60 #endif
61
62         return RPT_DEBUG_ALL|RPT_INFO_ALL|RPT_OPERATOR_ALL|RPT_WARNING_ALL|RPT_ERROR_ALL;
63 }
64
65 // TODO, get this working again!
66 static int report_replay_exec(bContext *C, wmOperator *UNUSED(op))
67 {
68 //      SpaceInfo *sc= CTX_wm_space_info(C);
69 //      ReportList *reports= CTX_wm_reports(C);
70 //      int report_mask= info_report_mask(sc);
71 //      Report *report;
72
73 #if 0
74         sc->type= CONSOLE_TYPE_PYTHON;
75
76         for(report=reports->list.last; report; report=report->prev) {
77                 if((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL) && (report->flag & SELECT)) {
78                         console_history_add_str(sc, report->message, 0);
79                         WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
80
81                         ED_area_tag_redraw(CTX_wm_area(C));
82                 }
83         }
84
85         sc->type= CONSOLE_TYPE_REPORT;
86 #endif
87         ED_area_tag_redraw(CTX_wm_area(C));
88
89         return OPERATOR_FINISHED;
90 }
91
92 void INFO_OT_report_replay(wmOperatorType *ot)
93 {
94         /* identifiers */
95         ot->name= "Replay Operators";
96         ot->description= "Replay selected reports";
97         ot->idname= "INFO_OT_report_replay";
98
99         /* api callbacks */
100         ot->poll= ED_operator_info_active;
101         ot->exec= report_replay_exec;
102
103         /* flags */
104         /* ot->flag= OPTYPE_REGISTER; */
105
106         /* properties */
107 }
108
109 static int select_report_pick_exec(bContext *C, wmOperator *op)
110 {
111         int report_index= RNA_int_get(op->ptr, "report_index");
112         Report *report= BLI_findlink(&CTX_wm_reports(C)->list, report_index);
113
114         if(!report)
115                 return OPERATOR_CANCELLED;
116
117         report->flag ^= SELECT; /* toggle */
118
119         ED_area_tag_redraw(CTX_wm_area(C));
120
121         return OPERATOR_FINISHED;
122 }
123
124 static int select_report_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
125 {
126         SpaceInfo *sinfo= CTX_wm_space_info(C);
127         ARegion *ar= CTX_wm_region(C);
128         ReportList *reports= CTX_wm_reports(C);
129         Report *report;
130
131         /* uses opengl */
132         wmSubWindowSet(CTX_wm_window(C), ar->swinid);
133         
134         report= info_text_pick(sinfo, ar, reports, event->mval[1]);
135
136         RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
137
138         return select_report_pick_exec(C, op);
139 }
140
141
142 void INFO_OT_select_pick(wmOperatorType *ot)
143 {
144         /* identifiers */
145         ot->name= "Select report";
146         ot->description= "Select reports by index";
147         ot->idname= "INFO_OT_select_pick";
148
149         /* api callbacks */
150         ot->poll= ED_operator_info_active;
151         ot->invoke= select_report_pick_invoke;
152         ot->exec= select_report_pick_exec;
153
154         /* flags */
155         /* ot->flag= OPTYPE_REGISTER; */
156
157         /* properties */
158         RNA_def_int(ot->srna, "report_index", 0, 0, INT_MAX, "Report", "The index of the report.", 0, INT_MAX);
159 }
160
161
162
163 static int report_select_all_toggle_exec(bContext *C, wmOperator *UNUSED(op))
164 {
165         SpaceInfo *sinfo= CTX_wm_space_info(C);
166         ReportList *reports= CTX_wm_reports(C);
167         int report_mask= info_report_mask(sinfo);
168         int deselect= 0;
169
170         Report *report;
171
172         for(report=reports->list.last; report; report=report->prev) {
173                 if((report->type & report_mask) && (report->flag & SELECT)) {
174                         deselect= 1;
175                         break;
176                 }
177         }
178
179
180         if(deselect) {
181                 for(report=reports->list.last; report; report=report->prev)
182                         if(report->type & report_mask)
183                                 report->flag &= ~SELECT;
184         }
185         else {
186                 for(report=reports->list.last; report; report=report->prev)
187                         if(report->type & report_mask)
188                                 report->flag |= SELECT;
189         }
190
191         ED_area_tag_redraw(CTX_wm_area(C));
192
193         return OPERATOR_FINISHED;
194 }
195
196 void INFO_OT_select_all_toggle(wmOperatorType *ot)
197 {
198         /* identifiers */
199         ot->name= "(De)Select All";
200         ot->description= "(de)select all reports";
201         ot->idname= "INFO_OT_select_all_toggle";
202
203         /* api callbacks */
204         ot->poll= ED_operator_info_active;
205         ot->exec= report_select_all_toggle_exec;
206
207         /* flags */
208         /*ot->flag= OPTYPE_REGISTER;*/
209
210         /* properties */
211 }
212
213 /* borderselect operator */
214 static int borderselect_exec(bContext *C, wmOperator *op)
215 {
216         SpaceInfo *sinfo= CTX_wm_space_info(C);
217         ARegion *ar= CTX_wm_region(C);
218         ReportList *reports= CTX_wm_reports(C);
219         int report_mask= info_report_mask(sinfo);
220         Report *report_min, *report_max, *report;
221
222         //View2D *v2d= UI_view2d_fromcontext(C);
223
224
225         rcti rect;
226         //rctf rectf, rq;
227         short selecting= (RNA_int_get(op->ptr, "gesture_mode")==GESTURE_MODAL_SELECT);
228         //short mval[2];
229
230         rect.xmin= RNA_int_get(op->ptr, "xmin");
231         rect.ymin= RNA_int_get(op->ptr, "ymin");
232         rect.xmax= RNA_int_get(op->ptr, "xmax");
233         rect.ymax= RNA_int_get(op->ptr, "ymax");
234
235         /*
236         mval[0]= rect.xmin;
237         mval[1]= rect.ymin;
238         UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin);
239         mval[0]= rect.xmax;
240         mval[1]= rect.ymax;
241         UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax);
242 */
243
244         report_min= info_text_pick(sinfo, ar, reports, rect.ymax);
245         report_max= info_text_pick(sinfo, ar, reports, rect.ymin);
246
247         /* get the first report if none found */
248         if(report_min==NULL) {
249                 // printf("find_min\n");
250                 for(report=reports->list.first; report; report=report->next) {
251                         if(report->type & report_mask) {
252                                 report_min= report;
253                                 break;
254                         }
255                 }
256         }
257
258         if(report_max==NULL) {
259                 // printf("find_max\n");
260                 for(report=reports->list.last; report; report=report->prev) {
261                         if(report->type & report_mask) {
262                                 report_max= report;
263                                 break;
264                         }
265                 }
266         }
267
268         if(report_min==NULL || report_max==NULL)
269                 return OPERATOR_CANCELLED;
270
271         for(report= report_min; (report != report_max->next); report= report->next) {
272
273                 if((report->type & report_mask)==0)
274                         continue;
275
276                 if(selecting)
277                         report->flag |= SELECT;
278                 else
279                         report->flag &= ~SELECT;
280         }
281
282         ED_area_tag_redraw(CTX_wm_area(C));
283
284         return OPERATOR_FINISHED;
285 }
286
287
288 /* ****** Border Select ****** */
289 void INFO_OT_select_border(wmOperatorType *ot)
290 {
291         /* identifiers */
292         ot->name= "Border Select";
293         ot->description= "Toggle border selection";
294         ot->idname= "INFO_OT_select_border";
295
296         /* api callbacks */
297         ot->invoke= WM_border_select_invoke;
298         ot->exec= borderselect_exec;
299         ot->modal= WM_border_select_modal;
300
301         ot->poll= ED_operator_info_active;
302
303         /* flags */
304         /* ot->flag= OPTYPE_REGISTER; */
305
306         /* rna */
307         WM_operator_properties_gesture_border(ot, FALSE);
308 }
309
310
311
312 static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
313 {
314         SpaceInfo *sinfo= CTX_wm_space_info(C);
315         ReportList *reports= CTX_wm_reports(C);
316         int report_mask= info_report_mask(sinfo);
317
318
319         Report *report, *report_next;
320
321         for(report=reports->list.first; report; ) {
322
323                 report_next=report->next;
324
325                 if((report->type & report_mask) && (report->flag & SELECT)) {
326                         BLI_remlink(&reports->list, report);
327                         MEM_freeN((void *)report->message);
328                         MEM_freeN(report);
329                 }
330
331                 report= report_next;
332         }
333
334         ED_area_tag_redraw(CTX_wm_area(C));
335
336         return OPERATOR_FINISHED;
337 }
338
339 void INFO_OT_report_delete(wmOperatorType *ot)
340 {
341         /* identifiers */
342         ot->name= "Delete Reports";
343         ot->description= "Delete selected reports";
344         ot->idname= "INFO_OT_report_delete";
345
346         /* api callbacks */
347         ot->poll= ED_operator_info_active;
348         ot->exec= report_delete_exec;
349
350         /* flags */
351         /*ot->flag= OPTYPE_REGISTER;*/
352
353         /* properties */
354 }
355
356
357 static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
358 {
359         SpaceInfo *sinfo= CTX_wm_space_info(C);
360         ReportList *reports= CTX_wm_reports(C);
361         int report_mask= info_report_mask(sinfo);
362
363         Report *report;
364
365         DynStr *buf_dyn= BLI_dynstr_new();
366         char *buf_str;
367
368         for(report=reports->list.first; report; report= report->next) {
369                 if((report->type & report_mask) && (report->flag & SELECT)) {
370                         BLI_dynstr_append(buf_dyn, report->message);
371                         BLI_dynstr_append(buf_dyn, "\n");
372                 }
373         }
374
375         buf_str= BLI_dynstr_get_cstring(buf_dyn);
376         BLI_dynstr_free(buf_dyn);
377
378         WM_clipboard_text_set(buf_str, 0);
379
380         MEM_freeN(buf_str);
381         return OPERATOR_FINISHED;
382 }
383
384 void INFO_OT_report_copy(wmOperatorType *ot)
385 {
386         /* identifiers */
387         ot->name= "Copy Reports to Clipboard";
388         ot->description= "Copy selected reports to Clipboard";
389         ot->idname= "INFO_OT_report_copy";
390
391         /* api callbacks */
392         ot->poll= ED_operator_info_active;
393         ot->exec= report_copy_exec;
394
395         /* flags */
396         /*ot->flag= OPTYPE_REGISTER;*/
397
398         /* properties */
399 }