Пример #1
0
        /// <summary>
        /// Populates the window list with the current running windows.
        /// </summary>
        private void LoadData(InitialFocus focus)
        {
            _unfilteredWindowList = AppWindow.AllAltTabWindows
                                    .Select(window => new AppWindowViewModel(window))
                                    .OrderBy(w => w.WindowTitle)
                                    .ToList();

            var firstWindow = _unfilteredWindowList.FirstOrDefault();

            _filteredWindowList = new ObservableCollection <AppWindowViewModel>(_unfilteredWindowList);
            _windowCloser       = new WindowCloser();

            foreach (var 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);

            tb.Clear();
            tb.Focus();
            CenterWindowBelowCursor();
            ScrollSelectedItemIntoView();
        }
Пример #2
0
        /// <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();

            var firstWindow = _unfilteredWindowList.FirstOrDefault();

            var 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();

            for (var i = 0; i < _unfilteredWindowList.Count; i++)
            {
                _unfilteredWindowList[i].FormattedTitle        = new XamlHighlighter().Highlight(new[] { new StringPart(_unfilteredWindowList[i].AppWindow.Title) });
                _unfilteredWindowList[i].FormattedProcessTitle =
                    new XamlHighlighter().Highlight(new[] { new StringPart(_unfilteredWindowList[i].AppWindow.ProcessTitle) });
            }

            if (_sortWinList == true)
            {
                _unfilteredWindowList = _unfilteredWindowList.OrderBy(x => x.FormattedProcessTitle).ToList();
            }

            var _itemsCountToHighlight = Math.Min(_unfilteredWindowList.Count, 10);

            for (var i = 0; i < _itemsCountToHighlight; i++)
            {
                _unfilteredWindowList[i].FormattedTitle = new XamlHighlighter().Highlight(new[] { new StringPart("" + (i + 1) + " ", true) }) + _unfilteredWindowList[i].FormattedTitle;
            }

            if (_sortWinList == true)
            {
                lb.DataContext = null;
                lb.DataContext = _unfilteredWindowList;
            }
            else
            {
                lb.DataContext = _filteredWindowList;
            }

            FocusItemInList(focus, foregroundWindowMovedToBottom);

            if (tb.IsEnabled)
            {
                tb.Clear();
            }
            tb.Focus();
            CenterWindow();
            ScrollSelectedItemIntoView();
        }
Пример #3
0
        /// <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();

            // Move all un-activated top-most windows to the bottom of the list
            var topMostWindowList = _unfilteredWindowList.TakeWhile(windowModel =>
                                                                    windowModel.AppWindow.TopMost && windowModel.AppWindow != _foregroundWindow).ToList();

            _unfilteredWindowList = _unfilteredWindowList.Except(topMostWindowList).Concat(topMostWindowList).ToList();

            var firstWindow = _unfilteredWindowList.FirstOrDefault();
            var 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 (var 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) });
            }

            if (_sortWinList == true)
            {
                _unfilteredWindowList = _unfilteredWindowList.OrderBy(x => x.FormattedProcessTitle).ToList();
                AddPrefixNumbersToFormattedTitle(_unfilteredWindowList);

                lb.DataContext = null;
                lb.DataContext = _unfilteredWindowList;
            }
            else
            {
                AddPrefixNumbersToFormattedTitle(_filteredWindowList);
                lb.DataContext = _filteredWindowList;
            }

            FocusItemInList(focus, foregroundWindowMovedToBottom);

            if (tb.IsEnabled)
            {
                tb.Clear();
            }
            tb.Focus();
            CenterWindow();
            ScrollSelectedItemIntoView();
        }
Пример #4
0
        private void FocusItemInList(InitialFocus focus)
        {
            if (focus == InitialFocus.PreviousItem)
            {
                var previousItemIndex = lb.Items.Count - 1;

                lb.SelectedIndex = previousItemIndex > 0 ? previousItemIndex : 0;
            }
            else
            {
                lb.SelectedIndex = 0;
            }
        }
Пример #5
0
        void NativeWidget_Opened(object sender, EventArgs e)
        {
            if (DisableArrowKeyNavigation)
            {
                FrameworkElement popupRoot = GetPopupRoot();
                if (popupRoot != null)
                {
                    KeyboardNavigation.SetDirectionalNavigation(popupRoot, KeyboardNavigationMode.Once);
                }
            }

            if (InitialFocus != null)
            {
                InitialFocus.Focus();
            }
        }
Пример #6
0
        private void FocusItemInList(InitialFocus focus, bool foregroundWindowMovedToBottom)
        {
            if (focus == InitialFocus.PreviousItem)
            {
                var previousItemIndex = lb.Items.Count - 1;
                if (foregroundWindowMovedToBottom)
                {
                    previousItemIndex--;
                }

                lb.SelectedIndex = previousItemIndex > 0 ? previousItemIndex : 0;
            }
            else
            {
                lb.SelectedIndex = 0;
            }
        }
Пример #7
0
        /// <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();

            var firstWindow = _unfilteredWindowList.FirstOrDefault();

            var 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.OrderBy(i => i.WindowTitle));
            _windowCloser       = new WindowCloser();

            foreach (var window in _unfilteredWindowList)
            {
                window.FormattedTitle        = new XamlHighlighter().Highlight(new[] { new StringPart(window.WindowTitle) });
                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();
        }
Пример #8
0
        private void FocusItemInList(InitialFocus focus, bool foregroundWindowMovedToBottom)
        {
            if (focus == InitialFocus.PreviousItem)
            {
                var previousItemIndex = lb.Items.Count - 1;
                if (foregroundWindowMovedToBottom)
                {
                    previousItemIndex--;
                }

                lb.SelectedIndex = previousItemIndex > 0 ? previousItemIndex : 0;
            }
            else
            {
                lb.SelectedIndex = 0;
            }
        }
Пример #9
0
        /// <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();

            var firstWindow = _unfilteredWindowList.FirstOrDefault();

            var 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 (var 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();
        }