This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/editors/space_spreadsheet/spreadsheet_ops.cc
Hans Goudey 97746129d5 Cleanup: replace UNUSED macro with commented args in C++ code
This is the conventional way of dealing with unused arguments in C++,
since it works on all compilers.

Regex find and replace: `UNUSED\((\w+)\)` -> `/*$1*/`
2022-10-03 17:38:16 -05:00

126 lines
3.6 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BKE_screen.h"
#include "DNA_space_types.h"
#include "ED_screen.h"
#include "BLI_listbase.h"
#include "MEM_guardedalloc.h"
#include "BKE_context.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "WM_api.h"
#include "WM_types.h"
#include "spreadsheet_intern.hh"
#include "spreadsheet_row_filter.hh"
using namespace blender::ed::spreadsheet;
static int row_filter_add_exec(bContext *C, wmOperator * /*op*/)
{
SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C);
SpreadsheetRowFilter *row_filter = spreadsheet_row_filter_new();
BLI_addtail(&sspreadsheet->row_filters, row_filter);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_SPREADSHEET, sspreadsheet);
return OPERATOR_FINISHED;
}
static void SPREADSHEET_OT_add_row_filter_rule(wmOperatorType *ot)
{
ot->name = "Add Row Filter";
ot->description = "Add a filter to remove rows from the displayed data";
ot->idname = "SPREADSHEET_OT_add_row_filter_rule";
ot->exec = row_filter_add_exec;
ot->poll = ED_operator_spreadsheet_active;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int row_filter_remove_exec(bContext *C, wmOperator *op)
{
SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C);
SpreadsheetRowFilter *row_filter = (SpreadsheetRowFilter *)BLI_findlink(
&sspreadsheet->row_filters, RNA_int_get(op->ptr, "index"));
if (row_filter == nullptr) {
return OPERATOR_CANCELLED;
}
BLI_remlink(&sspreadsheet->row_filters, row_filter);
spreadsheet_row_filter_free(row_filter);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_SPREADSHEET, sspreadsheet);
return OPERATOR_FINISHED;
}
static void SPREADSHEET_OT_remove_row_filter_rule(wmOperatorType *ot)
{
ot->name = "Remove Row Filter";
ot->description = "Remove a row filter from the rules";
ot->idname = "SPREADSHEET_OT_remove_row_filter_rule";
ot->exec = row_filter_remove_exec;
ot->poll = ED_operator_spreadsheet_active;
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX);
}
static int select_component_domain_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
{
GeometryComponentType component_type = static_cast<GeometryComponentType>(
RNA_int_get(op->ptr, "component_type"));
eAttrDomain attribute_domain = static_cast<eAttrDomain>(
RNA_int_get(op->ptr, "attribute_domain_type"));
SpaceSpreadsheet *sspreadsheet = CTX_wm_space_spreadsheet(C);
sspreadsheet->geometry_component_type = component_type;
sspreadsheet->attribute_domain = attribute_domain;
/* Refresh header and main region. */
WM_main_add_notifier(NC_SPACE | ND_SPACE_SPREADSHEET, nullptr);
return OPERATOR_FINISHED;
}
static void SPREADSHEET_OT_change_spreadsheet_data_source(wmOperatorType *ot)
{
ot->name = "Change Visible Data Source";
ot->description = "Change visible data source in the spreadsheet";
ot->idname = "SPREADSHEET_OT_change_spreadsheet_data_source";
ot->invoke = select_component_domain_invoke;
RNA_def_int(ot->srna, "component_type", 0, 0, INT16_MAX, "Component Type", "", 0, INT16_MAX);
RNA_def_int(ot->srna,
"attribute_domain_type",
0,
0,
INT16_MAX,
"Attribute Domain Type",
"",
0,
INT16_MAX);
ot->flag = OPTYPE_INTERNAL;
}
void spreadsheet_operatortypes()
{
WM_operatortype_append(SPREADSHEET_OT_add_row_filter_rule);
WM_operatortype_append(SPREADSHEET_OT_remove_row_filter_rule);
WM_operatortype_append(SPREADSHEET_OT_change_spreadsheet_data_source);
}