Esempio n. 1
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            GlobalWindowManager.AddWindow(this);

            m_bInitializing = true;
            FontUtil.AssignDefaultBold(m_lblContext);
            m_lblContext.Text = m_strContext;

            foreach (string strEnc in m_vEncText)
            {
                m_cmbEnc.Items.Add(strEnc);
            }

            string strDet;
            uint   uStartOffset;

            BinaryDataClassifier.GetStringEncoding(m_pbData, false,
                                                   out strDet, out uStartOffset);
            int iDet = Array.IndexOf <string>(m_vEncText, strDet);

            m_cmbEnc.SelectedIndex = ((iDet >= 0) ? iDet : 0);

            m_bInitializing = false;
            UpdateTextPreview();
        }
Esempio n. 2
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            GlobalWindowManager.AddWindow(this);

            m_bInitializing = true;
            this.Icon       = AppIcons.Default;

            FontUtil.AssignDefaultBold(m_lblContext);
            Debug.Assert(!m_lblContext.AutoSize);             // For RTL support
            m_lblContext.Text = m_strContext;

            m_cmbEnc.Items.Add(KPRes.BinaryNoConv);
            foreach (StrEncodingInfo sei in StrUtil.Encodings)
            {
                m_cmbEnc.Items.Add(sei.Name);
            }

            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out m_uStartOffset);

            int iSel = 0;

            if (seiGuess != null)
            {
                iSel = Math.Max(m_cmbEnc.FindStringExact(seiGuess.Name), 0);
            }
            m_cmbEnc.SelectedIndex = iSel;

            m_bInitializing = false;
            UpdateTextPreview();
        }
Esempio n. 3
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if ((m_pbData == null) || (m_pwDatabase == null))
            {
                throw new InvalidOperationException();
            }

            m_bInitializing = true;

            GlobalWindowManager.AddWindow(this);

            // Callable from KPScript without parent form
            Debug.Assert(this.StartPosition == FormStartPosition.CenterScreen);

            this.Icon = AppIcons.Default;
            this.Text = KPRes.GenericCsvImporter;

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         Properties.Resources.B48x48_Binary, KPRes.GenericCsvImporter,
                                         KPRes.CsvImportDesc);

            // FontUtil.AssignDefaultBold(m_grpSyntax);
            // FontUtil.AssignDefaultBold(m_grpSem);

            UIUtil.SetExplorerTheme(m_lvFields, false);
            UIUtil.SetExplorerTheme(m_lvImportPreview, false);

            foreach (StrEncodingInfo seiEnum in StrUtil.Encodings)
            {
                m_cmbEnc.Items.Add(seiEnum.Name);
            }

            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out m_uStartOffset);

            int iSel = 0;

            if (seiGuess != null)
            {
                iSel = Math.Max(m_cmbEnc.FindStringExact(seiGuess.Name), 0);
            }
            m_cmbEnc.SelectedIndex = iSel;

            string[] vChars = new string[] { ",", ";", ".", ":", "\"", @"'",
                                             StrCharTab, StrCharNewLine };
            foreach (string strChar in vChars)
            {
                m_cmbFieldSep.Items.Add(strChar);
                m_cmbRecSep.Items.Add(strChar);
                m_cmbTextQual.Items.Add(strChar);
            }
            m_cmbFieldSep.SelectedIndex = 0;
            m_cmbRecSep.SelectedIndex   = 7;
            m_cmbTextQual.SelectedIndex = 4;

            m_lvFields.Columns.Add(KPRes.Field);

            AddCsvField(CsvFieldType.Title, null, null);
            AddCsvField(CsvFieldType.UserName, null, null);
            AddCsvField(CsvFieldType.Password, null, null);
            AddCsvField(CsvFieldType.Url, null, null);
            AddCsvField(CsvFieldType.Notes, null, null);

            for (int i = (int)CsvFieldType.First; i < (int)CsvFieldType.Count; ++i)
            {
                m_cmbFieldType.Items.Add(CsvFieldToString((CsvFieldType)i));
            }
            m_cmbFieldType.SelectedIndex = (int)CsvFieldType.Group;

            m_cmbFieldFormat.Text = string.Empty;

            UIUtil.AccSetName(m_btnFieldMoveUp, KPRes.MoveUp);
            UIUtil.AccSetName(m_btnFieldMoveDown, KPRes.MoveDown);

            m_bInitializing = false;

            UpdateTextPreview();
            UpdateImportPreview();
            GuessCsvStructure();

            ProcessResize();
            EnableControlsEx();
        }
