OSDN Git Service

#30244 自動テスト用svn:ignoreの指定ミスを修正
[wptscs/wpts.git] / Wptscs / ConfigForm.cs
index b5464a0..ef25cfd 100644 (file)
@@ -18,6 +18,7 @@ namespace Honememo.Wptscs
     using System.Linq;
     using System.Reflection;
     using System.Text;
+    using System.Threading;
     using System.Windows.Forms;
     using Honememo.Utilities;
     using Honememo.Wptscs.Models;
@@ -147,7 +148,7 @@ namespace Honememo.Wptscs
 
                     // 全部成功なら画面を閉じる
                     // ※ エラーの場合、どうしても駄目ならキャンセルボタンで閉じてもらう
-                    this.Close();
+                    this.DialogResult = DialogResult.OK;
                 }
                 catch (Exception ex)
                 {
@@ -200,7 +201,7 @@ namespace Honememo.Wptscs
             // 空または日付として認識可能な値の場合OK
             string value = e.FormattedValue.ToString();
             DateTime dummy;
-            if (String.IsNullOrWhiteSpace(value) || DateTime.TryParse(value, out dummy))
+            if (string.IsNullOrWhiteSpace(value) || DateTime.TryParse(value, out dummy))
             {
                 return;
             }
@@ -221,7 +222,7 @@ namespace Honememo.Wptscs
             // ※ 他の列で消さないのは、エラーを出しているのがRowValidatingの場合もあるから
             if (this.dataGridViewItems.Columns[e.ColumnIndex].Name == "ColumnTimestamp")
             {
-                this.dataGridViewItems.Rows[e.RowIndex].ErrorText = String.Empty;
+                this.dataGridViewItems.Rows[e.RowIndex].ErrorText = string.Empty;
             }
         }
 
