2011-02-23 10:52:22 +00:00
/*
2008-12-31 17:12:17 +00:00
* $ Id $
*
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
2010-02-12 13:34:04 +00:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2008-12-31 17:12:17 +00:00
*
* Contributor ( s ) : Blender Foundation ( 2008 )
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
2011-02-27 20:20:01 +00:00
/** \file blender/makesrna/intern/rna_text.c
* \ ingroup RNA
*/
2008-12-31 17:12:17 +00:00
# include <stdlib.h>
# include <limits.h>
2009-01-08 13:57:29 +00:00
# include "MEM_guardedalloc.h"
2008-12-31 17:12:17 +00:00
# include "BKE_text.h"
# include "RNA_define.h"
# include "rna_internal.h"
# include "DNA_text_types.h"
2009-03-13 13:38:41 +00:00
# include "WM_types.h"
2008-12-31 17:12:17 +00:00
# ifdef RNA_RUNTIME
2009-04-22 18:39:44 +00:00
int text_file_modified ( Text * text ) ;
2008-12-31 17:12:17 +00:00
static void rna_Text_filename_get ( PointerRNA * ptr , char * value )
{
Text * text = ( Text * ) ptr - > data ;
if ( text - > name )
strcpy ( value , text - > name ) ;
else
strcpy ( value , " " ) ;
}
static int rna_Text_filename_length ( PointerRNA * ptr )
{
Text * text = ( Text * ) ptr - > data ;
return ( text - > name ) ? strlen ( text - > name ) : 0 ;
}
static void rna_Text_filename_set ( PointerRNA * ptr , const char * value )
{
Text * text = ( Text * ) ptr - > data ;
if ( text - > name )
MEM_freeN ( text - > name ) ;
if ( strlen ( value ) )
text - > name = BLI_strdup ( value ) ;
else
text - > name = NULL ;
}
2009-04-22 18:39:44 +00:00
static int rna_Text_modified_get ( PointerRNA * ptr )
{
Text * text = ( Text * ) ptr - > data ;
return text_file_modified ( text ) ;
}
2010-08-11 05:21:43 +00:00
static void rna_TextLine_body_get ( PointerRNA * ptr , char * value )
2008-12-31 17:12:17 +00:00
{
TextLine * line = ( TextLine * ) ptr - > data ;
if ( line - > line )
strcpy ( value , line - > line ) ;
else
strcpy ( value , " " ) ;
}
2010-08-11 05:21:43 +00:00
static int rna_TextLine_body_length ( PointerRNA * ptr )
2008-12-31 17:12:17 +00:00
{
TextLine * line = ( TextLine * ) ptr - > data ;
return line - > len ;
}
2010-08-11 05:21:43 +00:00
static void rna_TextLine_body_set ( PointerRNA * ptr , const char * value )
2008-12-31 17:12:17 +00:00
{
TextLine * line = ( TextLine * ) ptr - > data ;
2010-08-11 05:21:43 +00:00
int len = strlen ( value ) ;
2008-12-31 17:12:17 +00:00
if ( line - > line )
MEM_freeN ( line - > line ) ;
2010-08-11 05:21:43 +00:00
line - > line = MEM_mallocN ( ( len + 1 ) * sizeof ( char ) , " rna_text_body " ) ;
line - > len = len ;
memcpy ( line - > line , value , len + 1 ) ;
2009-03-13 13:38:41 +00:00
if ( line - > format ) {
MEM_freeN ( line - > format ) ;
line - > format = NULL ;
2008-12-31 17:12:17 +00:00
}
}
# else
static void rna_def_text_line ( BlenderRNA * brna )
{
StructRNA * srna ;
PropertyRNA * prop ;
srna = RNA_def_struct ( brna , " TextLine " , NULL ) ;
2010-02-10 21:15:44 +00:00
RNA_def_struct_ui_text ( srna , " Text Line " , " Line of text in a Text datablock " ) ;
2008-12-31 17:12:17 +00:00
2010-08-11 05:21:43 +00:00
prop = RNA_def_property ( srna , " body " , PROP_STRING , PROP_NONE ) ;
RNA_def_property_string_funcs ( prop , " rna_TextLine_body_get " , " rna_TextLine_body_length " , " rna_TextLine_body_set " ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Line " , " Text in the line " ) ;
2009-03-13 13:38:41 +00:00
RNA_def_property_update ( prop , NC_TEXT | NA_EDITED , NULL ) ;
2008-12-31 17:12:17 +00:00
}
static void rna_def_text_marker ( BlenderRNA * brna )
{
StructRNA * srna ;
PropertyRNA * prop ;
srna = RNA_def_struct ( brna , " TextMarker " , NULL ) ;
2010-02-10 21:15:44 +00:00
RNA_def_struct_ui_text ( srna , " Text Marker " , " Marker highlighting a portion of text in a Text datablock " ) ;
2008-12-31 17:12:17 +00:00
prop = RNA_def_property ( srna , " line " , PROP_INT , PROP_UNSIGNED ) ;
RNA_def_property_int_sdna ( prop , NULL , " lineno " ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Line " , " Line in which the marker is located " ) ;
2008-12-31 17:12:17 +00:00
2010-08-19 12:51:31 +00:00
prop = RNA_def_property ( srna , " character_index_start " , PROP_INT , PROP_UNSIGNED ) ;
RNA_def_property_int_sdna ( prop , NULL , " start " ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Start " , " Start position of the marker in the line " ) ;
2008-12-31 17:12:17 +00:00
2010-08-19 12:51:31 +00:00
prop = RNA_def_property ( srna , " character_index_end " , PROP_INT , PROP_UNSIGNED ) ;
RNA_def_property_int_sdna ( prop , NULL , " end " ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " End " , " Start position of the marker in the line " ) ;
2008-12-31 17:12:17 +00:00
prop = RNA_def_property ( srna , " group " , PROP_INT , PROP_UNSIGNED ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_range ( prop , 0 , ( int ) 0xFFFF ) ;
RNA_def_property_ui_text ( prop , " Group " , " " ) ;
2010-08-18 08:26:18 +00:00
prop = RNA_def_property ( srna , " is_temporary " , PROP_BOOLEAN , PROP_NONE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_boolean_sdna ( prop , NULL , " flags " , TMARK_TEMP ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Temporary " , " Marker is temporary " ) ;
2008-12-31 17:12:17 +00:00
2010-08-18 08:26:18 +00:00
prop = RNA_def_property ( srna , " use_edit_all " , PROP_BOOLEAN , PROP_NONE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_boolean_sdna ( prop , NULL , " flags " , TMARK_EDITALL ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Edit All " , " Edit all markers of the same group as one " ) ;
2008-12-31 17:12:17 +00:00
2010-12-31 04:12:20 +00:00
prop = RNA_def_property ( srna , " color " , PROP_FLOAT , PROP_COLOR_GAMMA ) ;
2010-12-14 16:33:04 +00:00
RNA_def_property_range ( prop , 0.0f , 1.0f ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Color " , " Color to display the marker with " ) ;
2008-12-31 17:12:17 +00:00
}
static void rna_def_text ( BlenderRNA * brna )
{
StructRNA * srna ;
PropertyRNA * prop ;
srna = RNA_def_struct ( brna , " Text " , " ID " ) ;
2010-02-10 21:15:44 +00:00
RNA_def_struct_ui_text ( srna , " Text " , " Text datablock referencing an external or packed text file " ) ;
2009-06-03 23:16:51 +00:00
RNA_def_struct_ui_icon ( srna , ICON_TEXT ) ;
2009-05-29 15:12:31 +00:00
RNA_def_struct_clear_flag ( srna , STRUCT_ID_REFCOUNT ) ;
2008-12-31 17:12:17 +00:00
2010-06-02 17:58:28 +00:00
prop = RNA_def_property ( srna , " filepath " , PROP_STRING , PROP_NONE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_string_funcs ( prop , " rna_Text_filename_get " , " rna_Text_filename_length " , " rna_Text_filename_set " ) ;
2010-06-02 17:58:28 +00:00
RNA_def_property_ui_text ( prop , " File Path " , " Filename of the text file " ) ;
2008-12-31 17:12:17 +00:00
2010-08-18 07:14:10 +00:00
prop = RNA_def_property ( srna , " is_dirty " , PROP_BOOLEAN , PROP_NONE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_boolean_sdna ( prop , NULL , " flags " , TXT_ISDIRTY ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Dirty " , " Text file has been edited since last save " ) ;
2008-12-31 17:12:17 +00:00
2010-08-18 07:14:10 +00:00
prop = RNA_def_property ( srna , " is_modified " , PROP_BOOLEAN , PROP_NONE ) ;
2009-04-22 18:39:44 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
RNA_def_property_boolean_funcs ( prop , " rna_Text_modified_get " , NULL ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Modified " , " Text file on disk is different than the one in memory " ) ;
2009-04-22 18:39:44 +00:00
2010-08-18 07:14:10 +00:00
prop = RNA_def_property ( srna , " is_in_memory " , PROP_BOOLEAN , PROP_NONE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_boolean_sdna ( prop , NULL , " flags " , TXT_ISMEM ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Memory " , " Text file is in memory, without a corresponding file on disk " ) ;
2008-12-31 17:12:17 +00:00
2009-11-20 15:01:09 +00:00
prop = RNA_def_property ( srna , " use_module " , PROP_BOOLEAN , PROP_NONE ) ;
RNA_def_property_boolean_sdna ( prop , NULL , " flags " , TXT_ISSCRIPT ) ;
2010-06-11 14:10:02 +00:00
RNA_def_property_ui_text ( prop , " Register " , " Register this text as a module on loading, Text name must end with \" .py \" " ) ;
2009-11-20 15:01:09 +00:00
2010-08-17 13:14:41 +00:00
prop = RNA_def_property ( srna , " use_tabs_as_spaces " , PROP_BOOLEAN , PROP_NONE ) ;
2010-01-14 21:30:51 +00:00
RNA_def_property_boolean_sdna ( prop , NULL , " flags " , TXT_TABSTOSPACES ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Tabs as Spaces " , " Automatically converts all new tabs into spaces " ) ;
2010-01-14 21:30:51 +00:00
2008-12-31 17:12:17 +00:00
prop = RNA_def_property ( srna , " lines " , PROP_COLLECTION , PROP_NONE ) ;
RNA_def_property_struct_type ( prop , " TextLine " ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Lines " , " Lines of text " ) ;
2008-12-31 17:12:17 +00:00
2009-09-16 18:04:01 +00:00
prop = RNA_def_property ( srna , " current_line " , PROP_POINTER , PROP_NONE ) ;
RNA_def_property_flag ( prop , PROP_NEVER_NULL ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_pointer_sdna ( prop , NULL , " curl " ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_struct_type ( prop , " TextLine " ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Current Line " , " Current line, and start line of selection if one exists " ) ;
2008-12-31 17:12:17 +00:00
prop = RNA_def_property ( srna , " current_character " , PROP_INT , PROP_UNSIGNED ) ;
RNA_def_property_int_sdna ( prop , NULL , " curc " ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Current Character " , " Index of current character in current line, and also start index of character in selection if one exists " ) ;
2008-12-31 17:12:17 +00:00
2010-08-18 07:45:32 +00:00
prop = RNA_def_property ( srna , " select_end_line " , PROP_POINTER , PROP_NONE ) ;
2009-09-16 18:04:01 +00:00
RNA_def_property_flag ( prop , PROP_NEVER_NULL ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_pointer_sdna ( prop , NULL , " sell " ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_struct_type ( prop , " TextLine " ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Selection End Line " , " End line of selection " ) ;
2008-12-31 17:12:17 +00:00
2010-08-18 07:45:32 +00:00
prop = RNA_def_property ( srna , " select_end_character " , PROP_INT , PROP_UNSIGNED ) ;
2008-12-31 17:12:17 +00:00
RNA_def_property_int_sdna ( prop , NULL , " selc " ) ;
2009-03-23 13:24:48 +00:00
RNA_def_property_clear_flag ( prop , PROP_EDITABLE ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Selection End Character " , " Index of character after end of selection in the selection end line " ) ;
2008-12-31 17:12:17 +00:00
prop = RNA_def_property ( srna , " markers " , PROP_COLLECTION , PROP_NONE ) ;
RNA_def_property_struct_type ( prop , " TextMarker " ) ;
2010-02-10 21:15:44 +00:00
RNA_def_property_ui_text ( prop , " Markers " , " Text markers highlighting part of the text " ) ;
2009-09-16 06:02:56 +00:00
RNA_api_text ( srna ) ;
2008-12-31 17:12:17 +00:00
}
void RNA_def_text ( BlenderRNA * brna )
{
rna_def_text_line ( brna ) ;
rna_def_text_marker ( brna ) ;
rna_def_text ( brna ) ;
}
# endif