PowerControl: Simplify Next, Select and SelectNext

This commit is contained in:
Kamil Trzciński 2022-12-19 22:17:05 +01:00
parent 130a6fb745
commit 06f2d9a702
5 changed files with 41 additions and 93 deletions

View file

@ -160,26 +160,22 @@ namespace PowerControl.Menu
scheduleApply();
}
public override void SelectNext()
public override void SelectNext(int change)
{
int index = Options.IndexOf(SelectedOption ?? ActiveOption);
if (index < 0)
SelectIndex(0); // select first
else if (CycleOptions)
SelectIndex((index + 1) % Options.Count);
else
SelectIndex(index + 1);
}
{
if (change > 0)
SelectIndex(0); // select first
else
SelectIndex(Options.Count); // select last
return;
}
public override void SelectPrev()
{
int index = Options.IndexOf(SelectedOption ?? ActiveOption);
if (index < 0)
SelectIndex(Options.Count - 1); // select last
else if (CycleOptions)
SelectIndex((index - 1 + Options.Count) % Options.Count);
if (CycleOptions)
SelectIndex((index + change + Options.Count) % Options.Count);
else
SelectIndex(index - 1);
SelectIndex(index + change);
}
private String optionText(Object option)