Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 105 additions & 9 deletions FASTER/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,41 @@
Application.Current.Shutdown();
}

private static IEnumerable<ToggleButton> GetProfileToggleButtons(System.Windows.Controls.ListBox menu)
{
foreach (var item in menu.Items)
{
if (item is System.Windows.Controls.DockPanel dp)
{
var tb = dp.Children.OfType<ToggleButton>().FirstOrDefault();
if (tb != null) yield return tb;
}
else if (item is ToggleButton t)
{
yield return t;
}
}
}

private void ToggleButton_Click(object sender, RoutedEventArgs e)
{
var list = new List<ToggleButton>();
list.AddRange(IMainMenuItems.Items.Cast<ToggleButton>().Where(i => i.IsChecked == true));
list.AddRange(IServerProfilesMenu.Items.Cast<ToggleButton>().Where(i => i.IsChecked == true));
list.AddRange(GetProfileToggleButtons(IServerProfilesMenu).Where(i => i.IsChecked == true));

Check warning on line 188 in FASTER/MainWindow.xaml.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unnecessary Boolean literal(s).

See more on https://sonarcloud.io/project/issues?id=Foxlider_FASTER&issues=AZ4sk22sh_oryJbHcRFv&open=AZ4sk22sh_oryJbHcRFv&pullRequest=265
list.AddRange(IOtherMenuItems.Items.Cast<ToggleButton>().Where(i => i.IsChecked == true));

if (sender is not ToggleButton nav || !NavEnabled) return;

//Don't navigate if same menu is clicked
if (nav == lastNavButton) return;



//Clear selected Buttons
IServerProfilesMenu.SelectedItem = null;
foreach (var item in list.Where(item => item.Name != nav.Name))
{ item.IsChecked = false; }

nav.IsChecked = true;
lastNavButton = nav;

Expand Down Expand Up @@ -216,7 +232,7 @@
MainContent.Content = ContentAbout;
break;
default:
if (IServerProfilesMenu.Items.Cast<ToggleButton>().FirstOrDefault(p => p.Name == nav.Name) != null)
if (GetProfileToggleButtons(IServerProfilesMenu).FirstOrDefault(p => p.Name == nav.Name) != null)
{
var profile = new Profile();
MainContent.Content = profile;
Expand Down Expand Up @@ -259,22 +275,31 @@
}
}

private ToggleButton GetSelectedProfileToggleButton()
{
var selected = IServerProfilesMenu.SelectedItem;
if (selected is System.Windows.Controls.DockPanel dp)
return dp.Children.OfType<ToggleButton>().FirstOrDefault();
return selected as ToggleButton;
}

private void MenuItemClone_Click(object sender, RoutedEventArgs e)
{
if (IServerProfilesMenu.SelectedIndex == -1)
{ return; }

try
{
var selectedBtn = GetSelectedProfileToggleButton();
var temp = Properties.Settings.Default.Profiles.FirstOrDefault(s =>
s.Id == ((ToggleButton) IServerProfilesMenu.SelectedItem).Name);
s.Id == selectedBtn?.Name);
if (temp == null)
{
DisplayMessage("Could not find the selected profile.");
return;
}

ServerProfile serverProfile = temp.Clone();
ServerProfile serverProfile = temp.Clone();
ServerProfileCollection.AddServerProfile(serverProfile);
}
catch (Exception err)
Expand All @@ -291,8 +316,9 @@

try
{
var selectedBtn = GetSelectedProfileToggleButton();
var temp = Properties.Settings.Default.Profiles.FirstOrDefault(s =>
s.Id == ((ToggleButton)IServerProfilesMenu.SelectedItem).Name);
s.Id == selectedBtn?.Name);
if (temp == null)
{
DisplayMessage("Could not find the selected profile.");
Expand Down Expand Up @@ -435,18 +461,88 @@
HorizontalContentAlignment = HorizontalAlignment.Left,
};
newItem.SetValue(TextOptions.TextFormattingModeProperty, TextFormattingMode.Display);
Dispatcher?.Invoke(() => { IServerProfilesMenu.Items.Add(newItem); });

var profileId = profile.Id;

var btnUp = new System.Windows.Controls.Button
{
Content = "▲",
FontSize = 10,
Width = 18,
Height = 18,
Padding = new Thickness(0),
Margin = new Thickness(0, 0, 1, 0),
VerticalAlignment = VerticalAlignment.Center,
Style = (Style)FindResource("MahApps.Styles.Button.MetroSquare"),
BorderThickness = new Thickness(0),
ToolTip = "Move Up",
};
btnUp.Click += (s, e) => { e.Handled = true; MoveProfileUp(profileId); };

var btnDown = new System.Windows.Controls.Button
{
Content = "▼",
FontSize = 10,
Width = 18,
Height = 18,
Padding = new Thickness(0),
Margin = new Thickness(0, 0, 2, 0),
VerticalAlignment = VerticalAlignment.Center,
Style = (Style)FindResource("MahApps.Styles.Button.MetroSquare"),
BorderThickness = new Thickness(0),
ToolTip = "Move Down",
};
btnDown.Click += (s, e) => { e.Handled = true; MoveProfileDown(profileId); };

var rowPanel = new System.Windows.Controls.DockPanel
{
HorizontalAlignment = HorizontalAlignment.Stretch,
LastChildFill = true,
};
System.Windows.Controls.DockPanel.SetDock(btnUp, System.Windows.Controls.Dock.Right);
System.Windows.Controls.DockPanel.SetDock(btnDown, System.Windows.Controls.Dock.Right);
rowPanel.Children.Add(btnDown);
rowPanel.Children.Add(btnUp);
rowPanel.Children.Add(newItem);

Dispatcher?.Invoke(() => { IServerProfilesMenu.Items.Add(rowPanel); });

newItem.Click += ToggleButton_Click;

if (ContentProfileViews.Any(tab => profile.Id == tab.Profile.Id))
if (ContentProfileViews.Any(tab => profile.Id == tab.Profile.Id))
continue;

var p = new ProfileViewModel(profile);
ContentProfileViews.Add(p);
}
}

private void MoveProfileUp(string profileId)
{
var profiles = Properties.Settings.Default.Profiles;
int idx = profiles.FindIndex(p => p.Id == profileId);
if (idx <= 0) return;
var item = profiles[idx];
profiles.RemoveAt(idx);
profiles.Insert(idx - 1, item);
Properties.Settings.Default.Profiles = profiles;
Properties.Settings.Default.Save();
LoadServerProfiles();
}

private void MoveProfileDown(string profileId)
{
var profiles = Properties.Settings.Default.Profiles;
int idx = profiles.FindIndex(p => p.Id == profileId);
if (idx < 0 || idx >= profiles.Count - 1) return;
var item = profiles[idx];
profiles.RemoveAt(idx);
profiles.Insert(idx + 1, item);
Properties.Settings.Default.Profiles = profiles;
Properties.Settings.Default.Save();
LoadServerProfiles();
}

private async Task ModConversion()
{
var properties = Properties.Settings.Default;
Expand Down
Loading