indexing description: "[ EiffelMedia Settings Generator ]" date: "$Date$" revision: "$Revision$" class EM_SETTINGS_GENERATOR inherit EM_CLASS_GENERATOR redefine process_additional_parameters end create make feature -- Generator process_additional_parameters is -- check for additional command line arguments and process them do if arguments.index_of_word_option ("-no-widgets") /= 0 then no_widgets := true end end generate_classes is -- generate the classes and write the files do io.put_string ("Generating settings class...%N") generate_main_class if not has_error and not no_singleton then io.put_string ("Generating shared settings class...%N") generate_shared_class end if not has_error then io.put_string ("Writing " + main_class_name + ".e...%N") write_main_file end if not has_error and not no_singleton then io.put_string ("Writing " + shared_class_name + ".e...%N") write_shared_file end if not has_error then io.put_string ("Success%N") end end generate_main_class is -- Generate code for settings class do main_class_content := "" main_class_content.append_string(header_code) main_class_content.append_string ("feature -- Initialization%N%N") main_class_content.append_string (make_code) main_class_content.append_string ("feature -- Attributes%N%N") main_class_content.append_string (attribute_code) main_class_content.append_string ("feature -- Defaults%N%N") main_class_content.append_string (defaults_code) main_class_content.append_string (restore_defaults_code) main_class_content.append_string ("feature -- Element change%N%N") main_class_content.append_string (setter_code) main_class_content.append_string ("feature -- User settings%N%N") main_class_content.append_string (set_user_file_code) main_class_content.append_string(file_attribute_code) main_class_content.append_string (write_user_settings_code) main_class_content.append_string (read_user_settings_code) if not no_widgets then main_class_content.append_string ("feature -- Widgets%N%N") main_class_content.append_string (widgets_attribute_code) main_class_content.append_string (create_widgets_code) main_class_content.append_string(free_widgets_code) main_class_content.append_string (apply_settings_code) main_class_content.append_string (reset_widgets_code) main_class_content.append_string (created_bools_code) end main_class_content.append_string (footer_code) end generate_shared_class is -- Generate code for shared settings class do create shared_class_content.make_empty shared_class_content.append_string ("indexing%N%N") shared_class_content.append_string (" description: %"[%N%N") shared_class_content.append_string (do_not_edit_message) shared_class_content.append_string ("%N%N") shared_class_content.append_string ("%T%TSettings singleton%N%N") shared_class_content.append_string ("%T]%"%N") shared_class_content.append_string ("%Tdate: %"$Date$%"%N") shared_class_content.append_string ("%Trevision: %"$Revision$%"") shared_class_content.append_string ("%N%N") shared_class_content.append_string ("class%N") shared_class_content.append_string ("%T" + shared_class_name.as_upper + "%N%N") shared_class_content.append_string ("feature -- Initialization%N%N") shared_class_content.append_string ("%T" + main_class_name.as_lower + ": " + main_class_name.as_upper + " is%N") shared_class_content.append_string("%T%T%T-- Shared settings%N") shared_class_content.append_string ("%T%Tindexing%N") shared_class_content.append_string ("%T%T%Tonce_status: global%N") shared_class_content.append_string ("%T%Tonce%N") shared_class_content.append_string ("%T%T%Tcreate Result.make%N") shared_class_content.append_string("%T%Tend%N%N") shared_class_content.append_string ("end%N") end feature -- Code header_code: STRING is require not has_error do create Result.make_empty Result.append_string ("indexing%N%N") Result.append_string (" description: %"[%N%N") Result.append_string (do_not_edit_message) Result.append_string ("%N%N") Result.append_string ("%T%TSettings that can be accessed, modified, loaded and saved%N%N") Result.append_string ("%T]%"%N") Result.append_string ("%Tdate: %"$Date$%"%N") Result.append_string ("%Trevision: %"$Revision$%"") Result.append_string ("%N%N") Result.append_string ("class%N") Result.append_string ("%T" + main_class_name.as_upper + "%N%N") Result.append_string ("inherit%N") Result.append_string ("%TXM_CALLBACKS_FILTER_FACTORY%N") Result.append_string ("%Texport {NONE} all end%N%N") Result.append_string ("%TEM_SHARED_USER_DIRECTORY%N") Result.append_string ("%Texport {NONE} all end%N%N") Result.append_string ("%TEM_SHARED_APPLICATION_ID%N%N") Result.append_string ("creation%N%Tmake%N%N") end footer_code: STRING is require not has_error do Result := "" Result.append_string ("end%N") end make_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name: STRING do Result := "" Result.append_string ("%Tmake is%N") Result.append_string ("%T%Trequire%N") Result.append_string ("%T%T%Tapplication_id_set: application_id.item /= void%N") Result.append_string ("%T%Tdo%N") Result.append_string ("%T%T%Tset_user_file (user_directory.item, application_id.item + %"_" + main_class_name + ".xml%")%N%N") -- Initialization from xml_table.start until xml_table.after loop Result.append_string ("%T%T%T-- Inits for Section: " + xml_table.key_for_iteration + "%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration -- Set all Values to their defaults check_for_attributes (<<"name">>, current_entry) if attributes_ok then a_name := current_entry.item ("name") if current_entry.item("type").as_lower.is_equal ("string") then Result.append_string("%T%T%T" + a_name + " := " + defaults_prefix + a_name +defaults_postfix + ".out%N") else Result.append_string("%T%T%T" + a_name + " := " + defaults_prefix + a_name +defaults_postfix + "%N") end end xml_table.item_for_iteration.forth end Result.append_string ("%N") xml_table.forth end Result.append_string ("%T%Tend%N%N") end feature -- Attributes code attribute_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_type: STRING do Result := "" -- Attributes from xml_table.start until xml_table.after loop Result.append_string ("%T-- Attributes for Section: " + xml_table.key_for_iteration + "%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration check_for_attributes (<<"name", "type">>, current_entry) if attributes_ok then a_name := current_entry.item("name") a_type := current_entry.item("type") -- todo Result.append_string("%T" + a_name + ": " + a_type.as_upper + "%N") end xml_table.item_for_iteration.forth end Result.append_string ("%N") xml_table.forth end end setter_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_type: STRING do Result := "" -- Value Setters from xml_table.start until xml_table.after loop Result.append_string ("%T-- Setter for Section: " + xml_table.key_for_iteration + "%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration check_for_attributes (<<"name", "type">>, current_entry) if attributes_ok then a_name := current_entry.item("name") a_type := current_entry.item("type") Result.append_string("%Tset_" + a_name + " (val: " + a_type.as_upper + ") is%N") Result.append_string ("%T%Tdo%N") Result.append_string ("%T%T%T" + a_name + " := val%N") Result.append_string ("%T%Tend%N%N") end xml_table.item_for_iteration.forth end Result.append_string ("%N") xml_table.forth end end feature -- defaults code defaults_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_type, a_default: STRING do Result := "" -- Default values from xml_table.start until xml_table.after loop Result.append_string ("%T-- Defaults for Section: " + xml_table.key_for_iteration + "%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration check_for_attributes (<<"name", "type", "default">>, current_entry) if attributes_ok then -- todo: error checking a_name := current_entry.item("name") a_type := current_entry.item("type") a_default := current_entry.item("default") Result.append_string("%T" + defaults_prefix + a_name + defaults_postfix + ": " + a_type.as_upper + " is ") if a_type.as_lower.is_equal("string") then Result.append_string("%"" + a_default + "%"") else Result.append_string(a_default) end Result.append_string ("%N") end xml_table.item_for_iteration.forth end Result.append_string ("%N") xml_table.forth end end restore_defaults_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] do Result := "" -- Restore Defaults Result.append_string ("%Trestore_all_defaults is%N") Result.append_string ("%T%Tdo%N") from xml_table.start until xml_table.after loop Result.append_string ("%T%T%Trestore_" + xml_table.key_for_iteration + "_defaults%N") xml_table.forth end Result.append_string ("%T%Tend%N%N") from xml_table.start until xml_table.after loop Result.append_string ("%Trestore_" + xml_table.key_for_iteration + "_defaults is%N") Result.append_string ("%T%Tdo%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration check_for_attributes (<<"name", "default">>, current_entry) if attributes_ok then if current_entry.item ("type").as_lower.is_equal ("string") then Result.append_string ("%T%T%T" + current_entry.item ("name") + " := " + defaults_prefix + current_entry.item ("name") + defaults_postfix + ".out%N") else Result.append_string ("%T%T%T" + current_entry.item ("name") + " := " + defaults_prefix + current_entry.item ("name") + defaults_postfix + "%N") end end xml_table.item_for_iteration.forth end Result.append_string ("%T%Tend%N%N") xml_table.forth end end feature -- Widget code apply_settings_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_widget: STRING do create Result.make_empty -- Apply Settings Result.append_string ("%Tapply_all_settings is%N") Result.append_string ("%T%Tdo%N") from xml_table.start until xml_table.after loop Result.append_string ("%T%T%Tapply_" + xml_table.key_for_iteration + "_settings%N") xml_table.forth end Result.append_string ("%T%Tend%N%N") from xml_table.start until xml_table.after loop Result.append_string ("%Tapply_" + xml_table.key_for_iteration + "_settings is%N") Result.append_string("%T%Trequire%N") Result.append_string("%T%T%Twidgets_created: " + xml_table.key_for_iteration + "_widgets_created%N") Result.append_string ("%T%Tdo%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop --main_class_content.append_string (apply_settings_code (xml_table.item_for_iteration.item_for_iteration)) current_entry := xml_table.item_for_iteration.item_for_iteration if current_entry.has ("widget") then check_for_attributes (<<"name", "widget">>, current_entry) if attributes_ok then a_name := current_entry.item("name") a_widget := current_entry.item ("widget") Result.append_string ("%T%T%T") if a_widget.as_lower.is_equal("checkbox") then Result.append_string (a_name + " := " + widget_prefix + a_name + widget_postfix + ".is_checked%N") elseif a_widget.as_lower.is_equal("slider") then Result.append_string (a_name + " := " + widget_prefix + a_name + widget_postfix + ".current_value%N") elseif a_widget.as_lower.is_equal("combobox") then Result.append_string (a_name + " := " + widget_prefix + a_name + widget_postfix + ".selected_element%N") elseif a_widget.as_lower.is_equal("textlist") then Result.append_string (a_name + " := " + widget_prefix + a_name + widget_postfix + ".selected_element%N") else print_error ("Unkown widget: " + a_widget) end end end xml_table.item_for_iteration.forth end Result.append_string ("%T%Tend%N%N") xml_table.forth end end reset_widgets_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_widget: STRING do Result := "" -- Reset Widgets Result.append_string ("%Treset_all_widgets is%N") Result.append_string ("%T%Tdo%N") from xml_table.start until xml_table.after loop Result.append_string ("%T%T%Treset_" + xml_table.key_for_iteration + "_widgets%N") xml_table.forth end Result.append_string ("%T%Tend%N%N") from xml_table.start until xml_table.after loop Result.append_string ("%Treset_" + xml_table.key_for_iteration + "_widgets is%N") Result.append_string("%T%Trequire%N") Result.append_string("%T%T%Twidgets_created: " + xml_table.key_for_iteration + "_widgets_created%N") Result.append_string ("%T%Tdo%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop --main_class_content.append_string (reset_widgets_code (xml_table.item_for_iteration.item_for_iteration)) current_entry := xml_table.item_for_iteration.item_for_iteration if current_entry.has ("widget") then check_for_attributes (<<"name", "widget">>, current_entry) if attributes_ok then a_name := current_entry.item("name") a_widget := current_entry.item ("widget") if a_widget.as_lower.is_equal("checkbox") then Result.append_string("%T%T%Tif " + a_name + " = true then%N") Result.append_string ("%T%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_checked%N") Result.append_string ("%T%T%Telse%N") Result.append_string ("%T%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_unchecked%N") Result.append_string("%T%T%Tend%N") elseif a_widget.as_lower.is_equal("slider") then Result.append_string("%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_current_value(" + a_name + ")%N") elseif a_widget.as_lower.is_equal("combobox") then Result.append_string ("%T%T%Tif " + widget_prefix + a_name + widget_postfix + ".has (" + a_name + ") then%N") Result.append_string("%T%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_selected_element(" + a_name + ")%N") Result.append_string ("%T%T%Tend%N") elseif a_widget.as_lower.is_equal("textlist") then Result.append_string ("%T%T%Tif " + widget_prefix + a_name + widget_postfix + ".has (" + a_name + ") then%N") Result.append_string("%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_selected_element(" + a_name + ")%N") Result.append_string ("%T%T%Tend%N") else print_error ("Unkown widget: " + a_widget) end end end xml_table.item_for_iteration.forth end Result.append_string ("%T%Tend%N%N") xml_table.forth end end widgets_attribute_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_widget, a_type: STRING do create Result.make_empty -- Widgets from xml_table.start until xml_table.after loop Result.append_string ("%T-- Widgets for Section: " + xml_table.key_for_iteration + "%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration if current_entry.has ("widget") then -- main_class_content.append_string (widgets_attribute_code (xml_table.item_for_iteration.item_for_iteration)) check_for_attributes (<<"name", "widget", "type">>, current_entry) if attributes_ok then a_name := current_entry.item("name") a_widget := current_entry.item("widget") a_type := current_entry.item("type") -- todo Result.append_string("%T" + widget_prefix + a_name + widget_postfix + ": EM_" + a_widget.as_upper) if a_widget.is_equal ("combobox") or a_widget.is_equal ("textlist") then Result.append_string ("[" + a_type.as_upper + "]") end Result.append_string ("%N") end end xml_table.item_for_iteration.forth end Result.append_string ("%N") xml_table.forth end end free_widgets_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name: STRING do Result := "" Result.append_string ("%Tfree_all_widgets is%N") Result.append_string ("%T%Tdo%N") from xml_table.start until xml_table.after loop Result.append_string ("%T%T%Tfree_" + xml_table.key_for_iteration + "_widgets%N") xml_table.forth end Result.append_string ("%T%T%Tall_widgets_created := false%N") Result.append_string ("%T%Tend%N%N") from xml_table.start until xml_table.after loop Result.append_string ("%Tfree_" + xml_table.key_for_iteration + "_widgets is%N") Result.append_string ("%T%Tdo%N") Result.append_string ("%T%T%Tall_widgets_created := false%N") Result.append_string ("%T%T%T" + xml_table.key_for_iteration + "_widgets_created := false%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration -- Create all widgets and their attributes if current_entry.has ("widget") then check_for_attributes (<<"name">>, current_entry) if attributes_ok then a_name := current_entry.item("name") Result.append_string ("%T%T%T" + widget_prefix + a_name + widget_postfix + " := void%N") end end xml_table.item_for_iteration.forth end Result.append_string ("%T%Tend%N%N") xml_table.forth end end create_widgets_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_widget: STRING do Result := "" Result.append_string ("%Tcreate_all_widgets is%N") Result.append_string ("%T%Tdo%N") from xml_table.start until xml_table.after loop Result.append_string ("%T%T%Tcreate_" + xml_table.key_for_iteration + "_widgets%N") xml_table.forth end Result.append_string ("%T%T%Tall_widgets_created := true%N") Result.append_string ("%T%Tend%N%N") from xml_table.start until xml_table.after loop Result.append_string ("%Tcreate_" + xml_table.key_for_iteration + "_widgets is%N") Result.append_string ("%T%Tdo%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_entry := xml_table.item_for_iteration.item_for_iteration -- Create all widgets and their attributes if current_entry.has ("widget") then check_for_attributes (<<"name", "widget">>, current_entry) if attributes_ok then a_name := current_entry.item("name") a_widget := current_entry.item ("widget") if a_widget.as_lower.is_equal("checkbox") then Result.append_string(checkbox_creation_code(current_entry)) elseif a_widget.as_lower.is_equal("slider") then Result.append_string(slider_creation_code(current_entry)) elseif a_widget.as_lower.is_equal("combobox") then Result.append_string(combobox_creation_code (current_entry)) elseif a_widget.as_lower.is_equal("textlist") then Result.append_string(textlist_creation_code (current_entry)) else print_error ("Unkown widget: " + a_widget) end end end xml_table.item_for_iteration.forth end Result.append_string ("%T%T%T" + xml_table.key_for_iteration + "_widgets_created := true%N") Result.append_string ("%T%Tend%N%N") xml_table.forth end end checkbox_creation_code (a_table: DS_HASH_TABLE[STRING, STRING]): STRING is require not has_error xml_table /= void local a_name: STRING do Result := "" check_for_attributes (<<"name", "default">>, a_table) if attributes_ok then a_name := a_table.item ("name") Result.append_string("%T%T%Tcreate " + widget_prefix + a_name + widget_postfix + ".make_empty%N") Result.append_string ("%T%T%Tif " + a_name + " then%N") Result.append_string ("%T%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_checked%N") Result.append_string ("%T%T%Telse%N") Result.append_string ("%T%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_unchecked%N") Result.append_string ("%T%T%Tend%N") end end slider_creation_code (a_table: DS_HASH_TABLE[STRING, STRING]): STRING is require not has_error xml_table /= void local a_min, a_max: STRING a_name: STRING a_default: STRING a_direction: STRING do Result := "" check_for_attributes (<<"name", "min", "max", "default">>, a_table) if attributes_ok then a_name := a_table.item ("name") a_min := a_table.item("min") a_max := a_table.item("max") a_default := a_table.item("default") if a_table.has ("direction") then a_direction := a_table.item("direction") end if a_direction /= void and then a_direction.as_lower.is_equal ("vertical") then Result.append_string("%T%T%Tcreate " + widget_prefix + a_name + widget_postfix + ".make_from_range_vertical(" + a_min + ", " + a_max + ")%N") else Result.append_string("%T%T%Tcreate " + widget_prefix + a_name + widget_postfix + ".make_from_range_horizontal(" + a_min + ", " + a_max + ")%N") end Result.append_string("%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_current_value(" + a_name + ")%N") end end combobox_creation_code (a_table: DS_HASH_TABLE[STRING, STRING]): STRING is require not has_error xml_table /= void local a_name, a_default, a_list: STRING splitted_list: LIST[STRING] do Result := "" check_for_attributes (<<"name", "default", "list">>, a_table) if attributes_ok then a_name := a_table.item ("name") a_default := a_table.item ("default") a_list := a_table.item("list") Result.append_string ("%T%T%Tcreate " + widget_prefix + a_name + widget_postfix + ".make_empty%N") splitted_list := a_list.split (list_splitter) from splitted_list.start until splitted_list.after loop if not splitted_list.item.is_equal ("") then Result.append_string ("%T%T%T" + widget_prefix + a_name + widget_postfix + ".put(%"" + splitted_list.item + "%")%N") else Result.append_string ("%T%T%T" + widget_prefix + a_name + widget_postfix + ".insert_void_element%N") end splitted_list.forth end Result.append_string ("%T%T%Tif " + widget_prefix + a_name + widget_postfix + ".has (" + a_name + ") then%N") Result.append_string ("%T%T%T%T" + widget_prefix + a_name + widget_postfix + ".set_selected_element (" + a_name + ")%N") Result.append_string ("%T%T%Tend%N") end end textlist_creation_code (a_table: DS_HASH_TABLE[STRING, STRING]): STRING is require not has_error xml_table /= void do Result := combobox_creation_code (a_table) end created_bools_code: STRING is require not has_error xml_table /= void do Result := "" Result.append_string ("%Tall_widgets_created: BOOLEAN%N") from xml_table.start until xml_table.after loop Result.append_string ("%T" + xml_table.key_for_iteration + "_widgets_created: BOOLEAN%N") xml_table.forth end Result.append_string ("%N") end -- The idea here was that one could specify additional attributes for the widgets. -- The problem is: if I support attributes a and b, I also have to support attribute c, -- then someone will request attribute d... So I don't support it at all and let the user -- set it in the program, which is the same amount of work anyway. -- widget_optional_code (a_table: DS_HASH_TABLE[STRING, STRING]): STRING is -- do -- Result := "" -- check_for_attributes (<<"name">>, a_table) -- if attributes_ok then -- if a_table.has ("tooltip") then -- Result.append_string(a_table.item ("name") + widget_postfix + ".set_tooltip(%"" + a_table.item ("tooltip") + "%")%N") -- end -- if a_table.has ("x") then -- Result.append_string(a_table.item ("name") + widget_postfix + ".set_x(" + a_table.item ("x") + ")%N") -- end -- if a_table.has ("y") then -- Result.append_string(a_table.item ("name") + widget_postfix + ".set_y(" + a_table.item ("y") + ")%N") -- end -- if a_table.has ("width") then -- Result.append_string(a_table.item ("name") + widget_postfix + ".set_width(" + a_table.item ("width") + ")%N") -- end -- if a_table.has ("height") then -- Result.append_string(a_table.item ("name") + widget_postfix + ".set_height(" + a_table.item ("height") + ")%N") -- end -- end -- end feature -- user settings code file_attribute_code: STRING is require not has_error xml_table /= void do -- File attributes Result := "" Result.append_string ("%Tuser_dir: KL_DIRECTORY%N") Result.append_string ("%Tuser_file: PLAIN_TEXT_FILE%N") Result.append_string ("%N") end set_user_file_code: STRING is require not has_error xml_table /= void do Result := "" Result.append_string ("%Tset_user_file (a_directory: STRING; a_filename: STRING) is%N") Result.append_string ("%T%Trequire%N") Result.append_string ("%T%T%Ta_filename /= void%N") Result.append_string ("%T%T%Ta_directory.item (a_directory.count) = '/'%N") Result.append_string ("%T%Tdo%N") Result.append_string ("%T%T%Tcreate user_dir.make (a_directory)%N") Result.append_string ("%T%T%Tcreate user_file.make (a_directory + a_filename)%N") Result.append_string ("%T%Tend%N%N") end read_user_settings_code: STRING is require not has_error xml_table /= void local current_item: DS_HASH_TABLE[STRING, STRING] do Result := "" Result.append("%Tuser_settings_parser: XM_EIFFEL_PARSER%N") Result.append("%Tuser_settings_filter: EM_SETTINGS_READER_XM_FILTER%N") Result.append("%Tuser_settings_table: DS_HASH_TABLE[STRING, STRING]%N%N") Result.append("%Tread_user_settings is%N") Result.append("%T%Tdo%N") Result.append("%T%T%Tif user_file.exists and then user_file.is_readable then%N") Result.append("%T%T%T%Tuser_file.open_read%N") Result.append("%T%T%T%Tcreate user_settings_filter.make_null%N") Result.append("%T%T%T%Tcreate user_settings_parser.make%N") Result.append("%T%T%T%Tuser_settings_parser.set_callbacks (callbacks_pipe (<>))%N") Result.append("%T%T%T%Tuser_file.read_stream (user_file.count)%N") Result.append("%T%T%T%Tuser_settings_parser.parse_from_string (user_file.last_string)%N") Result.append("%T%T%T%Tuser_settings_table := user_settings_filter.user_settings_table%N") Result.append("%T%T%T%Tuser_file.close%N") from xml_table.start until xml_table.after loop Result.append_string ("%T%T%T%T-- Apply " + xml_table.key_for_iteration + " settings%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop current_item := xml_table.item_for_iteration.item_for_iteration check_for_attributes (<<"name", "type">>, current_item) if attributes_ok then Result.append("%T%T%T%Tif user_settings_table.has(%"" + current_item.item("name") + "%") then%N") if current_item.item ("type").is_equal ("string") then Result.append("%T%T%T%T%T" + current_item.item("name") + " := user_settings_table.item(%"" + current_item.item("name") + "%")%N") else Result.append("%T%T%T%T%Tif user_settings_table.item(%"" + current_item.item("name") + "%").is_" + current_item.item("type").as_lower + " then%N") Result.append("%T%T%T%T%T%T" + current_item.item("name") + " := user_settings_table.item(%"" + current_item.item("name") + "%").to_" + current_item.item("type").as_lower + "%N") Result.append("%T%T%T%T%Tend%N") end Result.append("%T%T%T%Tend%N") end xml_table.item_for_iteration.forth end Result.append_string ("%N") xml_table.forth end Result.append("%T%T%Tend%N") Result.append("%T%Tend%N%N") end write_user_settings_code: STRING is require not has_error xml_table /= void local current_entry: DS_HASH_TABLE[STRING, STRING] a_name, a_type: STRING do Result := "" Result.append_string ("%Twrite_user_settings is%N") Result.append_string ("%T%Tdo%N") Result.append_string("%T%T%Tif not user_file.exists then%N") Result.append_string ("%T%T%T%Tif not user_dir.exists then%N") Result.append_string ("%T%T%T%T%Tuser_dir.recursive_create_directory%N") Result.append_string ("%T%T%T%Tend%N") Result.append_string ("%T%T%T%T if user_file.is_creatable then%N") Result.append_string ("%T%T%T%T%T user_file.create_read_write%N") Result.append_string ("%T%T%T%T%Tuser_file.close %N") Result.append_string ("%T%T%T%Tend%N") Result.append_string ("%T%T%Tend%N") Result.append_string ("%T%T%Tif user_file.exists and then user_file.is_writable then%N") Result.append_string("%T%T%T%Tuser_file.open_write%N") Result.append_string ("%T%T%T%Tuser_file.put_string (%"%%N%%N%")%N") Result.append_string ("%T%T%T%Tuser_file.put_string (%"%%N%")%N") from xml_table.start until xml_table.after loop Result.append_string ("%T%T%T%T-- Write " + xml_table.key_for_iteration + " settings%N") from xml_table.item_for_iteration.start until xml_table.item_for_iteration.after loop --main_class_content.append_string (write_settings_code (xml_table.item_for_iteration.item_for_iteration)) current_entry := xml_table.item_for_iteration.item_for_iteration check_for_attributes (<<"name", "type">>, current_entry) if attributes_ok then a_name := current_entry.item("name") a_type := current_entry.item("type") Result.append_string("%T%T%T%Tif not " + a_name + ".is_equal(" + defaults_prefix + a_name + defaults_postfix + ") then%N") Result.append_string("%T%T%T%T%Tuser_file.put_string (%"%%T%%N%")%N") Result.append_string ("%T%T%T%Tend%N") end xml_table.item_for_iteration.forth end Result.append_string ("%N") xml_table.forth end Result.append_string("%T%T%T%Tuser_file.put_string(%"%%N%%N%")%N") Result.append_string ("%T%T%T%Tuser_file.close%N") Result.append_string ("%T%T%Telse%N") Result.append_string ("%T%T%T%Tdebug%N") Result.append_string ("%T%T%T%T%Tio.put_string(%"Failed to write settings%%N%")%N") Result.append_string ("%T%T%T%Tend%N") Result.append_string ("%T%T%Tend%N") Result.append_string ("%T%Tend%N%N") end feature -- Command line print_help is -- print help for the command line tool do io.put_string ("usage: " + cropped_program_name (arguments.program_name) + " input_file.xml [-o output_class_name] [--no-widgets] [--no-singleton]%N") io.put_string ("-o, --output%T%Tspecify the name of the generated class%N") io.put_string ("--no-widgets%T%Tdo not create any widgets code%N") io.put_string ("--no-singleton%T%Tdo not create a singleton class%N") io.put_string ("-h, --help%T%Tshow this usage message%N") end feature -- Attributes no_widgets: BOOLEAN feature -- Constants defaults_prefix: STRING is "default_" defaults_postfix: STRING is "" widget_prefix: STRING is "widget_" widget_postfix: STRING is "" list_splitter: CHARACTER is '|' end