private void buttonOK_Click(object sender, EventArgs e)
        {
            using (new WaitCursor(this, WaitCursorOption.ShortSleep))
            {
                var prefix =
                    prefixCheckBox.Checked
                                                ? prefixTextBox.Text.Trim() + @" "
                                                : string.Empty;

                var didCopy =
                    _fileGroup.CreateAndAddNewFile(
                        ((Pair <string, Pair <string, string> >)referenceLanguageComboBox.SelectedItem).Second.Second,
                        newFileNameTextBox.Text.Trim(),
                        ((Pair <string, Pair <string, string> >)referenceLanguageComboBox.SelectedItem).Second.First,
                        ((Pair <string, CultureInfo>)newLanguageComboBox.SelectedItem).Second.Name,
                        copyTextsCheckBox.Checked,
                        automaticallyTranslateCheckBox.Checked,
                        prefix);

                if (!didCopy)
                {
                    XtraMessageBox.Show(
                        this,
                        Resources.CreateNewFileForm_buttonOK_Click_The_resource_file_for_the_language_you_selected_was_already_present_and_simply_was_added__but_not_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);
			}
		}
Example #3
0
        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);
            }
        }