Example #1
0
        private void textBoxPath_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (backgroundWorker.IsBusy)
                {
                    backgroundWorker.CancelAsync();
                }


                if (!String.IsNullOrEmpty(textBoxKeyword.Text))
                {
                    textBoxKeyword.Text = String.Empty;
                }

                listBoxFileList.Items.Clear();

                string dirPath = textBoxPath.Text;

                searchItems = new List <SearchItem>();

                //入力したパスがヘッダーファイルに存在しているか否か
                if (FileControl.IndexHeaderExists(indexHeaderFileData, dirPath))
                {
                    searchItems = indexFileData.Select(f => new SearchItem(f, Path.GetFileName(f), Path.GetDirectoryName(f).Replace(dirPath, ""))).ToList();
                    listBoxFileList.Items.AddRange(searchItems.ToArray());
                }
                else
                {
                    /*
                     * try{
                     *      //var fileList = Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories);
                     *      var fileList = Directory.EnumerateFiles(dirPath, "*", SearchOption.AllDirectories);
                     *
                     *      searchItems = fileList.Select(f => new SearchItem(f, Path.GetFileName(f), Path.GetDirectoryName(f).Replace(dirPath, ""))).ToList();
                     *
                     *      listBoxFileList.Items.AddRange(searchItems.ToArray());
                     *
                     * }catch(System.Exception ex){
                     *
                     * }
                     */
                    //スレッド処理
                    //backgroundWorker.RunWorkerAsync();
                    backgroundWorker.RunWorkerAsync(dirPath);
                }
            }
            else if (e.KeyCode == Keys.Escape)
            {
                //MessageBox.Show("Escape");
                if (backgroundWorker.IsBusy)
                {
                    //MessageBox.Show("IsBusy");
                    backgroundWorker.CancelAsync();
                }
            }
        }
Example #2
0
        private void ComponentInitialize()
        {
            this.Text = "File Search";
            this.Size = new Size(640, 480);

            labelPathName = new Label()
            {
                Location = new Point(5, 5)
                , Size   = new Size(this.ClientSize.Width - 5 - 5, 15)
                , Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left)
                , Font   = new Font("MS ゴシック", 9)
                , Text   = "SearchFilePath"
                ,
            };

            textBoxPath = new TextBox()
            {
                Location = new Point(5, 20)
                , Size   = new Size(this.ClientSize.Width - 5 - 5, 40)
                , Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left)
                , Font   = new Font("MS ゴシック", 9)
                ,
            };

            labelKeywordName = new Label()
            {
                Bounds   = new Rectangle(5, 40, this.ClientSize.Width - 5 - 5, 15)
                , Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left)
                , Font   = new Font("MS ゴシック", 9)
                , Text   = "SearchKeyword"
                ,
            };

            textBoxKeyword = new TextBox()
            {
                Location = new Point(5, 55)
                , Size   = new Size(this.ClientSize.Width - 5 - 5, 40)
                , Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left)
                , Font   = new Font("MS ゴシック", 9)
                ,
            };

            listBoxFileList = new ListBox()
            {
                Location              = new Point(5, 80)
                , Size                = new Size(this.ClientSize.Width - 5 - 5, this.ClientSize.Height - 110)
                , Anchor              = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left)
                , Font                = new Font("MS ゴシック", 9)
                , IntegralHeight      = false
                , HorizontalScrollbar = true
                ,
            };

            contextMenuRight = new ContextMenuStrip()
            {
            };

            backgroundWorker = new BackgroundWorker()
            {
                WorkerSupportsCancellation = true
                ,
            };

            statusStrip = new StatusStrip()
            {
            };

            statusLabel = new ToolStripStatusLabel()
            {
                Width = 640
                ,
            };

            contextMenuRight.Items.Add("開く", null, contextMenuOpen_Click);
            if (File.Exists(sakuraPath))
            {
                contextMenuRight.Items.Add("SAKURAで開く", null, contextMenuSakura_Click);
            }
            contextMenuRight.Items.Add("ファイルパスコピー", null, contextMenuPathCopy_Click);

            listBoxFileList.ContextMenuStrip = contextMenuRight;

            contextMenuRight.Opening += new CancelEventHandler(contextMenuRight_Opening);

            textBoxKeyword.TextChanged += textBoxKeyword_TextChanged;
            textBoxPath.KeyDown        += textBoxPath_KeyDown;

            listBoxFileList.MouseDoubleClick += new MouseEventHandler(listBoxFileList_MouseDoubleClick);

            this.Controls.Add(labelPathName);
            this.Controls.Add(textBoxPath);
            this.Controls.Add(labelKeywordName);
            this.Controls.Add(textBoxKeyword);
            this.Controls.Add(listBoxFileList);
            this.Controls.Add(statusStrip);

            statusStrip.Items.Add(statusLabel);

            backgroundWorker.DoWork             += new DoWorkEventHandler(backgroundWorker_DoWork);
            backgroundWorker.ProgressChanged    += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

            //インデックスファイルの読み込みor生成
            if (File.Exists(FileControl.SEARCH_INDEX_FILE_PATH))
            {
                indexFileData = FileControl.IndexFileRead();
            }
            else
            {
                File.WriteAllText(FileControl.SEARCH_INDEX_FILE_PATH, "");
                indexFileData = FileControl.IndexFileRead();
            }

            //インデックスファイル(ヘッダー)の読み込みor生成
            if (File.Exists(FileControl.SEARCH_INDEX_HEADER_FILE_PATH))
            {
                indexHeaderFileData = FileControl.IndexHeaderFileRead();
            }
            else
            {
                File.WriteAllText(FileControl.SEARCH_INDEX_HEADER_FILE_PATH, "");
                indexHeaderFileData = FileControl.IndexHeaderFileRead();
            }
        }