Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_text/text_ops.c')
-rw-r--r--source/blender/editors/space_text/text_ops.c298
1 files changed, 255 insertions, 43 deletions
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 8f7bd83cbf4..95e7d906b11 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -61,7 +61,9 @@
static void txt_screen_clamp(SpaceText *st, ARegion *ar);
-/************************ util ***************************/
+/* -------------------------------------------------------------------- */
+/** \name Util
+ * \{ */
/**
* Tests if the given character represents a start of a new line or the
@@ -138,14 +140,18 @@ static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size)
return out_buf;
}
-/************************ poll ***************************/
-
BLI_INLINE int text_pixel_x_to_column(SpaceText *st, const int x)
{
/* add half the char width so mouse cursor selection is inbetween letters */
return (x + (st->cwidth / 2)) / st->cwidth;
}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Operator Poll
+ * \{ */
+
static bool text_new_poll(bContext *UNUSED(C))
{
return 1;
@@ -206,7 +212,11 @@ static bool text_region_edit_poll(bContext *C)
return 1;
}
-/********************** updates *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Updates
+ * \{ */
void text_update_line_edited(TextLine *line)
{
@@ -230,7 +240,11 @@ void text_update_edited(Text *text)
}
}
-/******************* new operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name New Operator
+ * \{ */
static int text_new_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -281,7 +295,11 @@ void TEXT_OT_new(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* open operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Open Operator
+ * \{ */
static void text_open_init(bContext *C, wmOperator *op)
{
@@ -392,7 +410,11 @@ void TEXT_OT_open(wmOperatorType *ot)
ot->srna, "internal", 0, "Make internal", "Make text file internal after loading");
}
-/******************* reload operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Reload Operator
+ * \{ */
static int text_reload_exec(bContext *C, wmOperator *op)
{
@@ -443,7 +465,11 @@ void TEXT_OT_reload(wmOperatorType *ot)
ot->poll = text_edit_poll;
}
-/******************* delete operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Delete Operator
+ * \{ */
static bool text_unlink_poll(bContext *C)
{
@@ -495,7 +521,11 @@ void TEXT_OT_unlink(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* make internal operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Make Internal Operator
+ * \{ */
static int text_make_internal_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -529,7 +559,11 @@ void TEXT_OT_make_internal(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* save operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Save Operator
+ * \{ */
static bool text_save_poll(bContext *C)
{
@@ -614,7 +648,11 @@ void TEXT_OT_save(wmOperatorType *ot)
ot->poll = text_save_poll;
}
-/******************* save as operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Save As Operator
+ * \{ */
static int text_save_as_exec(bContext *C, wmOperator *op)
{
@@ -690,7 +728,11 @@ void TEXT_OT_save_as(wmOperatorType *ot)
FILE_SORT_ALPHA); // XXX TODO, relative_path
}
-/******************* run script operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Run Script Operator
+ * \{ */
static bool text_run_script_poll(bContext *C)
{
@@ -765,7 +807,11 @@ void TEXT_OT_run_script(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-/******************* refresh pyconstraints operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Refresh Pyconstraints Operator
+ * \{ */
static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
{
@@ -825,7 +871,11 @@ void TEXT_OT_refresh_pyconstraints(wmOperatorType *ot)
ot->poll = text_edit_poll;
}
-/******************* paste operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Paste Operator
+ * \{ */
static int text_paste_exec(bContext *C, wmOperator *op)
{
@@ -889,7 +939,11 @@ void TEXT_OT_paste(wmOperatorType *ot)
"Paste text selected elsewhere rather than copied (X11 only)");
}
-/**************** duplicate operator *******************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Duplicate Operator
+ * \{ */
static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -924,7 +978,11 @@ void TEXT_OT_duplicate_line(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* copy operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Copy Operator
+ * \{ */
static void txt_copy_clipboard(Text *text)
{
@@ -963,7 +1021,11 @@ void TEXT_OT_copy(wmOperatorType *ot)
ot->poll = text_edit_poll;
}
-/******************* cut operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Cut Operator
+ * \{ */
static int text_cut_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1002,7 +1064,11 @@ void TEXT_OT_cut(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* indent operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Indent Operator
+ * \{ */
static int text_indent_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1043,7 +1109,11 @@ void TEXT_OT_indent(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* unindent operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Unindent Operator
+ * \{ */
static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1079,7 +1149,11 @@ void TEXT_OT_unindent(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* line break operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Line Break Operator
+ * \{ */
static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1132,7 +1206,11 @@ void TEXT_OT_line_break(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* comment operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Comment Operator
+ * \{ */
static int text_comment_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1170,7 +1248,11 @@ void TEXT_OT_comment(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* uncomment operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Uncomment Operator
+ * \{ */
static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1209,7 +1291,55 @@ void TEXT_OT_uncomment(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* convert whitespace operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle-Comment Operator
+ * \{ */
+
+static int text_toggle_comment_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Text *text = CTX_data_edit_text(C);
+
+ if (txt_has_sel(text)) {
+ text_drawcache_tag_update(CTX_wm_space_text(C), 0);
+
+ ED_text_undo_push_init(C);
+
+ txt_order_cursors(text, false);
+ if (txt_uncomment(text) == false) {
+ txt_comment(text);
+ }
+ text_update_edited(text);
+
+ text_update_cursor_moved(C);
+ WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
+
+ return OPERATOR_FINISHED;
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+void TEXT_OT_toggle_comment(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Toggle Comment";
+ ot->idname = "TEXT_OT_toggle_comment";
+
+ /* api callbacks */
+ ot->exec = text_toggle_comment_exec;
+ ot->poll = text_edit_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Convert Whitespace Operator
+ * \{ */
enum { TO_SPACES, TO_TABS };
static const EnumPropertyItem whitespace_type_items[] = {
@@ -1360,7 +1490,11 @@ void TEXT_OT_convert_whitespace(wmOperatorType *ot)
"Type of whitespace to convert to");
}
-/******************* select all operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Select All Operator
+ * \{ */
static int text_select_all_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1386,7 +1520,11 @@ void TEXT_OT_select_all(wmOperatorType *ot)
ot->poll = text_edit_poll;
}
-/******************* select line operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Select Line Operator
+ * \{ */
static int text_select_line_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1412,7 +1550,11 @@ void TEXT_OT_select_line(wmOperatorType *ot)
ot->poll = text_edit_poll;
}
-/******************* select word operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Select Word Operator
+ * \{ */
static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -1441,7 +1583,11 @@ void TEXT_OT_select_word(wmOperatorType *ot)
ot->poll = text_edit_poll;
}
-/********************* move lines operators ***********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Move Lines Operators
+ * \{ */
static int move_lines_exec(bContext *C, wmOperator *op)
{
@@ -1487,7 +1633,11 @@ void TEXT_OT_move_lines(wmOperatorType *ot)
RNA_def_enum(ot->srna, "direction", direction_items, 1, "Direction", "");
}
-/************************ move operator ************************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Move Operator
+ * \{ */
static const EnumPropertyItem move_type_items[] = {
{LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""},
@@ -2126,7 +2276,11 @@ void TEXT_OT_move(wmOperatorType *ot)
RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to");
}
-/******************* move select operator ********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Move Select Operator
+ * \{ */
static int text_move_select_exec(bContext *C, wmOperator *op)
{
@@ -2155,7 +2309,11 @@ void TEXT_OT_move_select(wmOperatorType *ot)
"Where to move cursor to, to make a selection");
}
-/******************* jump operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Jump Operator
+ * \{ */
static int text_jump_exec(bContext *C, wmOperator *op)
{
@@ -2203,7 +2361,11 @@ void TEXT_OT_jump(wmOperatorType *ot)
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_TEXT);
}
-/******************* delete operator **********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Delete Operator
+ * \{ */
static const EnumPropertyItem delete_type_items[] = {
{DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""},
@@ -2317,7 +2479,11 @@ void TEXT_OT_delete(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
-/******************* toggle overwrite operator **********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Toggle Overwrite Operator
+ * \{ */
static int text_toggle_overwrite_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -2342,7 +2508,11 @@ void TEXT_OT_overwrite_toggle(wmOperatorType *ot)
ot->poll = text_space_edit_poll;
}
-/******************* scroll operator **********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Scroll Operator
+ * \{ */
static void txt_screen_clamp(SpaceText *st, ARegion *ar)
{
@@ -2571,7 +2741,11 @@ void TEXT_OT_scroll(wmOperatorType *ot)
ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll", -100, 100);
}
-/******************** scroll bar operator *******************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Scroll Bar Operator
+ * \{ */
static bool text_region_scroll_poll(bContext *C)
{
@@ -3073,7 +3247,11 @@ void TEXT_OT_selection_set(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "select", 0, "Select", "Set selection end rather than cursor");
}
-/******************* set cursor operator **********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Set Cursor Operator
+ * \{ */
static int text_cursor_set_exec(bContext *C, wmOperator *op)
{
@@ -3121,7 +3299,11 @@ void TEXT_OT_cursor_set(wmOperatorType *ot)
RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX);
}
-/******************* line number operator **********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Line Number Operator
+ * \{ */
static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
@@ -3177,7 +3359,11 @@ void TEXT_OT_line_number(wmOperatorType *ot)
ot->poll = text_region_edit_poll;
}
-/******************* insert operator **********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Insert Operator
+ * \{ */
static int text_insert_exec(bContext *C, wmOperator *op)
{
@@ -3284,7 +3470,11 @@ void TEXT_OT_insert(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-/******************* find operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Find Operator
+ * \{ */
/* mode */
#define TEXT_FIND 0
@@ -3378,7 +3568,11 @@ void TEXT_OT_find(wmOperatorType *ot)
ot->poll = text_space_edit_poll;
}
-/******************* replace operator *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Replace Operator
+ * \{ */
static int text_replace_exec(bContext *C, wmOperator *op)
{
@@ -3400,7 +3594,11 @@ void TEXT_OT_replace(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/******************* find set selected *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Find Set Selected
+ * \{ */
static int text_find_set_selected_exec(bContext *C, wmOperator *op)
{
@@ -3431,7 +3629,11 @@ void TEXT_OT_find_set_selected(wmOperatorType *ot)
ot->poll = text_space_edit_poll;
}
-/******************* replace set selected *********************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Replace Set Selected
+ * \{ */
static int text_replace_set_selected_exec(bContext *C, wmOperator *UNUSED(op))
{
@@ -3461,7 +3663,11 @@ void TEXT_OT_replace_set_selected(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
-/****************** resolve conflict operator ******************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Resolve Conflict Operator
+ * \{ */
enum { RESOLVE_IGNORE, RESOLVE_RELOAD, RESOLVE_SAVE, RESOLVE_MAKE_INTERNAL };
static const EnumPropertyItem resolution_items[] = {
@@ -3574,7 +3780,11 @@ void TEXT_OT_resolve_conflict(wmOperatorType *ot)
"How to solve conflict due to differences in internal and external text");
}
-/********************** to 3d object operator *****************/
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name To 3D Object Operator
+ * \{ */
static int text_to_3d_object_exec(bContext *C, wmOperator *op)
{
@@ -3604,3 +3814,5 @@ void TEXT_OT_to_3d_object(wmOperatorType *ot)
RNA_def_boolean(
ot->srna, "split_lines", 0, "Split Lines", "Create one object per line in the text");
}
+
+/** \} */