Ejemplo n.º 1
0
        public void コマンドラインがFileNameとArgumentsプロパティに反映される(
            string commandLine, string expectedFileName, string expectedArguments)
        {
            var actual = new ProcessStartInfo();

            actual.BindFromCommandLine(commandLine);

            Assert.AreEqual(actual.FileName, expectedFileName);
            Assert.AreEqual(actual.Arguments, expectedArguments);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// FilerWindow の新しいインスタンスを初期化します。
        /// </summary>
        public FilerWindow()
        {
            InitializeComponent();

            if (System.IO.File.Exists(historyFilePath) == false)
            {
                if (new System.IO.FileInfo(historyFilePath).Directory.Exists == false)
                {
                    new System.IO.FileInfo(historyFilePath).Directory.Create();
                }
                using (System.IO.File.Create(historyFilePath)) { }
            }

            var processTextBoxShortcutKey = new ShortcutKeyInvoker(this.processTextBox);
            processTextBoxShortcutKey.Add(() =>
            {
                if (this.intellisenceListBox.Items.Count == 0)
                {
                    this.intellisence.IsOpen = false;
                }
                else
                {
                    this.intellisence.IsOpen = true;
                }
                return true;
            }, Key.Space, ModifierKeys.Control);

            processTextBoxShortcutKey.Add(() =>
            {
                MessageBox.Show("action");
                return true;
            }, Key.Space, ModifierKeys.Control | ModifierKeys.Alt);
            processTextBoxShortcutKey.Add(() =>
                {
                    if (this.intellisence.IsOpen == false)
                    {
                        return false;
                    }

                    this.intellisenceListBox.SelectedIndex = 0;
                    this.intellisenceListBox.FocusSelectedItem();
                    return true;
                }, Key.Down, ModifierKeys.None);
            processTextBoxShortcutKey.Add(() =>
                {
                    var process = new ProcessStartInfo();
                    process.BindFromCommandLine(this.processTextBox.Text);

                    using (Process.Start(process)) { }

                    if (this.intellisenceSource.Select(x => x.ToUpper()).Contains(this.processTextBox.Text) == false)
                    {
                        using (var writer = new System.IO.StreamWriter(historyFilePath, true, System.Text.Encoding.GetEncoding(932)))
                        {
                            writer.WriteLine(this.processTextBox.Text);
                        }
                        this.intellisenceSource.Add(this.processTextBox.Text);
                    }
                    this.Close();
                    return true;
                }, Key.Enter, ModifierKeys.None);
            processTextBoxShortcutKey.Add(() =>
                {
                    if (this.intellisence.IsOpen == false)
                    {
                        return false;
                    }

                    if (this.intellisenceListBox.Items.Count != 1)
                    {
                        return false;
                    }

                    this.processTextBox.Text = Convert.ToString(this.intellisenceListBox.Items[0]);
                    this.processTextBox.Select(this.processTextBox.Text.Length, 0);
                    return true;
                }, Key.Tab, ModifierKeys.None);
            var intellisenceListBoxShortcutKey = new ShortcutKeyInvoker(this.intellisenceListBox);
            intellisenceListBoxShortcutKey.Add(() =>
                {
                    if (this.intellisenceListBox.SelectedIndex != 0)
                    {
                        return false;
                    }

                    this.intellisenceListBox.SelectedIndex = -1;

                    this.processTextBox.Focus();
                    return true;
                }
            ,Key.Up, ModifierKeys.None);
            var intellisenceDecide = new Func<bool>(() =>
            {
                this.processTextBox.Text = this.intellisenceListBox.SelectedItem as string;
                this.processTextBox.Select(this.processTextBox.Text.Length, 0);

                this.processTextBox.Focus();
                return true;
            });

            intellisenceListBoxShortcutKey.Add(intellisenceDecide, Key.Tab, ModifierKeys.None);
            intellisenceListBoxShortcutKey.Add(intellisenceDecide, Key.Enter, ModifierKeys.None);
        }