Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort functionality + shortcut + shortcut replace #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 28 additions & 3 deletions Switcheroo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public partial class MainWindow : Window
private AltTabHook _altTabHook;
private SystemWindow _foregroundWindow;
private bool _altTabAutoSwitch;
private bool _sorted = false;

public MainWindow()
{
Expand Down Expand Up @@ -102,13 +103,17 @@ private void SetUpKeyBindings()
{
Opacity = 0;
}
else if (args.SystemKey == Key.S && Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
else if (args.SystemKey == Key.Q && Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
{
_altTabAutoSwitch = false;
tb.Text = "";
tb.IsEnabled = true;
tb.Focus();
}
else if (args.SystemKey == Key.S && Keyboard.Modifiers.HasFlag(ModifierKeys.Alt))
{
SortWindowsList();
}
};

KeyUp += (sender, args) =>
Expand All @@ -132,6 +137,26 @@ private void SetUpKeyBindings()
}
};
}

private void SortWindowsList()
{
if (!_sorted)
{
// sort
_unfilteredWindowList = _unfilteredWindowList.OrderBy(x => x.FormattedProcessTitle).ToList();

// re-populate list
lb.DataContext = null;
lb.DataContext = _unfilteredWindowList;
_sorted = true;
}
else
{
// restore original
LoadData(InitialFocus.NextItem);
_sorted = false;
}
}

private void SetUpHotKey()
{
Expand Down Expand Up @@ -498,7 +523,7 @@ private void AltTabPressed(object sender, AltTabHookEventArgs e)
{
_altTabAutoSwitch = true;
tb.IsEnabled = false;
tb.Text = "Press Alt + S to search";
tb.Text = "Press Alt + Q to search";
}

Opacity = 1;
Expand Down Expand Up @@ -724,4 +749,4 @@ private enum InitialFocus
PreviousItem
}
}
}
}