Esempio n. 4
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            this.Icon           = AppIcons.Default;
            this.DoubleBuffered = true;

            m_strInitialFormRect = UIUtil.SetWindowScreenRectEx(this,
                                                                Program.Config.UI.DataEditorRect);

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);
            uint            uStartOffset;
            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out uStartOffset);
            string strData;

            try
            {
                strData = (seiGuess.Encoding.GetString(m_pbData, (int)uStartOffset,
                                                       m_pbData.Length - (int)uStartOffset) ?? string.Empty);
                strData = StrUtil.ReplaceNulls(strData);
            }
            catch (Exception) { Debug.Assert(false); strData = string.Empty; }

            ++m_uBlockEvents;

            UIUtil.AssignShortcut(m_menuFileSave, Keys.Control | Keys.S);
            UIUtil.AssignShortcut(m_menuFileExit, Keys.Escape, null, true);

            UIUtil.ConfigureTbButton(m_tbFileSave, KPRes.Save, null, m_menuFileSave);
            UIUtil.ConfigureTbButton(m_tbEditCut, KPRes.Cut, null);
            UIUtil.ConfigureTbButton(m_tbEditCopy, KPRes.Copy, null);
            UIUtil.ConfigureTbButton(m_tbEditPaste, KPRes.Paste, null);
            UIUtil.ConfigureTbButton(m_tbEditUndo, KPRes.Undo, null);
            UIUtil.ConfigureTbButton(m_tbEditRedo, KPRes.Redo, null);
            UIUtil.ConfigureTbButton(m_tbFormatBold, KPRes.Bold, null);
            UIUtil.ConfigureTbButton(m_tbFormatItalic, KPRes.Italic, null);
            UIUtil.ConfigureTbButton(m_tbFormatUnderline, KPRes.Underline, null);
            UIUtil.ConfigureTbButton(m_tbFormatStrikeout, KPRes.Strikeout, null);
            UIUtil.ConfigureTbButton(m_tbColorForeground, KPRes.TextColor, null);
            UIUtil.ConfigureTbButton(m_tbColorBackground, KPRes.BackgroundColor, null);
            UIUtil.ConfigureTbButton(m_tbAlignCenter, KPRes.AlignCenter, null);
            UIUtil.ConfigureTbButton(m_tbAlignLeft, KPRes.AlignLeft, null);
            UIUtil.ConfigureTbButton(m_tbAlignRight, KPRes.AlignRight, null);

            string strSearchTr = ((WinUtil.IsAtLeastWindowsVista ?
                                   string.Empty : " ") + KPRes.Search);

            UIUtil.SetCueBanner(m_tbFind, strSearchTr);

            UIUtil.EnableAutoCompletion(m_tbFontCombo, true);
            UIUtil.EnableAutoCompletion(m_tbFontSizeCombo, true);

            m_rtbText.Dock = DockStyle.Fill;
            m_ctxText.Attach(m_rtbText, this);
            m_tssStatusMain.Text = KPRes.Ready;
            m_rtbText.WordWrap   = Program.Config.UI.DataEditorWordWrap;

            InitFormattingToolBar();

            bool bSimpleText = true, bDefaultFont = true;

            if (m_bdc == BinaryDataClass.RichText)
            {
                try
                {
                    if (strData.Length > 0)
                    {
                        m_rtbText.Rtf = StrUtil.RtfFix(strData);
                        bDefaultFont  = false;
                    }
                    else
                    {
                        m_rtbText.Text = string.Empty;
                    }

                    bSimpleText = false;
                }
                catch (Exception) { }                // Show as simple text
            }

            if (bSimpleText)
            {
                m_rtbText.Text           = strData;
                m_rtbText.SimpleTextOnly = true;

                // CR is upgraded to CR+LF
                m_bNewLinesWin = (StrUtil.GetNewLineSeq(strData) != "\n");
            }
            else
            {
                m_menuViewFont.Text = KPRes.FontDefault + "...";
            }

            if (bDefaultFont && Program.Config.UI.DataEditorFont.OverrideUIDefault)
            {
                m_rtbText.SelectAll();
                m_rtbText.SelectionFont = Program.Config.UI.DataEditorFont.ToFont();
            }

            m_rtbText.Select(0, 0);
            --m_uBlockEvents;
            UpdateUIState(false, true);
        }
