1 /** 2 Version Control System (VCS) interface which reads and writes to the local VCS in use. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.editorvcsinterface; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 /** 24 Version Control System (VCS) interface which reads and writes to the local VCS in use. 25 26 Used by the editor to display VCS extracted information in the editor. The implementation of this API is included in VCS addons, which are essentially GDNative plugins that need to be put into the project folder. These VCS addons are scripts which are attached (on demand) to the object instance of `EditorVCSInterface`. All the functions listed below, instead of performing the task themselves, they call the internally defined functions in the VCS addons to provide a plug-n-play experience. 27 */ 28 @GodotBaseClass struct EditorVCSInterface 29 { 30 package(godot) enum string _GODOT_internal_name = "EditorVCSInterface"; 31 public: 32 @nogc nothrow: 33 union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; } 34 alias _GODOT_base this; 35 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 36 package(godot) __gshared bool _classBindingInitialized = false; 37 package(godot) static struct GDNativeClassBinding 38 { 39 __gshared: 40 @GodotName("_commit") GodotMethod!(void, String) _commit; 41 @GodotName("_get_file_diff") GodotMethod!(Array, String) _getFileDiff; 42 @GodotName("_get_modified_files_data") GodotMethod!(Dictionary) _getModifiedFilesData; 43 @GodotName("_get_project_name") GodotMethod!(String) _getProjectName; 44 @GodotName("_get_vcs_name") GodotMethod!(String) _getVcsName; 45 @GodotName("_initialize") GodotMethod!(bool, String) _initialize; 46 @GodotName("_is_vcs_initialized") GodotMethod!(bool) _isVcsInitialized; 47 @GodotName("_shut_down") GodotMethod!(bool) _shutDown; 48 @GodotName("_stage_file") GodotMethod!(void, String) _stageFile; 49 @GodotName("_unstage_file") GodotMethod!(void, String) _unstageFile; 50 @GodotName("commit") GodotMethod!(void, String) commit; 51 @GodotName("get_file_diff") GodotMethod!(Array, String) getFileDiff; 52 @GodotName("get_modified_files_data") GodotMethod!(Dictionary) getModifiedFilesData; 53 @GodotName("get_project_name") GodotMethod!(String) getProjectName; 54 @GodotName("get_vcs_name") GodotMethod!(String) getVcsName; 55 @GodotName("initialize") GodotMethod!(bool, String) initialize; 56 @GodotName("is_addon_ready") GodotMethod!(bool) isAddonReady; 57 @GodotName("is_vcs_initialized") GodotMethod!(bool) isVcsInitialized; 58 @GodotName("shut_down") GodotMethod!(bool) shutDown; 59 @GodotName("stage_file") GodotMethod!(void, String) stageFile; 60 @GodotName("unstage_file") GodotMethod!(void, String) unstageFile; 61 } 62 /// 63 pragma(inline, true) bool opEquals(in EditorVCSInterface other) const 64 { return _godot_object.ptr is other._godot_object.ptr; } 65 /// 66 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 67 { _godot_object.ptr = n; return null; } 68 /// 69 pragma(inline, true) bool opEquals(typeof(null) n) const 70 { return _godot_object.ptr is n; } 71 /// 72 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 73 mixin baseCasts; 74 /// Construct a new instance of EditorVCSInterface. 75 /// Note: use `memnew!EditorVCSInterface` instead. 76 static EditorVCSInterface _new() 77 { 78 static godot_class_constructor constructor; 79 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("EditorVCSInterface"); 80 if(constructor is null) return typeof(this).init; 81 return cast(EditorVCSInterface)(constructor()); 82 } 83 @disable new(size_t s); 84 /** 85 86 */ 87 void _commit(in String msg) 88 { 89 Array _GODOT_args = Array.make(); 90 _GODOT_args.append(msg); 91 String _GODOT_method_name = String("_commit"); 92 this.callv(_GODOT_method_name, _GODOT_args); 93 } 94 /** 95 96 */ 97 Array _getFileDiff(in String file_path) 98 { 99 Array _GODOT_args = Array.make(); 100 _GODOT_args.append(file_path); 101 String _GODOT_method_name = String("_get_file_diff"); 102 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 103 } 104 /** 105 106 */ 107 Dictionary _getModifiedFilesData() 108 { 109 Array _GODOT_args = Array.make(); 110 String _GODOT_method_name = String("_get_modified_files_data"); 111 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary); 112 } 113 /** 114 115 */ 116 String _getProjectName() 117 { 118 Array _GODOT_args = Array.make(); 119 String _GODOT_method_name = String("_get_project_name"); 120 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 121 } 122 /** 123 124 */ 125 String _getVcsName() 126 { 127 Array _GODOT_args = Array.make(); 128 String _GODOT_method_name = String("_get_vcs_name"); 129 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!String); 130 } 131 /** 132 133 */ 134 bool _initialize(in String project_root_path) 135 { 136 Array _GODOT_args = Array.make(); 137 _GODOT_args.append(project_root_path); 138 String _GODOT_method_name = String("_initialize"); 139 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 140 } 141 /** 142 143 */ 144 bool _isVcsInitialized() 145 { 146 Array _GODOT_args = Array.make(); 147 String _GODOT_method_name = String("_is_vcs_initialized"); 148 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 149 } 150 /** 151 152 */ 153 bool _shutDown() 154 { 155 Array _GODOT_args = Array.make(); 156 String _GODOT_method_name = String("_shut_down"); 157 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool); 158 } 159 /** 160 161 */ 162 void _stageFile(in String file_path) 163 { 164 Array _GODOT_args = Array.make(); 165 _GODOT_args.append(file_path); 166 String _GODOT_method_name = String("_stage_file"); 167 this.callv(_GODOT_method_name, _GODOT_args); 168 } 169 /** 170 171 */ 172 void _unstageFile(in String file_path) 173 { 174 Array _GODOT_args = Array.make(); 175 _GODOT_args.append(file_path); 176 String _GODOT_method_name = String("_unstage_file"); 177 this.callv(_GODOT_method_name, _GODOT_args); 178 } 179 /** 180 Creates a version commit if the addon is initialized, else returns without doing anything. Uses the files which have been staged previously, with the commit message set to a value as provided as in the argument. 181 */ 182 void commit(in String msg) 183 { 184 checkClassBinding!(typeof(this))(); 185 ptrcall!(void)(GDNativeClassBinding.commit, _godot_object, msg); 186 } 187 /** 188 Returns an $(D Array) of $(D Dictionary) objects containing the diff output from the VCS in use, if a VCS addon is initialized, else returns an empty $(D Array) object. The diff contents also consist of some contextual lines which provide context to the observed line change in the file. 189 Each $(D Dictionary) object has the line diff contents under the keys: 190 - `"content"` to store a $(D String) containing the line contents 191 - `"status"` to store a $(D String) which contains `"+"` in case the content is a line addition but it stores a `"-"` in case of deletion and an empty string in the case the line content is neither an addition nor a deletion. 192 - `"new_line_number"` to store an integer containing the new line number of the line content. 193 - `"line_count"` to store an integer containing the number of lines in the line content. 194 - `"old_line_number"` to store an integer containing the old line number of the line content. 195 - `"offset"` to store the offset of the line change since the first contextual line content. 196 */ 197 Array getFileDiff(in String file_path) 198 { 199 checkClassBinding!(typeof(this))(); 200 return ptrcall!(Array)(GDNativeClassBinding.getFileDiff, _godot_object, file_path); 201 } 202 /** 203 Returns a $(D Dictionary) containing the path of the detected file change mapped to an integer signifying what kind of change the corresponding file has experienced. 204 The following integer values are being used to signify that the detected file is: 205 - `0`: New to the VCS working directory 206 - `1`: Modified 207 - `2`: Renamed 208 - `3`: Deleted 209 - `4`: Typechanged 210 */ 211 Dictionary getModifiedFilesData() 212 { 213 checkClassBinding!(typeof(this))(); 214 return ptrcall!(Dictionary)(GDNativeClassBinding.getModifiedFilesData, _godot_object); 215 } 216 /** 217 Returns the project name of the VCS working directory. 218 */ 219 String getProjectName() 220 { 221 checkClassBinding!(typeof(this))(); 222 return ptrcall!(String)(GDNativeClassBinding.getProjectName, _godot_object); 223 } 224 /** 225 Returns the name of the VCS if the VCS has been initialized, else return an empty string. 226 */ 227 String getVcsName() 228 { 229 checkClassBinding!(typeof(this))(); 230 return ptrcall!(String)(GDNativeClassBinding.getVcsName, _godot_object); 231 } 232 /** 233 Initializes the VCS addon if not already. Uses the argument value as the path to the working directory of the project. Creates the initial commit if required. Returns `true` if no failure occurs, else returns `false`. 234 */ 235 bool initialize(in String project_root_path) 236 { 237 checkClassBinding!(typeof(this))(); 238 return ptrcall!(bool)(GDNativeClassBinding.initialize, _godot_object, project_root_path); 239 } 240 /** 241 Returns `true` if the addon is ready to respond to function calls, else returns `false`. 242 */ 243 bool isAddonReady() 244 { 245 checkClassBinding!(typeof(this))(); 246 return ptrcall!(bool)(GDNativeClassBinding.isAddonReady, _godot_object); 247 } 248 /** 249 Returns `true` if the VCS addon has been initialized, else returns `false`. 250 */ 251 bool isVcsInitialized() 252 { 253 checkClassBinding!(typeof(this))(); 254 return ptrcall!(bool)(GDNativeClassBinding.isVcsInitialized, _godot_object); 255 } 256 /** 257 Shuts down the VCS addon to allow cleanup code to run on call. Returns `true` is no failure occurs, else returns `false`. 258 */ 259 bool shutDown() 260 { 261 checkClassBinding!(typeof(this))(); 262 return ptrcall!(bool)(GDNativeClassBinding.shutDown, _godot_object); 263 } 264 /** 265 Stages the file which should be committed when $(D EditorVCSInterface.commit) is called. Argument should contain the absolute path. 266 */ 267 void stageFile(in String file_path) 268 { 269 checkClassBinding!(typeof(this))(); 270 ptrcall!(void)(GDNativeClassBinding.stageFile, _godot_object, file_path); 271 } 272 /** 273 Unstages the file which was staged previously to be committed, so that it is no longer committed when $(D EditorVCSInterface.commit) is called. Argument should contain the absolute path. 274 */ 275 void unstageFile(in String file_path) 276 { 277 checkClassBinding!(typeof(this))(); 278 ptrcall!(void)(GDNativeClassBinding.unstageFile, _godot_object, file_path); 279 } 280 }