private void RemoveWindow(AppWindowViewModel window) { int index = _filteredWindowList.IndexOf(window); if (index < 0) { return; } if (lb.SelectedIndex == index) { if (_filteredWindowList.Count > index + 1) { lb.SelectedIndex++; } else { if (index > 0) { lb.SelectedIndex--; } } } _filteredWindowList.Remove(window); _unfilteredWindowList.Remove(window); }
/// <summary> /// Switches the window associated with the selected item. /// </summary> private void Switch() { if (lb.Items.Count > 0) { AppWindowViewModel win = (AppWindowViewModel)(lb.SelectedItem ?? lb.Items[0]); win.AppWindow.SwitchToLastVisibleActivePopup(); } HideWindow(); }
public async Task <bool> TryCloseAsync(AppWindowViewModel window) { window.IsBeingClosed = true; window.AppWindow.Close(); while (!_isDisposed && !window.AppWindow.IsClosedOrHidden) { await Task.Delay(CheckInterval).ConfigureAwait(false); } return(window.AppWindow.IsClosedOrHidden); }
private async void CloseWindow(object sender, ExecutedRoutedEventArgs e) { if (lb.Items.Count > 0) { AppWindowViewModel win = (AppWindowViewModel)lb.SelectedItem; if (win != null) { bool isClosed = await _windowCloser.TryCloseAsync(win); if (isClosed) { RemoveWindow(win); } } } else { HideWindow(); } e.Handled = true; }
/// <summary> /// Populates the window list with the current running windows. /// </summary> private void LoadData(InitialFocus focus) { _unfilteredWindowList = new WindowFinder().GetWindows().Select(window => new AppWindowViewModel(window)).ToList(); AppWindowViewModel firstWindow = _unfilteredWindowList.FirstOrDefault(); bool foregroundWindowMovedToBottom = false; // Move first window to the bottom of the list if it's related to the foreground window if (firstWindow != null && AreWindowsRelated(firstWindow.AppWindow, _foregroundWindow)) { _unfilteredWindowList.RemoveAt(0); _unfilteredWindowList.Add(firstWindow); foregroundWindowMovedToBottom = true; } _filteredWindowList = new ObservableCollection <AppWindowViewModel>(_unfilteredWindowList); _windowCloser = new WindowCloser(); foreach (AppWindowViewModel window in _unfilteredWindowList) { window.FormattedTitle = new XamlHighlighter().Highlight(new[] { new StringPart(window.AppWindow.Title) }); window.FormattedProcessTitle = new XamlHighlighter().Highlight(new[] { new StringPart(window.AppWindow.ProcessTitle) }); } lb.DataContext = null; lb.DataContext = _filteredWindowList; FocusItemInList(focus, foregroundWindowMovedToBottom); tb.Clear(); tb.Focus(); CenterWindow(); ScrollSelectedItemIntoView(); }