Esempio n. 5
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            m_bInitializing = true;

            GlobalWindowManager.AddWindow(this);

            this.Icon           = AppIcons.Default;
            this.DoubleBuffered = true;

            string strTitle = KPRes.DataViewerKP;

            if (m_strDataDesc.Length > 0)
            {
                strTitle = m_strDataDesc + " - " + strTitle;
            }
            this.Text = strTitle;

            m_strInitialFormRect = UIUtil.SetWindowScreenRectEx(this,
                                                                Program.Config.UI.DataViewerRect);

            m_tssStatusMain.Text = KPRes.Ready;
            m_ctxText.Attach(m_rtbText, this);
            m_rtbText.Dock        = DockStyle.Fill;
            m_webBrowser.Dock     = DockStyle.Fill;
            m_pnlImageViewer.Dock = DockStyle.Fill;
            m_picBox.Dock         = DockStyle.Fill;

            m_tslEncoding.Text = KPRes.Encoding + ":";

            foreach (StrEncodingInfo seiEnum in StrUtil.Encodings)
            {
                m_tscEncoding.Items.Add(seiEnum.Name);
            }

            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out m_uStartOffset);

            int iSel = 0;

            if (seiGuess != null)
            {
                iSel = Math.Max(m_tscEncoding.FindStringExact(seiGuess.Name), 0);
            }
            m_tscEncoding.SelectedIndex = iSel;

            m_tslZoom.Text = KPRes.Zoom + ":";

            // Required for mouse wheel handling
            Debug.Assert(m_tscZoom.DropDownStyle == ComboBoxStyle.DropDownList);

            m_tscZoom.Items.Add(m_strZoomAuto);
            int[] vZooms = new int[] { 10, 25, 50, 75, 100, 125, 150, 200, 400 };
            foreach (int iZoom in vZooms)
            {
                m_tscZoom.Items.Add(iZoom.ToString() + "%");
            }
            m_tscZoom.SelectedIndex = 0;

            m_tsbZoomOut.ToolTipText = KPRes.Zoom + " - (" + KPRes.KeyboardKeyCtrl +
                                       "+-)";
            m_tsbZoomIn.ToolTipText = KPRes.Zoom + " + (" + KPRes.KeyboardKeyCtrl +
                                      "++)";

            m_tslViewer.Text = KPRes.ShowIn + ":";

            m_tscViewers.Items.Add(m_strViewerHex);
            m_tscViewers.Items.Add(m_strViewerText);
            m_tscViewers.Items.Add(m_strViewerImage);
            m_tscViewers.Items.Add(m_strViewerWeb);

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);

            if ((m_bdc == BinaryDataClass.Text) || (m_bdc == BinaryDataClass.RichText))
            {
                m_tscViewers.SelectedIndex = 1;
            }
            else if (m_bdc == BinaryDataClass.Image)
            {
                m_tscViewers.SelectedIndex = 2;
            }
            else if (m_bdc == BinaryDataClass.WebDocument)
            {
                m_tscViewers.SelectedIndex = 3;
            }
            else
            {
                m_tscViewers.SelectedIndex = 0;
            }

            if (this.DvfInit != null)
            {
                this.DvfInit(this, new DvfContextEventArgs(this, m_pbData,
                                                           m_strDataDesc, m_tscViewers));
            }

            m_picBox.MouseWheel += this.OnPicBoxMouseWheel;

            m_bInitializing = false;
            UpdateDataView();
        }
