Example #1
0
        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);
                }
            }
        }
Example #2
0
        protected void OnExportCommandsButtonPress(object sender, EventArgs e)
        {
            Gtk.FileChooserDialog fileChooser = new Gtk.FileChooserDialog
                                                    ("Choose files"
                                                    , this
                                                    , FileChooserAction.SelectFolder
                                                    , "Select"
                                                    , ResponseType.Accept
                                                    , "Cancel"
                                                    , ResponseType.Close);
            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 + "/exported_commands.xml";
                UIUtils.ShutDownWindow(ref fileChooser);
                UITabPage currentTabPage = GetCurrentTabPage();
                currentTabPage.GetGameConfig();

                GamesConfigLoader   gamesLoader         = MainApp.GetInstance().GetConfig().GetGameConfig();
                FileOperationResult fileOperationResult = gamesLoader.Export(fullPath, currentTabPage.GetGameConfig());

                if (!fileOperationResult.IsSuccess())
                {
                    UIUtils.ShutDownWindowSafe(ref _windowPrompt);
                    _windowPrompt = new WindowPrompt(fileOperationResult.GetResult());
                    _windowPrompt.OnAcceptEvent += OnAlertAccept;
                    _windowPrompt.SetCancelVisible(false);
                    _windowPrompt.Show();
                    MainApp.GetInstance().MoveWindowToMousePos(_windowPrompt);
                }
            }
        }