Blender V5.0
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
8
9#include <climits>
10#include <cstdlib>
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_dynstr.h"
16#include "BLI_listbase.h"
17#include "BLI_utildefines.h"
18
19#include "BKE_context.hh"
20
21#include "WM_api.hh"
22#include "WM_types.hh"
23
24#include "ED_screen.hh"
25#include "ED_select_utils.hh"
26
27#include "RNA_access.hh"
28#include "RNA_define.hh"
29
30#include "info_intern.hh"
31
32static void reports_select_all(ReportList *reports, int report_mask, int action)
33{
34 if (action == SEL_TOGGLE) {
35 action = SEL_SELECT;
36 LISTBASE_FOREACH_BACKWARD (const Report *, report, &reports->list) {
37 if ((report->type & report_mask) && (report->flag & SELECT)) {
38 action = SEL_DESELECT;
39 break;
40 }
41 }
42 }
43
44 LISTBASE_FOREACH_BACKWARD (Report *, report, &reports->list) {
45 if (report->type & report_mask) {
46 switch (action) {
47 case SEL_SELECT:
48 report->flag = SELECT;
49 break;
50 case SEL_DESELECT:
51 report->flag = ~SELECT;
52 break;
53 case SEL_INVERT:
54 report->flag ^= SELECT;
55 break;
56 default:
57 BLI_assert(0);
58 }
59 }
60 }
61}
62
63int info_report_mask(const SpaceInfo * /*sinfo*/)
64{
65#if 0
66 int report_mask = 0;
67
68 if (sinfo->rpt_mask & INFO_RPT_DEBUG) {
69 report_mask |= RPT_DEBUG_ALL;
70 }
71 if (sinfo->rpt_mask & INFO_RPT_INFO) {
72 report_mask |= RPT_INFO_ALL;
73 }
74 if (sinfo->rpt_mask & INFO_RPT_OP) {
75 report_mask |= RPT_OPERATOR_ALL;
76 }
77 if (sinfo->rpt_mask & INFO_RPT_WARN) {
78 report_mask |= RPT_WARNING_ALL;
79 }
80 if (sinfo->rpt_mask & INFO_RPT_ERR) {
81 report_mask |= RPT_ERROR_ALL;
82 }
83
84 return report_mask;
85#endif
86
89}
90
92{
93 /* TODO: get this working again! */
94#if 0
96 ReportList *reports = CTX_wm_reports(C);
97 int report_mask = info_report_mask(sc);
98 Report *report;
99
100 sc->type = CONSOLE_TYPE_PYTHON;
101
102 for (report = reports->list.last; report; report = report->prev) {
103 if ((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) &&
104 (report->flag & SELECT))
105 {
106 console_history_add_str(sc, report->message, 0);
107 WM_operator_name_call(C, "CONSOLE_OT_execute", blender::wm::OpCallContext::ExecDefault, nullptr, nullptr);
108
110 }
111 }
112
113 sc->type = CONSOLE_TYPE_REPORT;
114#endif
116
117 return OPERATOR_FINISHED;
118}
119
121{
122 /* identifiers */
123 ot->name = "Replay Operators";
124 ot->description = "Replay selected reports";
125 ot->idname = "INFO_OT_report_replay";
126
127 /* API callbacks. */
129 ot->exec = report_replay_exec;
130
131 /* flags */
132 // ot->flag = OPTYPE_REGISTER;
133
134 /* properties */
135}
136
138{
139 int report_index = RNA_int_get(op->ptr, "report_index");
140 bool extend = RNA_boolean_get(op->ptr, "extend");
141
142 Report *report = static_cast<Report *>(BLI_findlink(&CTX_wm_reports(C)->list, report_index));
143
144 SpaceInfo *sinfo = CTX_wm_space_info(C);
145 ReportList *reports = CTX_wm_reports(C);
146 const int report_mask = info_report_mask(sinfo);
147 if (!report) {
148 return OPERATOR_CANCELLED;
149 }
150
151 if (!extend) {
152 reports_select_all(reports, report_mask, SEL_DESELECT);
153 }
154 report->flag ^= SELECT; /* toggle */
155
157
158 return OPERATOR_FINISHED;
159}
160
162 wmOperator *op,
163 const wmEvent *event)
164{
165 SpaceInfo *sinfo = CTX_wm_space_info(C);
166 ARegion *region = CTX_wm_region(C);
167 ReportList *reports = CTX_wm_reports(C);
168 Report *report;
169
170 report = static_cast<Report *>(info_text_pick(sinfo, region, reports, event->mval[1]));
171
172 RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
173
174 return select_report_pick_exec(C, op);
175}
176
178{
179 /* identifiers */
180 ot->name = "Select Report";
181 ot->description = "Select reports by index";
182 ot->idname = "INFO_OT_select_pick";
183
184 /* API callbacks. */
188
189 /* flags */
190 // ot->flag = OPTYPE_REGISTER;
191
192 /* properties */
193 PropertyRNA *prop;
195 ot->srna, "report_index", 0, 0, INT_MAX, "Report", "Index of the report", 0, INT_MAX);
196 prop = RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend report selection");
198}
199
201{
202 SpaceInfo *sinfo = CTX_wm_space_info(C);
203 ReportList *reports = CTX_wm_reports(C);
204 const int report_mask = info_report_mask(sinfo);
205
206 int action = RNA_enum_get(op->ptr, "action");
207 reports_select_all(reports, report_mask, action);
208
210
211 return OPERATOR_FINISHED;
212}
213
215{
216 /* identifiers */
217 ot->name = "(De)select All";
218 ot->description = "Change selection of all visible reports";
219 ot->idname = "INFO_OT_select_all";
220
221 /* API callbacks. */
224
225 /* properties */
227}
228
229/* box_select operator */
231{
232 SpaceInfo *sinfo = CTX_wm_space_info(C);
233 ARegion *region = CTX_wm_region(C);
234 ReportList *reports = CTX_wm_reports(C);
235 int report_mask = info_report_mask(sinfo);
236 Report *report_min, *report_max;
237 rcti rect;
238
240
241 const eSelectOp sel_op = eSelectOp(RNA_enum_get(op->ptr, "mode"));
242 const int select = (sel_op != SEL_OP_SUB);
243 if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
244 LISTBASE_FOREACH (Report *, report, &reports->list) {
245 if ((report->type & report_mask) == 0) {
246 continue;
247 }
248 report->flag &= ~SELECT;
249 }
250 }
251
252 report_min = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymax));
253 report_max = static_cast<Report *>(info_text_pick(sinfo, region, reports, rect.ymin));
254
255 /* get the first report if none found */
256 if (report_min == nullptr) {
257 // printf("find_min\n");
258 LISTBASE_FOREACH (Report *, report, &reports->list) {
259 if (report->type & report_mask) {
260 report_min = report;
261 break;
262 }
263 }
264 }
265
266 if (report_max == nullptr) {
267 // printf("find_max\n");
268 LISTBASE_FOREACH_BACKWARD (Report *, report, &reports->list) {
269 if (report->type & report_mask) {
270 report_max = report;
271 break;
272 }
273 }
274 }
275
276 if (report_min == nullptr || report_max == nullptr) {
277 return OPERATOR_CANCELLED;
278 }
279
280 for (Report *report = report_min; (report != report_max->next); report = report->next) {
281 if ((report->type & report_mask) == 0) {
282 continue;
283 }
284 SET_FLAG_FROM_TEST(report->flag, select, SELECT);
285 }
286
288
289 return OPERATOR_FINISHED;
290}
291
292/* ****** Box Select ****** */
293
295{
296 /* identifiers */
297 ot->name = "Box Select";
298 ot->description = "Toggle box selection";
299 ot->idname = "INFO_OT_select_box";
300
301 /* API callbacks. */
302 ot->invoke = WM_gesture_box_invoke;
303 ot->exec = box_select_exec;
304 ot->modal = WM_gesture_box_modal;
305 ot->cancel = WM_gesture_box_cancel;
306
308
309 /* flags */
310 // ot->flag = OPTYPE_REGISTER;
311
312 /* properties */
315}
316
318{
319 SpaceInfo *sinfo = CTX_wm_space_info(C);
320 ReportList *reports = CTX_wm_reports(C);
321 int report_mask = info_report_mask(sinfo);
322
323 Report *report, *report_next;
324
325 for (report = static_cast<Report *>(reports->list.first); report;) {
326 report_next = report->next;
327
328 if ((report->type & report_mask) && (report->flag & SELECT)) {
329 BLI_remlink(&reports->list, report);
330 MEM_freeN(report->message);
331 MEM_freeN(report);
332 }
333
334 report = report_next;
335 }
336
338
339 return OPERATOR_FINISHED;
340}
341
343{
344 /* identifiers */
345 ot->name = "Delete Reports";
346 ot->description = "Delete selected reports";
347 ot->idname = "INFO_OT_report_delete";
348
349 /* API callbacks. */
351 ot->exec = report_delete_exec;
352
353 /* flags */
354 // ot->flag = OPTYPE_REGISTER;
355
356 /* properties */
357}
358
360{
361 SpaceInfo *sinfo = CTX_wm_space_info(C);
362 ReportList *reports = CTX_wm_reports(C);
363 int report_mask = info_report_mask(sinfo);
364
365 DynStr *buf_dyn = BLI_dynstr_new();
366 char *buf_str;
367
368 LISTBASE_FOREACH (Report *, report, &reports->list) {
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, false);
379
380 MEM_freeN(buf_str);
381 return OPERATOR_FINISHED;
382}
383
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. */
393 ot->exec = report_copy_exec;
394
395 /* flags */
396 // ot->flag = OPTYPE_REGISTER;
397
398 /* properties */
399}
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 RPT_PROPERTY_ALL
Definition BKE_report.hh:49
#define RPT_ERROR_ALL
Definition BKE_report.hh:51
#define RPT_INFO_ALL
Definition BKE_report.hh:47
#define RPT_OPERATOR_ALL
Definition BKE_report.hh:48
#define RPT_WARNING_ALL
Definition BKE_report.hh:50
#define RPT_DEBUG_ALL
Definition BKE_report.hh:46
#define BLI_assert(a)
Definition BLI_assert.h:46
A dynamically sized string ADT.
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.cc:37
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.cc:56
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:534
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_BACKWARD(type, var, list)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
#define SET_FLAG_FROM_TEST(value, test, flag)
@ INFO_RPT_INFO
@ INFO_RPT_WARN
@ INFO_RPT_ERR
@ INFO_RPT_OP
@ INFO_RPT_DEBUG
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:693
bool ED_operator_info_active(bContext *C)
eSelectOp
@ SEL_OP_SUB
@ SEL_SELECT
@ SEL_INVERT
@ SEL_DESELECT
@ SEL_TOGGLE
#define SEL_OP_USE_PRE_DESELECT(sel_op)
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition RNA_types.hh:344
#define C
Definition RandGen.cpp:29
ConsoleLine * console_history_add_str(SpaceConsole *sc, char *str, bool own)
#define SELECT
#define select(A, B, C)
void * info_text_pick(const SpaceInfo *sinfo, const ARegion *region, const ReportList *reports, int mouse_y)
Definition info_draw.cc:201
static wmOperatorStatus box_select_exec(bContext *C, wmOperator *op)
void INFO_OT_select_all(wmOperatorType *ot)
void INFO_OT_report_copy(wmOperatorType *ot)
void INFO_OT_select_pick(wmOperatorType *ot)
int info_report_mask(const SpaceInfo *)
void INFO_OT_report_replay(wmOperatorType *ot)
void INFO_OT_report_delete(wmOperatorType *ot)
static void reports_select_all(ReportList *reports, int report_mask, int action)
static wmOperatorStatus report_delete_exec(bContext *C, wmOperator *)
static wmOperatorStatus report_select_all_exec(bContext *C, wmOperator *op)
static wmOperatorStatus report_replay_exec(bContext *C, wmOperator *)
static wmOperatorStatus select_report_pick_exec(bContext *C, wmOperator *op)
static wmOperatorStatus report_copy_exec(bContext *C, wmOperator *)
static wmOperatorStatus select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void INFO_OT_select_box(wmOperatorType *ot)
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
static wmOperatorStatus box_select_exec(bContext *C, wmOperator *op)
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
ListBase list
Definition BKE_report.hh:75
Report * prev
Definition BKE_report.hh:64
short flag
Definition BKE_report.hh:67
short type
Definition BKE_report.hh:66
const char * message
Definition BKE_report.hh:71
Report * next
Definition BKE_report.hh:64
int ymin
int ymax
int mval[2]
Definition WM_types.hh:763
struct PointerRNA * ptr
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, blender::wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
wmOperatorType * ot
Definition wm_files.cc:4237
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_gesture_box_invoke(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)