2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Campbell Barton
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/editors/space_info/info_report.c
32 #include "MEM_guardedalloc.h"
34 #include "BLI_blenlib.h"
35 #include "BLI_dynstr.h"
36 #include "BLI_utildefines.h"
38 #include "BKE_context.h"
43 #include "ED_screen.h"
46 #include "RNA_access.h"
47 #include "RNA_define.h"
49 #include "info_intern.h"
51 int info_report_mask(SpaceInfo *UNUSED(sinfo))
56 if (sinfo->rpt_mask & INFO_RPT_DEBUG) report_mask |= RPT_DEBUG_ALL;
57 if (sinfo->rpt_mask & INFO_RPT_INFO) report_mask |= RPT_INFO_ALL;
58 if (sinfo->rpt_mask & INFO_RPT_OP) report_mask |= RPT_OPERATOR_ALL;
59 if (sinfo->rpt_mask & INFO_RPT_WARN) report_mask |= RPT_WARNING_ALL;
60 if (sinfo->rpt_mask & INFO_RPT_ERR) report_mask |= RPT_ERROR_ALL;
65 return RPT_DEBUG_ALL | RPT_INFO_ALL | RPT_OPERATOR_ALL | RPT_PROPERTY_ALL | RPT_WARNING_ALL | RPT_ERROR_ALL;
68 // TODO, get this working again!
69 static int report_replay_exec(bContext *C, wmOperator *UNUSED(op))
71 // SpaceInfo *sc = CTX_wm_space_info(C);
72 // ReportList *reports = CTX_wm_reports(C);
73 // int report_mask = info_report_mask(sc);
77 sc->type = CONSOLE_TYPE_PYTHON;
79 for (report = reports->list.last; report; report = report->prev) {
80 if ((report->type & report_mask) &&
81 (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) &&
82 (report->flag & SELECT))
84 console_history_add_str(sc, report->message, 0);
85 WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
87 ED_area_tag_redraw(CTX_wm_area(C));
91 sc->type = CONSOLE_TYPE_REPORT;
93 ED_area_tag_redraw(CTX_wm_area(C));
95 return OPERATOR_FINISHED;
98 void INFO_OT_report_replay(wmOperatorType *ot)
101 ot->name = "Replay Operators";
102 ot->description = "Replay selected reports";
103 ot->idname = "INFO_OT_report_replay";
106 ot->poll = ED_operator_info_active;
107 ot->exec = report_replay_exec;
110 /* ot->flag = OPTYPE_REGISTER; */
115 static int select_report_pick_exec(bContext *C, wmOperator *op)
117 int report_index = RNA_int_get(op->ptr, "report_index");
118 Report *report = BLI_findlink(&CTX_wm_reports(C)->list, report_index);
121 return OPERATOR_CANCELLED;
123 report->flag ^= SELECT; /* toggle */
125 ED_area_tag_redraw(CTX_wm_area(C));
127 return OPERATOR_FINISHED;
130 static int select_report_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
132 SpaceInfo *sinfo = CTX_wm_space_info(C);
133 ARegion *ar = CTX_wm_region(C);
134 ReportList *reports = CTX_wm_reports(C);
138 wmSubWindowSet(CTX_wm_window(C), ar->swinid);
140 report = info_text_pick(sinfo, ar, reports, event->mval[1]);
142 RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
144 return select_report_pick_exec(C, op);
148 void INFO_OT_select_pick(wmOperatorType *ot)
151 ot->name = "Select report";
152 ot->description = "Select reports by index";
153 ot->idname = "INFO_OT_select_pick";
156 ot->poll = ED_operator_info_active;
157 ot->invoke = select_report_pick_invoke;
158 ot->exec = select_report_pick_exec;
161 /* ot->flag = OPTYPE_REGISTER; */
164 RNA_def_int(ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX);
169 static int report_select_all_toggle_exec(bContext *C, wmOperator *UNUSED(op))
171 SpaceInfo *sinfo = CTX_wm_space_info(C);
172 ReportList *reports = CTX_wm_reports(C);
173 int report_mask = info_report_mask(sinfo);
178 for (report = reports->list.last; report; report = report->prev) {
179 if ((report->type & report_mask) && (report->flag & SELECT)) {
187 for (report = reports->list.last; report; report = report->prev)
188 if (report->type & report_mask)
189 report->flag &= ~SELECT;
192 for (report = reports->list.last; report; report = report->prev)
193 if (report->type & report_mask)
194 report->flag |= SELECT;
197 ED_area_tag_redraw(CTX_wm_area(C));
199 return OPERATOR_FINISHED;
202 void INFO_OT_select_all_toggle(wmOperatorType *ot)
205 ot->name = "(De)select All";
206 ot->description = "Select or deselect all reports";
207 ot->idname = "INFO_OT_select_all_toggle";
210 ot->poll = ED_operator_info_active;
211 ot->exec = report_select_all_toggle_exec;
214 /*ot->flag = OPTYPE_REGISTER;*/
219 /* borderselect operator */
220 static int borderselect_exec(bContext *C, wmOperator *op)
222 SpaceInfo *sinfo = CTX_wm_space_info(C);
223 ARegion *ar = CTX_wm_region(C);
224 ReportList *reports = CTX_wm_reports(C);
225 int report_mask = info_report_mask(sinfo);
226 int extend = RNA_boolean_get(op->ptr, "extend");
227 Report *report_min, *report_max, *report;
229 //View2D *v2d = UI_view2d_fromcontext(C);
234 short selecting = (RNA_int_get(op->ptr, "gesture_mode") == GESTURE_MODAL_SELECT);
237 WM_operator_properties_border_to_rcti(op, &rect);
242 UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmin, &rectf.ymin);
245 UI_view2d_region_to_view(v2d, mval[0], mval[1], &rectf.xmax, &rectf.ymax);
249 for (report = reports->list.first; report; report = report->next) {
251 if ((report->type & report_mask) == 0)
254 report->flag &= ~SELECT;
258 report_min = info_text_pick(sinfo, ar, reports, rect.ymax);
259 report_max = info_text_pick(sinfo, ar, reports, rect.ymin);
261 /* get the first report if none found */
262 if (report_min == NULL) {
263 // printf("find_min\n");
264 for (report = reports->list.first; report; report = report->next) {
265 if (report->type & report_mask) {
272 if (report_max == NULL) {
273 // printf("find_max\n");
274 for (report = reports->list.last; report; report = report->prev) {
275 if (report->type & report_mask) {
282 if (report_min == NULL || report_max == NULL)
283 return OPERATOR_CANCELLED;
285 for (report = report_min; (report != report_max->next); report = report->next) {
287 if ((report->type & report_mask) == 0)
291 report->flag |= SELECT;
293 report->flag &= ~SELECT;
296 ED_area_tag_redraw(CTX_wm_area(C));
298 return OPERATOR_FINISHED;
302 /* ****** Border Select ****** */
303 void INFO_OT_select_border(wmOperatorType *ot)
306 ot->name = "Border Select";
307 ot->description = "Toggle border selection";
308 ot->idname = "INFO_OT_select_border";
311 ot->invoke = WM_border_select_invoke;
312 ot->exec = borderselect_exec;
313 ot->modal = WM_border_select_modal;
314 ot->cancel = WM_border_select_cancel;
316 ot->poll = ED_operator_info_active;
319 /* ot->flag = OPTYPE_REGISTER; */
322 WM_operator_properties_gesture_border(ot, TRUE);
327 static int report_delete_exec(bContext *C, wmOperator *UNUSED(op))
329 SpaceInfo *sinfo = CTX_wm_space_info(C);
330 ReportList *reports = CTX_wm_reports(C);
331 int report_mask = info_report_mask(sinfo);
334 Report *report, *report_next;
336 for (report = reports->list.first; report; ) {
338 report_next = report->next;
340 if ((report->type & report_mask) && (report->flag & SELECT)) {
341 BLI_remlink(&reports->list, report);
342 MEM_freeN((void *)report->message);
346 report = report_next;
349 ED_area_tag_redraw(CTX_wm_area(C));
351 return OPERATOR_FINISHED;
354 void INFO_OT_report_delete(wmOperatorType *ot)
357 ot->name = "Delete Reports";
358 ot->description = "Delete selected reports";
359 ot->idname = "INFO_OT_report_delete";
362 ot->poll = ED_operator_info_active;
363 ot->exec = report_delete_exec;
366 /*ot->flag = OPTYPE_REGISTER;*/
372 static int report_copy_exec(bContext *C, wmOperator *UNUSED(op))
374 SpaceInfo *sinfo = CTX_wm_space_info(C);
375 ReportList *reports = CTX_wm_reports(C);
376 int report_mask = info_report_mask(sinfo);
380 DynStr *buf_dyn = BLI_dynstr_new();
383 for (report = reports->list.first; report; report = report->next) {
384 if ((report->type & report_mask) && (report->flag & SELECT)) {
385 BLI_dynstr_append(buf_dyn, report->message);
386 BLI_dynstr_append(buf_dyn, "\n");
390 buf_str = BLI_dynstr_get_cstring(buf_dyn);
391 BLI_dynstr_free(buf_dyn);
393 WM_clipboard_text_set(buf_str, 0);
396 return OPERATOR_FINISHED;
399 void INFO_OT_report_copy(wmOperatorType *ot)
402 ot->name = "Copy Reports to Clipboard";
403 ot->description = "Copy selected reports to Clipboard";
404 ot->idname = "INFO_OT_report_copy";
407 ot->poll = ED_operator_info_active;
408 ot->exec = report_copy_exec;
411 /*ot->flag = OPTYPE_REGISTER;*/