Esempio n. 6
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            this.Icon = Properties.Resources.KeePass;

            m_tslViewer.Text   = KPRes.ShowIn + ":";
            m_tslEncoding.Text = KPRes.Encoding + ":";

            if (m_strDataDesc.Length > 0)
            {
                this.Text = m_strDataDesc + " - " + this.Text;
            }

            this.DoubleBuffered = true;

            m_tssStatusMain.Text = KPRes.Ready;

            m_ctxText.Attach(m_rtbText);

            m_bInitializing = true;

            m_rtbText.Dock        = DockStyle.Fill;
            m_webBrowser.Dock     = DockStyle.Fill;
            m_pnlImageViewer.Dock = DockStyle.Fill;
            m_picBox.Dock         = DockStyle.Fill;

            m_tscEncoding.Items.Add(BinaryDataClassifier.BdeAnsi + " (" +
                                    KPRes.SystemCodePage + ")");
            m_tscEncoding.Items.Add(BinaryDataClassifier.BdeAscii);
            m_tscEncoding.Items.Add(BinaryDataClassifier.BdeUtf7);
            m_tscEncoding.Items.Add(BinaryDataClassifier.BdeUtf8);
            m_tscEncoding.Items.Add(BinaryDataClassifier.BdeUtf32);
            m_tscEncoding.Items.Add(BinaryDataClassifier.BdeUnicodeLE);
            m_tscEncoding.Items.Add(BinaryDataClassifier.BdeUnicodeBE);

            string   strEnc;
            Encoding enc = BinaryDataClassifier.GetStringEncoding(m_pbData,
                                                                  false, out strEnc, out m_uStartOffset);

            if (strEnc == BinaryDataClassifier.BdeAnsi)
            {
                m_tscEncoding.SelectedIndex = 0;
            }
            else if (strEnc == BinaryDataClassifier.BdeAscii)
            {
                m_tscEncoding.SelectedIndex = 1;
            }
            else if (strEnc == BinaryDataClassifier.BdeUtf7)
            {
                m_tscEncoding.SelectedIndex = 2;
            }
            else if (strEnc == BinaryDataClassifier.BdeUtf8)
            {
                m_tscEncoding.SelectedIndex = 3;
            }
            else if (strEnc == BinaryDataClassifier.BdeUtf32)
            {
                m_tscEncoding.SelectedIndex = 4;
            }
            else if (strEnc == BinaryDataClassifier.BdeUnicodeLE)
            {
                m_tscEncoding.SelectedIndex = 5;
            }
            else if (strEnc == BinaryDataClassifier.BdeUnicodeBE)
            {
                m_tscEncoding.SelectedIndex = 6;
            }
            else
            {
                m_tscEncoding.SelectedIndex = 0;
            }

            m_tscViewers.Items.Add(KPRes.TextViewer);
            m_tscViewers.Items.Add(KPRes.ImageViewer);
            m_tscViewers.Items.Add(KPRes.WebBrowser);

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);

            if ((m_bdc == BinaryDataClass.Text) || (m_bdc == BinaryDataClass.RichText))
            {
                m_tscViewers.SelectedIndex = 0;
            }
            else if (m_bdc == BinaryDataClass.Image)
            {
                m_tscViewers.SelectedIndex = 1;
            }
            else if (m_bdc == BinaryDataClass.WebDocument)
            {
                m_tscViewers.SelectedIndex = 2;
            }
            else
            {
                m_tscViewers.SelectedIndex = 0;
            }

            if (this.Initializing != null)
            {
                this.Initializing(this, new DvfContextEventArgs(this,
                                                                m_pbData, m_strDataDesc, m_tscViewers));
            }

            m_bInitializing = false;
            UpdateDataView(enc);
        }
