Beispiel #1
0
        private void GetControlTreeItems(TreeNodeCollection tnBase,
                                         List <TreeNode> vNodes, List <string> vValues)
        {
            foreach (TreeNode tn in tnBase)
            {
                KPFormCustomization    kpfc = (tn.Tag as KPFormCustomization);
                KPControlCustomization kpcc = (tn.Tag as KPControlCustomization);

                vNodes.Add(tn);
                if (kpfc != null)
                {
                    vValues.Add(kpfc.Window.Name + "©" + kpfc.Window.TextEnglish +
                                "©" + kpfc.Window.Text);
                }
                else if (kpcc != null)
                {
                    vValues.Add(kpcc.Name + "©" + kpcc.TextEnglish + "©" + kpcc.Text);
                }
                else
                {
                    vValues.Add(tn.Text);
                }

                GetControlTreeItems(tn.Nodes, vNodes, vValues);
            }
        }
Beispiel #2
0
        private void ShowCustomControlProps(KPControlCustomization kpcc)
        {
            if (kpcc == null)
            {
                return;                          // No assert
            }
            m_kpccLast = kpcc;

            UIUtil.SetMultilineText(m_tbCtrlEngText, m_kpccLast.TextEnglish);
            m_tbCtrlTrlText.Text = m_kpccLast.Text;

            m_tbLayoutX.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.X);
            m_tbLayoutY.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.Y);
            m_tbLayoutW.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.Width);
            m_tbLayoutH.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.Height);
        }
Beispiel #3
0
        private static void MergeControlCustomizations(KPControlCustomization ccInto,
                                                       KPControlCustomization ccFrom, StringBuilder sbUnusedText)
        {
            if (ccFrom.Text.Length > 0)
            {
                bool bTextValid = true;

                if (!m_bIgnoreBaseHash && (ccFrom.BaseHash.Length > 0) &&
                    !ccInto.MatchHash(ccFrom.BaseHash))
                {
                    bTextValid = false;
                }

                if (bTextValid)
                {
                    ccInto.Text = ccFrom.Text;
                }
                else                 // Create a backup
                {
                    string strTrimmed = ccFrom.Text.Trim();
                    if (strTrimmed.Length > 0)
                    {
                        sbUnusedText.AppendLine(strTrimmed);
                    }
                }
            }

            if (ccFrom.Layout.X.Length > 0)
            {
                ccInto.Layout.X = ccFrom.Layout.X;
            }
            if (ccFrom.Layout.Y.Length > 0)
            {
                ccInto.Layout.Y = ccFrom.Layout.Y;
            }
            if (ccFrom.Layout.Width.Length > 0)
            {
                ccInto.Layout.Width = ccFrom.Layout.Width;
            }
            if (ccFrom.Layout.Height.Length > 0)
            {
                ccInto.Layout.Height = ccFrom.Layout.Height;
            }
        }
Beispiel #4
0
        private static void AddForm(List <KPFormCustomization> listForms, Form f)
        {
            KPFormCustomization kpfc = new KPFormCustomization();

            kpfc.FullName    = f.GetType().FullName;
            kpfc.FormEnglish = f;

            kpfc.Window.TextEnglish = f.Text;
            kpfc.Window.BaseHash    = KPControlCustomization.HashControl(f);

            foreach (Control c in f.Controls)
            {
                AddControl(kpfc, c);
            }

            kpfc.Controls.Sort();

            listForms.Add(kpfc);
        }
Beispiel #5
0
        private void ShowCustomControlProps(KPControlCustomization kpcc)
        {
            if(kpcc == null) return; // No assert

            m_kpccLast = kpcc;

            UIUtil.SetMultilineText(m_tbCtrlEngText, m_kpccLast.TextEnglish);
            m_tbCtrlTrlText.Text = m_kpccLast.Text;

            m_tbLayoutX.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.X);
            m_tbLayoutY.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.Y);
            m_tbLayoutW.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.Width);
            m_tbLayoutH.Text = KpccLayout.ToControlRelativeString(m_kpccLast.Layout.Height);
        }
