From 93f0ee18d7ca0d2ff803ae15d455b8e485fdb5c0 Mon Sep 17 00:00:00 2001 From: Tim Young Date: Mon, 30 Oct 2017 16:47:06 -0500 Subject: [PATCH] add start to form translation. Dir choice dialog --- EduNetworkBuilder/App.config | 3 + EduNetworkBuilder/EduNetworkBuilder.csproj | 2 +- EduNetworkBuilder/NBSettings.cs | 4 + .../Properties/Settings.Designer.cs | 12 ++ .../Properties/Settings.settings | 3 + .../TranslationWindow.Designer.cs | 116 +++++++++++++++++- EduNetworkBuilder/TranslationWindow.cs | 71 +++++++++++ 7 files changed, 209 insertions(+), 2 deletions(-) diff --git a/EduNetworkBuilder/App.config b/EduNetworkBuilder/App.config index 18776bf..ea52c00 100644 --- a/EduNetworkBuilder/App.config +++ b/EduNetworkBuilder/App.config @@ -46,6 +46,9 @@ + + + \ No newline at end of file diff --git a/EduNetworkBuilder/EduNetworkBuilder.csproj b/EduNetworkBuilder/EduNetworkBuilder.csproj index f375c29..69228c3 100644 --- a/EduNetworkBuilder/EduNetworkBuilder.csproj +++ b/EduNetworkBuilder/EduNetworkBuilder.csproj @@ -28,7 +28,7 @@ Tim Young true publish.htm - 44 + 45 1.0.0.%2a false true diff --git a/EduNetworkBuilder/NBSettings.cs b/EduNetworkBuilder/NBSettings.cs index 0f7a79a..9619190 100644 --- a/EduNetworkBuilder/NBSettings.cs +++ b/EduNetworkBuilder/NBSettings.cs @@ -35,6 +35,7 @@ namespace EduNetworkBuilder public bool AutoDHCPAllMachinesAtNetworkLoad = false; //Mainly for teachers public string LastTrans1Lang = ""; public string LastTrans2Lang = ""; + public string FormLastTransDir = ""; public NBSettings() { @@ -67,6 +68,7 @@ namespace EduNetworkBuilder ToClass.MainWindowWidth = FromClass.MainWindowWidth; ToClass.BelongsToUser = FromClass.BelongsToUser; ToClass.AutoDHCPAllMachinesAtNetworkLoad = FromClass.AutoDHCPAllMachinesAtNetworkLoad; + ToClass.FormLastTransDir = FromClass.FormLastTransDir; foreach (string one in FromClass.ScoreList) { @@ -121,6 +123,7 @@ namespace EduNetworkBuilder AutoDHCPAllMachinesAtNetworkLoad = Properties.Settings.Default.AutoDHCP; LastTrans1Lang = Properties.Settings.Default.LastTrans1Lang; LastTrans2Lang = Properties.Settings.Default.LastTrans2Lang; + FormLastTransDir = Properties.Settings.Default.FormTransLastDir; foreach (string one in Properties.Settings.Default.ScoreList) { @@ -253,6 +256,7 @@ namespace EduNetworkBuilder Properties.Settings.Default.AutoDHCP = AutoDHCPAllMachinesAtNetworkLoad; Properties.Settings.Default.LastTrans1Lang = LastTrans1Lang; Properties.Settings.Default.LastTrans2Lang = LastTrans2Lang; + Properties.Settings.Default.FormTransLastDir = FormLastTransDir; Properties.Settings.Default.ScoreList.Clear(); foreach(string One in ScoreList) diff --git a/EduNetworkBuilder/Properties/Settings.Designer.cs b/EduNetworkBuilder/Properties/Settings.Designer.cs index 2d0f0d2..43a5f69 100644 --- a/EduNetworkBuilder/Properties/Settings.Designer.cs +++ b/EduNetworkBuilder/Properties/Settings.Designer.cs @@ -188,5 +188,17 @@ namespace EduNetworkBuilder.Properties { this["LastTrans2Lang"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string FormTransLastDir { + get { + return ((string)(this["FormTransLastDir"])); + } + set { + this["FormTransLastDir"] = value; + } + } } } diff --git a/EduNetworkBuilder/Properties/Settings.settings b/EduNetworkBuilder/Properties/Settings.settings index a6624f6..f2f8f15 100644 --- a/EduNetworkBuilder/Properties/Settings.settings +++ b/EduNetworkBuilder/Properties/Settings.settings @@ -44,5 +44,8 @@ + + + \ No newline at end of file diff --git a/EduNetworkBuilder/TranslationWindow.Designer.cs b/EduNetworkBuilder/TranslationWindow.Designer.cs index bce3d45..c1d27d8 100644 --- a/EduNetworkBuilder/TranslationWindow.Designer.cs +++ b/EduNetworkBuilder/TranslationWindow.Designer.cs @@ -42,8 +42,19 @@ this.tpFormStuff = new System.Windows.Forms.TabPage(); this.tb2URL = new System.Windows.Forms.TextBox(); this.tb1URL = new System.Windows.Forms.TextBox(); + this.btnChooseDir = new System.Windows.Forms.Button(); + this.lblFormDir = new System.Windows.Forms.Label(); + this.panelTranslateFormItems = new System.Windows.Forms.Panel(); + this.cbFormLang1Choice = new System.Windows.Forms.ComboBox(); + this.cbFormLang2Choice = new System.Windows.Forms.ComboBox(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.lblFormItem = new System.Windows.Forms.Label(); + this.tbFormItem1 = new System.Windows.Forms.TextBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); this.tcTabPages.SuspendLayout(); this.tpMessageTitle.SuspendLayout(); + this.tpFormStuff.SuspendLayout(); + this.panelTranslateFormItems.SuspendLayout(); this.SuspendLayout(); // // cb1Language @@ -172,10 +183,13 @@ // // tpFormStuff // + this.tpFormStuff.Controls.Add(this.panelTranslateFormItems); + this.tpFormStuff.Controls.Add(this.lblFormDir); + this.tpFormStuff.Controls.Add(this.btnChooseDir); this.tpFormStuff.Location = new System.Drawing.Point(4, 25); this.tpFormStuff.Name = "tpFormStuff"; this.tpFormStuff.Padding = new System.Windows.Forms.Padding(3); - this.tpFormStuff.Size = new System.Drawing.Size(428, 434); + this.tpFormStuff.Size = new System.Drawing.Size(450, 438); this.tpFormStuff.TabIndex = 1; this.tpFormStuff.Text = "Forms"; this.tpFormStuff.UseVisualStyleBackColor = true; @@ -196,6 +210,93 @@ this.tb1URL.TabIndex = 19; this.tb1URL.Leave += new System.EventHandler(this.tb1URL_Leave); // + // btnChooseDir + // + this.btnChooseDir.Location = new System.Drawing.Point(28, 20); + this.btnChooseDir.Name = "btnChooseDir"; + this.btnChooseDir.Size = new System.Drawing.Size(75, 23); + this.btnChooseDir.TabIndex = 0; + this.btnChooseDir.Text = "..."; + this.btnChooseDir.UseVisualStyleBackColor = true; + this.btnChooseDir.Click += new System.EventHandler(this.btnChooseDir_Click); + // + // lblFormDir + // + this.lblFormDir.AutoSize = true; + this.lblFormDir.Location = new System.Drawing.Point(109, 23); + this.lblFormDir.Name = "lblFormDir"; + this.lblFormDir.Size = new System.Drawing.Size(117, 17); + this.lblFormDir.TabIndex = 1; + this.lblFormDir.Text = "Choose Directory"; + // + // panelTranslateFormItems + // + this.panelTranslateFormItems.Controls.Add(this.textBox1); + this.panelTranslateFormItems.Controls.Add(this.tbFormItem1); + this.panelTranslateFormItems.Controls.Add(this.lblFormItem); + this.panelTranslateFormItems.Controls.Add(this.comboBox1); + this.panelTranslateFormItems.Controls.Add(this.cbFormLang2Choice); + this.panelTranslateFormItems.Controls.Add(this.cbFormLang1Choice); + this.panelTranslateFormItems.Location = new System.Drawing.Point(6, 88); + this.panelTranslateFormItems.Name = "panelTranslateFormItems"; + this.panelTranslateFormItems.Size = new System.Drawing.Size(434, 338); + this.panelTranslateFormItems.TabIndex = 2; + // + // cbFormLang1Choice + // + this.cbFormLang1Choice.FormattingEnabled = true; + this.cbFormLang1Choice.Location = new System.Drawing.Point(28, 89); + this.cbFormLang1Choice.Name = "cbFormLang1Choice"; + this.cbFormLang1Choice.Size = new System.Drawing.Size(121, 24); + this.cbFormLang1Choice.TabIndex = 0; + // + // cbFormLang2Choice + // + this.cbFormLang2Choice.FormattingEnabled = true; + this.cbFormLang2Choice.Location = new System.Drawing.Point(28, 227); + this.cbFormLang2Choice.Name = "cbFormLang2Choice"; + this.cbFormLang2Choice.Size = new System.Drawing.Size(121, 24); + this.cbFormLang2Choice.TabIndex = 1; + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(106, 3); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(306, 24); + this.comboBox1.TabIndex = 3; + // + // lblFormItem + // + this.lblFormItem.AutoSize = true; + this.lblFormItem.Location = new System.Drawing.Point(21, 6); + this.lblFormItem.Name = "lblFormItem"; + this.lblFormItem.Size = new System.Drawing.Size(34, 17); + this.lblFormItem.TabIndex = 4; + this.lblFormItem.Text = "Item"; + // + // tbFormItem1 + // + this.tbFormItem1.AcceptsReturn = true; + this.tbFormItem1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tbFormItem1.Location = new System.Drawing.Point(28, 119); + this.tbFormItem1.Multiline = true; + this.tbFormItem1.Name = "tbFormItem1"; + this.tbFormItem1.Size = new System.Drawing.Size(384, 72); + this.tbFormItem1.TabIndex = 5; + // + // textBox1 + // + this.textBox1.AcceptsReturn = true; + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.Location = new System.Drawing.Point(28, 257); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(384, 72); + this.textBox1.TabIndex = 6; + // // TranslationWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); @@ -212,6 +313,10 @@ this.tcTabPages.ResumeLayout(false); this.tpMessageTitle.ResumeLayout(false); this.tpMessageTitle.PerformLayout(); + this.tpFormStuff.ResumeLayout(false); + this.tpFormStuff.PerformLayout(); + this.panelTranslateFormItems.ResumeLayout(false); + this.panelTranslateFormItems.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -233,5 +338,14 @@ private System.Windows.Forms.TabPage tpFormStuff; private System.Windows.Forms.TextBox tb1URL; private System.Windows.Forms.TextBox tb2URL; + private System.Windows.Forms.Panel panelTranslateFormItems; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox tbFormItem1; + private System.Windows.Forms.Label lblFormItem; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.ComboBox cbFormLang2Choice; + private System.Windows.Forms.ComboBox cbFormLang1Choice; + private System.Windows.Forms.Label lblFormDir; + private System.Windows.Forms.Button btnChooseDir; } } \ No newline at end of file diff --git a/EduNetworkBuilder/TranslationWindow.cs b/EduNetworkBuilder/TranslationWindow.cs index 83a100e..d39e673 100644 --- a/EduNetworkBuilder/TranslationWindow.cs +++ b/EduNetworkBuilder/TranslationWindow.cs @@ -15,6 +15,7 @@ namespace EduNetworkBuilder { Network myNet = null; string[,] LanguageChoices = { { NB.Translate("NB_NBEn"), "en" }, { NB.Translate("NB_NBFr"), "fr" } }; + string FormChosenDir = ""; public TranslationWindow(Network ToEdit) { @@ -29,7 +30,16 @@ namespace EduNetworkBuilder { cb1Language.Items.Clear(); cb2Language.Items.Clear(); + + panelTranslateFormItems.Enabled = false; + NBSettings mySettings = NB.GetSettings(); + + //See if the file we are editing has the right folder. If so, we do not need to choose one + FormChosenDir = mySettings.FormLastTransDir; + if (!TryToChooseFormDir(FormChosenDir)) + TryToChooseFormDir(Path.GetDirectoryName(myNet.NetworkFilename)); + for (int i = 0; i < LanguageChoices.GetLength(0); i++) { cb1Language.Items.Add(LanguageChoices[i, 0]); @@ -72,6 +82,7 @@ namespace EduNetworkBuilder { mySettings.LastTrans2Lang = LanguageChoices[i, 1]; } + mySettings.FormLastTransDir = FormChosenDir; } mySettings.Save(); } @@ -216,5 +227,65 @@ namespace EduNetworkBuilder } RefreshContents(); } + + + + + //**********************************************************************// + //******************* Form Translation Things **************************// + //**********************************************************************// + bool TryToChooseFormDir(string Choice) + { + string targetfile = "edustrings.resx"; + if (Choice == null || Choice == "") return false; + //We want to have a file named edustrings.resx there + + //There may be other files: edustrings.fr.resx + //If these exist, we are OK. Otherwise, see if there is a "languages" dir and try that if it does exist + string toCheck = Path.GetFileName(Choice).ToLower(); + if (File.Exists(Choice)) + if (toCheck == targetfile) + { + FormChosenDir = Path.GetDirectoryName(Choice); + panelTranslateFormItems.Enabled = true; + lblFormDir.Text = "Dir: " + FormChosenDir; + lblFormDir.AutoSize = true; + lblFormDir.MaximumSize = new Size(250, 200); + return true; + } + + if(Directory.Exists(Choice)) + { + //It is a directory. See if it has the correct file in it. + if (TryToChooseFormDir(Path.Combine(Choice, targetfile))) + { + return true; //It was successful + } + //If we get here, it did not have the file. See if there is a "languages" directory + if (TryToChooseFormDir(Path.Combine(Choice, "languages", targetfile))) + { + return true; //It was successful + } + } + return false; + } + + private void btnChooseDir_Click(object sender, EventArgs e) + { + string startingDir = FormChosenDir; + if (FormChosenDir == "" && File.Exists(myNet.NetworkFilename)) + startingDir = Path.GetDirectoryName(myNet.NetworkFilename); + //Prompt for a directory. + + OpenFileDialog ofd = NB.SelectDirectoryDialog("Directory with language files", startingDir); + if(ofd.FileName != "") + { + //try to see if the chosen filename has appropriate files. We need the English, at least + if(!TryToChooseFormDir(Path.GetDirectoryName(ofd.FileName))) + { + MessageBox.Show("Invalid Directory."); + } + } + } } }