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); }
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); }
// Cf. other overload public static BinaryDataClass Classify(string strUrl, byte[] pbData) { BinaryDataClass bdc = ClassifyUrl(strUrl); if (bdc != BinaryDataClass.Unknown) { return(bdc); } return(ClassifyData(pbData)); }
internal static void BuildOpenWithMenu(DynamicMenu dm, string strItem, ProtectedBinary pb, bool bReadOnly) { if (dm == null) { Debug.Assert(false); return; } dm.Clear(); if (string.IsNullOrEmpty(strItem)) { Debug.Assert(false); return; } if (pb == null) { Debug.Assert(false); return; } byte[] pbData = pb.ReadData(); if (pbData == null) { Debug.Assert(false); return; } BinaryDataClass bdc = BinaryDataClassifier.Classify(strItem, pbData); BinaryDataOpenOptions oo = new BinaryDataOpenOptions(); oo.Handler = BinaryDataHandler.InternalViewer; dm.AddItem(KPRes.InternalViewer, Properties.Resources.B16x16_View_Detailed, oo); oo = new BinaryDataOpenOptions(); oo.Handler = BinaryDataHandler.InternalEditor; ToolStripMenuItem tsmiIntEditor = dm.AddItem(KPRes.InternalEditor, Properties.Resources.B16x16_View_Detailed, oo); oo = new BinaryDataOpenOptions(); oo.Handler = BinaryDataHandler.ExternalApp; ToolStripMenuItem tsmiExt = dm.AddItem(KPRes.ExternalApp, Properties.Resources.B16x16_Make_KDevelop, oo); if (!DataEditorForm.SupportsDataType(bdc) || bReadOnly) { tsmiIntEditor.Enabled = false; } if (bReadOnly) { tsmiExt.Enabled = false; } }
private static BinaryDataHandler ChooseHandler(string strName, byte[] pbData, BinaryDataOpenOptions opt) { BinaryDataClass bdc = BinaryDataClassifier.Classify(strName, pbData); if (DataEditorForm.SupportsDataType(bdc) && !opt.ReadOnly) { return(BinaryDataHandler.InternalEditor); } if (DataViewerForm.SupportsDataType(bdc)) { return(BinaryDataHandler.InternalViewer); } return(BinaryDataHandler.ExternalApp); }
// Cf. other overload public static BinaryDataClass Classify(string strUrl, ProtectedBinary pb) { BinaryDataClass bdc = ClassifyUrl(strUrl); if (bdc != BinaryDataClass.Unknown) { return(bdc); } if (pb == null) { throw new ArgumentNullException("pb"); } byte[] pbData = pb.ReadData(); try { bdc = ClassifyData(pbData); } finally { if (pb.IsProtected) { MemUtil.ZeroByteArray(pbData); } } return(bdc); }
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; 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); 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); 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 { 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); }
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(); } 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); }
public static bool SupportsDataType(BinaryDataClass bdc) { return((bdc == BinaryDataClass.Text) || (bdc == BinaryDataClass.RichText)); }
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, this); 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; 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); }
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); 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; 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; if(m_strDataDesc.Length > 0) this.Text = m_strDataDesc + " - " + this.Text; 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(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.DvfInit != null) this.DvfInit(this, new DvfContextEventArgs(this, m_pbData, m_strDataDesc, m_tscViewers)); 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; 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); }
public static bool SupportsDataType(BinaryDataClass bdc) { return ((bdc == BinaryDataClass.Text) || (bdc == BinaryDataClass.RichText)); }
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(); }