fix: override operator

This commit is contained in:
Fabian 2021-06-14 15:17:07 +02:00
parent bc24525cec
commit 7421511079
2 changed files with 11 additions and 41 deletions

View File

@ -921,24 +921,21 @@ class SessionPresetServerAdd(bpy.types.Operator):
assert(context)
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout
# TODO: menu pour rentrer le nom
# TODO: override en label pour prévenir (icon) si jamais ce nom existe déjà
col = layout.column()
settings = utils.get_preferences()
col.prop(settings, "server_name", text="server name")
def execute(self, context):
assert(context)
settings = utils.get_preferences()
existing_preset = settings.server_preset.get(settings.server_name)
new_server = existing_preset if existing_preset else settings.server_preset.add()
new_server.name = settings.server_name
new_server.server_ip = settings.ip
@ -947,43 +944,14 @@ class SessionPresetServerAdd(bpy.types.Operator):
settings.server_preset_interface = settings.server_name
if new_server == existing_preset :
self.report({'INFO'}, "Server '" + settings.server_name + "' override")
else :
self.report({'INFO'}, "New '" + settings.server_name + "' server preset")
return {'FINISHED'}
# class SessionPresetServerOverwrite(bpy.types.Operator):
# bl_idname = "session.preset_server_overwrite"
# bl_description = "Overwrite the server preset that already has this name" # TODO : or increment the name
# bl_label = "Overwrite server preset ?"
# bl_options = {'REGISTER'}
# @classmethod
# def poll(cls, context):
# return True
# def execute(self, context):
# assert(context)
# settings = utils.get_preferences()
# old_server = settings.server_preset.get(settings.server_name)
# old_server.server_ip = settings.ip
# old_server.server_port = settings.port
# old_server.server_password = settings.password
# settings.server_preset_interface = settings.server_name
# self.report({'INFO'}, "Server overwrite")
# return {'FINISHED'}
# def invoke(self, context, event):
# assert(context)
# settings = utils.get_preferences()
# return context.window_manager.invoke_confirm(self, event)
class SessionPresetServerRemove(bpy.types.Operator):
"""Remove a server to the server list preset"""
bl_idname = "session.preset_server_remove"
@ -1030,7 +998,6 @@ classes = (
SessionPurgeOperator,
SessionPresetServerAdd,
SessionPresetServerRemove,
# SessionPresetServerOverwrite,
)
def update_external_dependencies():

View File

@ -42,7 +42,7 @@ DEFAULT_PRESETS = {
"public session" : {
"server_ip": "51.75.71.183",
"server_port": 5555,
"server_password": "admin"
"server_password": ""
},
}
@ -473,6 +473,9 @@ class SessionPrefs(bpy.types.AddonPreferences):
# custom at launch server preset
def generate_default_presets(self):
for preset_name, preset_data in DEFAULT_PRESETS.items():
existing_preset = self.server_preset.get(preset_name)
if existing_preset :
continue
new_server = self.server_preset.add()
new_server.name = preset_name
new_server.server_ip = preset_data.get('server_ip')