Exemplo n.º 1
0
        public static void Bind(HotKeys engine, ToolStripMenuItem rootMenu, string mappingFile)
        {
            if (engine.Started)
            {
                EnsureDefaults(mappingFile);

                if (File.Exists(mappingFile))
                {
                    TrayIcon.InvokeMenu.DropDownItems.Clear();

                    foreach (HotKeyBinding item in LoadFrom(mappingFile))
                    {
                        try
                        {
                            string[] tokens = item.HotKey.Split('+').Select(x => x.Trim()).ToArray();

                            Keys key = tokens.Last().ToKeys();

                            Modifiers modifiers = tokens.Take(tokens.Length - 1)
                                                  .ToModifiers();

                            var handlerName = item.Name;

                            Action handler;
                            if (EmbeddedHandlers.ContainsKey(handlerName)) //<MultiClip.Show>
                            {
                                handler = EmbeddedHandlers[handlerName];
                            }
                            else
                            {
                                string app  = item.Application;
                                string args = item.Args;

                                handler = () =>
                                {
                                    try
                                    {
                                        if (!item.CreateConsole)
                                        {
                                            var info = new ProcessStartInfo
                                            {
                                                FileName               = app,
                                                Arguments              = args,
                                                UseShellExecute        = false,
                                                RedirectStandardOutput = true,
                                                CreateNoWindow         = true
                                            };
                                            Process.Start(info);
                                        }
                                        else
                                        {
                                            Process.Start(app, args);
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Operations.MsgBox(e.Message, "MultiClip - " + handlerName);
                                    }
                                };
                            }

                            rootMenu.DropDownItems.Add(handlerName, null, (s, e) => handler());
                            engine.Bind(modifiers, key, handler);
                        }
                        catch { }
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static void Bind(HotKeys engine, ToolStripMenuItem rootMenu)
 {
     Bind(engine, rootMenu, hotKeysMapping);
 }