Beispiel #6
0
        private static void MergeControlCustomizations(KPControlCustomization ccInto,
            KPControlCustomization ccFrom, StringBuilder sbUnusedText)
        {
            if(ccFrom.Text.Length > 0)
            {
                bool bTextValid = true;

                if(!m_bIgnoreBaseHash && (ccFrom.BaseHash.Length > 0) &&
                    !ccInto.MatchHash(ccFrom.BaseHash))
                    bTextValid = false;

                if(bTextValid) ccInto.Text = ccFrom.Text;
                else // Create a backup
                {
                    string strTrimmed = ccFrom.Text.Trim();
                    if(strTrimmed.Length > 0) sbUnusedText.AppendLine(strTrimmed);
                }
            }

            if(ccFrom.Layout.X.Length > 0) ccInto.Layout.X = ccFrom.Layout.X;
            if(ccFrom.Layout.Y.Length > 0) ccInto.Layout.Y = ccFrom.Layout.Y;
            if(ccFrom.Layout.Width.Length > 0) ccInto.Layout.Width = ccFrom.Layout.Width;
            if(ccFrom.Layout.Height.Length > 0) ccInto.Layout.Height = ccFrom.Layout.Height;
        }
Beispiel #7
0
        private static void AddControl(KPFormCustomization kpfc, Control c)
        {
            if((kpfc == null) || (c == null)) { Debug.Assert(false); return; }

            bool bAdd = true;
            Type t = c.GetType();

            if(c.Text.Length == 0) bAdd = false;
            else if(c.Name.Length == 0) bAdd = false;
            else if(t == typeof(MenuStrip)) bAdd = false;
            else if(t == typeof(PictureBox)) bAdd = false;
            else if(t == typeof(TreeView)) bAdd = false;
            else if(t == typeof(ToolStrip)) bAdd = false;
            else if(t == typeof(WebBrowser)) bAdd = false;
            else if(t == typeof(Panel)) bAdd = false;
            else if(t == typeof(StatusStrip)) bAdd = false;
            else if(c.Text.StartsWith(@"<") && c.Text.EndsWith(@">")) bAdd = false;

            if(t == typeof(TabControl)) bAdd = true;
            else if(t == typeof(ProgressBar)) bAdd = true;
            else if(t == typeof(TextBox)) bAdd = true;
            else if(t == typeof(PromptedTextBox)) bAdd = true;
            else if(t == typeof(RichTextBox)) bAdd = true;
            else if(t == typeof(KeePass.UI.CustomRichTextBoxEx)) bAdd = true;
            else if(t == typeof(ComboBox)) bAdd = true;
            else if(t == typeof(KeePass.UI.ImageComboBoxEx)) bAdd = true;
            else if(t == typeof(Label)) bAdd = true;
            else if(t == typeof(ListView)) bAdd = true;
            else if(t == typeof(CustomListViewEx)) bAdd = true;
            else if(t == typeof(Button)) bAdd = true;
            else if(t == typeof(KeePass.UI.QualityProgressBar)) bAdd = true;
            else if(t == typeof(DateTimePicker)) bAdd = true;
            else if(t == typeof(CheckedListBox)) bAdd = true;

            if(bAdd && (c.Name.Length > 0))
            {
                KPControlCustomization kpcc = new KPControlCustomization();
                kpcc.Name = c.Name;
                kpcc.BaseHash = KPControlCustomization.HashControl(c);

                if((t != typeof(TabControl)) && (t != typeof(NumericUpDown)))
                    kpcc.TextEnglish = c.Text;
                else kpcc.TextEnglish = string.Empty;

                kpfc.Controls.Add(kpcc);
            }

            foreach(Control cSub in c.Controls) AddControl(kpfc, cSub);
        }
