2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2008 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup sptext
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-12-14 14:43:08 +00:00
|
|
|
#include "DNA_windowmanager_types.h"
|
|
|
|
|
|
2025-02-11 16:59:42 +01:00
|
|
|
#include "BLI_listbase.h"
|
2025-01-26 20:08:00 +01:00
|
|
|
#include "BLI_string.h"
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2023-09-25 17:48:21 -04:00
|
|
|
#include "BKE_screen.hh"
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2023-11-30 18:26:53 +01:00
|
|
|
#include "DNA_text_types.h"
|
|
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "ED_screen.hh"
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2023-08-04 23:11:22 +02:00
|
|
|
#include "WM_types.hh"
|
2008-12-14 14:43:08 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
2020-02-03 17:55:13 +11:00
|
|
|
|
2023-06-08 14:00:18 +10:00
|
|
|
#include "text_intern.hh"
|
2008-12-14 14:43:08 +00:00
|
|
|
|
|
|
|
|
/* ************************ header area region *********************** */
|
|
|
|
|
|
2009-03-13 13:38:41 +00:00
|
|
|
/************************** properties ******************************/
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
|
2020-04-03 13:25:03 +02:00
|
|
|
static ARegion *text_has_properties_region(ScrArea *area)
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
{
|
2020-03-06 16:56:42 +01:00
|
|
|
ARegion *region, *arnew;
|
2011-05-20 05:27:31 +00:00
|
|
|
|
2020-04-03 13:25:03 +02:00
|
|
|
region = BKE_area_find_region_type(area, RGN_TYPE_UI);
|
2020-03-06 16:56:42 +01:00
|
|
|
if (region) {
|
|
|
|
|
return region;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
/* add subdiv level; after header */
|
2020-04-03 13:25:03 +02:00
|
|
|
region = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
|
2011-05-20 05:27:31 +00:00
|
|
|
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
/* is error! */
|
2023-06-08 14:00:18 +10:00
|
|
|
if (region == nullptr) {
|
|
|
|
|
return nullptr;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2024-11-15 02:00:11 +01:00
|
|
|
arnew = BKE_area_region_new();
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-04-03 13:25:03 +02:00
|
|
|
BLI_insertlinkafter(&area->regionbase, region, arnew);
|
2012-03-31 04:24:02 +00:00
|
|
|
arnew->regiontype = RGN_TYPE_UI;
|
|
|
|
|
arnew->alignment = RGN_ALIGN_LEFT;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
arnew->flag = RGN_FLAG_HIDDEN;
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
return arnew;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 11:47:00 +02:00
|
|
|
static bool text_properties_poll(bContext *C)
|
2009-08-19 00:55:30 +00:00
|
|
|
{
|
2023-06-08 14:00:18 +10:00
|
|
|
return (CTX_wm_space_text(C) != nullptr);
|
2.5: Text Editor back.
There was very little structure in this code, using many globals
and duplicated code. Now it should be better structured. Most
things should work, the main parts that are not back yet are the
python plugins and markers. Notes:
* Blenfont is used for drawing the text, nicely anti-aliased.
* A monospace truetype font was added, since that is needed for
the text editor. It's Bitstream Vera Sans Mono. This is the
default gnome terminal font, but it doesn't fit entirely well
with the other font I think, can be changed easily of course.
* Clipboard copy/cut/paste now always uses the system clipboard,
the code for the own cut buffer was removed.
* The interface buttons should support copy/cut/paste again now
as well.
* WM_clipboard_text_get/WM_clipboard_text_set were added to the
windowmanager code.
* Find panel is now a kind of second header, instead of a panel.
This needs especially a way to start editing the text field
immediately on open still.
* Operators are independent of the actual space when possible,
was a bit of puzzling but got it solved nice with notifiers,
and some lazy init for syntax highlight in the drawing code.
* RNA was created for the text editor space and used for buttons.
* Operators:
* New, Open, Reload, Save, Save As, Make Internal
* Run Script, Refresh Pyconstraints
* Copy, Cut, Paste
* Convert Whitespace, Uncomment, Comment, Indent, Unindent
* Line Break, Insert
* Next Marker, Previous Marker, Clear All Markers, Mark All
* Select Line, Select All
* Jump, Move, Move Select, Delete, Toggle Overwrite
* Scroll, Scroll Bar, Set Cursor, Line Number
* Find and Replace, Find, Replace, Find Set Selected,
Replace Set Selected
* To 3D Object
* Resolve Conflict
2009-02-28 23:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-08 14:00:18 +10:00
|
|
|
static int text_text_search_exec(bContext *C, wmOperator * /*op*/)
|
2013-03-24 13:43:40 +00:00
|
|
|
{
|
2020-04-03 13:25:03 +02:00
|
|
|
ScrArea *area = CTX_wm_area(C);
|
|
|
|
|
ARegion *region = text_has_properties_region(area);
|
2013-03-24 13:43:40 +00:00
|
|
|
SpaceText *st = CTX_wm_space_text(C);
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
if (region) {
|
2023-11-30 18:26:53 +01:00
|
|
|
Text *text = st->text;
|
|
|
|
|
|
|
|
|
|
/* Use active text selection as search query, if selection is on a single line. */
|
2023-12-01 10:38:37 +11:00
|
|
|
if (text && (text->curl == text->sell) && (text->curc != text->selc)) {
|
|
|
|
|
const ARegion *active_region = CTX_wm_region(C);
|
|
|
|
|
if (active_region && active_region->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
|
const char *sel_start = text->curl->line + std::min(text->curc, text->selc);
|
|
|
|
|
const int sel_len = std::abs(text->curc - text->selc);
|
|
|
|
|
BLI_strncpy(st->findstr, sel_start, std::min(sel_len + 1, ST_MAX_FIND_STR));
|
|
|
|
|
}
|
2023-11-30 18:26:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool draw = false;
|
|
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
if (region->flag & RGN_FLAG_HIDDEN) {
|
|
|
|
|
ED_region_toggle_hidden(C, region);
|
2023-11-30 18:26:53 +01:00
|
|
|
draw = true;
|
2019-04-22 09:19:45 +10:00
|
|
|
}
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2023-11-30 18:26:53 +01:00
|
|
|
const char *active_category = UI_panel_category_active_get(region, false);
|
|
|
|
|
if (active_category && !STREQ(active_category, "Text")) {
|
|
|
|
|
UI_panel_category_active_set(region, "Text");
|
|
|
|
|
draw = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Build the layout and draw so `find_text` text button can be activated. */
|
|
|
|
|
if (draw) {
|
|
|
|
|
ED_region_do_layout(C, region);
|
|
|
|
|
ED_region_do_draw(C, region);
|
|
|
|
|
}
|
2020-02-03 17:55:13 +11:00
|
|
|
|
2023-11-30 18:26:53 +01:00
|
|
|
UI_textbutton_activate_rna(C, region, st, "find_text");
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2020-03-06 16:56:42 +01:00
|
|
|
ED_region_tag_redraw(region);
|
2013-03-24 13:43:40 +00:00
|
|
|
}
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TEXT_OT_start_find(wmOperatorType *ot)
|
|
|
|
|
{
|
|
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Find";
|
|
|
|
|
ot->description = "Start searching text";
|
|
|
|
|
ot->idname = "TEXT_OT_start_find";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-24 13:43:40 +00:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = text_text_search_exec;
|
|
|
|
|
ot->poll = text_properties_poll;
|
|
|
|
|
}
|