internal static byte[] ConvertAttachment(string strDesc, byte[] pbData) { BinaryDataClass bdc = BinaryDataClassifier.Classify(strDesc, pbData); if (bdc == BinaryDataClass.Text) { string strContext = (KPRes.File + (string.IsNullOrEmpty(strDesc) ? string.Empty : (": " + strDesc))); TextEncodingForm dlg = new TextEncodingForm(); dlg.InitEx(strContext, pbData); if (dlg.ShowDialog() == DialogResult.OK) { Encoding enc = dlg.SelectedEncoding; if (enc != null) { try { string strText = enc.GetString(pbData); return((new UTF8Encoding(false)).GetBytes(strText)); } catch (Exception) { Debug.Assert(false); } } } else { return(null); } } return(pbData); }
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(); }
internal static byte[] ConvertAttachment(string strDesc, byte[] pbData) { BinaryDataClass bdc = BinaryDataClassifier.Classify(strDesc, pbData); if (bdc == BinaryDataClass.Text) { string strContext = (KPRes.File + (string.IsNullOrEmpty(strDesc) ? string.Empty : (": " + strDesc))); TextEncodingForm dlg = new TextEncodingForm(); dlg.InitEx(strContext, pbData); if (UIUtil.ShowDialogNotValue(dlg, DialogResult.OK)) { return(null); } Encoding enc = dlg.SelectedEncoding; int iStart = (int)dlg.DataStartOffset; UIUtil.DestroyForm(dlg); if (enc != null) { try { string strText = (enc.GetString(pbData, iStart, pbData.Length - iStart) ?? string.Empty); strText = StrUtil.ReplaceNulls(strText); return(StrUtil.Utf8.GetBytes(strText)); } catch (Exception) { Debug.Assert(false); } } } return(pbData); }
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(); }
private ProtectedBinary OpenBinaryDataLegacy(string name, ProtectedBinary binary) { ProtectedBinary modifiedData = null; var data = binary.ReadData(); var dataClass = BinaryDataClassifier.Classify(name, data); if (DataEditorForm.SupportsDataType(dataClass)) { var editor = new DataEditorForm(); editor.InitEx(name, data); editor.ShowDialog(); if (editor.EditedBinaryData != null) { modifiedData = new ProtectedBinary(binary.IsProtected, editor.EditedBinaryData); } UIUtil.DestroyForm(editor); } else { var viewer = new DataViewerForm(); viewer.InitEx(name, data); UIUtil.ShowDialogAndDestroy(viewer); } return(modifiedData); }
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(); }
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); }
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(); }
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); }
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(); }
public static Image GetImageForPath(string strPath, Size?osz, bool bAllowCache, bool bNewImageObject) { if (strPath == null) { Debug.Assert(false); strPath = string.Empty; } Size sz = GetSizeOrSmall(osz); Image img = null; bool bImgIsNew = false; string strKey = GetCacheItemKey(FiTypePath, strPath, sz); if (bAllowCache && g_dCache.TryGetValue(strKey, out img)) { if (bNewImageObject) { img = (img.Clone() as Image); } return(img); } Debug.Assert(img == null); if (strPath.Length == 0) { img = Properties.Resources.B16x16_Binary; bImgIsNew = false; } try { if ((img == null) && !NativeLib.IsUnix()) { string strDisplayName; NativeMethods.SHGetFileInfo(strPath, sz.Width, sz.Height, out img, out strDisplayName); bImgIsNew = true; } } catch (Exception) { Debug.Assert(false); } if ((img == null) && !MonoWorkarounds.IsRequired(100003)) { img = UIUtil.GetFileIcon(strPath, sz.Width, sz.Height); bImgIsNew = true; } if (img == null) { BinaryDataClass bdc = BinaryDataClassifier.ClassifyUrl(strPath); if ((bdc == BinaryDataClass.Text) || (bdc == BinaryDataClass.RichText)) { img = Properties.Resources.B16x16_ASCII; } else if (bdc == BinaryDataClass.Image) { img = Properties.Resources.B16x16_Spreadsheet; } else if (bdc == BinaryDataClass.WebDocument) { img = Properties.Resources.B16x16_HTML; } else if (strPath.EndsWith(".exe", StrUtil.CaseIgnoreCmp)) { img = Properties.Resources.B16x16_Make_KDevelop; } else { img = Properties.Resources.B16x16_Binary; } bImgIsNew = false; } if (img == null) { Debug.Assert(false); return(null); } if ((img.Width != sz.Width) || (img.Height != sz.Height)) { Image imgSc = GfxUtil.ScaleImage(img, sz.Width, sz.Height, ScaleTransformFlags.UIIcon); if (bImgIsNew) { img.Dispose(); } img = imgSc; } if (bAllowCache) { g_dCache[strKey] = img; } if (bNewImageObject && (bAllowCache || !bImgIsNew)) { img = (img.Clone() as Image); } return(img); }
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); }
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); }
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); }