Exemplo n.º 1
0
        private string ExecuteScript(SnippetItem target)
        {
            if (target.Text == null)
            {
                return(null);
            }

            MyKourin.Echo   = true; //スクリプト開始時はエコーON
            MyKourin.Output = "";   //出力初期化
            //実行
            //結果値がnullでなくエコー設定がONの場合のみ出力に追加される。
            var ret = kourin.Execute(target.Text);

            if (ret != null)
            {
                if (MyKourin.Output.Length > 0)
                {
                    MyKourin.Output += Environment.NewLine;
                }
                MyKourin.Output += ret;
            }
            var output = MyKourin.Output;

            MyKourin.Output = null;
            return(output);
        }
Exemplo n.º 2
0
 private void setToolTip(SnippetItem item)
 {
     if (item == null)
     {
         setToolTip("");
     }
     else
     {
         setToolTip(item.Text);
     }
 }
Exemplo n.º 3
0
 private ListBox ParentListbox(SnippetItem item)
 {
     foreach (var x in listboxs)
     {
         if (x.Items.Contains(item))
         {
             return(x);
         }
     }
     return(null);
 }
Exemplo n.º 4
0
 private string ExecuteCommand(SnippetItem target)
 {
     if (target.Text == "ExecScript")
     {   //クリップボードの値を対象にスクリプト実行して結果を返す
         if (!System.Windows.Clipboard.ContainsText())
         {
             return(null);
         }
         var text = System.Windows.Clipboard.GetText();
         return(ExecuteScript(new SnippetItem()
         {
             Type = SnippetItem.ItemType.Script, Text = text
         }));
     }
     return(null);
 }
Exemplo n.º 5
0
        /// <summary>
        /// 処理実行
        /// </summary>
        private void Execute(SnippetItem target)
        {
            string text = null;

            try {
                switch (target.Type)
                {
                case SnippetItem.ItemType.Command:
                    text = ExecuteCommand(target); break;

                case SnippetItem.ItemType.Script:
                    text = ExecuteScript(target); break;

                default:
                    text = target.Text; break;
                }
            }catch (KarinException ex) {
                Shared.Logger.write(LogTypes.ERROR, "スクリプトエラー/" + ex.Message + Environment.NewLine + ex.ScriptStackTrace);
                MessageBox.Show("スクリプトエラー/" + ex.Message + Environment.NewLine + ex.ScriptStackTrace);
            }catch (Exception ex) {
                Shared.Logger.write(LogTypes.ERROR, "実行時エラー/" + ex.ToString());
                MessageBox.Show("実行時エラー/" + ex.GetType().Name + "/" + ex.Message);
            }
            if (text == null || text == "")
            {
                return;
            }

            //クリップボードに設定
            try { System.Windows.Clipboard.SetText(text); }
            catch (COMException ex) {
                //COMExceptionが出てもできてる場合が多い
                Shared.Logger.write(LogTypes.ERROR, "Clipboard.SetText異常/" + ex.ToString());
            }

            //ウィンドウのフォーカスが戻るまで一応少し間を空ける
            if (FocusHandle != IntPtr.Zero)
            {
                SetActiveWindow(FocusHandle);
                SetFocus(FocusHandle);
            }
            System.Threading.Thread.Sleep(Shared.Setting.Interval);

            //貼り付け
            //(Ctrl+v)
            Func <int, int, Input> CreateKeyInput = (vkey, flag) => {
                var input = new Input();
                input.dwType     = 1;
                input.ki         = new KeyboardInput();
                input.ki.wVk     = (short)(('a' <= vkey && vkey <= 'x') ? (vkey - 'a' + 'A') : vkey);
                input.ki.wScan   = (short)MapVirtualKey(input.ki.wVk, 0);
                input.ki.dwFlags = flag;
                return(input);
            };

            var inputs = new List <Input>();

            inputs.Add(CreateKeyInput(0x11, 0x0 | 0x4));                             //Ctrl
            inputs.Add(CreateKeyInput(Shared.Setting.PasteKey /*0x56*/, 0x0 | 0x4)); //v
            inputs.Add(CreateKeyInput(Shared.Setting.PasteKey /*0x56*/, 0x2 | 0x4));
            inputs.Add(CreateKeyInput(0x11, 0x2 | 0x4));

            var ed = inputs.ToArray();

            SendInput(ed.Length, ed, Marshal.SizeOf(ed[0]));

            //貼り付け
            //(WindowMessage)
            //駄目。秀丸やメモ帳はできるが
            //ChromeやVisualStudioは受け付けない。
            //SendMessage(focusWHnd, WM_PASTE, 0, 0);
        }
