private void FormClosingHandler(object sender, EventArgs e) { string filename = "soundboard.config"; using (FileStream fileStream = new FileStream(filename, FileMode.Create)) using (StreamWriter sw = new StreamWriter(fileStream)) using (XmlTextWriter writer = new XmlTextWriter(sw)) { writer.Formatting = Formatting.Indented; writer.Indentation = 4; writer.WriteStartDocument(); writer.WriteStartElement("tabs"); for (int i = 0; i < Tabs.Items.Count; ++i) { MetroTabItem tab = (MetroTabItem)Tabs.Items[i]; if (tab.Content is Grid) { string name = tab.Header.ToString(); writer.WriteStartElement("tab"); writer.WriteElementString("name", name); { Grid grid = (Grid)tab.Content; int j = 0; foreach (var child in grid.Children) { if (child is SoundButton) { SoundButton button = (SoundButton)child; writer.WriteStartElement("button" + j++); writer.WriteAttributeString("name", button.GetFileName()); writer.WriteAttributeString("path", button.GetFile()); //writer.WriteString("test"); writer.WriteEndElement(); } } } writer.WriteEndElement(); } else // it doesn't have a grid, so it's not a sound page { continue; } } writer.WriteEndElement(); writer.WriteEndDocument(); } }
public MenuButton(SoundButton _buddy) : base() { Content = "•••"; FontSize = 15; Style = (Style)FindResource("MetroCircleButtonStyle"); Width = 40; Height = 40; Margin = new Thickness(0, 15, 15, 0); VerticalAlignment = VerticalAlignment.Top; HorizontalAlignment = HorizontalAlignment.Right; Click += new RoutedEventHandler(menuButton_Click); buddy = _buddy; }
public void UpdateSoundList() { sounds.Clear(); foreach (MetroTabItem tab in Tabs.Items) { if (tab.Content is Grid) { Grid grid = (Grid)tab.Content; foreach (var child in grid.Children) { if (child is SoundButton) { SoundButton button = (SoundButton)child; sounds[button.Content.ToString()] = button.GetFile(); } } } } }
private void CreatePageContent(MetroTabItem tab, List <Tuple <string, string> > buttons = null) { Grid parentGrid = new Grid(); ColumnDefinition col1 = new ColumnDefinition(); col1.Width = new GridLength(1, GridUnitType.Star); parentGrid.ColumnDefinitions.Add(col1); ColumnDefinition col2 = new ColumnDefinition(); col2.Width = new GridLength(1, GridUnitType.Star); parentGrid.ColumnDefinitions.Add(col2); RowDefinition row; for (int i = 0; i < 5; ++i) { row = new RowDefinition(); row.Height = new GridLength(1, GridUnitType.Star); parentGrid.RowDefinitions.Add(row); // sound button SoundButton soundButton = new SoundButton(); Grid.SetColumn(soundButton, 0); Grid.SetRow(soundButton, i); parentGrid.Children.Add(soundButton); if (buttons != null) { soundButton.SetFile(buttons[i].Item2, buttons[i].Item1); } // menu button MenuButton menuButton = new MenuButton(soundButton); Grid.SetColumn(menuButton, 0); Grid.SetRow(menuButton, i); parentGrid.Children.Add(menuButton); // progress bar SoundProgressBar progressBar = new SoundProgressBar(); Grid.SetColumn(progressBar, 0); Grid.SetRow(progressBar, i); parentGrid.Children.Add(progressBar); soundButton.SetSoundProgressBar(progressBar); } for (int i = 0; i < 5; ++i) { // only have to add the rows once (above) // sound button SoundButton soundButton = new SoundButton(); Grid.SetColumn(soundButton, 1); Grid.SetRow(soundButton, i); parentGrid.Children.Add(soundButton); if (buttons != null) { soundButton.SetFile(buttons[i + 5].Item2, buttons[i + 5].Item1); } // menu button MenuButton menuButton = new MenuButton(soundButton); Grid.SetColumn(menuButton, 1); Grid.SetRow(menuButton, i); parentGrid.Children.Add(menuButton); // progress bar SoundProgressBar progressBar = new SoundProgressBar(); Grid.SetColumn(progressBar, 1); Grid.SetRow(progressBar, i); parentGrid.Children.Add(progressBar); soundButton.SetSoundProgressBar(progressBar); } tab.Content = parentGrid; }
private void KeyDownHandler(object sender, KeyEventArgs e) { Mouse.Capture(null); char c = GetCharFromKey(e.Key); if (char.IsLetter(c) || char.IsPunctuation(c) || char.IsNumber(c)) { searchString += c; } else if (e.Key == Key.Space) { searchString += ' '; } else if (e.Key == Key.Back && searchString.Length > 0) { searchString = searchString.Substring(0, searchString.Length - 1); } else if (e.Key == Key.Escape) { // if the search bar is open, close it if (Search.IsOpen) { searchString = ""; // don'even wait for it to close to clear the query Search.IsOpen = false; } // otherwise, stop any playing sounds else { ButtonAutomationPeer peer = new ButtonAutomationPeer(Silence); IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; invokeProv.Invoke(); } return; } else if (e.Key == Key.Down) { bool foundFocused = false; // loop through the buttons and focus the next one foreach (var child in ResultsPanel.Children) { if (child is SoundButton) { if (foundFocused) { // we found the last focused button, so focus this one ((SoundButton)child).Focus(); focusedButton = ((SoundButton)child); break; } if (((SoundButton)child).IsFocused) { // we found the focused button! focus the next one foundFocused = true; } } } return; } else if (e.Key == Key.Up) { SoundButton previousButton = null; // loop through the buttons and focus the previous one foreach (var child in ResultsPanel.Children) { if (child is SoundButton) { if (((SoundButton)child).IsFocused) { // focus the previous one! if (previousButton != null) { previousButton.Focus(); focusedButton = previousButton; break; } } previousButton = (SoundButton)child; } } return; } else if (e.Key == Key.Enter) { // play the sound! foreach (var child in ResultsPanel.Children) { if (child is SoundButton && ((SoundButton)child).IsFocused) { ButtonAutomationPeer peer = new ButtonAutomationPeer((SoundButton)child); IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider; invokeProv.Invoke(); } } return; } else { return; } Query.Text = searchString; Query.CaretIndex = Query.Text.Length; Search.IsOpen = true; // get rid of any previous buttons / do reverse iteration to prevent weird bugs for (int i = ResultsPanel.Children.Count - 1; i >= 0; --i) { if (ResultsPanel.Children[i] is SoundButton) { ResultsPanel.Children.Remove((SoundButton)ResultsPanel.Children[i]); } } // perform search if (searchString != "") { foreach (KeyValuePair <string, string> entry in sounds) { if (entry.Key.ToLower().Contains(searchString.ToLower())) { SoundButton button = new SoundButton(true); button.SetFile(entry.Value, entry.Key, false); ResultsPanel.Children.Add(button); } } // if we've added at least one button, focus the first one if (ResultsPanel.Children.Count > 0) { ((SoundButton)ResultsPanel.Children[0]).Focus(); focusedButton = ((SoundButton)ResultsPanel.Children[0]); } } }