private async void addButton_Click(object sender, RoutedEventArgs e) { if (!this.CheckCodeFormat(this.cheatCodeBox.Text, (s) => { MessageBox.Show(s, AppResources.ErrorCaption, MessageBoxButton.OK); })) { return; } string[] codes = this.GetCodes(this.cheatCodeBox.Text); for (int i = 0; i < codes.Length; i++) { CheatData cheat = new CheatData() { CheatCode = codes[i], Description = this.cheatDescBox.Text, Enabled = true }; this.cheatCodes.Add(cheat); } RefreshCheatList(); this.cheatCodeBox.Text = ""; this.cheatDescBox.Text = ""; FileHandler.SaveCheatCodes(this.romEntry, this.cheatCodes); }
//private async void OKButton_Click(object sender, EventArgs e) //{ // await FileHandler.SaveCheatCodes(this.romEntry, this.cheatCodes); // if (this.NavigationService.CanGoBack) // this.NavigationService.GoBack(); //} //private void cancelButton_Click(object sender, EventArgs e) //{ // if (this.NavigationService.CanGoBack) // this.NavigationService.GoBack(); //} private async void removeButton_Click(object sender, EventArgs e) { if (this.cheatList.SelectedItem == null) { MessageBox.Show(AppResources.CheatNoSelection, AppResources.ErrorCaption, MessageBoxButton.OK); return; } this.cheatCodes.Remove(this.cheatList.SelectedItem as CheatData); this.cheatList.SelectedItem = null; this.RefreshCheatList(); await FileHandler.SaveCheatCodes(this.romEntry, this.cheatCodes); }
//protected override async void OnNavigatingFrom(NavigatingCancelEventArgs e) //{ // await FileHandler.SaveCheatCodes(this.romEntry, this.cheatCodes); //this caused crash because the app leave this page before this is done, so UnauthorizedAcessException // base.OnNavigatingFrom(e); //} protected override async void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { //Check if the PopUp window is open if (popupWindow != null && popupWindow.IsOpen) { //Close the PopUp Window popupWindow.IsOpen = false; //Keep the back button from navigating away from the current page e.Cancel = true; } else if (mainPivot.SelectedItem == this.searchPivot && (cheatTextStackpanel.Visibility == Visibility.Visible || codeList.Visibility == Visibility.Visible)) //in cheat page and browser windows open { if (cheatTextStackpanel.Visibility == Visibility.Visible) { gameList.Visibility = Visibility.Collapsed; codeList.Visibility = Visibility.Visible; cheatTextStackpanel.Visibility = Visibility.Collapsed; } else if (codeList.Visibility == Visibility.Visible) { gameList.Visibility = Visibility.Visible; codeList.Visibility = Visibility.Collapsed; cheatTextStackpanel.Visibility = Visibility.Collapsed; } e.Cancel = true; } else { //There is no PopUp open and no browser windows open, save then go back e.Cancel = true; //save the cheat code if (this.romEntry != null) { await FileHandler.SaveCheatCodes(this.romEntry, this.cheatCodes); } if (this.NavigationService.CanGoBack) { this.NavigationService.GoBack(); } } }
private async void editButton_Click(object sender, EventArgs e) { if (this.cheatList.SelectedItem == null) { MessageBox.Show(AppResources.CheatNoSelection, AppResources.ErrorCaption, MessageBoxButton.OK); return; } CheatData cheatdata = this.cheatList.SelectedItem as CheatData; //disable current page this.IsHitTestVisible = false; ApplicationBar.IsVisible = false; //create new popup instance popupWindow = new Popup(); EditCheatControl.TextToEdit = cheatdata.CheatCode; EditCheatControl.PromptText = AppResources.EnterNewCheatText; popupWindow.Child = new EditCheatControl(); popupWindow.VerticalOffset = 0; popupWindow.HorizontalOffset = 0; popupWindow.IsOpen = true; popupWindow.Closed += async(s1, e1) => { this.IsHitTestVisible = true; ApplicationBar.IsVisible = true; if (EditCheatControl.IsOKClicked && this.CheckCodeFormat(EditCheatControl.TextToEdit, (s) => { MessageBox.Show(s, AppResources.ErrorCaption, MessageBoxButton.OK); })) { cheatdata.CheatCode = EditCheatControl.TextToEdit; RefreshCheatList(); await FileHandler.SaveCheatCodes(this.romEntry, this.cheatCodes); } }; }
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) { FileHandler.SaveCheatCodes(this.romEntry, this.cheatCodes); base.OnNavigatingFrom(e); }