From 2b7d6d390435bd21a808ab618fe03ac04846be36 Mon Sep 17 00:00:00 2001 From: Victor Lin <60565737+v-xup6@users.noreply.github.com> Date: Sat, 6 Mar 2021 17:42:18 +0800 Subject: [PATCH] Add files via upload Added ability to adjust text size for text label method Also added ability to change UI language of the plugin --- src/MultilingualGH/MultilingualComp.cs | 55 +++++++++++++------ src/MultilingualGH/MultilingualGH.csproj | 3 +- src/MultilingualGH/MultilingualGH.csproj.user | 2 +- src/MultilingualGH/MultilingualGHInfo.cs | 1 - src/MultilingualGH/MultilingualInstance.cs | 5 +- src/MultilingualGH/MultilingualMenu.cs | 54 +++++++++++++----- src/MultilingualGH/Properties/AssemblyInfo.cs | 10 ++-- src/MultilingualGH/Translation.cs | 51 ++++++++++++----- src/MultilingualGH/UI.cs | 47 ++++++++++++++++ src/MultilingualGH/UserForm.Designer.cs | 9 +-- 10 files changed, 179 insertions(+), 58 deletions(-) create mode 100644 src/MultilingualGH/UI.cs diff --git a/src/MultilingualGH/MultilingualComp.cs b/src/MultilingualGH/MultilingualComp.cs index 68a94f0..e03cb97 100644 --- a/src/MultilingualGH/MultilingualComp.cs +++ b/src/MultilingualGH/MultilingualComp.cs @@ -17,7 +17,7 @@ public class MultilingualComp : GH_Component public MultilingualComp() : base("MultilingualGH", "MGH", - "Annotates components with desired language.", + UI.CompDes, "Params", "Util") { } @@ -25,7 +25,7 @@ public MultilingualComp() protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager) { - pManager.AddTextParameter("Exclude", "X", "List of components to exclude from annotations", GH_ParamAccess.list); + pManager.AddTextParameter(UI.CompIn, "X", UI.CompInDes, GH_ParamAccess.list); pManager[0].Optional = true; } @@ -43,14 +43,14 @@ public override void AddedToDocument(GH_Document document) { if (mgh.compGuid != Guid.Empty && mgh.compGuid != InstanceGuid) { - MessageBox.Show("There is already an instance of MultilingualGH on the canvas. No need for another one.", "MultilingualGH", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(UI.TooMany, "MultilingualGH", MessageBoxButtons.OK, MessageBoxIcon.Information); document.RemoveObject(this, false); } else { mgh.compGuid = InstanceGuid; MultilingualMenu.mghDropdown.Enabled = false; - MultilingualMenu.mghDropdown.ToolTipText = "Menu disabled when MGH component is in use"; + MultilingualMenu.mghDropdown.ToolTipText = UI.MenuDisabled; document.ObjectsDeleted += RemovedMe; IGH_Param inputParam = base.Params.Input[0]; if (mgh.excludeUser != string.Empty && inputParam.SourceCount == 0) @@ -80,19 +80,38 @@ public override void AppendAdditionalMenuItems(ToolStripDropDown menu) var canvas = Grasshopper.Instances.ActiveCanvas; var items = MultilingualMenu.mghDropdown.DropDownItems; base.AppendAdditionalMenuItems(menu); - Menu_AppendItem(menu, "Use Text Label", (s, e) => + Menu_AppendItem(menu, UI.UseTextLabel, (s, e) => { mgh.textLabel = !mgh.textLabel; ((ToolStripComboBox)items["Method"]).SelectedIndex = mgh.textLabel ? 1 : 0; MultilingualInstance.EventHandler(canvas, mgh); }, true, mgh.textLabel); - Menu_AppendItem(menu, "Use Default Exclusions", (s, e) => + if (mgh.textLabel) + { + NumericUpDown textSize = new NumericUpDown + { + Minimum = 1, + Maximum = 254, + Increment = 1, + Value = mgh.size, + DecimalPlaces = 0 + }; + textSize.ValueChanged += (s, e) => + { + var inputSize = ((NumericUpDown)s).Value; + if (inputSize > textSize.Maximum) inputSize = textSize.Maximum; + else if (inputSize < textSize.Minimum) inputSize = textSize.Minimum; + mgh.size = Convert.ToInt32(inputSize); + }; + Menu_AppendCustomItem(menu, textSize); + } + Menu_AppendItem(menu, UI.UseDefaultExclusions, (s, e) => { mgh.excludeDefault = !mgh.excludeDefault; ((ToolStripMenuItem)items["Default"]).Checked = mgh.excludeDefault; MultilingualInstance.EventHandler(canvas, mgh); }, true, mgh.excludeDefault); - Menu_AppendItem(menu, "Keep annotations", (s, e) => + Menu_AppendItem(menu, UI.KeepAnnotations, (s, e) => { mgh.keep = !mgh.keep; ((ToolStripMenuItem)items["Keep"]).Checked = mgh.keep; @@ -103,12 +122,12 @@ public override void AppendAdditionalMenuItems(ToolStripDropDown menu) { Menu_AppendItem(menu, lang, (s, e) => LangSelection(lang), true, mgh.language == lang); } - if(Translation.extraFiles.Count>0) + if (Translation.extraFiles.Count > 0) Menu_AppendSeparator(menu); foreach (var plugin in Translation.extraFiles) { string shorten = $"*{plugin.Split('_')[0]}*"; - Menu_AppendItem(menu, plugin, (s, e) => PluginSelection(shorten), mgh.language!="English", mgh.language != "English" && mgh.extras.Contains(shorten)); + Menu_AppendItem(menu, plugin, (s, e) => PluginSelection(shorten), mgh.language != "English", mgh.language != "English" && mgh.extras.Contains(shorten)); } } internal void LangSelection(string lang) @@ -123,7 +142,7 @@ internal void LangSelection(string lang) mgh.prevLang = lang; ExpireSolution(true); } - MultilingualInstance.EventHandler(Grasshopper.Instances.ActiveCanvas, mgh); + MultilingualInstance.EventHandler(Grasshopper.Instances.ActiveCanvas, mgh); } } internal void PluginSelection(string plugin) @@ -138,7 +157,7 @@ internal void PluginSelection(string plugin) } if (mgh.enabled) { - if(clean) + if (clean) Translation.Clear(Grasshopper.Instances.ActiveCanvas.Document); ExpireSolution(true); MultilingualInstance.EventHandler(Grasshopper.Instances.ActiveCanvas, mgh); @@ -147,7 +166,7 @@ internal void PluginSelection(string plugin) protected override void SolveInstance(IGH_DataAccess DA) { - AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Version " + MultilingualGHInfo.Ver); + AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, UI.Version + MultilingualGHInfo.Ver); var canvas = Grasshopper.Instances.ActiveCanvas; if (mgh == null) AddedToDocument(canvas.Document); if (Translation.noRoot) this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $" Folder '{Translation.folder}' not found"); @@ -163,7 +182,7 @@ protected override void SolveInstance(IGH_DataAccess DA) mgh.excludeUser = string.Empty; ((ToolStripMenuItem)MultilingualMenu.mghDropdown.DropDownItems["User"]).Checked = false; } - Message = mgh.enabled ? mgh.language : "Disabled"; + Message = mgh.enabled ? mgh.language : UI.Disabled; if (mgh.language == "English") DA.SetData(0, "https://github.com/v-xup6/MultilingualGH"); @@ -171,12 +190,12 @@ protected override void SolveInstance(IGH_DataAccess DA) { Translation.translations[mgh.language].TryGetValue("*Translator*", out string credit); StringBuilder eCredits = new StringBuilder(); - foreach(string plugin in mgh.extras.Split(new string[] { "**", "*" }, StringSplitOptions.RemoveEmptyEntries)) + foreach (string plugin in mgh.extras.Split(new string[] { "**", "*" }, StringSplitOptions.RemoveEmptyEntries)) { Translation.extraTranslations[plugin].TryGetValue("*Translator*", out string cred); eCredits.Append(", " + cred); } - DA.SetData(0, "Translation(s) by " + credit+eCredits.ToString()); + DA.SetData(0, UI.TranslationBy + credit + eCredits.ToString()); } MultilingualInstance.EventHandler(canvas, mgh); } @@ -208,7 +227,7 @@ public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH { MultilingualInstance.documents.TryGetValue(sender.Document.DocumentID, out MultilingualInstance mgh); mgh.enabled = !mgh.enabled; - base.Owner.Message = mgh.enabled ? mgh.language : "Disabled"; + base.Owner.Message = mgh.enabled ? mgh.language : UI.Disabled; if (mgh.enabled) { if (!mgh.textLabel) @@ -238,6 +257,8 @@ public override bool Write(GH_IO.Serialization.GH_IWriter writer) writer.SetBoolean("MGHKeepAnno", mgh.keep); writer.SetBoolean("MGHUseDe", mgh.excludeDefault); writer.SetBoolean("MGHLabelMethod", mgh.textLabel); + writer.SetString("MGHExtras", mgh.extras); + writer.SetInt32("MGHTextSize", mgh.size); return base.Write(writer); } public override bool Read(GH_IO.Serialization.GH_IReader reader) @@ -251,6 +272,8 @@ public override bool Read(GH_IO.Serialization.GH_IReader reader) reader.TryGetBoolean("MGHKeepAnno", ref mgh.keep); reader.TryGetBoolean("MGHUseDe", ref mgh.excludeDefault); reader.TryGetBoolean("MGHLabelMethod", ref mgh.textLabel); + reader.TryGetString("MGHExtras", ref mgh.extras); + reader.TryGetInt32("MGHTextSize", ref mgh.size); } return base.Read(reader); } diff --git a/src/MultilingualGH/MultilingualGH.csproj b/src/MultilingualGH/MultilingualGH.csproj index 7c08631..574dc52 100644 --- a/src/MultilingualGH/MultilingualGH.csproj +++ b/src/MultilingualGH/MultilingualGH.csproj @@ -17,7 +17,7 @@ true full - true + false bin\ DEBUG;TRACE prompt @@ -51,6 +51,7 @@ + diff --git a/src/MultilingualGH/MultilingualGH.csproj.user b/src/MultilingualGH/MultilingualGH.csproj.user index 46cec84..afc06ae 100644 --- a/src/MultilingualGH/MultilingualGH.csproj.user +++ b/src/MultilingualGH/MultilingualGH.csproj.user @@ -1,6 +1,6 @@  - C:\Program Files\Rhino 6\System\Rhino.exe + C:\Program Files\Rhino 7\System\Rhino.exe \ No newline at end of file diff --git a/src/MultilingualGH/MultilingualGHInfo.cs b/src/MultilingualGH/MultilingualGHInfo.cs index 2a7e592..726caf6 100644 --- a/src/MultilingualGH/MultilingualGHInfo.cs +++ b/src/MultilingualGH/MultilingualGHInfo.cs @@ -62,6 +62,5 @@ public override string Version return Ver; } } - } } diff --git a/src/MultilingualGH/MultilingualInstance.cs b/src/MultilingualGH/MultilingualInstance.cs index cb14948..29770d3 100644 --- a/src/MultilingualGH/MultilingualInstance.cs +++ b/src/MultilingualGH/MultilingualInstance.cs @@ -18,6 +18,7 @@ class MultilingualInstance internal string extras = string.Empty; internal string prevLang; internal Guid compGuid = Guid.Empty; + internal int size = 8; internal MultilingualInstance() { @@ -28,6 +29,7 @@ internal MultilingualInstance() keep = Grasshopper.Instances.Settings.GetValue("MGHKeepAnno", false); language = Grasshopper.Instances.Settings.GetValue("MGHLangSel", "English"); extras = Grasshopper.Instances.Settings.GetValue("MGHExtras", string.Empty); + size = Grasshopper.Instances.Settings.GetValue("MGHTextSize", 8); } static internal void SaveSettings(MultilingualInstance mgh) { @@ -37,7 +39,8 @@ static internal void SaveSettings(MultilingualInstance mgh) Grasshopper.Instances.Settings.SetValue("MGHUseUe", mgh.excludeUser); Grasshopper.Instances.Settings.SetValue("MGHKeepAnno", mgh.keep); Grasshopper.Instances.Settings.SetValue("MGHLangSel", mgh.language); - Grasshopper.Instances.Settings.GetValue("MGHExtras", mgh.extras); + Grasshopper.Instances.Settings.SetValue("MGHExtras", mgh.extras); + Grasshopper.Instances.Settings.SetValue("MGHTextSize", mgh.size); } static internal void EventHandler(GH_Canvas sender, MultilingualInstance mgh) { diff --git a/src/MultilingualGH/MultilingualMenu.cs b/src/MultilingualGH/MultilingualMenu.cs index 38ec87e..5c59403 100644 --- a/src/MultilingualGH/MultilingualMenu.cs +++ b/src/MultilingualGH/MultilingualMenu.cs @@ -37,7 +37,7 @@ static void Setup(GH_Canvas canvas) if (docServer.DocumentCount == 0) { mghDropdown.Enabled = false; - mghDropdown.ToolTipText = "No GH document opened"; + mghDropdown.ToolTipText = UI.NoDoc; } }; GH_DocumentEditor docEditor = Grasshopper.Instances.DocumentEditor; @@ -72,7 +72,7 @@ static void CreateMenu(GH_DocumentEditor docEditor) static void SetupMenu() { var canvas = Grasshopper.Instances.ActiveCanvas; - ToolStripMenuItem toggle = new ToolStripMenuItem { Name = "Version", Text = "Version " + MultilingualGHInfo.Ver, ToolTipText = "Click to enable/disable", Checked = mgh.enabled }; + ToolStripMenuItem toggle = new ToolStripMenuItem { Name = "Version", Text = UI.Version + MultilingualGHInfo.Ver, ToolTipText = UI.ClickEnable, Checked = mgh.enabled }; toggle.Click += (s, e) => { mgh.enabled = !mgh.enabled; @@ -86,21 +86,40 @@ static void SetupMenu() mgh.prevLang = mgh.language; } }; - ToolStripMenuItem keepOption = new ToolStripMenuItem { Name = "Keep", Text = "Keep Annotations", Checked = mgh.keep }; + ToolStripMenuItem keepOption = new ToolStripMenuItem { Name = "Keep", Text = UI.KeepAnnotations, Checked = mgh.keep }; keepOption.Click += (s, e) => { mgh.keep = !mgh.keep; keepOption.Checked = mgh.keep; }; + NumericUpDown textSize = new NumericUpDown + { + Minimum = 1, + Maximum = 254, + Increment = 1, + Value = mgh.size, + DecimalPlaces = 0 + }; + textSize.ValueChanged += (s, e) => + { + var inputSize = ((NumericUpDown)s).Value; + if (inputSize > textSize.Maximum) inputSize = textSize.Maximum; + else if (inputSize < textSize.Minimum) inputSize = textSize.Minimum; + mgh.size = Convert.ToInt32(inputSize); + }; + textSize.Enabled = mgh.textLabel; + ToolStripControlHost numericSize = new ToolStripControlHost(textSize, "TextSize"); + ToolStripMenuItem defaultOption = new ToolStripMenuItem { Name = "Default", Text = UI.UseDefaultExclusions, Checked = mgh.excludeDefault }; ToolStripComboBox translationMethod = new ToolStripComboBox { Name = "Method", DropDownStyle = ComboBoxStyle.DropDownList, FlatStyle = FlatStyle.Flat }; translationMethod.Items.AddRange(new object[] { - "Bubble Label", - "Text Label"}); + UI.BubbleLabel, + UI.TextLabel}); translationMethod.SelectedIndex = 1; translationMethod.SelectedIndexChanged += (s, e) => { bool basic = translationMethod.SelectedIndex == 0; keepOption.Enabled = basic; + textSize.Enabled = !basic; if (!basic) { mgh.keep = false; @@ -109,7 +128,6 @@ static void SetupMenu() mgh.textLabel = !basic; if (mgh.compGuid == Guid.Empty) MultilingualInstance.EventHandler(canvas, mgh); }; - ToolStripMenuItem defaultOption = new ToolStripMenuItem { Name = "Default", Text = "Use Default Exclusions", Checked = mgh.excludeDefault }; defaultOption.Click += (s, e) => { mgh.excludeDefault = !mgh.excludeDefault; @@ -117,7 +135,7 @@ static void SetupMenu() canvas.Refresh(); defaultOption.Checked = mgh.excludeDefault; }; - ToolStripMenuItem userOption = new ToolStripMenuItem { Name = "User", Text = "Custom Exclusions", Checked = mgh.excludeUser != string.Empty }; + ToolStripMenuItem userOption = new ToolStripMenuItem { Name = "User", Text = UI.CustomExclusions, Checked = mgh.excludeUser != string.Empty }; userOption.Click += (s, e) => { UserForm form = new UserForm(); @@ -129,17 +147,19 @@ static void SetupMenu() } userOption.Checked = mgh.excludeUser != string.Empty; }; - ToolStripMenuItem saveSettings = new ToolStripMenuItem { Name = "Save", Text = "Save As Default", ToolTipText = "Save current settings as the default values for new documents" }; + ToolStripMenuItem saveSettings = new ToolStripMenuItem { Name = "Save", Text = UI.SaveAsDefault, ToolTipText = UI.SaveDeTooltip }; saveSettings.Click += (s, e) => { MultilingualInstance.SaveSettings(mgh); MessageBox.Show($"Settings saved as default\r\n" + $"Enabled: {mgh.enabled}\r\n" + $"Text Label: {mgh.textLabel}\r\n" + + $"Text Size: {mgh.size}\r\n" + $"Default Exclusions: {mgh.excludeDefault}\r\n" + $"User Exclusions: {mgh.excludeUser.Length > 0}\r\n" + $"Keep Annotations: {mgh.keep}\r\n" + - $"Language: {mgh.language}"); + $"Language: {mgh.language}\r\n" + + $"Plugins: {mgh.extras.Length > 0}\r\n"); }; ToolStripMenuItem langOption = new ToolStripMenuItem { Name = "English", Text = "English", Checked = "English" == mgh.language }; langOption.Click += new EventHandler(LanguageSelection_Click); @@ -147,6 +167,7 @@ static void SetupMenu() List menuOptions = new List { toggle, translationMethod, + numericSize, new ToolStripSeparator(), saveSettings, new ToolStripSeparator(), @@ -161,7 +182,7 @@ static void SetupMenu() { ToolStripMenuItem help = new ToolStripMenuItem { - Text = "Help" + Text = UI.Help }; help.Click += (s, e) => { @@ -180,7 +201,7 @@ static void SetupMenu() foreach (var lang in Translation.files) { Translation.translations[lang].TryGetValue("*Translator*", out string credit); - langOption = new ToolStripMenuItem { Name = lang, Text = lang, ToolTipText = "Translation by " + credit, Checked = lang == mgh.language }; + langOption = new ToolStripMenuItem { Name = lang, Text = lang, ToolTipText = UI.TranslationBy + credit, Checked = lang == mgh.language }; langOption.Click += new EventHandler(LanguageSelection_Click); menuOptions.Add(langOption); } @@ -192,7 +213,7 @@ static void SetupMenu() { var plugin = fileName.Split('_')[0]; Translation.extraTranslations[plugin].TryGetValue("*Translator*", out string credit); - var pluginTranslations = new ToolStripMenuItem { Name = fileName, Text = fileName, ToolTipText = "Translation by " + credit, Checked = mgh.extras.Contains($"*{plugin}*") }; + var pluginTranslations = new ToolStripMenuItem { Name = fileName, Text = fileName, ToolTipText = UI.TranslationBy + credit, Checked = mgh.extras.Contains($"*{plugin}*") }; pluginTranslations.Click += new EventHandler(PluginSelection_Click); menuOptions.Add(pluginTranslations); } @@ -200,7 +221,7 @@ static void SetupMenu() mghDropdown.DropDownItems.AddRange(menuOptions.ToArray()); options = mghDropdown.DropDownItems; mghDropdown.Enabled = false; - mghDropdown.ToolTipText = "No GH document opened"; + mghDropdown.ToolTipText = UI.NoDoc; mghDropdown.Name = "MultilingualGH"; mghDropdown.Text = "MultilingualGH"; } @@ -236,7 +257,7 @@ static void LanguageSelection_Click(object sender, EventArgs e) { foreach (var plugin in Translation.extraFiles) { - ((ToolStripMenuItem)options[plugin]).Checked = mgh.extras.Contains(plugin); + ((ToolStripMenuItem)options[plugin]).Checked = mgh.extras.Contains(plugin.Split('_')[0]); ((ToolStripMenuItem)options[plugin]).Enabled = true; } } @@ -270,12 +291,15 @@ static internal void UpdateMenu(MultilingualInstance mgh) { ((ToolStripMenuItem)options["Keep"]).Checked = false; ((ToolStripMenuItem)options["Keep"]).Enabled = false; + ((NumericUpDown)((ToolStripControlHost)options["TextSize"]).Control).Enabled = true; } else { ((ToolStripMenuItem)options["Keep"]).Enabled = true; ((ToolStripMenuItem)options["Keep"]).Checked = mgh.keep; + ((NumericUpDown)((ToolStripControlHost)options["TextSize"]).Control).Enabled = false; } + ((NumericUpDown)((ToolStripControlHost)options["TextSize"]).Control).Value = mgh.size; ((ToolStripMenuItem)options["Default"]).Checked = mgh.excludeDefault; ((ToolStripMenuItem)options["User"]).Checked = mgh.excludeUser != string.Empty; bool isEng = mgh.language == "English"; @@ -293,7 +317,7 @@ static internal void UpdateMenu(MultilingualInstance mgh) } else { - ((ToolStripMenuItem)options[plugin]).Checked = mgh.extras.Contains(plugin); + ((ToolStripMenuItem)options[plugin]).Checked = mgh.extras.Contains(plugin.Split('_')[0]); ((ToolStripMenuItem)options[plugin]).Enabled = true; } } diff --git a/src/MultilingualGH/Properties/AssemblyInfo.cs b/src/MultilingualGH/Properties/AssemblyInfo.cs index 51e89f5..ac47e2c 100644 --- a/src/MultilingualGH/Properties/AssemblyInfo.cs +++ b/src/MultilingualGH/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using System.Resources; +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -36,7 +37,8 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.5.*")] +[assembly: AssemblyVersion("1.2.0.*")] #pragma warning disable CS7035 // The specified version string does not conform to the recommended format - major.minor.build.revision -[assembly: AssemblyFileVersion("1.1.5.*")] -#pragma warning restore CS7035 // The specified version string does not conform to the recommended format - major.minor.build.revision \ No newline at end of file +[assembly: AssemblyFileVersion("1.2.0.*")] +#pragma warning restore CS7035 // The specified version string does not conform to the recommended format - major.minor.build.revision +[assembly: NeutralResourcesLanguage("en")] diff --git a/src/MultilingualGH/Translation.cs b/src/MultilingualGH/Translation.cs index c7ec609..1741703 100644 --- a/src/MultilingualGH/Translation.cs +++ b/src/MultilingualGH/Translation.cs @@ -28,6 +28,7 @@ class Translation static internal readonly List extraFiles = new List(); static internal readonly Dictionary> translations = new Dictionary>(); static internal Dictionary> extraTranslations = new Dictionary>(); + static internal bool UILang = false; static byte temp; static internal void GetFiles() @@ -39,9 +40,17 @@ static internal void GetFiles() { var translationDictionary = new Dictionary(); string nameOnly = Path.GetFileNameWithoutExtension(file); - files.Add(nameOnly); ParseFile(file, ref translationDictionary); - translations.Add(nameOnly, translationDictionary); + if(!nameOnly.StartsWith("UILang")) + { + files.Add(nameOnly); + translations.Add(nameOnly, translationDictionary); + } + else if (!UILang) + { + UI.Update(translationDictionary); + UILang = true; + } } } else @@ -58,6 +67,18 @@ static internal void GetFiles() extraTranslations.Add(nameOnly.Split('_')[0], translationDictionary); } } + /*if (Directory.Exists(Path.Combine(folder, "UILang"))) + { + string[] inFolder = Directory.GetFiles(Path.Combine(folder, "UILang")); + foreach (var file in inFolder) + { + var translationDictionary = new Dictionary(); + string nameOnly = Path.GetFileNameWithoutExtension(file); + uiFiles.Add(nameOnly); + ParseFile(file, ref translationDictionary); + uiTranslations.Add(nameOnly, translationDictionary); + } + }*/ } static private void ParseFile(string file, ref Dictionary translationDictionary) { @@ -143,7 +164,6 @@ static internal void CompAdded(object sender, object e) } ghDoc.RemoveObjects(shouldRemove.Keys, false); } - static private Guid galapagosID = new Guid("E6DD2904-14BC-455b-8376-948BF2E3A7BC"); static internal void Paint(GH_Canvas sender) { MultilingualInstance.documents.TryGetValue(sender.Document.DocumentID, out MultilingualInstance mgh); @@ -153,26 +173,27 @@ static internal void Paint(GH_Canvas sender) { var exclusions = ExclusionSetup(mgh); bool ZUI = GH_Canvas.ZoomFadeHigh == 255; - float size = ZUI ? 6 : 8; + float size = (float)(ZUI ? mgh.size*0.5 : mgh.size); + Font font = new Font("sans-serif", size); + SolidBrush brush = new SolidBrush(Color.Black); + StringFormat alignment = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far }; foreach (var comp in sender.Document.Objects) { - if (IsExclusion(comp, exclusions) || comp is GH_Group) continue; + RectangleF bnd = comp.Attributes.Bounds; + if (!sender.Viewport.IsVisible(ref bnd, 20) || IsExclusion(comp, exclusions) || comp is GH_Group) continue; RectangleF anchor = comp.Attributes.Bounds; float x = anchor.X + 0.5f * anchor.Width; - float y; - if (comp.ComponentGuid == galapagosID || ((IGH_ActiveObject)comp).RuntimeMessageLevel == GH_RuntimeMessageLevel.Blank || ZUI) - y = anchor.Y - 0.25f * size; + float y = anchor.Y - 0.1f * size; + /*if (!(comp is IGH_ActiveObject component) || component.RuntimeMessageLevel == GH_RuntimeMessageLevel.Blank || ZUI) + y = anchor.Y - 0.1f * size; else - y = anchor.Y - 1.25f * size; + y = anchor.Y - 1.25f * size;*/ - Font font = new Font("Arial", size); - SolidBrush brush = new SolidBrush(Color.Black); - StringFormat alignment = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Far }; sender.Graphics.DrawString(Alias(mgh, comp), font, brush, x, y, alignment); - font.Dispose(); - brush.Dispose(); - alignment.Dispose(); } + font.Dispose(); + brush.Dispose(); + alignment.Dispose(); } } static ConcurrentDictionary ExclusionSetup(MultilingualInstance mgh) diff --git a/src/MultilingualGH/UI.cs b/src/MultilingualGH/UI.cs new file mode 100644 index 0000000..a380538 --- /dev/null +++ b/src/MultilingualGH/UI.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MultilingualGH +{ + static internal class UI + { + static public string Version { get; set; } = "Version "; + static public string Disabled { get; set; } = "Disabled"; + static public string TranslationBy { get; set; } = "Translation(s) by "; + + static public string CompDes { get; set; } = "Annotates components with desired language."; + static public string CompIn { get; set; } = "Exclude"; + static public string CompInDes { get; set; } = "List of components to exclude from annotations"; + + static public string UseTextLabel { get; set; } = "Use Text Label"; + static public string UseDefaultExclusions { get; set; } = "Use Default Exclusions"; + static public string CustomExclusions { get; set; } = "Custom Exclusions"; + static public string KeepAnnotations { get; set; } = "Keep Annotations"; + static public string BubbleLabel { get; set; } = "Bubble Label"; + static public string TextLabel { get; set; } = "Text Label"; + static public string SaveAsDefault { get; set; } = "Save As Default"; + static public string Help { get; set; } = "Help..."; + + static public string TooMany { get; set; } = "There is already an instance of MultilingualGH on the canvas. No need for another one."; + static public string MenuDisabled { get; set; } = "Menu disabled when MGH component is in use"; + static public string NoDoc { get; set; } = "No GH document opened"; + static public string ClickEnable { get; set; } = "Click to enable/disable"; + static public string SaveDeTooltip { get; set; } = "Save current settings as the default values for new documents"; + + + static internal void Update (Dictionary uiTran) + { + System.Reflection.PropertyInfo[] properties = typeof(UI).GetProperties(); + foreach(var property in properties) + { + if(uiTran.TryGetValue(property.Name, out string value)) + { + property.SetValue(null, value); + } + } + } + } +} diff --git a/src/MultilingualGH/UserForm.Designer.cs b/src/MultilingualGH/UserForm.Designer.cs index e2fa9b9..1e068c2 100644 --- a/src/MultilingualGH/UserForm.Designer.cs +++ b/src/MultilingualGH/UserForm.Designer.cs @@ -38,7 +38,7 @@ private void InitializeComponent() // this.submitButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.submitButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.submitButton.Location = new System.Drawing.Point(210, 246); + this.submitButton.Location = new System.Drawing.Point(214, 240); this.submitButton.Name = "submitButton"; this.submitButton.Size = new System.Drawing.Size(66, 27); this.submitButton.TabIndex = 0; @@ -57,7 +57,7 @@ private void InitializeComponent() this.textBox.Margin = new System.Windows.Forms.Padding(2, 2, 2, 7); this.textBox.Multiline = true; this.textBox.Name = "textBox"; - this.textBox.Size = new System.Drawing.Size(475, 227); + this.textBox.Size = new System.Drawing.Size(477, 221); this.textBox.TabIndex = 1; // // UserForm @@ -65,16 +65,17 @@ private void InitializeComponent() this.AcceptButton = this.submitButton; this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; - this.ClientSize = new System.Drawing.Size(497, 283); + this.ClientSize = new System.Drawing.Size(495, 277); this.Controls.Add(this.textBox); this.Controls.Add(this.submitButton); this.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(513, 322); + this.MinimumSize = new System.Drawing.Size(511, 316); this.Name = "UserForm"; this.Padding = new System.Windows.Forms.Padding(7); this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Define Exclusions"; this.TopMost = true; this.ResumeLayout(false);