private void buttonOK_Click(object sender, EventArgs e) { Result = null; using (new WaitCursor(this, WaitCursorOption.ShortSleep)) { var cultures = getCultures(); var baseFolderPath = baseFolderTextEdit.Text.Trim(); var baseFileName = baseFileNameTextEdit.Text.Trim(); var extension = @"." + extensionComboBoxEdit.Text.Trim('.'); var created = 0; using (new BackgroundWorkerLongProgressGui( delegate(object snd, DoWorkEventArgs args) { try { var bw = (BackgroundWorker)snd; // -- // First pass, add all in-memory to check for same file group. var fg = new FileGroup(_project); if (cultures != null) { foreach (var culture in cultures) { var fileName = _project.IsNeutralLanguage(culture) ? baseFileName + extension : generateFileName(fg, culture); fg.Add(new FileInformation(fg) { File = new ZlpFileInfo(fileName) }); } // Look for same entries. if (_project.FileGroups.HasFileGroupWithChecksum( fg.GetChecksum(_project))) { throw new MessageBoxException( this, Resources.SR_ProjectFilesUserControl_AddResourceFilesWithDialog_ExistsInTheProject, MessageBoxIcon.Information); } else { // -- // Second pass, add all existing. fg = new FileGroup(_project); foreach (var culture in cultures) { if (bw.CancellationPending) { throw new OperationCanceledException(); } var fileName = _project.IsNeutralLanguage(culture) ? baseFileName + extension : generateFileName(fg, culture); FileInformation ffi; if (_project.IsNeutralLanguage(culture)) { ffi = new FileInformation(fg) { File = new ZlpFileInfo(ZlpPathHelper.Combine(baseFolderPath, fileName)) }; fg.Add(ffi); } else { ffi = fg.CreateAndAddNewFile( baseFolderPath, fileName); } // Must create real file. ZlpIOHelper.WriteAllText(ffi.File.FullName, Resources.SR_EmptyResourceFile); created++; } } } if (_projectFolder != null) { fg.ProjectFolder = _projectFolder; } _project.FileGroups.Add(fg); _project.MarkAsModified(); Result = fg; } catch (OperationCanceledException) { // Ignore. } }, Resources.SR_CreateNewFilesForm_Creating, BackgroundWorkerLongProgressGui.CancellationMode.Cancelable, this)) { } // -- XtraMessageBox.Show( this, string.Format( Resources.SR_CreateNewFilesForm_Finished03, created), @"Zeta Resource Editor", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void buttonOK_Click(object sender, EventArgs e) { _result = null; using (new WaitCursor(this, WaitCursorOption.ShortSleep)) { var cultures = getCultures(); var baseFolderPath = baseFolderTextEdit.Text.Trim(); var baseFileName = baseFileNameTextEdit.Text.Trim(); var extension = @"." + extensionComboBoxEdit.Text.Trim('.'); var created = 0; using (new BackgroundWorkerLongProgressGui( delegate(object snd, DoWorkEventArgs args) { try { var bw = (BackgroundWorker)snd; // -- // First pass, add all in-memory to check for same file group. var fg = new FileGroup(_project); if (cultures != null) { foreach (var culture in cultures) { var fileName = _project.IsNeutralLanguage(culture) ? baseFileName + extension : generateFileName(fg, culture); fg.Add(new FileInformation(fg) { File = new ZlpFileInfo(fileName) }); } // Look for same entries. if (_project.FileGroups.HasFileGroupWithChecksum( fg.GetChecksum(_project))) { throw new MessageBoxException( this, Resources.SR_ProjectFilesUserControl_AddResourceFilesWithDialog_ExistsInTheProject, MessageBoxIcon.Information); } else { // -- // Second pass, add all existing. fg = new FileGroup(_project); foreach (var culture in cultures) { if (bw.CancellationPending) { throw new OperationCanceledException(); } var fileName = _project.IsNeutralLanguage(culture) ? baseFileName + extension : generateFileName(fg, culture); FileInformation ffi; if (_project.IsNeutralLanguage(culture)) { ffi = new FileInformation(fg) { File = new ZlpFileInfo(ZlpPathHelper.Combine(baseFolderPath, fileName)) }; fg.Add(ffi); } else { ffi = fg.CreateAndAddNewFile( baseFolderPath, fileName, culture.Name); } // Must create real file. ZlpIOHelper.WriteAllText(ffi.File.FullName, Resources.SR_EmptyResourceFile); created++; } } } if (_projectFolder != null) { fg.ProjectFolder = _projectFolder; } _project.FileGroups.Add(fg); _project.MarkAsModified(); _result = fg; } catch (OperationCanceledException) { // Ignore. } }, Resources.SR_CreateNewFilesForm_Creating, BackgroundWorkerLongProgressGui.CancellationMode.Cancelable, this)) { } // -- XtraMessageBox.Show( this, string.Format( Resources.SR_CreateNewFilesForm_Finished03, created), @"Zeta Resource Editor", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void AddExistingResourceFilesWithDialog() { using (var ofd = new OpenFileDialog()) { ofd.Multiselect = true; ofd.Filter = string.Format(@"{0} (*.resx;*.resw)|*.resx;*.resw", Resources.SR_MainForm_openToolStripMenuItemClick_ResourceFiles); ofd.RestoreDirectory = true; var initialDir = ConvertHelper.ToString( PersistanceHelper.RestoreValue( MainForm.UserStorageIntelligent, @"filesInitialDir")); ofd.InitialDirectory = initialDir; if (ofd.ShowDialog(this) == DialogResult.OK) { PersistanceHelper.SaveValue( MainForm.UserStorageIntelligent, @"filesInitialDir", ZlpPathHelper.GetDirectoryPathNameFromFilePath(ofd.FileName)); // -- var fileGroup = new FileGroup(Project); foreach (var filePath in ofd.FileNames) { fileGroup.Add(new FileInformation(fileGroup) { File = new ZlpFileInfo(filePath) }); } // Look for same entries. if (Project.FileGroups.HasFileGroupWithChecksum( fileGroup.GetChecksum(Project))) { throw new MessageBoxException( this, Resources.SR_ProjectFilesUserControl_AddResourceFilesWithDialog_ExistsInTheProject, MessageBoxIcon.Information); } else { var parentProjectFolder = treeView.SelectedNode.Tag as ProjectFolder; if (parentProjectFolder != null) { fileGroup.ProjectFolder = parentProjectFolder; } Project.FileGroups.Add(fileGroup); Project.MarkAsModified(); var node = addFileGroupToTree(treeView.SelectedNode, fileGroup); // -- sortTree(); treeView.SelectedNode = node; // Immediately open for editing. editResourceFiles(); UpdateUI(); } } } }