From b536fae289d7846287ccd010c8b696cd152e9980 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 7 Mar 2022 14:05:33 +0000 Subject: [PATCH] Fixes TextField context menu not showing with the current localization. --- Terminal.Gui/Views/TextField.cs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index bb6e89282..eff54d9d8 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -7,7 +7,9 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; +using System.Threading; using NStack; using Terminal.Gui.Resources; using Rune = System.Rune; @@ -25,6 +27,7 @@ namespace Terminal.Gui { int selectedStart = -1; // -1 represents there is no text selection. ustring selectedText; HistoryText historyText = new HistoryText (); + CultureInfo currentCulture; /// /// Tracks whether the text field should be considered "used", that is, that the user has moved in the entry, so new input should be appended at the cursor position, rather than clearing the entry @@ -202,15 +205,17 @@ namespace Terminal.Gui { AddKeyBinding (Key.T | Key.CtrlMask, Command.SelectAll); AddKeyBinding (Key.D | Key.CtrlMask | Key.ShiftMask, Command.DeleteAll); + currentCulture = Thread.CurrentThread.CurrentUICulture; + ContextMenu = new ContextMenu (this, new MenuBarItem (new MenuItem [] { - new MenuItem (Strings.ctxSelectAll, "", () => SelectAll (), null, null, GetKeyFromCommand (Command.SelectAll)), - new MenuItem (Strings.ctxDeleteAll, "", () => DeleteAll (), null, null, GetKeyFromCommand (Command.DeleteAll)), - new MenuItem (Strings.ctxCopy, "", () => Copy (), null, null, GetKeyFromCommand (Command.Copy)), - new MenuItem (Strings.ctxCut, "", () => Cut (), null, null, GetKeyFromCommand (Command.Cut)), - new MenuItem (Strings.ctxPaste, "", () => Paste (), null, null, GetKeyFromCommand (Command.Paste)), - new MenuItem (Strings.ctxUndo, "", () => UndoChanges (), null, null, GetKeyFromCommand (Command.Undo)), - new MenuItem (Strings.ctxRedo, "", () => RedoChanges (), null, null, GetKeyFromCommand (Command.Redo)), + new MenuItem (Strings.ctxSelectAll, "", () => SelectAll (), null, null, GetKeyFromCommand (Command.SelectAll)), + new MenuItem (Strings.ctxDeleteAll, "", () => DeleteAll (), null, null, GetKeyFromCommand (Command.DeleteAll)), + new MenuItem (Strings.ctxCopy, "", () => Copy (), null, null, GetKeyFromCommand (Command.Copy)), + new MenuItem (Strings.ctxCut, "", () => Cut (), null, null, GetKeyFromCommand (Command.Cut)), + new MenuItem (Strings.ctxPaste, "", () => Paste (), null, null, GetKeyFromCommand (Command.Paste)), + new MenuItem (Strings.ctxUndo, "", () => UndoChanges (), null, null, GetKeyFromCommand (Command.Undo)), + new MenuItem (Strings.ctxRedo, "", () => RedoChanges (), null, null, GetKeyFromCommand (Command.Redo)), }) ); ContextMenu.KeyChanged += ContextMenu_KeyChanged; @@ -921,6 +926,20 @@ namespace Terminal.Gui { void ShowContextMenu () { + if (currentCulture != Thread.CurrentThread.CurrentUICulture) { + + currentCulture = Thread.CurrentThread.CurrentUICulture; + + ContextMenu.MenuItens = new MenuBarItem (new MenuItem [] { + new MenuItem (Strings.ctxSelectAll, "", () => SelectAll (), null, null, GetKeyFromCommand (Command.SelectAll)), + new MenuItem (Strings.ctxDeleteAll, "", () => DeleteAll (), null, null, GetKeyFromCommand (Command.DeleteAll)), + new MenuItem (Strings.ctxCopy, "", () => Copy (), null, null, GetKeyFromCommand (Command.Copy)), + new MenuItem (Strings.ctxCut, "", () => Cut (), null, null, GetKeyFromCommand (Command.Cut)), + new MenuItem (Strings.ctxPaste, "", () => Paste (), null, null, GetKeyFromCommand (Command.Paste)), + new MenuItem (Strings.ctxUndo, "", () => UndoChanges (), null, null, GetKeyFromCommand (Command.Undo)), + new MenuItem (Strings.ctxRedo, "", () => RedoChanges (), null, null, GetKeyFromCommand (Command.Redo)), + }); + } ContextMenu.Show (); }