Beispiel #1
0
 //Open Snipe by Shortcut (Ctrl + Shift + I or Print)
 private void OpenFromShortcutImg(HotKey h)
 {
     h.HotKeyPressed -= OpenFromShortcutImg;
     Crop(false, false);
     h.HotKeyPressed += OpenFromShortcutImg;
 }
Beispiel #2
0
 //Open Snipe by Shortcut (Ctrl + Shift + I or Print)
 private void OpenFromShortcutGif(HotKey h)
 {
     h.HotKeyPressed -= OpenFromShortcutGif;
     Crop(false, true);
     h.HotKeyPressed += OpenFromShortcutGif;
 }
Beispiel #3
0
        private async void InitializeTray()
        {
            Visibility = Visibility.Hidden;

            //Wait for Dispatcher to utilize (Apparently it won't work without a Delay)
            await Task.Delay(1000);

            Key  imgKey   = FileIO.ShortcutImgKey;
            Key  gifKey   = FileIO.ShortcutGifKey;
            bool usePrint = FileIO.UsePrint;

            HotKey imgHotKey = null;

            try {
                imgHotKey = usePrint
                    ? new HotKey(ModifierKeys.None, Key.PrintScreen, this)
                    : new HotKey(ModifierKeys.Control | ModifierKeys.Shift, imgKey, this);
                imgHotKey.HotKeyPressed += OpenFromShortcutImg;
            } catch {
                //ignored
            }
            try {
                HotKey gifHotKey = new HotKey(ModifierKeys.Control | ModifierKeys.Shift, gifKey, this);
                gifHotKey.HotKeyPressed += OpenFromShortcutGif;
            } catch {
                //ignored
            }

            ContextMenu menu = new ContextMenu();

            menu.MenuItems.Add(strings.gif, delegate { Crop(false, true); });

            menu.MenuItems.Add("-");

            menu.MenuItems.Add(strings.help, delegate {
                try {
                    Process.Start(Path.Combine(FileIO.ProgramFiles, "ImgurSniper.UI.exe"), "Help");
                } catch {
                    // ignored
                }
            });

            menu.MenuItems.Add(strings.settings, delegate {
                try {
                    Process.Start(Path.Combine(FileIO.ProgramFiles, "ImgurSniper.UI.exe"));
                } catch {
                    // ignored
                }
            });
            menu.MenuItems.Add(strings.exit, delegate { Application.Current.Shutdown(); });

            _nicon = new NotifyIcon {
                Icon        = Properties.Resources.Logo,
                ContextMenu = menu,
                Visible     = true,
                Text        = strings.clickorpress +
                              (usePrint ? strings.printKeyShortcut : string.Format(strings.ctrlShiftShortcut, imgKey)) +
                              strings.toSnipeNew
            };
            _nicon.MouseClick += (sender, e) => {
                if (e.Button == MouseButtons.Left)
                {
                    if (imgHotKey == null)
                    {
                        Crop(false, false);
                    }
                    else
                    {
                        OpenFromShortcutImg(imgHotKey);
                    }
                }
            };

            Application.Current.Exit += delegate {
                _nicon.Icon    = null;
                _nicon.Visible = false;
                _nicon.Dispose();
                _nicon = null;
            };
        }