Esempio n. 7
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            this.Icon = Properties.Resources.KeePass;

            string strTitle = PwDefs.ShortProductName + " " + KPRes.DataViewer;

            if (m_strDataDesc.Length > 0)
            {
                strTitle = m_strDataDesc + " - " + strTitle;
            }
            this.Text = strTitle;

            this.DoubleBuffered = true;

            m_bInitializing = true;

            m_tssStatusMain.Text = KPRes.Ready;
            m_ctxText.Attach(m_rtbText, this);
            m_rtbText.Dock        = DockStyle.Fill;
            m_webBrowser.Dock     = DockStyle.Fill;
            m_pnlImageViewer.Dock = DockStyle.Fill;
            m_picBox.Dock         = DockStyle.Fill;

            m_tslEncoding.Text = KPRes.Encoding + ":";

            foreach (StrEncodingInfo seiEnum in StrUtil.Encodings)
            {
                m_tscEncoding.Items.Add(seiEnum.Name);
            }

            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out m_uStartOffset);

            int iSel = 0;

            if (seiGuess != null)
            {
                iSel = Math.Max(m_tscEncoding.FindStringExact(seiGuess.Name), 0);
            }
            m_tscEncoding.SelectedIndex = iSel;

            m_tslZoom.Text = KPRes.Zoom + ":";

            m_tscZoom.Items.Add(KPRes.Auto);
            int[] vZooms = new int[] { 10, 25, 50, 75, 100, 125, 150, 200, 400 };
            foreach (int iZoom in vZooms)
            {
                m_tscZoom.Items.Add(iZoom.ToString() + @"%");
            }
            m_tscZoom.SelectedIndex = 0;

            m_tslViewer.Text = KPRes.ShowIn + ":";

            m_tscViewers.Items.Add(m_strViewerHex);
            m_tscViewers.Items.Add(m_strViewerText);
            m_tscViewers.Items.Add(m_strViewerImage);
            m_tscViewers.Items.Add(m_strViewerWeb);

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);

            if ((m_bdc == BinaryDataClass.Text) || (m_bdc == BinaryDataClass.RichText))
            {
                m_tscViewers.SelectedIndex = 1;
            }
            else if (m_bdc == BinaryDataClass.Image)
            {
                m_tscViewers.SelectedIndex = 2;
            }
            else if (m_bdc == BinaryDataClass.WebDocument)
            {
                m_tscViewers.SelectedIndex = 3;
            }
            else
            {
                m_tscViewers.SelectedIndex = 0;
            }

            if (this.DvfInit != null)
            {
                this.DvfInit(this, new DvfContextEventArgs(this, m_pbData,
                                                           m_strDataDesc, m_tscViewers));
            }

            m_bInitializing = false;
            UpdateDataView();
        }
Esempio n. 8
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            if ((m_pbData == null) || (m_pwDatabase == null))
            {
                throw new InvalidOperationException();
            }

            m_bInitializing = true;

            GlobalWindowManager.AddWindow(this);

            this.Icon = Properties.Resources.KeePass;
            this.Text = KPRes.GenericCsvImporter + " - " + PwDefs.ShortProductName;

            // FontUtil.AssignDefaultBold(m_grpSyntax);
            // FontUtil.AssignDefaultBold(m_grpSem);

            UIUtil.SetExplorerTheme(m_lvFields, false);
            UIUtil.SetExplorerTheme(m_lvImportPreview, false);

            foreach (StrEncodingInfo seiEnum in StrUtil.Encodings)
            {
                m_cmbEnc.Items.Add(seiEnum.Name);
            }

            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out m_uStartOffset);

            int iSel = 0;

            if (seiGuess != null)
            {
                iSel = Math.Max(m_cmbEnc.FindStringExact(seiGuess.Name), 0);
            }
            m_cmbEnc.SelectedIndex = iSel;

            string[] vChars = new string[] { ",", ";", ".", ":", "\"", @"'",
                                             StrCharTab, StrCharNewLine };
            foreach (string strChar in vChars)
            {
                m_cmbFieldSep.Items.Add(strChar);
                m_cmbRecSep.Items.Add(strChar);
                m_cmbTextQual.Items.Add(strChar);
            }
            m_cmbFieldSep.SelectedIndex = 0;
            m_cmbRecSep.SelectedIndex   = 7;
            m_cmbTextQual.SelectedIndex = 4;

            m_lvFields.Columns.Add(KPRes.Field);

            AddCsvField(CsvFieldType.Title, null, null);
            AddCsvField(CsvFieldType.UserName, null, null);
            AddCsvField(CsvFieldType.Password, null, null);
            AddCsvField(CsvFieldType.Url, null, null);
            AddCsvField(CsvFieldType.Notes, null, null);

            for (int i = (int)CsvFieldType.First; i < (int)CsvFieldType.Count; ++i)
            {
                m_cmbFieldType.Items.Add(CsvFieldToString((CsvFieldType)i));
            }
            m_cmbFieldType.SelectedIndex = (int)CsvFieldType.Group;

            m_cmbFieldFormat.Text = string.Empty;

            m_bInitializing = false;

            UpdateTextPreview();
            UpdateImportPreview();
            GuessCsvStructure();

            ProcessResize();
            EnableControlsEx();

            UIUtil.SetFocus(m_btnTabNext, this);
        }
