public Command CreateNewCommand(MadCatzProfile profile, string defaultName) { if (profile == null) { throw new ArgumentNullException("profile"); } Command command = null; if (profile.Commands.GetCommandByName(defaultName) == null) { command = new ActionCommand(defaultName); } else { int counter = 1; while (profile.Commands.GetCommandByName(defaultName + counter) != null) { counter++; } command = new ActionCommand(defaultName + counter); } profile.Commands.Add(command); profileInfos[profile].Edited = true; return(command); }
public void ActiveProfileChanged(MadCatzProfile profile) { activeProfile = profile; iconsPresenter.ActiveProfileChanged(profile); commandsPresenter.ActiveProfileChanged(profile); assignPresenter.ActiveProfileChanged(profile); }
/// <summary> /// Sets the controls properties to the values in the given command. /// </summary> /// <param name="command">The command, if null is passed, the UI is cleared.</param> private void ShowCommandDetails(Command command) { if (command == null) { tbName.Text = ""; iIcon.Source = null; tbNoImage.Visibility = Visibility.Hidden; return; } tbName.Text = command.Name; MadCatzProfile profile = presenter.ActiveProfile; Blast blast = profile.Blasts.GetBlastForCommand(command); if (blast != null) { iIcon.Source = ImageHelper.CreateImage(blast.GetData()); tbNoImage.Visibility = Visibility.Hidden; iIcon.Visibility = Visibility.Visible; } else { tbNoImage.Visibility = Visibility.Visible; iIcon.Visibility = Visibility.Hidden; } }
/// <summary> /// Callback for the selection of a profile. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> private void OnProfileSelected(object sender, RoutedEventArgs e) { SetProfileDependingControlsEnabled(true); RadioButton button = (RadioButton)sender; MadCatzProfile profile = (MadCatzProfile)button.Tag; presenter.ActiveProfileChanged(profile); }
public MadCatzProfile CreateNewProfile(string name) { var profile = new MadCatzProfile(name); profiles.AddLast(profile); profileInfos.Add(profile, new ProfileInfo()); return(profile); }
public void ProfileClosed(MadCatzProfile profile) { spProfiles.Children.Remove(GetButtonByProfile(profile)); if (spProfiles.Children.Count == 0) { SetProfileDependingControlsEnabled(false); } }
/// <summary> /// Tests the API by loading the input file, saving it to memory and comparing it to the wished result file. /// </summary> /// <param name="inFile">The file to load and save.</param> /// <param name="resultFile">The file to compare to.</param> private static void DoLoadSaveTest(string inFile, string resultFile) { MadCatzProfile profile = ProfileFactory.Load(inFile); byte[] data = null; using (var stream = new MemoryStream()) { ProfileFactory.Save(stream, profile); data = stream.GetBuffer(); } StreamReader writtenReader = null; MemoryStream memStream = null; string written = null; try { memStream = new MemoryStream(data); writtenReader = new StreamReader(memStream); written = writtenReader.ReadToEnd().Trim().Replace("\0", string.Empty); writtenReader.Close(); writtenReader = null; memStream = null; } finally { if (writtenReader != null) { writtenReader.Close(); writtenReader = null; memStream = null; } if (memStream != null) { memStream.Close(); } } StreamReader originalReader = null; string original = null; try { originalReader = new StreamReader(resultFile); original = originalReader.ReadToEnd().Trim(); originalReader.Close(); originalReader = null; } finally { if (originalReader != null) { originalReader.Close(); } } Assert.AreEqual(original, written); }
public void ChangeCommandIcon(MadCatzProfile profile, Command command, Blast blast) { if (command == null) { throw new ArgumentNullException("command"); } command.SetIcon(blast); profileInfos[profile].Edited = true; }
public void ChangeCommandName(MadCatzProfile profile, Command command, string newName) { if (command == null) { throw new ArgumentNullException("command"); } command.Name = newName; profileInfos[profile].Edited = true; }
public void RemoveIcon(MadCatzProfile profile, Blast blast) { if (profile == null) { throw new ArgumentNullException("profile"); } profile.Blasts.Remove(blast); profileInfos[profile].Edited = true; }
public void RemoveCommand(MadCatzProfile profile, Command command) { if (profile == null) { throw new ArgumentNullException("profile"); } profile.Commands.Remove(command); profileInfos[profile].Edited = true; }
public void SaveProfile(MadCatzProfile profile) { if (!HasSaveFile(profile)) { throw new InvalidOperationException("Can't save the profile: there is no save location available."); } ProfileFactory.Save(profileInfos[profile].ProfileFile, profile); profileInfos[profile].Edited = false; }
public void SetActiveProfile(MadCatzProfile activeProfile) { if (activeProfile == null) { pEditor.IconsPanel.ActiveProfileChanged(null); pEditor.CommandsPanel.ActiveProfileChanged(null); pEditor.AssignPanel.ActiveProfileChanged(null); return; } GetButtonByProfile(activeProfile).IsChecked = true; }
/// <summary> /// Gets the RadioButton associated with the given profile. /// </summary> /// <param name="profile">The profile.</param> /// <returns>The button associated with the profile.</returns> private RadioButton GetButtonByProfile(MadCatzProfile profile) { foreach (UIElement elem in spProfiles.Children) { RadioButton button = (RadioButton)elem; if (button.Tag == profile) { return(button); } } return(null); }
public void OpenFileRequested() { FileInfo[] files = view.SelectProfileFiles(); if (files == null) { return; } string invalidFiles = null; LinkedList <string> validationMessages = new LinkedList <string>(); foreach (FileInfo file in files) { if (file.Extension.ToUpperInvariant() != PR0_FILE_EXTENSION) { if (invalidFiles == null) { invalidFiles = file.Name; } else { invalidFiles += "\n" + file.Name; } continue; } var report = new ClawValidationReport(); bool success = model.LoadProfile(file, report); if (report.SomethingHappened) { validationMessages.AddLast((string)App.Current.FindResource(VALIDATION_MSG_STH_HAPPENED) + "\n" + report.Message); } if (!success) { continue; } MadCatzProfile profile = model.Profiles.Last.Value; view.AddProfile(profile); } if (invalidFiles != null) { view.ShowErrorMessage((string)App.Current.FindResource(ERROR_MSG_INVALID_PROFILES) + "\n" + invalidFiles); } foreach (string msg in validationMessages) { view.ShowMessage(msg); } }
public void AddIcon(MadCatzProfile profile, byte[] pngData) { if (profile == null) { throw new ArgumentNullException("profile"); } var blast = new Blast(pngData); profile.Blasts.Add(blast); profileInfos[profile].Edited = true; }
/// <summary> /// Does a save as for the given profile. /// </summary> /// <param name="profile">The profile to save.</param> /// <returns>Whether the profile was saved.</returns> public bool SaveProfileAsRequested(MadCatzProfile profile) { FileInfo saveFile = view.SelectProfileSaveFile(profile, model.GetSaveFile(profile)); if (saveFile == null) { return(false); } model.SaveProfile(profile, saveFile); return(true); }
public void CreateNewProfileRequested() { string name = view.ShowTextQuestion((string)App.Current.FindResource(DIALOG_TITLE_NEW_PROFILE), (string)App.Current.FindResource(MSG_CREATE_NEW_PROFILE), new char[] { '\'' }); if (name == null) { return; } MadCatzProfile profile = model.CreateNewProfile(name); view.AddProfile(profile); }
public bool LoadProfile(FileInfo file, ValidationReport report) { var errorCatcher = new ErrorCatcherReport(); MadCatzProfile profile = ProfileFactory.Load(file, new BranchReport(new ValidationReport[] { report, errorCatcher })); if (!errorCatcher.ErrorOccured) { profiles.AddLast(profile); profileInfos.Add(profile, new ProfileInfo(file)); } return(!errorCatcher.ErrorOccured); }
public Controller TryInsertController(MadCatzProfile profile, Guid requestedUuid) { if (profile == null) { throw new ArgumentNullException("profile"); } Controller controller = Controller.CreateDefaultById(requestedUuid); profile.Controllers.Add(controller); profileInfos[profile].Edited = true; return(controller); }
public FileInfo SelectProfileSaveFile(MadCatzProfile profile, FileInfo currentSaveFile) { if (currentSaveFile != null) { saveProfileDialog.InitialDirectory = currentSaveFile.Directory.FullName; saveProfileDialog.FileName = currentSaveFile.Name; } bool?result = saveProfileDialog.ShowDialog(); if (!result.HasValue || !result.Value) { return(null); } return(new FileInfo(saveProfileDialog.FileName)); }
/// <summary> /// Notifies this panel that the selected profile changed. /// </summary> /// <param name="activeProfile">The new active profile.</param> public void ActiveProfileChanged(MadCatzProfile activeProfile) { lvIcons.Items.Clear(); if (activeProfile == null) { btAdd.IsEnabled = false; return; } btAdd.IsEnabled = true; foreach (Blast blast in activeProfile.Blasts) { var imageControl = ImageHelper.CreateImageControl(blast.GetData()); imageControl.Tag = blast; lvIcons.Items.Add(imageControl); } }
/// <summary> /// Loads an image from a file to the model. /// </summary> /// <param name="imageFile">The image file info.</param> private void LoadImage(FileInfo imageFile) { byte[] pngData = null; if (imageFile.Extension.ToUpperInvariant() != ".PNG") { pngData = LoadImageToPngData(imageFile); } else { pngData = LoadFileContents(imageFile); } MadCatzProfile activeProfile = mainPresenter.ActiveProfile; mainPresenter.Model.AddIcon(activeProfile, pngData); view.ActiveProfileChanged(activeProfile); }
/// <summary> /// Asks to save the given profile. /// </summary> /// <param name="profile">The profile to save.</param> /// <returns>Whether the profile was saved.</returns> public bool SaveProfileRequested(MadCatzProfile profile) { if (!model.HasSaveFile(profile)) { return(SaveProfileAsRequested(profile)); } try { model.SaveProfile(profile); return(true); } catch (IOException exc) { view.ShowErrorMessage(App.Current.FindResource(ERROR_MSG_UNABLE_TO_SAVE) + exc.ToString()); return(false); } }
public void ActiveProfileChanged(MadCatzProfile activeProfile) { lbCommands.Items.Clear(); if (activeProfile == null) { btCreate.IsEnabled = false; return; } btCreate.IsEnabled = true; foreach (Command command in activeProfile.Commands) { var item = new ListBoxItem(); item.Content = command.Name; item.Tag = command; lbCommands.Items.Add(item); } SortCommandList(); }
public void RemoveIconsRequested(LinkedList <Blast> blasts) { if (blasts == null) { throw new ArgumentNullException("blasts"); } if (!mainPresenter.ForwardYesNoQuestion((string)Application.Current.FindResource(QUESTION_SURE_TO_REMOVE_ICONS))) { return; } MadCatzProfile activeProfile = mainPresenter.ActiveProfile; foreach (Blast blast in blasts) { mainPresenter.Model.RemoveIcon(activeProfile, blast); } view.ActiveProfileChanged(activeProfile); }
public void ActiveProfileChanged(MadCatzProfile profile) { activeProfile = profile; lbControls.Items.Clear(); if (profile == null) { cbDevice.SelectedItem = null; cbMode.SelectedItem = null; blockChangeEvent = true; cbAssigned.SelectedItem = null; blockChangeEvent = false; SetControlsEnabled(false); return; } SetControlsEnabled(true); cbDevice.Items.Clear(); cbMode.Items.Clear(); LoadActiveProfileData(); }
public void CloseProfileRequested(MadCatzProfile profile) { if (profile == null) { throw new ArgumentNullException("profile"); } if (model.HasBeenEdited(profile)) { bool?doSave = view.ShowYesNoAbortQuestion(string.Format(CultureInfo.CurrentCulture, (string)App.Current.FindResource(QUESTION_SAVE_BEFORE_CLOSING), profile.Name)); if (!doSave.HasValue) { return; } // If saveing is cancelld it is also necessary to cancel closing. // Be aware: SaveProfileRequested is only executed when doSave.Value is true because of rapid evaluation. if (doSave.Value && !SaveProfileRequested(profile)) { return; } } model.CloseProfile(profile); if (profile == activeProfile) { if (model.Profiles.Count == 0) { activeProfile = null; } else { activeProfile = model.Profiles.First.Value; } view.SetActiveProfile(activeProfile); } view.ProfileClosed(profile); }
public void AddProfile(MadCatzProfile profile) { if (profile == null) { throw new ArgumentNullException("profile"); } RadioButton profileButton = new RadioButton(); profileButton.GroupName = "rbgProfiles"; var content = new ProfileButtonContentPanel(profileButton, profile.Name); content.OnCloseClick += OnProfileCloseClick; profileButton.Content = content; profileButton.Tag = profile; profileButton.SetResourceReference(RadioButton.StyleProperty, typeof(ToggleButton)); profileButton.Height = 30; profileButton.Margin = new Thickness(2, 0, 3, 0); profileButton.Checked += OnProfileSelected; spProfiles.Children.Add(profileButton); profileButton.IsChecked = true; InvalidateVisual(); }
public void AssociateCommand(MadCatzProfile profile, Shift shift, Control control, Command command) { if (profile == null) { throw new ArgumentNullException("profile"); } if (shift == null) { throw new ArgumentNullException("shift"); } if (!(control is ButtonControl)) { throw new InvalidOperationException("Can't associate a command to a non-button control."); } if (command != null && !profile.Commands.Contains(command)) { throw new ArgumentException("The given command needs to be in the same profile as the given control."); } profileInfos[profile].Edited = true; if (command == null) { shift.Assignments.RemoveAssignmentForControl(control); return; } var band = new Band(command); ButtonAssignment buttonAssignment = GetButtonAssignment(shift, control); buttonAssignment.Bands.Clear(); buttonAssignment.Bands.Add(band); }