Blender V4.3
info_report.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <climits>
10#include <cstdlib>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_dynstr.h"
16#include "BLI_utildefines.h"
17
18#include "BKE_context.hh"
19
20#include "WM_api.hh"
21#include "WM_types.hh"
22
23#include "ED_screen.hh"
24#include "ED_select_utils.hh"
25
26#include "RNA_access.hh"
27#include "RNA_define.hh"
28
29#include "info_intern.hh"
30
31static void reports_select_all(ReportList *reports, int report_mask, int action)
32{
33 if (action == SEL_TOGGLE) {
34 action = SEL_SELECT;
35 LISTBASE_FOREACH_BACKWARD (const Report *, report, &reports->list) {
36 if ((report->type & report_mask) && (report->flag & SELECT)) {
37 action = SEL_DESELECT;
38 break;
39 }
40 }
41 }
42
43 LISTBASE_FOREACH_BACKWARD (Report *, report, &reports->list) {
44 if (report->type & report_mask) {
45 switch (action) {
46 case SEL_SELECT:
47 report->flag = SELECT;
48 break;
49 case SEL_DESELECT:
50 report->flag = ~SELECT;
51 break;
52 case SEL_INVERT:
53 report->flag ^= SELECT;
54 break;
55 default:
56 BLI_assert(0);
57 }
58 }
59 }
60}
61
62int info_report_mask(const SpaceInfo * /*sinfo*/)
63{
64#if 0
65 int report_mask = 0;
66
67 if (sinfo->rpt_mask & INFO_RPT_DEBUG) {
68 report_mask |= RPT_DEBUG_ALL;
69 }
70 if (sinfo->rpt_mask & INFO_RPT_INFO) {
71 report_mask |= RPT_INFO_ALL;
72 }
73 if (sinfo->rpt_mask & INFO_RPT_OP) {
74 report_mask |= RPT_OPERATOR_ALL;
75 }
76 if (sinfo->rpt_mask & INFO_RPT_WARN) {
77 report_mask |= RPT_WARNING_ALL;
78 }
79 if (sinfo->rpt_mask & INFO_RPT_ERR) {
80 report_mask |= RPT_ERROR_ALL;
81 }
82
83 return report_mask;
84#endif
85
88}
89
90static int report_replay_exec(bContext *C, wmOperator * /*op*/)
91{
92 /* TODO: get this working again! */
93#if 0
95 ReportList *reports = CTX_wm_reports(C);
96 int report_mask = info_report_mask(sc);
97 Report *report;
98
99 sc->type = CONSOLE_TYPE_PYTHON;
100
101 for (report = reports->list.last; report; report = report->prev) {
102 if ((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) &&
103 (report->flag & SELECT))
104 {
105 console_history_add_str(sc, report->message, 0);
106 WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, nullptr, nullptr);
107
109 }
110 }
111
112 sc->type = CONSOLE_TYPE_REPORT;
113#endif
115
116 return OPERATOR_FINISHED;
117}
118
120{
121 /* identifiers */
122 ot->name = "Replay Operators";
123 ot->description = "Replay selected reports";
124 ot->idname = "INFO_OT_report_replay";
125
126 /* api callbacks */
129
130 /* flags */
131 // ot->flag = OPTYPE_REGISTER;
132
133 /* properties */
134}
135
137{
138 int report_index = RNA_int_get(op->ptr, "report_index");
139 bool extend = RNA_boolean_get(op->ptr, "extend");
140
141 Report *report = static_cast<Report *>(BLI_findlink(&CTX_wm_reports(C)->list, report_index));
142
143 SpaceInfo *sinfo = CTX_wm_space_info(C);
144 ReportList *reports = CTX_wm_reports(C);
145 const int report_mask = info_report_mask(sinfo);
146 if (!report) {
147 return OPERATOR_CANCELLED;
148 }
149
150 if (!extend) {
151 reports_select_all(reports, report_mask, SEL_DESELECT);
152 }
153 report->flag ^= SELECT; /* toggle */
154
156
157 return OPERATOR_FINISHED;
158}
159
160static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
161{
162 SpaceInfo *sinfo = CTX_wm_space_info(C);
163 ARegion *region = CTX_wm_region(C);
164 ReportList *reports = CTX_wm_reports(C);
165 Report *report;
166
167 report = static_cast<Report *>(info_text_pick(sinfo, region, reports, event->mval[1]));
168
169 RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
170
171 return select_report_pick_exec(C, op);
172}
173
175{
176 /* identifiers */
177 ot->name = "Select Report";
178 ot->description = "Select reports by index";
179 ot->idname = "INFO_OT_select_pick";
180
181 /* api callbacks */
185
186 /* flags */
187 // ot->flag = OPTYPE_REGISTER;
188
189 /* properties */
190 PropertyRNA *prop;
192 ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX);
193 prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend report selection");
195}
196
198{
199 SpaceInfo *sinfo = CTX_wm_space_info(C);
200 ReportList *reports = CTX_wm_reports(C);
201 const int report_mask = info_report_mask(sinfo);
202
203 int action = RNA_enum_get(op->ptr, "action");
204 reports_select_all(reports, report_mask, action);
205
207
208 return OPERATOR_FINISHED;
209}
210
212{
213 /* identifiers */
214 ot->name = "(De)select All";
215 ot->description = "Change selection of all visible reports";
216 ot->idname = "INFO_OT_select_all";
217
218 /* api callbacks */
221
222 /* properties */
224}
225
226/* box_select operator */
228{
229 SpaceInfo *sinfo = CTX_wm_space_info(C);
230 ARegion *region = CTX_wm_region(C);
231 ReportList *reports = CTX_wm_reports(C);
232 int report_mask = info_report_mask(sinfo);
233 Report *report_min, *report_max;
234 rcti rect;
235
237
238 const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
239 const int select = (sel_op != SEL_OP_SUB);
240 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
241 LISTBASE_FOREACH (Report *, report, &reports->list) {
242 if ((report->type & report_mask) == 0) {
243 continue;
244 }
245 report->flag &= ~SELECT;
246 }
247 }
248
249 report_min = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymax));
250 report_max = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymin));
251
252 /* get the first report if none found */
253 if (report_min == nullptr) {
254 // printf("find_min\n");
255 LISTBASE_FOREACH (Report *, report, &reports->list) {
256 if (report->type & report_mask) {
257 report_min = report;
258 break;
259 }
260 }
261 }
262
263 if (report_max == nullptr) {
264 // printf("find_max\n");
265 LISTBASE_FOREACH_BACKWARD (Report *, report, &reports->list) {
266 if (report->type & report_mask) {
267 report_max = report;
268 break;
269 }
270 }
271 }
272
273 if (report_min == nullptr || report_max == nullptr) {
274 return OPERATOR_CANCELLED;
275 }
276
277 for (Report *report = report_min; (report != report_max->next); report = report->next) {
278 if ((report->type & report_mask) == 0) {
279 continue;
280 }
281 SET_FLAG_FROM_TEST(report->flag, select, SELECT);
282 }
283
285
286 return OPERATOR_FINISHED;
287}
288
289/* ****** Box Select ****** */
290
292{
293 /* identifiers */
294 ot->name = "Box Select";
295 ot->description = "Toggle box selection";
296 ot->idname = "INFO_OT_select_box";
297
298 /* api callbacks */
303
305
306 /* flags */
307 // ot->flag = OPTYPE_REGISTER;
308
309 /* properties */
312}
313
314static int report_delete_exec(bContext *C, wmOperator * /*op*/)
315{
316 SpaceInfo *sinfo = CTX_wm_space_info(C);
317 ReportList *reports = CTX_wm_reports(C);
318 int report_mask = info_report_mask(sinfo);
319
320 Report *report, *report_next;
321
322 for (report = static_cast<Report *>(reports->list.first); report;) {
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
335
336 return OPERATOR_FINISHED;
337}
338
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 */
349
350 /* flags */
351 // ot->flag = OPTYPE_REGISTER;
352
353 /* properties */
354}
355
356static int report_copy_exec(bContext *C, wmOperator * /*op*/)
357{
358 SpaceInfo *sinfo = CTX_wm_space_info(C);
359 ReportList *reports = CTX_wm_reports(C);
360 int report_mask = info_report_mask(sinfo);
361
362 DynStr *buf_dyn = BLI_dynstr_new();
363 char *buf_str;
364
365 LISTBASE_FOREACH (Report *, report, &reports->list) {
366 if ((report->type & report_mask) && (report->flag & SELECT)) {
367 BLI_dynstr_append(buf_dyn, report->message);
368 BLI_dynstr_append(buf_dyn, "\n");
369 }
370 }
371
372 buf_str = BLI_dynstr_get_cstring(buf_dyn);
373 BLI_dynstr_free(buf_dyn);
374
375 WM_clipboard_text_set(buf_str, false);
376
377 MEM_freeN(buf_str);
378 return OPERATOR_FINISHED;
379}
380
382{
383 /* identifiers */
384 ot->name = "Copy Reports to Clipboard";
385 ot->description = "Copy selected reports to clipboard";
386 ot->idname = "INFO_OT_report_copy";
387
388 /* api callbacks */
391
392 /* flags */
393 // ot->flag = OPTYPE_REGISTER;
394
395 /* properties */
396}
ReportList * CTX_wm_reports(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
SpaceInfo * CTX_wm_space_info(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
#define BLI_assert(a)
Definition BLI_assert.h:50
A dynamically sized string ADT.
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition BLI_dynstr.c:149
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.c:37
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition BLI_dynstr.c:174
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.c:62
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_BACKWARD(type, var, list)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLI_remlink(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:130
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define SET_FLAG_FROM_TEST(value, test, flag)
@ INFO_RPT_INFO
@ INFO_RPT_WARN
@ INFO_RPT_ERR
@ INFO_RPT_OP
@ INFO_RPT_DEBUG
#define RPT_PROPERTY_ALL
#define RPT_ERROR_ALL
#define RPT_INFO_ALL
#define RPT_OPERATOR_ALL
#define RPT_WARNING_ALL
#define RPT_DEBUG_ALL
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:708
bool ED_operator_info_active(bContext *C)
#define SEL_OP_USE_PRE_DESELECT(sel_op)
@ SEL_SELECT
@ SEL_INVERT
@ SEL_DESELECT
@ SEL_TOGGLE
eSelectOp
@ SEL_OP_SUB
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition RNA_types.hh:245
@ WM_OP_EXEC_DEFAULT
Definition WM_types.hh:225
ConsoleLine * console_history_add_str(SpaceConsole *sc, char *str, bool own)
#define SELECT
void * info_text_pick(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports, int mouse_y)
Definition info_draw.cc:205
void INFO_OT_select_all(wmOperatorType *ot)
void INFO_OT_report_copy(wmOperatorType *ot)
void INFO_OT_select_pick(wmOperatorType *ot)
static int box_select_exec(bContext *C, wmOperator *op)
static int report_copy_exec(bContext *C, wmOperator *)
int info_report_mask(const SpaceInfo *)
void INFO_OT_report_replay(wmOperatorType *ot)
static int report_replay_exec(bContext *C, wmOperator *)
void INFO_OT_report_delete(wmOperatorType *ot)
static int report_select_all_exec(bContext *C, wmOperator *op)
static void reports_select_all(ReportList *reports, int report_mask, int action)
static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static int report_delete_exec(bContext *C, wmOperator *)
void INFO_OT_select_box(wmOperatorType *ot)
static int select_report_pick_exec(bContext *C, wmOperator *op)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
ccl_device_inline float4 select(const int4 mask, const float4 a, const float4 b)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void * last
void * first
struct Report * next
struct Report * prev
const char * message
int ymin
int ymax
int mval[2]
Definition WM_types.hh:728
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* modal)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1036
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
void(* cancel)(bContext *C, wmOperator *op)
Definition WM_types.hh:1028
struct PointerRNA * ptr
int WM_operator_name_call(bContext *C, const char *opstring, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
wmOperatorType * ot
Definition wm_files.cc:4125
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
int WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
int WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_operator_properties_border_to_rcti(wmOperator *op, rcti *r_rect)
void WM_operator_properties_gesture_box(wmOperatorType *ot)
void WM_operator_properties_select_operation_simple(wmOperatorType *ot)
void WM_operator_properties_select_action(wmOperatorType *ot, int default_action, bool hide_gui)
void WM_clipboard_text_set(const char *buf, bool selection)