protected void OnImportCommandsButtonPress(object sender, EventArgs e) { Gtk.FileChooserDialog fileChooser = new Gtk.FileChooserDialog ("Choose files" , this , FileChooserAction.Open , "Select" , ResponseType.Accept , "Cancel" , ResponseType.Close); Gtk.FileFilter xmlFileFilter = new Gtk.FileFilter(); xmlFileFilter.AddPattern("*.xml"); fileChooser.AddFilter(xmlFileFilter); int response = fileChooser.Run(); if (response == Utils.static_cast <int>(ResponseType.Close)) { UIUtils.ShutDownWindow(ref fileChooser); } else if (response == Utils.static_cast <int>(ResponseType.Accept)) { string fullPath = fileChooser.Filename; UIUtils.ShutDownWindow(ref fileChooser); GameConfigDescriptorLoader loader = new GameConfigDescriptorLoader(fullPath); FileOperationResult fileOperationResult = loader.Load(); if (fileOperationResult.IsSuccess()) { GameConfigDB sourceConfigDB = loader.GetConfig(); UITabPage currentTabPage = GetCurrentTabPage(); GameConfigDB targetConfigDB = currentTabPage.GetGameConfig(); foreach (GameConfigSectionDescriptor sectionDescriptor in sourceConfigDB.GetSections()) { targetConfigDB.AddSection(sectionDescriptor); currentTabPage.AddNewSection(sectionDescriptor); } currentTabPage.RefreshCanvas(); } else { UIUtils.ShutDownWindowSafe(ref _windowPrompt); _windowPrompt = new WindowPrompt(fileOperationResult.GetResult()); _windowPrompt.OnAcceptEvent += OnAlertAccept; _windowPrompt.SetCancelVisible(false); _windowPrompt.Show(); MainApp.GetInstance().MoveWindowToMousePos(_windowPrompt); } } }
public FileOperationResult Load() { try { XmlReader reader = XmlReader.Create(_descriptorFile); while (reader.Read()) { // Only detect start elements. if (reader.IsStartElement()) { // Get element name and switch on it. switch (reader.Name) { case "commands": { _gameConfigDB = new GameConfigDB(); string attribute = reader["name"]; Config.AssertResource(attribute); _gameConfigDB.SetName(attribute); attribute = reader["creationDate"]; Config.AssertResource(attribute); _gameConfigDB.SetCreationDate(Int32.Parse(attribute)); } break; case "section": { if (_currentGameConfigSectionDescriptor != null) { _gameConfigDB.AddSection(_currentGameConfigSectionDescriptor); _currentGameConfigSectionDescriptor = null; } _currentGameConfigSectionDescriptor = new GameConfigSectionDescriptor(); string attribute = reader["tittle"]; Config.AssertResource(attribute); _currentGameConfigSectionDescriptor._tittle = Utils.DecodeHTML(attribute); } break; case "command": { _currentGameConfigButtonDescriptor = new GameConfigButtonDescriptor(); string attribute = reader["type"]; Config.AssertResource(attribute); GameConfigButtonDescriptor.Etype type = Utils.static_cast <GameConfigButtonDescriptor.Etype>(Int32.Parse(attribute)); _currentGameConfigButtonDescriptor._type = type; attribute = reader["tittle"]; Config.AssertResource(attribute); _currentGameConfigButtonDescriptor._tittle = Utils.DecodeHTML(attribute); if (type == GameConfigButtonDescriptor.Etype.MultiCommand) { _currentGameConfigButtonDescriptor._commandList = new List <GameConfigCommandDescriptor>(); } else { attribute = reader["command"]; Config.AssertResource(attribute); _currentGameConfigButtonDescriptor._command = Utils.DecodeHTML(attribute); } if (type == GameConfigButtonDescriptor.Etype.FixedArgument || type == GameConfigButtonDescriptor.Etype.ExposedArgument) { attribute = reader["arguments"]; Config.AssertResource(attribute); _currentGameConfigButtonDescriptor._arguments = Utils.DecodeHTML(attribute); } _currentGameConfigSectionDescriptor._buttons.Add(_currentGameConfigButtonDescriptor); } break; case "command_sequence": { GameConfigCommandDescriptor commandDescriptor = new GameConfigCommandDescriptor(); string attribute = reader["command"]; Config.AssertResource(attribute); commandDescriptor._command = Utils.DecodeHTML(attribute); attribute = reader["arguments"]; Config.AssertResource(attribute); commandDescriptor._arguments = Utils.DecodeHTML(attribute); _currentGameConfigButtonDescriptor._commandList.Add(commandDescriptor); } break; } } } if (_currentGameConfigSectionDescriptor != null) { _gameConfigDB.AddSection(_currentGameConfigSectionDescriptor); _currentGameConfigSectionDescriptor = null; } reader.Close(); return(new FileOperationResult(true)); } catch (System.Exception ex) { return(new FileOperationResult(false, ex.Message)); } }