Beispiel #1
0
        public MainViewModel()
        {
            try
            {
                Shortcuts = new ObservableCollection <Shortcut>(XmlReader.GetShortcuts());
                Shortcuts.GiveIndexes();
            }
            catch (Exception)
            {
                Shortcuts = new ObservableCollection <Shortcut>();
            }

            Shortcuts.CollectionChanged += (s, _) => XmlReader.SaveShortcuts((IEnumerable <Shortcut>)s);

            ChangeVisibility = new DelegateCommand <EventArgs>(_ => Visibility = !Visibility);
            MouseWheel       = new DelegateCommand <MouseWheelEventArgs>(e => RotateShortcuts(-e.Delta / 120));
            DragEnter        = new DelegateCommand <DragEventArgs>(e => e.Effects = e.Data.IsFile() ? DragDropEffects.Copy : DragDropEffects.None);
            Drop             = new DelegateCommand <DragEventArgs>(e => Shortcuts.AddFiles(e.Data), e => e.Data.IsFile());

#if !DEBUG
            Hook.GlobalEvents().MouseClick += (s, e) =>
            {
                if (e.Button != System.Windows.Forms.MouseButtons.Middle)
                {
                    return;
                }

                ChangeVisibility.Execute(null);

                if (!Visibility)
                {
                    return;
                }

                WindowPosition = new Vector(e.X - WindowSize.X / 2, e.Y - WindowSize.Y / 2);
            };
#endif
        }