Esempio n. 9
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            this.Icon           = Properties.Resources.KeePass;
            this.DoubleBuffered = true;

            string strRect = Program.Config.UI.DataEditorRect;

            if (strRect.Length > 0)
            {
                UIUtil.SetWindowScreenRect(this, strRect);
            }
            m_strInitialFormRect = UIUtil.GetWindowScreenRect(this);

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);
            uint            uStartOffset;
            StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding(
                m_pbData, out uStartOffset);
            string strData;

            try
            {
                strData = (seiGuess.Encoding.GetString(m_pbData, (int)uStartOffset,
                                                       m_pbData.Length - (int)uStartOffset) ?? string.Empty);
            }
            catch (Exception) { Debug.Assert(false); strData = string.Empty; }

            BlockUIEvents(true);

            UIUtil.AssignShortcut(m_menuFileSave, Keys.Control | Keys.S);
            m_menuFileExit.ShortcutKeyDisplayString = KPRes.KeyboardKeyEsc;

            UIUtil.ConfigureTbButton(m_tbFileSave, KPRes.Save, null, m_menuFileSave);
            UIUtil.ConfigureTbButton(m_tbEditCut, KPRes.Cut, null);
            UIUtil.ConfigureTbButton(m_tbEditCopy, KPRes.Copy, null);
            UIUtil.ConfigureTbButton(m_tbEditPaste, KPRes.Paste, null);
            UIUtil.ConfigureTbButton(m_tbEditUndo, KPRes.Undo, null);
            UIUtil.ConfigureTbButton(m_tbEditRedo, KPRes.Redo, null);
            UIUtil.ConfigureTbButton(m_tbFormatBold, KPRes.Bold, null);
            UIUtil.ConfigureTbButton(m_tbFormatItalic, KPRes.Italic, null);
            UIUtil.ConfigureTbButton(m_tbFormatUnderline, KPRes.Underline, null);
            UIUtil.ConfigureTbButton(m_tbFormatStrikeout, KPRes.Strikeout, null);
            UIUtil.ConfigureTbButton(m_tbColorForeground, KPRes.TextColor, null);
            UIUtil.ConfigureTbButton(m_tbColorBackground, KPRes.BackgroundColor, null);
            UIUtil.ConfigureTbButton(m_tbAlignCenter, KPRes.AlignCenter, null);
            UIUtil.ConfigureTbButton(m_tbAlignLeft, KPRes.AlignLeft, null);
            UIUtil.ConfigureTbButton(m_tbAlignRight, KPRes.AlignRight, null);

            UIUtil.EnableAutoCompletion(m_tbFontCombo, true);
            UIUtil.EnableAutoCompletion(m_tbFontSizeCombo, true);

            m_rtbText.Dock = DockStyle.Fill;
            m_ctxText.Attach(m_rtbText, this);
            m_tssStatusMain.Text = KPRes.Ready;
            m_rtbText.WordWrap   = Program.Config.UI.DataEditorWordWrap;

            InitFormattingToolBar();

            bool bSimpleText = true;

            if (m_bdc == BinaryDataClass.RichText)
            {
                try
                {
                    if (strData.Length > 0)
                    {
                        m_rtbText.Rtf = strData;
                    }
                    else
                    {
                        m_rtbText.Text = string.Empty;
                    }

                    bSimpleText = false;
                }
                catch (Exception) { }                // Show as simple text
            }

            if (bSimpleText)
            {
                m_rtbText.Text           = strData;
                m_rtbText.SimpleTextOnly = true;

                if (Program.Config.UI.DataEditorFont.OverrideUIDefault)
                {
                    m_rtbText.SelectAll();
                    m_rtbText.SelectionFont = Program.Config.UI.DataEditorFont.ToFont();
                }
            }

            m_rtbText.Select(0, 0);
            BlockUIEvents(false);
            UpdateUIState(false, true);
        }
