def on_scc_import_confirmed(self, *a):
files = self.builder.get_object("lstImportPackage")
new_profile_names = {}
new_menu_names = {}
for enabled, name, importas, trash, obj in files:
if enabled != 0:
if isinstance(obj.obj, Profile):
new_profile_names[name] = importas
elif isinstance(obj.obj, MenuData):
new_menu_names["%s.menu" % (name,)] = "%s.menu" % (importas,)
def apply_replacements(obj):
for a in obj.get_all_actions():
if isinstance(a, ChangeProfileAction):
if a.profile in new_profile_names:
a.profile = new_profile_names[a.profile]
a.parameters = tuple([ a.profile ] + list(a.parameters[1:]))
elif isinstance(a, MenuAction):
if a.menu_id in new_menu_names:
a.menu_id = new_menu_names[a.menu_id]
a.parameters = tuple([ a.menu_id ] + list(a.parameters[1:]))
for enabled, trash, importas, trash, obj in files:
if enabled != 0:
# TODO: update references
if isinstance(obj.obj, Profile):
apply_replacements(obj.obj)
obj.obj.save(os.path.join(get_profiles_path(), "%s.sccprofile" % (importas,)))
elif isinstance(obj.obj, MenuData):
apply_replacements(obj.obj)
jstr = Encoder(sort_keys=True, indent=4).encode(obj.obj)
filename = os.path.join(get_menus_path(), "%s.menu" % (importas,))
open(filename, "w").write(jstr)
trash, trash, importas, trash, obj = files[0] # 1st is always profile that's being imported
self.app.new_profile(obj.obj, importas)
GLib.idle_add(self.window.destroy)
评论列表
文章目录