@@ -237,7 +238,7 @@ namespace Honememo.Wptscs
             if (e.RowIndex >= 0)
             {
                 DataGridViewRow row = this.dataGridViewItems.Rows[e.RowIndex];
-                if (String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnTimestamp"]))
+                if (string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnTimestamp"]))
                     && !this.IsEmptyDataGridViewItemsRow(row))
                 {
                     // 背景色を変更
@@ -263,9 +264,9 @@ namespace Honememo.Wptscs
             // 翻訳元、記事名、翻訳先が未入力の場合、バリデートNGメッセージを表示
             // ※ ただし全列が空(新規行など)の場合は無視
             DataGridViewRow row = this.dataGridViewItems.Rows[e.RowIndex];
-            if ((String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromCode"]))
-                || String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnToCode"]))
-                || String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromTitle"])))
+            if ((string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromCode"]))
+                || string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnToCode"]))
+                || string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromTitle"])))
                 && !this.IsEmptyDataGridViewItemsRow(row))
             {
                 row.ErrorText = Resources.WarningMessageEmptyTranslationDictionary;
@@ -340,7 +341,7 @@ namespace Honememo.Wptscs
                 };
 
                 string timestamp = FormUtils.ToString(row.Cells["ColumnTimestamp"]);
-                if (!String.IsNullOrWhiteSpace(timestamp))
+                if (!string.IsNullOrWhiteSpace(timestamp))
                 {
                     item.Timestamp = DateTime.Parse(timestamp);
 
@@ -364,12 +365,12 @@ namespace Honememo.Wptscs
         /// <returns>空の場合<c>true</c>。</returns>
         private bool IsEmptyDataGridViewItemsRow(DataGridViewRow row)
         {
-            return String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromCode"]))
-                && String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromTitle"]))
-                && String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnAlias"]))
-                && String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnToCode"]))
-                && String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnToTitle"]))
-                && String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnTimestamp"]));
+            return string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromCode"]))
+                && string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnFromTitle"]))
+                && string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnAlias"]))
+                && string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnToCode"]))
+                && string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnToTitle"]))
+                && string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnTimestamp"]));
         }
 
         #endregion
@@ -393,12 +394,12 @@ namespace Honememo.Wptscs
             }
 
             // 各行にデータを取り込み
-            foreach (IDictionary<string, string> record in table)
+            foreach (IDictionary<string, string[]> record in table)
             {
                 // 行を追加しその行を取得
                 DataGridViewRow row = view.Rows[view.Rows.Add()];
 
-                foreach (KeyValuePair<string, string> cell in record)
+                foreach (KeyValuePair<string, string[]> cell in record)
                 {
                     // 上で登録した列では足りなかった場合、その都度生成する
                     if (!view.Columns.Contains(cell.Key))
@@ -406,13 +407,14 @@ namespace Honememo.Wptscs
                         this.AddTranslationTableColumn(view.Columns, cell.Key, cell.Key);
                     }
 
-                    row.Cells[cell.Key].Value = cell.Value;
+                    // 改行区切りで表示
+                    row.Cells[cell.Key].Value = string.Join("\n", cell.Value);
                 }
             }
 
             // 可能であれば現在表示中の言語の列の昇順でソートする
             // ※ 無ければenで試みる
-            string code = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
+            string code = Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
             if (view.Columns.Contains(code))
             {
                 view.Sort(view.Columns[code], ListSortDirection.Ascending);
@@ -421,10 +423,6 @@ namespace Honememo.Wptscs
             {
                 view.Sort(view.Columns["en"], ListSortDirection.Ascending);
             }
-
-            // 列幅をデータ長に応じて自動調整
-            // ※ 常に行ってしまうと、読み込みに時間がかかるため
-            view.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
         }
 
         /// <summary>
@@ -437,14 +435,15 @@ namespace Honememo.Wptscs
             TranslationTable table = new TranslationTable();
             foreach (DataGridViewRow row in view.Rows)
             {
-                IDictionary<string, string> record = new SortedDictionary<string, string>();
+                IDictionary<string, string[]> record = new SortedDictionary<string, string[]>();
                 foreach (DataGridViewCell cell in row.Cells)
                 {
                     // 空のセルは格納しない、該当の組み合わせは消える
                     string value = FormUtils.ToString(cell);
-                    if (!String.IsNullOrWhiteSpace(value))
+                    if (!string.IsNullOrWhiteSpace(value))
                     {
-                        record[cell.OwningColumn.Name] = value;
+                        // 改行区切りの配列で格納
+                        record[cell.OwningColumn.Name] = CollectionUtils.Trim(value.Split('\n'));
                     }
                 }
 
@@ -478,11 +477,11 @@ namespace Honememo.Wptscs
         {
             Language.LanguageName name;
             if (lang.Names.TryGetValue(
-                System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName, out name))
+                Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName, out name))
             {
-                if (!String.IsNullOrEmpty(name.Name))
+                if (!string.IsNullOrEmpty(name.Name))
                 {
-                    return String.Format(Resources.HeadingViewHeaderText, name.Name, lang.Code);
+                    return string.Format(Resources.HeadingViewHeaderText, name.Name, lang.Code);
                 }
             }
 
@@ -503,14 +502,14 @@ namespace Honememo.Wptscs
             try
             {
                 // 変更前の設定を保存
-                if (!String.IsNullOrEmpty(this.comboBoxLanguageSelectedText))
+                if (!string.IsNullOrEmpty(this.comboBoxLanguageSelectedText))
                 {
                     // 設定が存在しなければ自動生成される
                     this.SaveChangedValue(this.GetMediaWikiNeedCreate(this.config.Websites, this.comboBoxLanguageSelectedText));
                 }
 
                 // 変更後の値に応じて、画面表示を更新
-                if (!String.IsNullOrEmpty(this.comboBoxLanguage.Text))
+                if (!string.IsNullOrEmpty(this.comboBoxLanguage.Text))
                 {
                     // 設定が存在しなければ基本的に自動生成されるのでそのまま使用
                     this.LoadCurrentValue(this.GetMediaWikiNeedCreate(this.config.Websites, this.comboBoxLanguage.Text));
@@ -531,7 +530,7 @@ namespace Honememo.Wptscs
                     this.groupBoxLanguage.Enabled = false;
 
                     // 現在の選択値を更新
-                    this.comboBoxLanguageSelectedText = String.Empty;
+                    this.comboBoxLanguageSelectedText = string.Empty;
                 }
             }
             catch (Exception ex)
@@ -548,17 +547,16 @@ namespace Honememo.Wptscs
         /// <param name="e">発生したイベント。</param>
         private void ButtonLunguageAdd_Click(object sender, EventArgs e)
         {
-            // 言語追加用ダイアログを表示
-            InputLanguageCodeDialog form = new InputLanguageCodeDialog(this.config);
-            form.ShowDialog();
-
-            // 値が登録された場合
-            if (!String.IsNullOrWhiteSpace(form.LanguageCode))
+            // 言語追加用ダイアログで言語コードを入力
+            using (AddLanguageDialog form = new AddLanguageDialog(this.config))
             {
-                // 値を一覧・見出しの対訳表に追加、登録した値を選択状態に変更
-                this.comboBoxLanguage.Items.Add(form.LanguageCode);
-                this.dataGridViewHeading.Columns.Add(form.LanguageCode, form.LanguageCode);
-                this.comboBoxLanguage.SelectedItem = form.LanguageCode;
+                if (form.ShowDialog() == DialogResult.OK)
+                {
+                    // 値をコンボボックスと見出しの対訳表に追加、登録した値を選択状態に変更
+                    this.comboBoxLanguage.Items.Add(form.LanguageCode);
+                    this.dataGridViewHeading.Columns.Add(form.LanguageCode, form.LanguageCode);
+                    this.comboBoxLanguage.SelectedItem = form.LanguageCode;
+                }
             }
         }
 
@@ -579,8 +577,9 @@ namespace Honememo.Wptscs
                 }
             }
 
-            // コンボボックスからも削除し、表示を更新する
+            // 値を見出しの対訳表とコンボボックスからも削除し、表示を更新する
             this.comboBoxLanguageSelectedText = null;
+            this.dataGridViewHeading.Columns.Remove(this.comboBoxLanguage.Text);
             this.comboBoxLanguage.Items.Remove(this.comboBoxLanguage.Text);
             this.ComboBoxLanguuage_SelectedIndexChanged(sender, e);
         }
@@ -596,7 +595,7 @@ namespace Honememo.Wptscs
             TextBox box = (TextBox)sender;
             box.Text = StringUtils.DefaultString(box.Text).Trim();
             int value;
-            if (!String.IsNullOrEmpty(box.Text) && !int.TryParse(box.Text, out value))
+            if (!string.IsNullOrEmpty(box.Text) && !int.TryParse(box.Text, out value))
             {
                 this.errorProvider.SetError(box, Resources.WarningMessageIgnoreNumericNamespace);
                 e.Cancel = true;
@@ -612,7 +611,7 @@ namespace Honememo.Wptscs
         {
             // 空か$1が含まれる文字列のみ許可
             TextBox box = (TextBox)sender;
-            if (!String.IsNullOrEmpty(box.Text) && !box.Text.Contains("$1"))
+            if (!string.IsNullOrEmpty(box.Text) && !box.Text.Contains("$1"))
             {
                 this.errorProvider.SetError(box, Resources.WarningMessageUnformatedBracket);
                 e.Cancel = true;
@@ -637,7 +636,7 @@ namespace Honememo.Wptscs
             // 言語コードは必須、またトリムして小文字に変換
             string code = FormUtils.ToString(row.Cells["ColumnCode"]).Trim().ToLower();
             row.Cells["ColumnCode"].Value = code;
-            if (String.IsNullOrEmpty(code))
+            if (string.IsNullOrEmpty(code))
             {
                 row.ErrorText = Resources.WarningMessageEmptyCodeColumn;
                 e.Cancel = true;
@@ -645,8 +644,8 @@ namespace Honememo.Wptscs
             }
 
             // 略称を設定する場合、呼称を必須とする
-            if (!String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnShortName"]))
-                && String.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnName"])))
+            if (!string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnShortName"]))
+                && string.IsNullOrWhiteSpace(FormUtils.ToString(row.Cells["ColumnName"])))
             {
                 row.ErrorText = Resources.WarningMessageShortNameColumnOnly;
                 e.Cancel = true;
@@ -781,6 +780,7 @@ namespace Honememo.Wptscs
             this.textBoxDocumentationTemplateDefaultPage.Text = StringUtils.DefaultString(site.DocumentationTemplateDefaultPage);
             this.textBoxLinkInterwikiFormat.Text = StringUtils.DefaultString(site.LinkInterwikiFormat);
             this.textBoxLangFormat.Text = StringUtils.DefaultString(site.LangFormat);
+            this.checkBoxHasLanguagePage.Checked = site.HasLanguagePage;
         }
 
         /// <summary>
@@ -804,7 +804,7 @@ namespace Honememo.Wptscs
             {
                 // 値が入ってないとかはガードしているはずだが、一応チェック
                 string code = FormUtils.ToString(this.dataGridViewLanguageName["ColumnCode", y]).Trim();
-                if (!String.IsNullOrEmpty(code))
+                if (!string.IsNullOrEmpty(code))
                 {
                     Language.LanguageName name = new Language.LanguageName();
                     name.Name = FormUtils.ToString(this.dataGridViewLanguageName["ColumnName", y]).Trim();
@@ -865,7 +865,7 @@ namespace Honememo.Wptscs
             site.DocumentationTemplates.Clear();
             foreach (string s in StringUtils.DefaultString(this.textBoxDocumentationTemplate.Text).Split('\n'))
             {
-                if (!String.IsNullOrWhiteSpace(s))
+                if (!string.IsNullOrWhiteSpace(s))
                 {
                     site.DocumentationTemplates.Add(s.Trim());
                 }
@@ -889,8 +889,10 @@ namespace Honememo.Wptscs
                 site.LangFormat = str;
             }
 
+            site.HasLanguagePage = this.checkBoxHasLanguagePage.Checked;
+
             // 以下、数値へのparseは事前にチェックしてあるので、ここではチェックしない
-            if (!String.IsNullOrWhiteSpace(this.textBoxTemplateNamespace.Text))
+            if (!string.IsNullOrWhiteSpace(this.textBoxTemplateNamespace.Text))
             {
                 int num = int.Parse(this.textBoxTemplateNamespace.Text);
                 if (site.TemplateNamespace != num)
@@ -899,7 +901,7 @@ namespace Honememo.Wptscs
                 }
             }
 
-            if (!String.IsNullOrWhiteSpace(this.textBoxCategoryNamespace.Text))
+            if (!string.IsNullOrWhiteSpace(this.textBoxCategoryNamespace.Text))
             {
                 int num = int.Parse(this.textBoxCategoryNamespace.Text);
                 if (site.CategoryNamespace != num)
@@ -908,7 +910,7 @@ namespace Honememo.Wptscs
                 }
             }
 
-            if (!String.IsNullOrWhiteSpace(this.textBoxFileNamespace.Text))
+            if (!string.IsNullOrWhiteSpace(this.textBoxFileNamespace.Text))
             {
                 int num = int.Parse(this.textBoxFileNamespace.Text);
                 if (site.FileNamespace != num)
@@ -1011,7 +1013,7 @@ namespace Honememo.Wptscs
         /// <param name="e">発生したイベント。</param>
         private void ResetErrorText_RowValidated(object sender, DataGridViewCellEventArgs e)
         {
-            ((DataGridView)sender).Rows[e.RowIndex].ErrorText = String.Empty;
+            ((DataGridView)sender).Rows[e.RowIndex].ErrorText = string.Empty;
         }
 
         /// <summary>
@@ -1024,7 +1026,7 @@ namespace Honememo.Wptscs
             // 全行のエラーメッセージを解除
             foreach (DataGridViewRow row in ((DataGridView)sender).Rows)
             {
-                row.ErrorText = String.Empty;
+                row.ErrorText = string.Empty;
             }
         }
 
@@ -1044,7 +1046,7 @@ namespace Honememo.Wptscs
             /// <summary>
             /// 取得日時が同じ場合にソートに用いる列名。
             /// </summary>
-            private static readonly string[] sortOrder = new string[] { "ColumnFromCode", "ColumnToCode", "ColumnFromTitle" };
+            private static readonly string[] SortOrder = new string[] { "ColumnFromCode", "ColumnToCode", "ColumnFromTitle" };
 
             /// <summary>
             /// 2行を比較し、一方が他方より小さいか、等しいか、大きいかを示す値を返します。
@@ -1067,9 +1069,9 @@ namespace Honememo.Wptscs
                 }
 
                 // 取得日時列が同じ場合、残りの列の昇順でソート
-                foreach (string column in sortOrder)
+                foreach (string column in SortOrder)
                 {
-                    compare = String.Compare(
+                    compare = string.Compare(
                         FormUtils.ToString(xrow.Cells[column]),
                         FormUtils.ToString(yrow.Cells[column]));
                     if (compare != 0)