Пример #1
0
        private void DealCmdCommand()
        {
            var command = cmd.Text.Trim();

            if (string.IsNullOrEmpty(command))
            {
                return;
            }

            CmdData data = CmdLikeTool.Instance.GetCmdData(command);

            if (data != null)
            {
                try
                {
                    data.DoCommand();
                    CmdLikeTool.Instance.CloseCmdWindow();
                }
                catch (Exception e)
                {
                    ShowTip(e.Message);
                }
            }
            else
            {
                ShowTip("指令不存在");
            }
        }
Пример #2
0
        private void AddSystemCmdData(string key, CmdCommandType type, string cmdCommand, string description)
        {
            var data = new CmdData(key);

            data.KeyBinding         = key;
            data.DescriptionBinding = description;
            data.type             = type;
            data.cmdCommand       = cmdCommand;
            config.systemDic[key] = data;
        }
Пример #3
0
        /// <summary>
        /// 根据key获取cmdData
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public CmdData GetCmdData(string key)
        {
            CmdData data = null;

            if (config.cmdDic.TryGetValue(key, out data))
            {
                return(data.Clone());
            }

            if (config.systemDic.TryGetValue(key, out data))
            {
                return(data.Clone());
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// 添加自定义路径
        /// </summary>
        /// <param name="key"></param>
        /// <param name="path"></param>
        public bool AddCustomCmdData(string key, string path)
        {
            if (config.cmdDic.ContainsKey(key) || config.systemDic.ContainsKey(key) || string.IsNullOrEmpty(key))
            {
                return(false);
            }

            // 检测路径是否存在
            if (!File.Exists(path) && !Directory.Exists(path))
            {
                return(false);
            }

            var data = new CmdData(key);

            data.KeyBinding         = key;
            data.DescriptionBinding = path;
            data.type          = CmdCommandType.OpenFile;
            data.sortIndex     = ++addCustomTime;
            config.cmdDic[key] = data;

            return(true);
        }
Пример #5
0
        private void Grid_Drop(object sender, DragEventArgs e)
        {
            string fileName = "";

            try
            {
                fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            }
            catch
            {
                ShowMassage("无法识别该文件。");
                return;
            }

            var key = fileName;

            if (File.Exists(fileName))
            {
                var file = new FileInfo(fileName);
                key = file.Name;
            }
            else if (Directory.Exists(fileName))
            {
                var dir = new DirectoryInfo(fileName);
                key = dir.Name;
            }
            else
            {
                ShowMassage("无法识别该文件。");
                return;
            }

            // 与原有的重复
            if (CmdLikeTool.Instance.GetAllCommandKeys().Contains(key))
            {
                // 额外加一个后缀避免重复
                key += REPEAT;
            }

            // 与新添加的重复
            foreach (var item in tempCmdList)
            {
                if (item.KeyBinding == key)
                {
                    key += REPEAT;
                    break;
                }
            }

            CmdData data = new CmdData();

            data.sortIndex          = ++addIndex;
            data.KeyBinding         = key;
            data.DescriptionBinding = fileName;
            tempCmdList.Add(data);

            // 刷新界面
            RefreshCustomPanel();

            ShowMassage(HAVE_CHANGE);
        }