2014-01-29 18:33:24 +08:00
|
|
|
|
using System;
|
2015-01-08 22:49:42 +08:00
|
|
|
|
using System.ComponentModel;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using System.Windows;
|
2016-01-07 05:34:42 +08:00
|
|
|
|
using System.Windows.Forms;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Windows.Media.Animation;
|
2016-03-26 09:20:42 +08:00
|
|
|
|
using System.Windows.Controls;
|
2014-12-26 19:36:43 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
2016-01-08 04:04:37 +08:00
|
|
|
|
using Wox.Core.Resource;
|
2015-01-05 22:41:17 +08:00
|
|
|
|
using Wox.Core.UserSettings;
|
2014-03-02 11:04:30 +08:00
|
|
|
|
using Wox.Helper;
|
2014-12-21 22:03:03 +08:00
|
|
|
|
using Wox.Infrastructure.Hotkey;
|
2016-02-23 05:43:37 +08:00
|
|
|
|
using Wox.ViewModel;
|
2016-01-07 05:34:42 +08:00
|
|
|
|
using DataFormats = System.Windows.DataFormats;
|
|
|
|
|
using DragEventArgs = System.Windows.DragEventArgs;
|
|
|
|
|
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
namespace Wox
|
|
|
|
|
{
|
2016-02-18 19:30:36 +08:00
|
|
|
|
public partial class MainWindow
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
#region Private Fields
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private readonly Storyboard _progressBarStoryboard = new Storyboard();
|
2016-04-21 08:53:21 +08:00
|
|
|
|
private Settings _settings;
|
2015-02-04 23:16:41 +08:00
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
#endregion
|
2016-02-27 07:43:57 +08:00
|
|
|
|
|
2016-04-21 08:53:21 +08:00
|
|
|
|
public MainWindow(Settings settings, MainViewModel mainVM)
|
2016-03-28 10:09:57 +08:00
|
|
|
|
{
|
|
|
|
|
DataContext = mainVM;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_settings = settings;
|
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2016-02-18 19:30:36 +08:00
|
|
|
|
}
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private void OnClosing(object sender, CancelEventArgs e)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.WindowLeft = Left;
|
|
|
|
|
_settings.WindowTop = Top;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs _)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2015-02-20 21:45:42 +08:00
|
|
|
|
InitProgressbarAnimation();
|
|
|
|
|
WindowIntelopHelper.DisableControlBox(this);
|
2016-02-12 17:20:46 +08:00
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
var vm = (MainViewModel)DataContext;
|
|
|
|
|
vm.TextBoxSelected += (o, e) => QueryTextBox.SelectAll();
|
|
|
|
|
vm.CursorMovedToEnd += (o, e) =>
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-27 07:43:57 +08:00
|
|
|
|
QueryTextBox.Focus();
|
|
|
|
|
QueryTextBox.CaretIndex = QueryTextBox.Text.Length;
|
|
|
|
|
};
|
|
|
|
|
vm.MainWindowVisibilityChanged += (o, e) =>
|
|
|
|
|
{
|
|
|
|
|
if (vm.MainWindowVisibility.IsVisible())
|
2016-02-12 17:20:46 +08:00
|
|
|
|
{
|
2016-02-27 07:43:57 +08:00
|
|
|
|
Activate();
|
|
|
|
|
QueryTextBox.Focus();
|
2016-03-25 10:38:10 +08:00
|
|
|
|
Left = GetWindowsLeft();
|
|
|
|
|
Top = GetWindowsTop();
|
2016-04-21 08:53:21 +08:00
|
|
|
|
_settings.ActivateTimes++;
|
2016-03-25 10:38:10 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
_settings.WindowLeft = Left;
|
|
|
|
|
_settings.WindowTop = Top;
|
2016-02-12 17:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-03-26 09:20:42 +08:00
|
|
|
|
// happlebao todo delete
|
2016-02-12 17:20:46 +08:00
|
|
|
|
vm.Left = GetWindowsLeft();
|
|
|
|
|
vm.Top = GetWindowsTop();
|
2016-02-27 05:34:27 +08:00
|
|
|
|
vm.MainWindowVisibility = Visibility.Visible;
|
2015-02-20 21:45:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double GetWindowsLeft()
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
if (_settings.RememberLastLaunchLocation)
|
2016-03-25 10:38:10 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
return _settings.WindowLeft;
|
2016-03-25 10:38:10 +08:00
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
|
2015-12-13 11:22:01 +08:00
|
|
|
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
2016-03-25 10:38:10 +08:00
|
|
|
|
var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.X, 0);
|
|
|
|
|
var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, screen.WorkingArea.Width, 0);
|
|
|
|
|
var left = (dip2.X - ActualWidth) / 2 + dip1.X;
|
|
|
|
|
return left;
|
2015-02-20 21:45:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double GetWindowsTop()
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
if (_settings.RememberLastLaunchLocation)
|
2016-03-25 10:38:10 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
return _settings.WindowTop;
|
2016-03-25 10:38:10 +08:00
|
|
|
|
}
|
2015-12-13 11:22:01 +08:00
|
|
|
|
|
2015-02-20 21:45:42 +08:00
|
|
|
|
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
|
2016-03-25 10:38:10 +08:00
|
|
|
|
var dip1 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
|
|
|
|
|
var dip2 = WindowIntelopHelper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Height);
|
|
|
|
|
var top = (dip2.Y - ActualHeight) / 4 + dip1.Y;
|
|
|
|
|
return top;
|
2015-02-01 22:46:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 04:46:19 +08:00
|
|
|
|
private void InitProgressbarAnimation()
|
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 100, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
|
|
|
|
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
|
|
|
|
|
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
|
2016-02-27 07:43:57 +08:00
|
|
|
|
_progressBarStoryboard.Children.Add(da);
|
|
|
|
|
_progressBarStoryboard.Children.Add(da1);
|
|
|
|
|
_progressBarStoryboard.RepeatBehavior = RepeatBehavior.Forever;
|
2016-03-28 10:09:57 +08:00
|
|
|
|
ProgressBar.Visibility = Visibility.Hidden;
|
|
|
|
|
ProgressBar.BeginStoryboard(_progressBarStoryboard);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private void OnMouseDown(object sender, MouseButtonEventArgs e)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
if (e.ChangedButton == MouseButton.Left) DragMove();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private void OnDeactivated(object sender, EventArgs e)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2016-03-28 10:09:57 +08:00
|
|
|
|
if (_settings.HideWhenDeactive)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2016-02-12 17:20:46 +08:00
|
|
|
|
App.API.HideApp();
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
|
2016-02-12 14:21:12 +08:00
|
|
|
|
{
|
2016-02-21 23:42:37 +08:00
|
|
|
|
var vm = DataContext as MainViewModel;
|
2016-02-19 22:58:27 +08:00
|
|
|
|
if (null == vm) return;
|
2016-02-12 14:21:12 +08:00
|
|
|
|
//when alt is pressed, the real key should be e.SystemKey
|
2016-02-19 22:58:27 +08:00
|
|
|
|
var key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
2016-02-12 14:21:12 +08:00
|
|
|
|
switch (key)
|
|
|
|
|
{
|
2016-02-19 22:58:27 +08:00
|
|
|
|
case Key.Escape:
|
|
|
|
|
vm.EscCommand.Execute(null);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.Tab:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.SelectPrevItemCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.SelectNextItemCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.N:
|
|
|
|
|
case Key.J:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.SelectNextItemCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.P:
|
|
|
|
|
case Key.K:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.SelectPrevItemCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.O:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
2016-03-26 09:20:42 +08:00
|
|
|
|
vm.LoadContextMenuCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.Enter:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.LoadContextMenuCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(null);
|
2016-02-19 22:58:27 +08:00
|
|
|
|
}
|
2016-03-26 09:20:42 +08:00
|
|
|
|
e.Handled = true;
|
2016-02-19 22:58:27 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2016-02-12 14:21:12 +08:00
|
|
|
|
case Key.Down:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.DisplayNextQueryCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.SelectNextItemCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.Up:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.DisplayPrevQueryCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vm.SelectPrevItemCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
2016-02-19 22:58:27 +08:00
|
|
|
|
|
|
|
|
|
case Key.D:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.SelectNextPageCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2016-02-12 14:21:12 +08:00
|
|
|
|
case Key.PageDown:
|
|
|
|
|
vm.SelectNextPageCommand.Execute(null);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
2016-02-19 22:58:27 +08:00
|
|
|
|
|
|
|
|
|
case Key.U:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.SelectPrevPageCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2016-02-12 14:21:12 +08:00
|
|
|
|
case Key.PageUp:
|
|
|
|
|
vm.SelectPrevPageCommand.Execute(null);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
break;
|
2016-02-19 22:58:27 +08:00
|
|
|
|
|
2016-02-12 17:20:46 +08:00
|
|
|
|
case Key.Back:
|
|
|
|
|
vm.BackCommand.Execute(e);
|
|
|
|
|
break;
|
2016-02-19 22:58:27 +08:00
|
|
|
|
|
|
|
|
|
case Key.F1:
|
|
|
|
|
vm.StartHelpCommand.Execute(null);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D1:
|
|
|
|
|
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D2:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D3:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(2);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D4:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(3);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Key.D5:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(4);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Key.D6:
|
|
|
|
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(5);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-03-26 09:20:42 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-19 22:58:27 +08:00
|
|
|
|
|
2016-03-26 09:20:42 +08:00
|
|
|
|
private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (sender != null && e.OriginalSource != null)
|
|
|
|
|
{
|
|
|
|
|
var r = (ResultListBox)sender;
|
|
|
|
|
var d = (DependencyObject)e.OriginalSource;
|
|
|
|
|
var item = ItemsControl.ContainerFromElement(r, d) as ListBoxItem;
|
|
|
|
|
var result = (ResultViewModel)item?.DataContext;
|
|
|
|
|
if (result != null)
|
|
|
|
|
{
|
|
|
|
|
var vm = DataContext as MainViewModel;
|
|
|
|
|
if (vm != null)
|
|
|
|
|
{
|
|
|
|
|
if (e.ChangedButton == MouseButton.Left)
|
|
|
|
|
{
|
|
|
|
|
vm.OpenResultCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
else if (e.ChangedButton == MouseButton.Right)
|
|
|
|
|
{
|
|
|
|
|
vm.LoadContextMenuCommand.Execute(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-12 14:21:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-18 19:30:36 +08:00
|
|
|
|
|
2016-03-26 09:20:42 +08:00
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private void OnDrop(object sender, DragEventArgs e)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
2015-01-08 22:49:42 +08:00
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
// Note that you can have more than one file.
|
2015-01-08 22:49:42 +08:00
|
|
|
|
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
if (files[0].ToLower().EndsWith(".wox"))
|
|
|
|
|
{
|
2014-12-27 12:34:51 +08:00
|
|
|
|
PluginManager.InstallPlugin(files[0]);
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-01-21 23:00:56 +08:00
|
|
|
|
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidWoxPluginFileFormat"));
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-12 14:21:12 +08:00
|
|
|
|
e.Handled = false;
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-27 07:43:57 +08:00
|
|
|
|
private void OnPreviewDragOver(object sender, DragEventArgs e)
|
2014-07-24 04:46:19 +08:00
|
|
|
|
{
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2016-03-11 12:23:46 +08:00
|
|
|
|
|
|
|
|
|
private void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
App.API.OpenSettingDialog();
|
|
|
|
|
}
|
2014-07-24 04:46:19 +08:00
|
|
|
|
}
|
2013-12-22 19:35:21 +08:00
|
|
|
|
}
|