private void OnStrKeyDown(object sender, KeyEventArgs e) { if ((e.KeyCode == Keys.Return) || (e.KeyCode == Keys.Enter)) { UIUtil.SetHandled(e, true); ListView.SelectedListViewItemCollection lvsic = m_lvStrings.SelectedItems; if (lvsic.Count != 1) { return; } KPStringTableItem kpstItem = (lvsic[0].Tag as KPStringTableItem); if (kpstItem == null) { Debug.Assert(false); return; } kpstItem.Value = StrUtil.SafeXmlString(m_tbStrTrl.Text); this.UpdateStringTableUI(); int iIndex = lvsic[0].Index; if (iIndex < m_lvStrings.Items.Count - 1) { lvsic[0].Selected = false; UIUtil.SetFocusedItem(m_lvStrings, m_lvStrings.Items[ iIndex + 1], true); } m_bModified = true; } }
private void TrlAddMenuCommands(KPStringTable kpst, ListViewGroup grp, ToolStripItemCollection tsic) { foreach (ToolStripItem tsi in tsic) { if (tsi.Text.Length == 0) { continue; } if (tsi.Text.StartsWith(@"<") && tsi.Text.EndsWith(@">")) { continue; } KPStringTableItem kpstItem = new KPStringTableItem(); kpstItem.Name = tsi.Name; kpstItem.ValueEnglish = tsi.Text; kpst.Strings.Add(kpstItem); ListViewItem lvi = new ListViewItem(); lvi.Group = grp; lvi.Text = tsi.Name; lvi.SubItems.Add(tsi.Text); lvi.SubItems.Add(string.Empty); lvi.Tag = kpstItem; lvi.ImageIndex = 0; m_lvStrings.Items.Add(lvi); ToolStripMenuItem tsmi = (tsi as ToolStripMenuItem); if (tsmi != null) { TrlAddMenuCommands(kpst, grp, tsmi.DropDownItems); } } }
private void UpdateStringTableUI() { foreach (ListViewItem lvi in m_lvStrings.Items) { KPStringTableItem kpstItem = (lvi.Tag as KPStringTableItem); Debug.Assert(kpstItem != null); if (kpstItem == null) { continue; } lvi.SubItems[2].Text = kpstItem.Value; } }
private void OnStringsSelectedIndexChanged(object sender, EventArgs e) { ListView.SelectedListViewItemCollection lvsic = m_lvStrings.SelectedItems; if (lvsic.Count != 1) { m_tbStrEng.Text = string.Empty; m_tbStrTrl.Text = string.Empty; return; } KPStringTableItem kpstItem = (lvsic[0].Tag as KPStringTableItem); Debug.Assert(kpstItem != null); if (kpstItem == null) { return; } UIUtil.SetMultilineText(m_tbStrEng, lvsic[0].SubItems[1].Text); m_tbStrTrl.Text = lvsic[0].SubItems[2].Text; }
private void OnEditNextUntrl(object sender, EventArgs e) { if (m_tabMain.SelectedTab == m_tabStrings) { int nItems = m_lvStrings.Items.Count; if (nItems == 0) { Debug.Assert(false); return; } ListViewItem lviStart = m_lvStrings.FocusedItem; int iOffset = ((lviStart != null) ? (lviStart.Index + 1) : 0); for (int i = 0; i < nItems; ++i) { int j = ((iOffset + i) % nItems); ListViewItem lvi = m_lvStrings.Items[j]; KPStringTableItem kpstItem = (lvi.Tag as KPStringTableItem); if (kpstItem == null) { Debug.Assert(false); continue; } if (string.IsNullOrEmpty(kpstItem.Value) && !string.IsNullOrEmpty(kpstItem.ValueEnglish)) { m_lvStrings.EnsureVisible(j); lvi.Selected = true; lvi.Focused = true; UIUtil.SetFocus(m_tbStrTrl, this); return; } } } else if (m_tabMain.SelectedTab == m_tabDialogs) { List <TreeNode> vNodes = new List <TreeNode>(); List <string> vValues = new List <string>(); GetControlTreeItems(m_tvControls.Nodes, vNodes, vValues); int iOffset = vNodes.IndexOf(m_tvControls.SelectedNode) + 1; for (int i = 0; i < vNodes.Count; ++i) { int j = ((iOffset + i) % vNodes.Count); TreeNode tn = vNodes[j]; string strEng = null, strText = null; KPControlCustomization kpcc = (tn.Tag as KPControlCustomization); if (kpcc != null) { strEng = kpcc.TextEnglish; strText = kpcc.Text; } if (string.IsNullOrEmpty(strEng) || (Array.IndexOf <string>( m_vEmpty, strEng) >= 0)) { strText = "Dummy"; } if (string.IsNullOrEmpty(strText)) { m_tvControls.SelectedNode = tn; UIUtil.SetFocus(m_tbCtrlTrlText, this); return; } } } else { Debug.Assert(false); return; } // Unsupported tab // MessageService.ShowInfo("No untranslated strings found on the current tab page."); MessageBox.Show(this, "No untranslated strings found on the current tab page.", TrlUtilName, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void CreateStringTableUI() { int nWidth = m_lvStrings.ClientSize.Width - 20; m_ilStr.ColorDepth = ColorDepth.Depth32Bit; m_ilStr.ImageSize = new Size(16, 16); m_ilStr.Images.Add(Properties.Resources.B16x16_Binary); m_ilStr.Images.Add(Properties.Resources.B16x16_KRec_Record); m_ilStr.Images.Add(Properties.Resources.B16x16_LedGreen); m_ilStr.Images.Add(Properties.Resources.B16x16_LedLightBlue); m_ilStr.Images.Add(Properties.Resources.B16x16_LedLightGreen); m_ilStr.Images.Add(Properties.Resources.B16x16_LedOrange); m_ilStr.Images.Add(Properties.Resources.B16x16_View_Remove); m_lvStrings.SmallImageList = m_ilStr; m_tvControls.ImageList = m_ilStr; m_lvStrings.Columns.Add("ID", nWidth / 5); m_lvStrings.Columns.Add("English", (nWidth * 2) / 5); m_lvStrings.Columns.Add("Translated", (nWidth * 2) / 5); m_trl.StringTables.Clear(); KPStringTable kpstP = new KPStringTable(); kpstP.Name = "KeePass.Resources.KPRes"; m_trl.StringTables.Add(kpstP); KPStringTable kpstL = new KPStringTable(); kpstL.Name = "KeePassLib.Resources.KLRes"; m_trl.StringTables.Add(kpstL); KPStringTable kpstM = new KPStringTable(); kpstM.Name = "KeePass.Forms.MainForm.m_menuMain"; m_trl.StringTables.Add(kpstM); KPStringTable kpstE = new KPStringTable(); kpstE.Name = "KeePass.Forms.MainForm.m_ctxPwList"; m_trl.StringTables.Add(kpstE); KPStringTable kpstG = new KPStringTable(); kpstG.Name = "KeePass.Forms.MainForm.m_ctxGroupList"; m_trl.StringTables.Add(kpstG); KPStringTable kpstT = new KPStringTable(); kpstT.Name = "KeePass.Forms.MainForm.m_ctxTray"; m_trl.StringTables.Add(kpstT); KPStringTable kpstET = new KPStringTable(); kpstET.Name = "KeePass.Forms.PwEntryForm.m_ctxTools"; m_trl.StringTables.Add(kpstET); KPStringTable kpstDT = new KPStringTable(); kpstDT.Name = "KeePass.Forms.PwEntryForm.m_ctxDefaultTimes"; m_trl.StringTables.Add(kpstDT); KPStringTable kpstLO = new KPStringTable(); kpstLO.Name = "KeePass.Forms.PwEntryForm.m_ctxListOperations"; m_trl.StringTables.Add(kpstLO); KPStringTable kpstPG = new KPStringTable(); kpstPG.Name = "KeePass.Forms.PwEntryForm.m_ctxPwGen"; m_trl.StringTables.Add(kpstPG); KPStringTable kpstSM = new KPStringTable(); kpstSM.Name = "KeePass.Forms.PwEntryForm.m_ctxStrMoveToStandard"; m_trl.StringTables.Add(kpstSM); KPStringTable kpstBA = new KPStringTable(); kpstBA.Name = "KeePass.Forms.PwEntryForm.m_ctxBinAttach"; m_trl.StringTables.Add(kpstBA); KPStringTable kpstTT = new KPStringTable(); kpstTT.Name = "KeePass.Forms.EcasTriggersForm.m_ctxTools"; m_trl.StringTables.Add(kpstTT); KPStringTable kpstDE = new KPStringTable(); kpstDE.Name = "KeePass.Forms.DataEditorForm.m_menuMain"; m_trl.StringTables.Add(kpstDE); KPStringTable kpstSD = new KPStringTable(); kpstSD.Name = "KeePassLib.Resources.KSRes"; m_trl.StringTables.Add(kpstSD); Type tKP = typeof(KPRes); ListViewGroup lvg = new ListViewGroup("KeePass Strings"); m_lvStrings.Groups.Add(lvg); foreach (string strKey in KPRes.GetKeyNames()) { PropertyInfo pi = tKP.GetProperty(strKey); MethodInfo mi = pi.GetGetMethod(); if (mi.ReturnType != typeof(string)) { MessageBox.Show(this, "Return type is not string:\r\n" + strKey, TrlUtilName + ": Fatal Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string strEng = (mi.Invoke(null, null) as string); if (strEng == null) { MessageBox.Show(this, "English string is null:\r\n" + strKey, TrlUtilName + ": Fatal Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } KPStringTableItem kpstItem = new KPStringTableItem(); kpstItem.Name = strKey; kpstItem.ValueEnglish = strEng; kpstP.Strings.Add(kpstItem); ListViewItem lvi = new ListViewItem(); lvi.Group = lvg; lvi.Text = strKey; lvi.SubItems.Add(strEng); lvi.SubItems.Add(string.Empty); lvi.Tag = kpstItem; lvi.ImageIndex = 0; m_lvStrings.Items.Add(lvi); } Type tKL = typeof(KLRes); lvg = new ListViewGroup("KeePass Library Strings"); m_lvStrings.Groups.Add(lvg); foreach (string strLibKey in KLRes.GetKeyNames()) { PropertyInfo pi = tKL.GetProperty(strLibKey); MethodInfo mi = pi.GetGetMethod(); if (mi.ReturnType != typeof(string)) { MessageBox.Show(this, "Return type is not string:\r\n" + strLibKey, TrlUtilName + ": Fatal Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string strEng = (mi.Invoke(null, null) as string); if (strEng == null) { MessageBox.Show(this, "English string is null:\r\n" + strLibKey, TrlUtilName + ": Fatal Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } KPStringTableItem kpstItem = new KPStringTableItem(); kpstItem.Name = strLibKey; kpstItem.ValueEnglish = strEng; kpstL.Strings.Add(kpstItem); ListViewItem lvi = new ListViewItem(); lvi.Group = lvg; lvi.Text = strLibKey; lvi.SubItems.Add(strEng); lvi.SubItems.Add(string.Empty); lvi.Tag = kpstItem; lvi.ImageIndex = 0; m_lvStrings.Items.Add(lvi); } lvg = new ListViewGroup("Main Menu Commands"); m_lvStrings.Groups.Add(lvg); KeePass.Forms.MainForm mf = new KeePass.Forms.MainForm(); TrlAddMenuCommands(kpstM, lvg, mf.MainMenu.Items); lvg = new ListViewGroup("Entry Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstE, lvg, mf.EntryContextMenu.Items); lvg = new ListViewGroup("Group Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstG, lvg, mf.GroupContextMenu.Items); lvg = new ListViewGroup("System Tray Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstT, lvg, mf.TrayContextMenu.Items); KeePass.Forms.PwEntryForm ef = new KeePass.Forms.PwEntryForm(); lvg = new ListViewGroup("Entry Tools Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstET, lvg, ef.ToolsContextMenu.Items); lvg = new ListViewGroup("Default Times Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstDT, lvg, ef.DefaultTimesContextMenu.Items); lvg = new ListViewGroup("List Operations Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstLO, lvg, ef.ListOperationsContextMenu.Items); lvg = new ListViewGroup("Password Generator Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstPG, lvg, ef.PasswordGeneratorContextMenu.Items); KeePass.Forms.EcasTriggersForm tf = new KeePass.Forms.EcasTriggersForm(); lvg = new ListViewGroup("Ecas Trigger Tools Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstTT, lvg, tf.ToolsContextMenu.Items); KeePass.Forms.DataEditorForm df = new KeePass.Forms.DataEditorForm(); lvg = new ListViewGroup("Data Editor Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstDE, lvg, df.MainMenuEx.Items); lvg = new ListViewGroup("Standard String Movement Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstSM, lvg, ef.StandardStringMovementContextMenu.Items); lvg = new ListViewGroup("Entry Attachments Context Menu Commands"); m_lvStrings.Groups.Add(lvg); TrlAddMenuCommands(kpstBA, lvg, ef.AttachmentsContextMenu.Items); Type tSD = typeof(KSRes); lvg = new ListViewGroup("KeePassLibSD Strings"); m_lvStrings.Groups.Add(lvg); foreach (string strLibSDKey in KSRes.GetKeyNames()) { PropertyInfo pi = tSD.GetProperty(strLibSDKey); MethodInfo mi = pi.GetGetMethod(); if (mi.ReturnType != typeof(string)) { MessageBox.Show(this, "Return type is not string:\r\n" + strLibSDKey, TrlUtilName + ": Fatal Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string strEng = (mi.Invoke(null, null) as string); if (strEng == null) { MessageBox.Show(this, "English string is null:\r\n" + strLibSDKey, TrlUtilName + ": Fatal Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } KPStringTableItem kpstItem = new KPStringTableItem(); kpstItem.Name = strLibSDKey; kpstItem.ValueEnglish = strEng; kpstL.Strings.Add(kpstItem); ListViewItem lvi = new ListViewItem(); lvi.Group = lvg; lvi.Text = strLibSDKey; lvi.SubItems.Add(strEng); lvi.SubItems.Add(string.Empty); lvi.Tag = kpstItem; lvi.ImageIndex = 0; m_lvStrings.Items.Add(lvi); } }