Esempio n. 10
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            Debug.Assert(m_pbData != null);
            if (m_pbData == null)
            {
                throw new InvalidOperationException();
            }

            GlobalWindowManager.AddWindow(this);

            this.Icon           = Properties.Resources.KeePass;
            this.DoubleBuffered = true;

            m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData);
            string   strEncodingName;
            uint     uStartOffset;
            Encoding enc = BinaryDataClassifier.GetStringEncoding(m_pbData,
                                                                  false, out strEncodingName, out uStartOffset);
            string strData = enc.GetString(m_pbData);

            BlockUIEvents(true);

            UIUtil.ConfigureTbButton(m_tbFileSave, KPRes.Save, null);
            UIUtil.ConfigureTbButton(m_tbEditCut, KPRes.Cut, null);
            UIUtil.ConfigureTbButton(m_tbEditCopy, KPRes.Copy, null);
            UIUtil.ConfigureTbButton(m_tbEditPaste, KPRes.Paste, null);
            UIUtil.ConfigureTbButton(m_tbEditUndo, KPRes.Undo, null);
            UIUtil.ConfigureTbButton(m_tbEditRedo, KPRes.Redo, null);
            UIUtil.ConfigureTbButton(m_tbFormatBold, KPRes.Bold, null);
            UIUtil.ConfigureTbButton(m_tbFormatItalic, KPRes.Italic, null);
            UIUtil.ConfigureTbButton(m_tbFormatUnderline, KPRes.Underline, null);
            UIUtil.ConfigureTbButton(m_tbFormatStrikeout, KPRes.Strikeout, null);
            UIUtil.ConfigureTbButton(m_tbColorForeground, KPRes.TextColor, null);
            UIUtil.ConfigureTbButton(m_tbColorBackground, KPRes.BackgroundColor, null);
            UIUtil.ConfigureTbButton(m_tbAlignCenter, KPRes.AlignCenter, null);
            UIUtil.ConfigureTbButton(m_tbAlignLeft, KPRes.AlignLeft, null);
            UIUtil.ConfigureTbButton(m_tbAlignRight, KPRes.AlignRight, null);

            m_rtbText.Dock = DockStyle.Fill;
            m_ctxText.Attach(m_rtbText);
            m_tssStatusMain.Text = KPRes.Ready;
            m_rtbText.WordWrap   = Program.Config.UI.DataEditorWordWrap;

            InitFormattingToolBar();

            bool bSimpleText = true;

            if (m_bdc == BinaryDataClass.RichText)
            {
                try { m_rtbText.Rtf = strData; bSimpleText = false; }
                catch (Exception) { }                // Show as simple text
            }

            if (bSimpleText)
            {
                m_rtbText.Text           = strData;
                m_rtbText.SimpleTextOnly = true;

                if (Program.Config.UI.DataEditorFont.OverrideUIDefault)
                {
                    m_rtbText.SelectAll();
                    m_rtbText.SelectionFont = Program.Config.UI.DataEditorFont.ToFont();
                }
            }

            m_rtbText.Select(0, 0);
            BlockUIEvents(false);
            UpdateUIState(false, true);
        }