Beispiel #8
0
        private void UpdateStatusImages(TreeNodeCollection vtn)
        {
            if (vtn == null)
            {
                vtn = m_tvControls.Nodes;
            }

            foreach (TreeNode tn in vtn)
            {
                KPFormCustomization    kpfc = (tn.Tag as KPFormCustomization);
                KPControlCustomization kpcc = (tn.Tag as KPControlCustomization);

                if (kpfc != null)
                {
                    tn.ImageIndex         = m_inxWindow;
                    tn.SelectedImageIndex = m_inxWindow;
                }
                else if (kpcc != null)
                {
                    int iCurrentImage = tn.ImageIndex, iNewImage;

                    if (Array.IndexOf <string>(m_vEmpty, kpcc.TextEnglish) >= 0)
                    {
                        iNewImage = ((kpcc.Text.Length == 0) ? m_inxOk : m_inxWarning);
                    }
                    else if ((kpcc.TextEnglish.Length > 0) && (kpcc.Text.Length > 0))
                    {
                        iNewImage = m_inxOk;
                    }
                    else if ((kpcc.TextEnglish.Length > 0) && (kpcc.Text.Length == 0))
                    {
                        iNewImage = m_inxMissing;
                    }
                    else if ((kpcc.TextEnglish.Length == 0) && (kpcc.Text.Length == 0))
                    {
                        iNewImage = m_inxOk;
                    }
                    else if ((kpcc.TextEnglish.Length == 0) && (kpcc.Text.Length > 0))
                    {
                        iNewImage = m_inxWarning;
                    }
                    else
                    {
                        iNewImage = m_inxWarning;
                    }

                    if (iNewImage != iCurrentImage)
                    {
                        tn.ImageIndex         = iNewImage;
                        tn.SelectedImageIndex = iNewImage;
                    }
                }
                else
                {
                    Debug.Assert(false);
                }

                if (tn.Nodes != null)
                {
                    UpdateStatusImages(tn.Nodes);
                }
            }
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        private static void AddControl(KPFormCustomization kpfc, Control c)
        {
            if ((kpfc == null) || (c == null))
            {
                Debug.Assert(false); return;
            }

            bool bAdd = true;
            Type t    = c.GetType();

            if (c.Text.Length == 0)
            {
                bAdd = false;
            }
            else if (c.Name.Length == 0)
            {
                bAdd = false;
            }
            else if (t == typeof(MenuStrip))
            {
                bAdd = false;
            }
            else if (t == typeof(PictureBox))
            {
                bAdd = false;
            }
            else if (t == typeof(TreeView))
            {
                bAdd = false;
            }
            else if (t == typeof(ToolStrip))
            {
                bAdd = false;
            }
            else if (t == typeof(WebBrowser))
            {
                bAdd = false;
            }
            else if (t == typeof(Panel))
            {
                bAdd = false;
            }
            else if (t == typeof(StatusStrip))
            {
                bAdd = false;
            }
            else if (c.Text.StartsWith(@"<") && c.Text.EndsWith(@">"))
            {
                bAdd = false;
            }

            if (t == typeof(TabControl))
            {
                bAdd = true;
            }
            else if (t == typeof(ProgressBar))
            {
                bAdd = true;
            }
            else if (t == typeof(QualityProgressBar))
            {
                bAdd = true;
            }
            else if (t == typeof(TextBox))
            {
                bAdd = true;
            }
            else if (t == typeof(PromptedTextBox))
            {
                bAdd = true;
            }
            else if (t == typeof(SecureTextBoxEx))
            {
                bAdd = true;
            }
            else if (t == typeof(RichTextBox))
            {
                bAdd = true;
            }
            else if (t == typeof(CustomRichTextBoxEx))
            {
                bAdd = true;
            }
            else if (t == typeof(ComboBox))
            {
                bAdd = true;
            }
            else if (t == typeof(ImageComboBoxEx))
            {
                bAdd = true;
            }
            else if (t == typeof(Label))
            {
                bAdd = true;
            }
            else if (t == typeof(ListView))
            {
                bAdd = true;
            }
            else if (t == typeof(CustomListViewEx))
            {
                bAdd = true;
            }
            else if (t == typeof(CheckedListBox))
            {
                bAdd = true;
            }
            else if (t == typeof(Button))
            {
                bAdd = true;
            }
            else if (t == typeof(DateTimePicker))
            {
                bAdd = true;
            }

            if (bAdd && (c.Name.Length > 0))
            {
                KPControlCustomization kpcc = new KPControlCustomization();
                kpcc.Name     = c.Name;
                kpcc.BaseHash = KPControlCustomization.HashControl(c);

                if ((t != typeof(TabControl)) && (t != typeof(NumericUpDown)))
                {
                    kpcc.TextEnglish = c.Text;
                }
                else
                {
                    kpcc.TextEnglish = string.Empty;
                }

                kpfc.Controls.Add(kpcc);
            }

            foreach (Control cSub in c.Controls)
            {
                AddControl(kpfc, cSub);
            }
        }