forked from kkabt/blendgit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
341 lines (262 loc) · 10 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
''' ##### GNU GPL Version3 #####
BlendGit: Keep track of revisions of blend files in git from blender
Original work Copyright (C) 2012 scorpion81
Modified work Copyright (C) 2020 Kei Kabuto
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 3 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, see <https://www.gnu.org/licenses/>.
'''
bl_info = {
"name": "BlendGit",
"description": "Keep track of revisions of blend files in git from blender",
"author": "scorpion81, Kei Kabuto",
"version": (3, 3, 7),
"blender": (2, 83, 0),
"location": "Topbar / Sidebar -> Git",
"warning": "",
"wiki_url": "",
"tracker_url": "https://github.com/kei-kabuto/blendgit/",
"support": "COMMUNITY",
"category": "User",
}
if "bpy" in locals():
from importlib import reload as _r
_r(props)
_r(ops_main)
_r(ops_extra)
_r(ui)
_r(image_util)
_r(backend_git)
_r(common)
else:
from . import (
props,
ops_main,
ops_extra,
ui,
image_util,
backend_git,
common
)
import bpy
from bpy.props import *
from bpy.app import handlers
import sys
URL_DOCS = "https://git-scm.com/docs"
URL_LOGOS = "https://git-scm.com/downloads/logos"
URL_GITHUB = "https://github.com/"
class CommandShortcut(bpy.types.PropertyGroup):
name: StringProperty()
command: StringProperty()
show_popup: BoolProperty()
need_confirm: BoolProperty()
class GIT_OT_shortcut_add(bpy.types.Operator):
bl_idname="git.shortcut_add"
bl_label="Add Command Shortcut"
bl_description=""
bl_options={'INTERNAL', 'REGISTER', 'UNDO'}
propname: StringProperty()
def execute(self, context):
prefs = common.get_addon_prefs(context)
if hasattr(prefs, self.propname):
coll = getattr(prefs, self.propname)
coll.add()
return {'FINISHED'}
class GIT_OT_shortcut_remove(bpy.types.Operator):
bl_idname="git.shortcut_remove"
bl_label="Remove Command Shortcut"
bl_description=""
bl_options={'INTERNAL', 'REGISTER', 'UNDO'}
propname: StringProperty()
index: IntProperty(default=-1)
def execute(self, context):
if self.index==-1:
return {'CANCELLED'}
prefs = common.get_addon_prefs(context)
if hasattr(prefs, self.propname):
coll = getattr(prefs, self.propname)
coll.remove(self.index)
return {'FINISHED'}
class BlendGitPreferences(bpy.types.AddonPreferences):
bl_idname = __name__
active_tab: EnumProperty(
items=[
('path', "Path", ""),
('log', "Log", ""),
('shortcut', "Shortcuts", ""),
('ui', "UI", ""),
('link', "Link", "")
],
default='path'
)
def update_execpath(self, context):
git = backend_git.Git(context)
gcon = common.get_git_context(context)
if git.operative:
gcon.version = list(git.command(["version"]))[0]
else:
gcon.version = ""
git_execpath: StringProperty(
subtype='FILE_PATH',
update=update_execpath
)
log_commands: CollectionProperty(type=CommandShortcut)
log_command: EnumProperty(
items=lambda s,c: [(cmd.command, cmd.name, "") for cmd in s.log_commands],
update=lambda s,c: ops_main.reload_logs(c)
)
# UI
popup_width: IntProperty(
name="Popup Width",
min=100, max=1000,
default=300
)
thumbnail_extension: EnumProperty(
items=[
('none', "None", ""),
('fill', "Fill", ""),
],
default='none'
)
show_panel_topbar: BoolProperty(default=True, name="Topbar Panel Popup Button")
show_command_topbar: BoolProperty(default=True, name="Topbar Command Popup Button")
show_v3d_panels: BoolProperty(default=True, name="3D View Panels")
# shortcuts
shortcuts: CollectionProperty(type=CommandShortcut)
# archive
archive_dir: StringProperty(
name="Archive Directory",
subtype='DIR_PATH',
description="select: [selected]/<project>/<commit_hash>.zip\nnot select: <project>/archive/<commit_hash>.zip"
)
def draw(self, context):
layout = self.layout
row = layout.row()
row.prop(self, 'active_tab', expand=True)
layout.separator()
tab = self.active_tab
if tab == 'path':
layout.prop(self, "git_execpath", text="git.exe")
layout.prop(self, "archive_dir")
elif tab == 'log':
layout.label(text="Log Commands")
if len(self.log_commands) > 0:
split = layout.split(factor=0.3, align=True)
col_name = split.column()
col_cmd = split.column()
col_name.label(text="Name", translate=False)
col_cmd.label(text="Command", translate=False)
for idx, sc in enumerate(self.log_commands):
col_name.prop(sc, "name", text="")
row = col_cmd.row(align=True)
row.prop(sc, "command", text="")
row.separator()
op = row.operator("git.shortcut_remove", text="", icon="REMOVE")
op.propname = 'log_commands'
op.index = idx
layout.separator()
layout.operator("git.shortcut_add", text="Add Log Command", icon="ADD").propname = 'log_commands'
elif tab == 'shortcut':
layout.label(text="Command Shortcuts")
if len(self.shortcuts) > 0:
split = layout.split(factor=0.3, align=True)
col_name = split.column()
col_cmd = split.column()
col_name.label(text="Name", translate=False)
col_cmd.label(text="Command", translate=False)
for idx, sc in enumerate(self.shortcuts):
col_name.prop(sc, "name", text="")
row = col_cmd.row(align=True)
row.prop(sc, "command", text="")
row.prop(sc, "show_popup", text="", icon='WINDOW', toggle=True)
row.prop(sc, "need_confirm", text="", icon='ERROR', toggle=True)
row.separator()
op = row.operator("git.shortcut_remove", text="", icon="REMOVE")
op.propname = 'shortcuts'
op.index = idx
layout.separator()
layout.operator("git.shortcut_add", text="Add Command Shortcut", icon="ADD").propname = 'shortcuts'
elif tab == 'ui':
layout.use_property_split = True
layout.label(text="Panel", icon='MENU_PANEL')
layout.prop(self, 'show_panel_topbar')
layout.prop(self, 'show_command_topbar')
layout.prop(self, 'show_v3d_panels')
layout.separator()
layout.label(text="Popup", icon='WINDOW')
layout.prop(self, 'popup_width', slider=True)
layout.prop(self, 'thumbnail_extension', text="Thumbnail Extention", expand=True)
elif tab == 'link':
grid = layout.grid_flow(even_columns=True)
grid.operator("wm.url_open", text="Git Documentation", icon='URL').url = URL_DOCS
grid.operator("wm.url_open", text="GitHub", icon='URL').url = URL_GITHUB
layout.separator()
layout.label(text="Credit")
credit = "Icon by Jason Long - Orange logomark for light backgrounds"
val = image_util.get_icon('LOGO')
row = layout.row(align=True)
row.label(text=credit, icon_value=val)
row.operator("wm.url_open", text="", icon='URL').url = URL_LOGOS
classes = (
CommandShortcut,
GIT_OT_shortcut_add,
GIT_OT_shortcut_remove,
BlendGitPreferences,
*props.classes,
*ops_main.classes,
*ops_extra.classes,
*ui.classes,
)
@handlers.persistent
def file_handler(dummy):
bpy.context.window_manager.git_context.rootdir = bpy.path.abspath("//")
bpy.ops.git.reload('INVOKE_DEFAULT')
@handlers.persistent
def data_handler(dummy):
for lib in (bpy.data.textures, bpy.data.images):
for data in lib:
dot, *hs = data.name
if dot=="." and common.extract_hash(hs):
data.user_clear()
_draw_right = None
def draw_right(self, context):
layout = self.layout
prefs = common.get_addon_prefs(context)
row = layout.row(align=True)
if prefs.show_panel_topbar:
row.operator("git.panel_popup", text="", icon_value=image_util.get_icon('LOGO'))
if prefs.show_command_topbar:
row.operator("git.command_popup", text="", icon='CONSOLE')
layout.separator()
_draw_right(self, context)
def register():
image_util.register()
from bpy.utils import register_class
for cls in classes:
register_class(cls)
props.register()
handlers.save_pre.append(data_handler)
handlers.load_post.append(file_handler)
handlers.save_post.append(file_handler)
global _draw_right
_draw_right = bpy.types.TOPBAR_HT_upper_bar.draw_right
bpy.types.TOPBAR_HT_upper_bar.draw_right = draw_right
def unregister():
bpy.types.TOPBAR_HT_upper_bar.draw_right = _draw_right
handlers.save_post.remove(file_handler)
handlers.load_post.remove(file_handler)
handlers.save_pre.remove(data_handler)
props.unregister()
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)
image_util.unregister()
if __name__ == "__main__":
register()