/// <summary> /// ファイルをプラグインで開きます /// </summary> private void OpenFile() { //開くダイアログのプラグインを取得します var openDialogPlugin = (IOpenDialog)_pluginManager.GetPlugin("open_dialog"); //ファイルを開くダイアログを表示します var path = openDialogPlugin.ShowDialog(); if (path == null) { return; } //ファイルが存在しない場合は処理しない if (File.Exists(path) == false) { return; } //ファイル選択イベントを発生させます var param = new FileSelectedEventParam { Path = path }; _pluginManager.GetEventManager().RaiseEvent(FileSelectedEventParam.Name, this, param); }
private void txtPath_KeyDown(object sender, KeyEventArgs e) { var path = txtPath.Text; if (e.KeyCode == Keys.Enter) { if (string.IsNullOrEmpty(path)) { return; //パスが未指定の場合は処理を抜けます } if (FileUtils.IsFile(path)) { //ファイルの場合、ファイル選択イベントを発生させます var param = new FileSelectedEventParam { Path = path }; _pluginManager.GetEventManager().RaiseEvent(FileSelectedEventParam.Name, this, param); } else { if (Directory.Exists(path) == false) { return; //フォルダが存在しない場合は処理を抜けます } //フォルダの場合、フォルダ選択イベントを発生させます var param = new DirSelectedEventParam { Path = path }; _pluginManager.GetEventManager().RaiseEvent(DirSelectedEventParam.Name, this, param); } } }
/* * /// <summary> * /// 選択されているセルの値を、タブ区切りの文字列で返します。 * /// 行は改行コードで区切ります。 * /// </summary> * /// <returns></returns> * private string GetSelectedCellValues() * { * //選択範囲の上下左右の端のindexを取得します * int minCol = fileListGrid.ColumnCount; //選択範囲の左端 * int minRow = fileListGrid.RowCount; //選択範囲の上端 * int maxCol = 0; //選択範囲の右端 * int maxRow = 0; //選択範囲の下端 * foreach (DataGridViewCell cell in fileListGrid.SelectedCells) { * if (cell.ColumnIndex < minCol) minCol = cell.ColumnIndex; * if (cell.RowIndex < minRow) minRow = cell.RowIndex; * if (cell.ColumnIndex > maxCol) maxCol = cell.ColumnIndex; * if (cell.RowIndex > maxRow) maxRow = cell.RowIndex; * } * * //選択されているセルの値だけを、連想配列にコピーします。キーは「列_行」 * var data = new Dictionary<string, string>(); * foreach (DataGridViewCell cell in fileListGrid.SelectedCells) { * var key = cell.ColumnIndex.ToString() + "_" + cell.RowIndex.ToString(); * data[key] = cell.Value?.ToString().Trim(); * } * * //連想配列の値を結合して文字列にします * var text = new StringBuilder(); * for (int row = minRow; row <= maxRow; row++) { * string line = ""; * for (int col = minCol; col <= maxCol; col++) { * var key = col.ToString() + "_" + row.ToString(); * if (data.TryGetValue(key, out string value)) { * line += value; * } * line += "\t"; * } * * //末尾がタブの場合は、削除します * if (line.EndsWith("\t")) line = StringUtils.RemoveRight(line, 1); * * if (StringUtils.IsNotEmpty(line.Trim('\t'))){ * //空行でない場合、戻り値用文字列に追加します * text.Append(line + "\n"); * } * } * return text.ToString(); * }*/ /// <summary> /// ファイルリストで選択されたフォルダまたはファイルの選択イベントを発生させます /// </summary> public void RaiseSelectedEvent(string path) { if (FileUtils.IsFile(path)) { //ファイルの場合、ファイル選択イベントを発生させます var param = new FileSelectedEventParam { Path = path }; _pluginManager.GetEventManager().RaiseEvent(FileSelectedEventParam.Name, this, param); } else { //フォルダの場合、フォルダ選択イベントを発生させます var param = new DirSelectedEventParam { Path = path }; _pluginManager.GetEventManager().RaiseEvent(DirSelectedEventParam.Name, this, param); } }
/// <summary> /// 日記ファイルをテキストエディターで開きます /// </summary> /// <param name="col"></param> /// <param name="row"></param> private void OpenMemo(int col, int row) { //行が偶数の場合は、日付行がクリックされているので、+1 します。 if (row % 2 == 0) { row++; } int year = _currentDate.Year; int month = _currentDate.Month; int day = StringUtils.ToInt(grid[col, row - 1].Value.ToString()); if (day == 0) { return; //セルから日付が取得できない場合は処理しない } //データフォルダのパスを作成します var dataDirPath = GetDataDirPath(year, month); var yyyyMMdd = year + month.ToString("00") + day.ToString("00"); var path = FileUtils.AppendPath(dataDirPath, yyyyMMdd + ".txt"); //フォルダがない場合は、フォルダを作成します FileUtils.CreateDir(dataDirPath); //ファイルがない場合は、ファイルを作成します if (File.Exists(path) == false) { File.Create(path).Close(); } //ファイル選択イベントを発生させます var param = new FileSelectedEventParam { Path = path }; _pluginManager.GetEventManager().RaiseEvent(FileSelectedEventParam.Name, this, param); }