public CSVEditManager(CSVForm csvForm) { m_CSVForm = csvForm; m_UndoStack = new Stack <IUndoRedo>(); m_RedoStack = new Stack <IUndoRedo>(); }
/// <summary> /// 加载csv文件 /// </summary> /// <param name="path">文件完整路径</param> private void LoadFile(string path) { CSVForm newCSVForm = new CSVForm(path); if (newCSVForm == null) { return; } newCSVForm.TopLevel = false; newCSVForm.Visible = true; newCSVForm.FormBorderStyle = FormBorderStyle.None; newCSVForm.Dock = DockStyle.Fill; newCSVForm.Show(); m_SplitContainer.Panel1.Controls.Add(newCSVForm); SetCSVForm(newCSVForm); }
private void SetCSVForm(CSVForm csvForm) { m_CSVForm = csvForm; UpdateFormText(); // 所有CSV窗口都被关闭 if (m_CSVForm == null) { if (m_GotoForm != null && !m_GotoForm.IsDisposed) { m_GotoForm.Close(); } if (m_SearchForm != null && !m_SearchForm.IsDisposed) { m_SearchForm.Close(); } } }
/// <summary> /// 合并文件 /// </summary> private void MergeCsv(DataTable originalCSV, string[][] amCSV) { CSVForm csvForm = MainForm.Instance.GetCSVForm(); csvForm.BeforeChangeCellValue(); // 做的操作(用于撤销) m_DoManyThingList = new List <CSVEditManager.IUndoRedo>(); m_CellChangeList = new List <CSVEditManager.CellValueChangeItem>(); m_MessageList = new List <DataGridViewConsoleForm.Message>(); // 遍历AM文件 for (int iRowInAMCSV = 0; iRowInAMCSV < amCSV.Length; iRowInAMCSV++) { string[] iterAMRow = amCSV[iRowInAMCSV]; // 这里Trim是为了匹配到源文件中的Key(Key头尾肯定不能用空白字符) string iterAMKey = iterAMRow[0].Trim(); // 跳过空key,Key为空代表这行为空行 if (string.IsNullOrWhiteSpace(iterAMKey)) { continue; } // 如果key是String ID,是表头,直接无视 if (iterAMKey.ToLower() == "String ID".ToLower()) { continue; } // key中不能包含空格,跳过 if (iterAMKey.Contains(" ")) { DataGridViewConsoleForm.Message message = new DataGridViewConsoleForm.Message { Level = DataGridViewConsoleForm.Level.Warning, Column = 0, Row = iRowInAMCSV, Caption = CSVEditor.Properties.Resources.MergeLocalizationToolAMCSVKeyContainsSpaceMessageCaption, Text = string.Format(CSVEditor.Properties.Resources.MergeLocalizationToolAMCSVKeyContainsSpaceMessageText, iterAMKey) }; m_MessageList.Add(message); continue; } // 源文件中是否存在AM文件中的Key // 存在的话直接merge,不存在的话,把这一行添加到源文件结尾 bool amKeyExistedInOriginal = false; for (int iRowInOriginalCSV = 0; iRowInOriginalCSV < originalCSV.Rows.Count; iRowInOriginalCSV++) { DataRow iterOriginalRow = originalCSV.Rows[iRowInOriginalCSV]; string iterOriginalKey = (string)iterOriginalRow[0]; if (iterOriginalKey.Trim() == iterAMKey) { amKeyExistedInOriginal = true; MergeRow(iRowInOriginalCSV, iterAMRow, iterOriginalRow); break; } } if (!amKeyExistedInOriginal) { // 添加新行 DataRow newRow = originalCSV.NewRow(); CSVEditManager.DoAddRowEvent doAddRowEvent = new CSVEditManager.DoAddRowEvent { Row = originalCSV.Rows.Count }; m_DoManyThingList.Add(doAddRowEvent); // Key newRow[0] = iterAMKey; CSVEditManager.CellValueChangeItem changeItem = new CSVEditManager.CellValueChangeItem { Row = originalCSV.Rows.Count, Column = 0, OldValue = "", NewValue = iterAMKey }; m_CellChangeList.Add(changeItem); // 初始化值 for (int iCell = 1; iCell < iterAMRow.Length; iCell++) { newRow[iCell] = ""; } MergeRow(originalCSV.Rows.Count, iterAMRow, newRow, true); originalCSV.Rows.Add(newRow); } } CSVEditManager.DoCellsValueChangeEvent doCellsValueChangeEvent = new CSVEditManager.DoCellsValueChangeEvent { ChangeList = m_CellChangeList }; m_DoManyThingList.Add(doCellsValueChangeEvent); csvForm.EditManager.DidManyThings(m_DoManyThingList); csvForm.AfterChangeCellValue(); csvForm.UpdateGridHeader(); DataGridViewConsoleForm.ShowForm(m_MessageList, csvForm.GetDataGridView(), "本地化合并"); Close(); }