<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using NHotkey;
using NHotkey.Wpf;
using Wox.Core.i18n;
using Wox.Core.Plugin;
using Wox.Core.Theme;
using Wox.Core.Updater;
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Plugin;
using Wox.Storage;
using ContextMenu = System.Windows.Forms.ContextMenu;
using NotifyIcon = System.Windows.Forms.NotifyIcon;
using Screen = System.Windows.Forms.Screen;
using MenuItem = System.Windows.Forms.MenuItem;
using Stopwatch = Wox.Infrastructure.Stopwatch;

namespace Wox
{
    public partial class MainWindow : IPublicAPI
    {

        #region Properties

        private readonly Storyboard progressBarStoryboard = new Storyboard();
        private NotifyIcon notifyIcon;
        private bool _queryHasReturn;
        private Query _lastQuery = new Query();
        private ToolTip toolTip = new ToolTip();

        private bool _ignoreTextChange = false;
        private List<Result> CurrentContextMenus = new List<Result>();
        private string textBeforeEnterContextMenuMode;

        #endregion

        #region Public API

        public void ChangeQuery(string query, bool requery = false)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                tbQuery.Text = query;
                tbQuery.CaretIndex = tbQuery.Text.Length;
                if (requery)
                {
                    TbQuery_OnTextChanged(null, null);
                }
            }));
        }

        public void ChangeQueryText(string query, bool selectAll = false)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                _ignoreTextChange = true;
                tbQuery.Text = query;
                tbQuery.CaretIndex = tbQuery.Text.Length;
                if (selectAll)
                {
                    tbQuery.SelectAll();
                }
            }));
        }

        public void CloseApp()
        {
            Application.Current.Shutdown();
        }

        public void RestarApp()
        {
            ProcessStartInfo info = new ProcessStartInfo
            {
                FileName = Application.ResourceAssembly.Location,
                Arguments = SingleInstance<App>.Restart
            };<commit_msg>Fix duplication of tray icons<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using NHotkey;
using NHotkey.Wpf;
using Wox.Core.i18n;
using Wox.Core.Plugin;
using Wox.Core.Theme;
using Wox.Core.Updater;
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Plugin;
using Wox.Storage;
using ContextMenu = System.Windows.Forms.ContextMenu;
using NotifyIcon = System.Windows.Forms.NotifyIcon;
using Screen = System.Windows.Forms.Screen;
using MenuItem = System.Windows.Forms.MenuItem;
using Stopwatch = Wox.Infrastructure.Stopwatch;

namespace Wox
{
    public partial class MainWindow : IPublicAPI
    {

        #region Properties

        private readonly Storyboard progressBarStoryboard = new Storyboard();
        private NotifyIcon notifyIcon;
        private bool _queryHasReturn;
        private Query _lastQuery = new Query();
        private ToolTip toolTip = new ToolTip();

        private bool _ignoreTextChange = false;
        private List<Result> CurrentContextMenus = new List<Result>();
        private string textBeforeEnterContextMenuMode;

        #endregion

        #region Public API

        public void ChangeQuery(string query, bool requery = false)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                tbQuery.Text = query;
                tbQuery.CaretIndex = tbQuery.Text.Length;
                if (requery)
                {
                    TbQuery_OnTextChanged(null, null);
                }
            }));
        }

        public void ChangeQueryText(string query, bool selectAll = false)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                _ignoreTextChange = true;
                tbQuery.Text = query;
                tbQuery.CaretIndex = tbQuery.Text.Length;
                if (selectAll)
                {
                    tbQuery.SelectAll();
                }
            }));
        }

        public void CloseApp()
        {
            notifyIcon.Visible = false;
            Application.Current.Shutdown();
        }

        public void RestarApp()
        {
            ProcessStartInfo info = new ProcessStartInfo
            {
                FileName = Application.ResourceAssembly.Location,
                Arguments = SingleInstance<App>.Restart
            };
{'fraction_non_alphanumeric': 0.08162878787878788, 'fraction_numerical': 0.0007575757575757576, 'mean_word_length': 2.1341246290801186, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6162904', 'n_tokens_mistral': 1398, 'n_tokens_neox': 1347, 'n_words': 334}