Exemplo n.º 6
0
        /// <summary>
        /// アイテムファイル読み込み
        /// </summary>
        private List <SnippetItem> CreateNode(string path)
        {
            Func <string, string> ReadText = (filePath) => {
                using (var reader = new StreamReader(filePath, Encoding.GetEncoding("SJIS")))
                    return(reader.ReadToEnd());
            };
            Func <string, string[]> ReadTexts = (filePath) => {
                var list = new List <string>();
                using (var reader = new StreamReader(filePath, Encoding.GetEncoding("SJIS"))){
                    string str = null;
                    while ((str = reader.ReadLine()) != null)
                    {
                        list.Add(str);
                    }
                    return(list.ToArray());
                }
            };
            //--------------------
            var ret = new List <SnippetItem>();

            //ディレクトリ
            if (Directory.Exists(path))
            {
                var itm = new SnippetItem();
                itm.Name     = Path.GetFileName(path);
                itm.Type     = SnippetItem.ItemType.Directory;
                itm.Children = new List <SnippetItem>();
                var paths = new List <string>();
                paths.AddRange(Directory.EnumerateDirectories(path));
                paths.AddRange(Directory.EnumerateFiles(path));
                paths.Sort();
                foreach (var child in paths)
                {
                    itm.Children.AddRange(CreateNode(child));
                }
                ret.Add(itm);
            }
            //テキスト
            else if (Path.GetExtension(path) == ".txt")
            {
                var txt = ReadText(path);
                var opt = "";
                if (txt.StartsWith("@@"))
                {
                    var re = new StringReader(txt);
                    opt = re.ReadLine().Remove(0, 2);
                    txt = re.ReadToEnd();
                    re.Dispose();
                }

                if (opt == "")
                {
                    //単一テキスト
                    var itm = new SnippetItem();
                    itm.Type = SnippetItem.ItemType.Text;
                    itm.Name = Path.GetFileNameWithoutExtension(path);
                    itm.Text = ReadText(path);
                    ret.Add(itm);
                }
                else if (opt == "list")
                {
                    //リスト
                    foreach (var s in Regex.Split(txt, Environment.NewLine))
                    {
                        if (s.Trim() == "")
                        {
                            continue;
                        }
                        var itm = new SnippetItem();
                        itm.Type = SnippetItem.ItemType.Text;

                        var ss = Regex.Split(s, "(\\s//|//\\s)");

                        if (ss.Length > 2)
                        {
                            itm.Name = ss[0].Trim();
                            itm.Text = string.Join("", ss.Skip(2)).Trim();
                        }
                        else
                        {
                            itm.Name = ss[0].Trim();
                            itm.Text = itm.Name;
                        }

                        if (Regex.IsMatch(itm.Text, "^#[0-9a-fA-F]{6}$"))
                        {
                            itm.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(itm.Text));
                        }

                        ret.Add(itm);
                    }
                }
            }
            //テキストリスト
            else if (Path.GetExtension(path) == ".list")
            {   //非推奨 互換用
                var itm = new SnippetItem();
                itm.Type     = SnippetItem.ItemType.Directory;
                itm.Name     = Path.GetFileNameWithoutExtension(path);
                itm.Children = new List <SnippetItem>();
                foreach (var txt in ReadTexts(path))
                {
                    var child = new SnippetItem();
                    child.Type = SnippetItem.ItemType.Text;
                    child.Name = txt;
                    child.Text = txt;
                    itm.Children.Add(child);
                }
                ret.Add(itm);
            }
            //スクリプト
            else if (Path.GetExtension(path) == ".scr" || Path.GetExtension(path) == ".ks")
            {
                var itm = new SnippetItem();
                itm.Type = SnippetItem.ItemType.Script;
                itm.Name = Path.GetFileNameWithoutExtension(path);
                itm.Text = ReadText(path).Trim();
                ret.Add(itm);
            }
            return(ret);
        }
Exemplo n.º 7
0
 private void ClosePopup(SnippetItem selected)
 {
     this.SelectedItem = selected;
     this.Close();
 }