|
Blender
V2.59
|
00001 /* 00002 * $Id: rna_text.c 35238 2011-02-27 20:20:01Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Blender Foundation (2008) 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 #include <stdlib.h> 00031 #include <limits.h> 00032 00033 #include "MEM_guardedalloc.h" 00034 00035 #include "BKE_text.h" 00036 00037 #include "RNA_define.h" 00038 00039 #include "rna_internal.h" 00040 00041 #include "DNA_text_types.h" 00042 00043 #include "WM_types.h" 00044 00045 #ifdef RNA_RUNTIME 00046 00047 int text_file_modified(Text *text); 00048 00049 static void rna_Text_filename_get(PointerRNA *ptr, char *value) 00050 { 00051 Text *text= (Text*)ptr->data; 00052 00053 if(text->name) 00054 strcpy(value, text->name); 00055 else 00056 strcpy(value, ""); 00057 } 00058 00059 static int rna_Text_filename_length(PointerRNA *ptr) 00060 { 00061 Text *text= (Text*)ptr->data; 00062 return (text->name)? strlen(text->name): 0; 00063 } 00064 00065 static void rna_Text_filename_set(PointerRNA *ptr, const char *value) 00066 { 00067 Text *text= (Text*)ptr->data; 00068 00069 if(text->name) 00070 MEM_freeN(text->name); 00071 00072 if(strlen(value)) 00073 text->name= BLI_strdup(value); 00074 else 00075 text->name= NULL; 00076 } 00077 00078 static int rna_Text_modified_get(PointerRNA *ptr) 00079 { 00080 Text *text= (Text*)ptr->data; 00081 return text_file_modified(text); 00082 } 00083 00084 static void rna_TextLine_body_get(PointerRNA *ptr, char *value) 00085 { 00086 TextLine *line= (TextLine*)ptr->data; 00087 00088 if(line->line) 00089 strcpy(value, line->line); 00090 else 00091 strcpy(value, ""); 00092 } 00093 00094 static int rna_TextLine_body_length(PointerRNA *ptr) 00095 { 00096 TextLine *line= (TextLine*)ptr->data; 00097 return line->len; 00098 } 00099 00100 static void rna_TextLine_body_set(PointerRNA *ptr, const char *value) 00101 { 00102 TextLine *line= (TextLine*)ptr->data; 00103 int len= strlen(value); 00104 00105 if(line->line) 00106 MEM_freeN(line->line); 00107 00108 line->line= MEM_mallocN((len + 1) * sizeof(char), "rna_text_body"); 00109 line->len= len; 00110 memcpy(line->line, value, len + 1); 00111 00112 if(line->format) { 00113 MEM_freeN(line->format); 00114 line->format= NULL; 00115 } 00116 } 00117 00118 #else 00119 00120 static void rna_def_text_line(BlenderRNA *brna) 00121 { 00122 StructRNA *srna; 00123 PropertyRNA *prop; 00124 00125 srna = RNA_def_struct(brna, "TextLine", NULL); 00126 RNA_def_struct_ui_text(srna, "Text Line", "Line of text in a Text datablock"); 00127 00128 prop= RNA_def_property(srna, "body", PROP_STRING, PROP_NONE); 00129 RNA_def_property_string_funcs(prop, "rna_TextLine_body_get", "rna_TextLine_body_length", "rna_TextLine_body_set"); 00130 RNA_def_property_ui_text(prop, "Line", "Text in the line"); 00131 RNA_def_property_update(prop, NC_TEXT|NA_EDITED, NULL); 00132 } 00133 00134 static void rna_def_text_marker(BlenderRNA *brna) 00135 { 00136 StructRNA *srna; 00137 PropertyRNA *prop; 00138 00139 srna = RNA_def_struct(brna, "TextMarker", NULL); 00140 RNA_def_struct_ui_text(srna, "Text Marker", "Marker highlighting a portion of text in a Text datablock"); 00141 00142 prop= RNA_def_property(srna, "line", PROP_INT, PROP_UNSIGNED); 00143 RNA_def_property_int_sdna(prop, NULL, "lineno"); 00144 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00145 RNA_def_property_ui_text(prop, "Line", "Line in which the marker is located"); 00146 00147 prop= RNA_def_property(srna, "character_index_start", PROP_INT, PROP_UNSIGNED); 00148 RNA_def_property_int_sdna(prop, NULL, "start"); 00149 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00150 RNA_def_property_ui_text(prop, "Start", "Start position of the marker in the line"); 00151 00152 prop= RNA_def_property(srna, "character_index_end", PROP_INT, PROP_UNSIGNED); 00153 RNA_def_property_int_sdna(prop, NULL, "end"); 00154 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00155 RNA_def_property_ui_text(prop, "End", "Start position of the marker in the line"); 00156 00157 prop= RNA_def_property(srna, "group", PROP_INT, PROP_UNSIGNED); 00158 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00159 RNA_def_property_range(prop, 0, (int)0xFFFF); 00160 RNA_def_property_ui_text(prop, "Group", ""); 00161 00162 prop= RNA_def_property(srna, "is_temporary", PROP_BOOLEAN, PROP_NONE); 00163 RNA_def_property_boolean_sdna(prop, NULL, "flags", TMARK_TEMP); 00164 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00165 RNA_def_property_ui_text(prop, "Temporary", "Marker is temporary"); 00166 00167 prop= RNA_def_property(srna, "use_edit_all", PROP_BOOLEAN, PROP_NONE); 00168 RNA_def_property_boolean_sdna(prop, NULL, "flags", TMARK_EDITALL); 00169 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00170 RNA_def_property_ui_text(prop, "Edit All", "Edit all markers of the same group as one"); 00171 00172 prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA); 00173 RNA_def_property_range(prop, 0.0f, 1.0f); 00174 RNA_def_property_ui_text(prop, "Color", "Color to display the marker with"); 00175 } 00176 00177 static void rna_def_text(BlenderRNA *brna) 00178 { 00179 StructRNA *srna; 00180 PropertyRNA *prop; 00181 00182 srna = RNA_def_struct(brna, "Text", "ID"); 00183 RNA_def_struct_ui_text(srna, "Text", "Text datablock referencing an external or packed text file"); 00184 RNA_def_struct_ui_icon(srna, ICON_TEXT); 00185 RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT); 00186 00187 prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_NONE); 00188 RNA_def_property_string_funcs(prop, "rna_Text_filename_get", "rna_Text_filename_length", "rna_Text_filename_set"); 00189 RNA_def_property_ui_text(prop, "File Path", "Filename of the text file"); 00190 00191 prop= RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE); 00192 RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISDIRTY); 00193 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00194 RNA_def_property_ui_text(prop, "Dirty", "Text file has been edited since last save"); 00195 00196 prop= RNA_def_property(srna, "is_modified", PROP_BOOLEAN, PROP_NONE); 00197 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00198 RNA_def_property_boolean_funcs(prop, "rna_Text_modified_get", NULL); 00199 RNA_def_property_ui_text(prop, "Modified", "Text file on disk is different than the one in memory"); 00200 00201 prop= RNA_def_property(srna, "is_in_memory", PROP_BOOLEAN, PROP_NONE); 00202 RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISMEM); 00203 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00204 RNA_def_property_ui_text(prop, "Memory", "Text file is in memory, without a corresponding file on disk"); 00205 00206 prop= RNA_def_property(srna, "use_module", PROP_BOOLEAN, PROP_NONE); 00207 RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_ISSCRIPT); 00208 RNA_def_property_ui_text(prop, "Register", "Register this text as a module on loading, Text name must end with \".py\""); 00209 00210 prop= RNA_def_property(srna, "use_tabs_as_spaces", PROP_BOOLEAN, PROP_NONE); 00211 RNA_def_property_boolean_sdna(prop, NULL, "flags", TXT_TABSTOSPACES); 00212 RNA_def_property_ui_text(prop, "Tabs as Spaces", "Automatically converts all new tabs into spaces"); 00213 00214 prop= RNA_def_property(srna, "lines", PROP_COLLECTION, PROP_NONE); 00215 RNA_def_property_struct_type(prop, "TextLine"); 00216 RNA_def_property_ui_text(prop, "Lines", "Lines of text"); 00217 00218 prop= RNA_def_property(srna, "current_line", PROP_POINTER, PROP_NONE); 00219 RNA_def_property_flag(prop, PROP_NEVER_NULL); 00220 RNA_def_property_pointer_sdna(prop, NULL, "curl"); 00221 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00222 RNA_def_property_struct_type(prop, "TextLine"); 00223 RNA_def_property_ui_text(prop, "Current Line", "Current line, and start line of selection if one exists"); 00224 00225 prop= RNA_def_property(srna, "current_character", PROP_INT, PROP_UNSIGNED); 00226 RNA_def_property_int_sdna(prop, NULL, "curc"); 00227 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00228 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"); 00229 00230 prop= RNA_def_property(srna, "select_end_line", PROP_POINTER, PROP_NONE); 00231 RNA_def_property_flag(prop, PROP_NEVER_NULL); 00232 RNA_def_property_pointer_sdna(prop, NULL, "sell"); 00233 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00234 RNA_def_property_struct_type(prop, "TextLine"); 00235 RNA_def_property_ui_text(prop, "Selection End Line", "End line of selection"); 00236 00237 prop= RNA_def_property(srna, "select_end_character", PROP_INT, PROP_UNSIGNED); 00238 RNA_def_property_int_sdna(prop, NULL, "selc"); 00239 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00240 RNA_def_property_ui_text(prop, "Selection End Character", "Index of character after end of selection in the selection end line"); 00241 00242 prop= RNA_def_property(srna, "markers", PROP_COLLECTION, PROP_NONE); 00243 RNA_def_property_struct_type(prop, "TextMarker"); 00244 RNA_def_property_ui_text(prop, "Markers", "Text markers highlighting part of the text"); 00245 00246 RNA_api_text(srna); 00247 } 00248 00249 void RNA_def_text(BlenderRNA *brna) 00250 { 00251 rna_def_text_line(brna); 00252 rna_def_text_marker(brna); 00253 rna_def_text(brna); 00254 } 00255 00256 #endif