private void ClearAllButton_Click(object sender, EventArgs e) { for (int i = 0; i < SourceFileListBox.Items.Count; i++) { SourceFileListBox.SetItemCheckState(i, CheckState.Unchecked); } }
// Add files in the selected directory to the checked list box; items // are added unchecked, the assumption being that the common action is // to work on one file at a time. // // Files in the selected directory are filtered by the 'File Filter' // string, which is treated as a regular expression. If the filter // is empty, it is considered to be the same as '*'. private void PopulateSourceFileList() { if (SourceFolderControl.FolderPath.Equals(String.Empty)) { // Early exit for uninitialized path return; } DirectoryInfo dirInfo = new DirectoryInfo(SourceFolderControl.FolderPath); if (dirInfo.Exists) { SourceFileListBox.BeginUpdate(); SourceFileListBox.Items.Clear(); string fileFilter = FilterTextBox.Text.Equals(String.Empty) ? "*" : FilterTextBox.Text; foreach (FileInfo fileInfo in dirInfo.GetFiles(fileFilter)) { SourceFileListBox.Items.Add(fileInfo, false); } SourceFileListBox.EndUpdate(); } }
/// <summary> /// ファイルリストへドロップされたファイルをリストに追加する /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ListBox_Drop(object sender, DragEventArgs e) { // ドロップされたファイルパスを取得 var dropFileArray = (string[])e.Data.GetData(DataFormats.FileDrop); // ファイルをすべてファイルリストに追加 dropFileArray.ToList <string>().ForEach(item => SourceFileListBox.Items.Add(item)); SourceFileListBox.ScrollIntoView(dropFileArray.Last <string>()); if (runner != null) { runner.ChangeSorceFileList(SourceFileListBox.Items.OfType <string>().ToList()); } }
/// <summary> /// キーダウンイベント /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SourceFileListBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == Key.Delete) { // Deleteキーの場合は選択状態のファイルを削除 DeleteFile_Click(sender, null); } else if (e.Key == Key.A && (Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.None) { // Ctrl+Aキーの場合は全選択と全解除をトグル動作 if (SourceFileListBox.SelectedItems.Count > 0) { SourceFileListBox.SelectedItems.Clear(); } else { SourceFileListBox.SelectAll(); } } else if (e.Key == Key.C && (Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.None) { // Ctrl+Cキーの場合は選択したファイルパスをクリップボードにコピー var stb = new StringBuilder(); foreach (string item in SourceFileListBox.SelectedItems) { stb.AppendLine(item); } Clipboard.SetText(stb.ToString()); } else if (e.Key == Key.V && (Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.None) { // Ctrl+Vキーの場合は選択したファイルパスをファイルリストに追加 if (Clipboard.ContainsText()) { using (var sr = new StringReader(Clipboard.GetText())) { while (sr.Peek() > -1) { SourceFileListBox.Items.Add(sr.ReadLine()); } } } } }
/// <summary> /// 状態を変更する /// </summary> /// <param name="allProgress"></param> /// <param name="allStatus"></param> /// <param name="fileProgress"></param> /// <param name="fileStatus"></param> private void SetStatus(int allProgress, string allStatus, int fileProgress, string fileStatus, string sourceFilePath) { if (Dispatcher.CheckAccess() == false) { Dispatcher.Invoke((Action)(() => { SetStatus(allProgress, allStatus, fileProgress, fileStatus, sourceFilePath); })); return; } if (allProgress != -1) { AllProgress.Value = allProgress; TaskbarManager.Instance.SetProgressValue(allProgress, 100); } if (allStatus != null) { AllStatus.Content = allStatus; } if (fileProgress != -1) { FileProgress.Value = fileProgress; } if (fileStatus != null) { FileStatus.Content = fileStatus; } if (SourceFileListBox.IsFocused == false) { var selectItems = SourceFileListBox.SelectedItems.OfType <string>(); if (!string.IsNullOrWhiteSpace(sourceFilePath) && (selectItems.Count() != 1 || selectItems.First() != sourceFilePath)) { SourceFileListBox.SelectedItems.Clear(); SourceFileListBox.SelectedItem = sourceFilePath; SourceFileListBox.ScrollIntoView(sourceFilePath); } } }
/// <summary> /// ファイル追加イベント /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void FileAdded(object sender, FileAddedEventArgs e) { if (Dispatcher.CheckAccess() == false) { Dispatcher.Invoke((Action)(() => { FileAdded(sender, e); })); return; } if (settingManager.ConvertSettingBody.EnableAutoAdd || settingManager.ConvertSettingBody.EnableFileAddOnStartup) { // 自動追加が有効な場合はファイルリストに追加 e.FileList.ForEach(item => { if (SourceFileListBox.Items.IndexOf(item) == -1) { SourceFileListBox.Items.Add(item); } }); SourceFileListBox.ScrollIntoView(e.FileList.Last()); } if (runner == null) { if (settingManager.ConvertSettingBody.EnableAutoConvert) { // 変換中でないかつ、自動実行が有効な場合は変換スタート ConvertStart_Click(this, null); } } else { // 既に変換中の場合はリストを更新 runner.ChangeSorceFileList(SourceFileListBox.Items.OfType <string>().ToList()); } }