/// <summary>Convert to a rich text form with the builder.</summary> /// <param name="builder"></param> public void ToRichText(RichTextBuilder builder) { if (IsTarget) { builder.ForegroundColor = Color.Blue; builder.AppendFormat("<{0}> ", AddressString); } if (IsFunction) { builder.ForegroundColor = Color.DarkGreen; } else if (IsPointer) { builder.ForegroundColor = Color.Purple; } builder.Append(ToStringValue()); if (IsInvalid) { builder.ForegroundColor = Color.Red; builder.Append(" <<" + Errors.Replace("\n", "; ") + ">>"); } builder.ForegroundColor = Color.Black; }
private void PopulateNotes(string value) { Debug.Assert(!mNotesEditingActive, "Can't populate while editing!"); var builder = new RichTextBuilder { DefaultFont = Font }; if (String.IsNullOrEmpty(value)) { // Populate it with a watermark builder.Append(KPRes.Notes, FontStyle.Italic); builder.Build(mNotes); mNotes.SelectAll(); mNotes.SelectionColor = SystemColors.GrayText; mNotes.Select(0, 0); mNotes.ReadOnly = true; } else { builder.Append(NotesRtfHelpers.ReplaceFormattingTags(value)); builder.Build(mNotes); UIUtil.RtfLinkifyReferences(mNotes, false); NotesRtfHelpers.RtfLinkifyUrls(mNotes); } }
public virtual void ToRichText(RichTextBuilder builder) { string format; if (OpcodeFormats.TryGetValue(Opcode, out format)) { for (int index = 0; index < format.Length; index++) { if (format[index] == '{') { if (format[index + 1] == '{') { index++; builder.Append('{'); } else { int end; for (end = ++index; format[end] != '}'; end++) { ; } int operandIndex = int.Parse(format.Substring(index, end - index)); ScriptOperand operand = GetOperand(operandIndex); operand.ToRichText(builder); index = end; } } else { builder.Append(format[index]); } } } else { if (IsOpcodeDefined) { builder.Append(Opcode.ToString()); } else { builder.ForegroundColor = Color.Red; builder.AppendFormat("{0:X2}", (int)Opcode); builder.ForegroundColor = Color.Black; } foreach (ScriptOperand operand in Operands) { builder.Append(" "); operand.ToRichText(builder); } } }
private static void EvAppendEntryFieldString(RichTextBuilder rb, string strItemSeparator, string strName, string strValue) { if (string.IsNullOrEmpty(strValue)) { return; } rb.Append(strName, System.Drawing.FontStyle.Bold, null, null, ":", " "); rb.Append(strValue); rb.Append(strItemSeparator); }
/// <summary> /// Convert to rich text. /// </summary> /// <param name="builder"></param> public void ToRichText(RichTextBuilder builder) { builder.AppendFormat("{0}: ", AddressString); Opcode.ToRichText(builder); for (int index = 0; index < Operands.Count; index++) { builder.Append(index == 0 ? " " : ", "); Operands[index].ToRichText(builder); } }
/// <summary></summary> public void ToRichText(RichTextBuilder builder) { Color foregroundColor = builder.ForegroundColor; try { if (!IsValid) { builder.ForegroundColor = Color.Red; } switch (Type) { default: builder.Append(this); break; } } finally { builder.ForegroundColor = foregroundColor; } }
private void InitPlaceholdersBox() { const string VkcBreak = @"<break />"; string[] vSpecialKeyCodes = new string[] { "TAB", "ENTER", "UP", "DOWN", "LEFT", "RIGHT", "HOME", "END", "PGUP", "PGDN", "INSERT", "DELETE", "SPACE", VkcBreak, "BACKSPACE", "BREAK", "CAPSLOCK", "ESC", "WIN", "LWIN", "RWIN", "APPS", "HELP", "NUMLOCK", "PRTSC", "SCROLLLOCK", VkcBreak, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", VkcBreak, "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE", "NUMPAD0", "NUMPAD1", "NUMPAD2", "NUMPAD3", "NUMPAD4", "NUMPAD5", "NUMPAD6", "NUMPAD7", "NUMPAD8", "NUMPAD9" }; string[] vSpecialPlaceholders = new string[] { "GROUP", "GROUP_PATH", "GROUP_NOTES", "PASSWORD_ENC", "URL:RMVSCM", "URL:SCM", "URL:HOST", "URL:PORT", "URL:PATH", "URL:QUERY", "URL:USERINFO", "URL:USERNAME", "URL:PASSWORD", // "BASE", "T-REPLACE-RX:/T/S/R/", "T-CONV:/T/C/", "C:Comment", VkcBreak, "DELAY 1000", "DELAY=200", "VKEY 13", "VKEY-NX 13", "VKEY-EX 13", "PICKCHARS", "PICKCHARS:Password:C=3", "NEWPASSWORD", "NEWPASSWORD:/Profile/", "HMACOTP", "CLEARFIELD", "APPACTIVATE " + KPRes.Title, "BEEP 800 200", VkcBreak, "APPDIR", "DB_PATH", "DB_DIR", "DB_NAME", "DB_BASENAME", "DB_EXT", "ENV_DIRSEP", "ENV_PROGRAMFILES_X86", VkcBreak, // "INTERNETEXPLORER", "FIREFOX", "OPERA", "GOOGLECHROME", // "SAFARI", VkcBreak, "DT_SIMPLE", "DT_YEAR", "DT_MONTH", "DT_DAY", "DT_HOUR", "DT_MINUTE", "DT_SECOND", "DT_UTC_SIMPLE", "DT_UTC_YEAR", "DT_UTC_MONTH", "DT_UTC_DAY", "DT_UTC_HOUR", "DT_UTC_MINUTE", "DT_UTC_SECOND" }; RichTextBuilder rb = new RichTextBuilder(); rb.AppendLine(KPRes.StandardFields, FontStyle.Bold, null, null, ":", null); rb.Append("{" + PwDefs.TitleField + "} "); rb.Append("{" + PwDefs.UserNameField + "} "); rb.Append("{" + PwDefs.PasswordField + "} "); rb.Append("{" + PwDefs.UrlField + "} "); rb.Append("{" + PwDefs.NotesField + "}"); bool bCustomInitialized = false, bFirst = true; foreach (KeyValuePair <string, ProtectedString> kvp in m_vStringDict) { if (!PwDefs.IsStandardField(kvp.Key)) { if (bCustomInitialized == false) { rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.CustomFields, FontStyle.Bold, null, null, ":", null); bCustomInitialized = true; } if (!bFirst) { rb.Append(" "); } rb.Append("{" + PwDefs.AutoTypeStringPrefix + kvp.Key + "}"); bFirst = false; } } rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.KeyboardKeyModifiers, FontStyle.Bold, null, null, ":", null); rb.Append(KPRes.KeyboardKeyShift + @": +, "); rb.Append(KPRes.KeyboardKeyCtrl + @": ^, "); rb.Append(KPRes.KeyboardKeyAlt + @": %"); rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.SpecialKeys, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strNav in vSpecialKeyCodes) { if (strNav == VkcBreak) { rb.AppendLine(); rb.AppendLine(); bFirst = true; } else { if (!bFirst) { rb.Append(" "); } rb.Append("{" + strNav + "}"); bFirst = false; } } rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.OtherPlaceholders, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strPH in vSpecialPlaceholders) { if (strPH == VkcBreak) { rb.AppendLine(); rb.AppendLine(); bFirst = true; } else { if (!bFirst) { rb.Append(" "); } rb.Append("{" + strPH + "}"); bFirst = false; } } if (SprEngine.FilterPlaceholderHints.Count > 0) { rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.PluginProvided, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strP in SprEngine.FilterPlaceholderHints) { if (string.IsNullOrEmpty(strP)) { continue; } if (!bFirst) { rb.Append(" "); } rb.Append(strP); bFirst = false; } } rb.Build(m_rtbPlaceholders); LinkifyRtf(m_rtbPlaceholders); }
/// <summary>Produce a rich text document that examines the file.</summary> /// <returns></returns> public override System.Windows.Forms.Control Browse(Action <double> progressUpdateCallback = null) { var box = new BetterRichTextBox() { Multiline = true, ReadOnly = true, WordWrap = true, }; bool recurse = false; box.SelectionChanged += (object sender, EventArgs args) => { if (recurse) { return; } try { Point scrollPosition = box.ScrollPosition; int resetStart = box.SelectionStart, resetLength = box.SelectionLength; box.BeginUpdate(); recurse = true; var start = box.SelectionStart; string text = box.Text; if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1)) { return; } while (IsIdentifier(text, start - 1)) { start--; } int end = box.SelectionStart; while (IsIdentifier(text, end)) { end++; } string searchText = text.Substring(start, end - start); box.SelectAll(); //box.SelectionFont = normal; box.SelectionBackColor = Color.Transparent; start = 0; while (true) { start = text.IndexOf(searchText, start); if (start < 0) { break; } if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) { box.Select(start, searchText.Length); //box.SelectionFont = underlined; box.SelectionBackColor = Color.Yellow; } start += searchText.Length; } box.Select(resetStart, resetLength); box.ScrollPosition = scrollPosition; } finally { box.EndUpdate(); box.Invalidate(); recurse = false; } }; RichTextBuilder builder = new RichTextBuilder(); foreach (EffectInstruction instruction in Instructions) { instruction.ToRichText(builder); builder.Append("\n"); } box.Rtf = builder.ToString(); return(box); }
/// <summary>Convert to a rich text form with the builder.</summary> /// <param name="builder"></param> public void ToRichText(RichTextBuilder builder) { if (IsTarget) { builder.ForegroundColor = Color.Blue; builder.AppendFormat("<{0}> ", AddressString); } if (IsFunction) builder.ForegroundColor = Color.DarkGreen; else if (IsPointer) builder.ForegroundColor = Color.Purple; builder.Append(ToStringValue()); if (IsInvalid) { builder.ForegroundColor = Color.Red; builder.Append(" <<" + Errors.Replace("\n", "; ") + ">>"); } builder.ForegroundColor = Color.Black; }
/// <summary>Produce a rich text document that examines the file.</summary> /// <returns></returns> public override System.Windows.Forms.Control Browse(Action<double> progressUpdateCallback = null) { var box = new BetterRichTextBox() { Multiline = true, ReadOnly = true, WordWrap = true, }; bool recurse = false; box.SelectionChanged += (object sender, EventArgs args) => { if (recurse) return; try { Point scrollPosition = box.ScrollPosition; int resetStart = box.SelectionStart, resetLength = box.SelectionLength; box.BeginUpdate(); recurse = true; var start = box.SelectionStart; string text = box.Text; if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1)) return; while (IsIdentifier(text, start - 1)) start--; int end = box.SelectionStart; while (IsIdentifier(text, end)) end++; string searchText = text.Substring(start, end - start); box.SelectAll(); //box.SelectionFont = normal; box.SelectionBackColor = Color.Transparent; start = 0; while (true) { start = text.IndexOf(searchText, start); if (start < 0) break; if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) { box.Select(start, searchText.Length); //box.SelectionFont = underlined; box.SelectionBackColor = Color.Yellow; } start += searchText.Length; } box.Select(resetStart, resetLength); box.ScrollPosition = scrollPosition; } finally { box.EndUpdate(); box.Invalidate(); recurse = false; } }; RichTextBuilder builder = new RichTextBuilder(); foreach (EffectInstruction instruction in Instructions) { instruction.ToRichText(builder); builder.Append("\n"); } box.Rtf = builder.ToString(); return box; }
public virtual void ToRichText(RichTextBuilder builder) { string format; if (OpcodeFormats.TryGetValue(Opcode, out format)) { for (int index = 0; index < format.Length; index++) { if (format[index] == '{') { if (format[index + 1] == '{') { index++; builder.Append('{'); } else { int end; for (end = ++index; format[end] != '}'; end++) ; int operandIndex = int.Parse(format.Substring(index, end - index)); ScriptOperand operand = GetOperand(operandIndex); operand.ToRichText(builder); index = end; } } else builder.Append(format[index]); } } else { if (IsOpcodeDefined) builder.Append(Opcode.ToString()); else { builder.ForegroundColor = Color.Red; builder.AppendFormat("{0:X2}", (int)Opcode); builder.ForegroundColor = Color.Black; } foreach (ScriptOperand operand in Operands) { builder.Append(" "); operand.ToRichText(builder); } } }
private void InitPlaceholdersBox() { const string VkcBreak = @"<break />"; string[] vSpecialKeyCodes = new string[] { "TAB", "ENTER", "UP", "DOWN", "LEFT", "RIGHT", "HOME", "END", "PGUP", "PGDN", "INSERT", "DELETE", VkcBreak, "BACKSPACE", "BREAK", "CAPSLOCK", "ESC", "HELP", "NUMLOCK", "PRTSC", "SCROLLLOCK", VkcBreak, "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", VkcBreak, "ADD", "SUBTRACT", "MULTIPLY", "DIVIDE" }; string[] vSpecialPlaceholders = new string[] { "GROUP", "GROUPPATH", "PASSWORD_ENC", "URL:RMVSCM", "C:Comment", VkcBreak, "DELAY 1000", "DELAY=200", "VKEY 65", "PICKCHARS", "PICKCHARS:Password:C=3", "NEWPASSWORD", "HMACOTP", "CLEARFIELD", VkcBreak, "APPDIR", "DB_PATH", "DB_DIR", "DB_NAME", "DB_BASENAME", "DB_EXT", "ENV_DIRSEP", VkcBreak, "DT_SIMPLE", "DT_YEAR", "DT_MONTH", "DT_DAY", "DT_HOUR", "DT_MINUTE", "DT_SECOND", "DT_UTC_SIMPLE", "DT_UTC_YEAR", "DT_UTC_MONTH", "DT_UTC_DAY", "DT_UTC_HOUR", "DT_UTC_MINUTE", "DT_UTC_SECOND" }; RichTextBuilder rb = new RichTextBuilder(); rb.AppendLine(KPRes.StandardFields, FontStyle.Bold, null, null, ":", null); rb.Append("{" + PwDefs.TitleField + "} "); rb.Append("{" + PwDefs.UserNameField + "} "); rb.Append("{" + PwDefs.PasswordField + "} "); rb.Append("{" + PwDefs.UrlField + "} "); rb.Append("{" + PwDefs.NotesField + "}"); bool bCustomInitialized = false, bFirst = true; foreach (KeyValuePair <string, ProtectedString> kvp in m_vStringDict) { if (!PwDefs.IsStandardField(kvp.Key)) { if (bCustomInitialized == false) { rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.CustomFields, FontStyle.Bold, null, null, ":", null); bCustomInitialized = true; } if (!bFirst) { rb.Append(" "); } rb.Append("{" + PwDefs.AutoTypeStringPrefix + kvp.Key + "}"); bFirst = false; } } rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.KeyboardKeyModifiers, FontStyle.Bold, null, null, ":", null); rb.Append(KPRes.KeyboardKeyShift + @": +, "); rb.Append(KPRes.KeyboardKeyCtrl + @": ^, "); rb.Append(KPRes.KeyboardKeyAlt + @": %"); rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.SpecialKeys, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strNav in vSpecialKeyCodes) { if (strNav == VkcBreak) { rb.AppendLine(); rb.AppendLine(); bFirst = true; } else { if (!bFirst) { rb.Append(" "); } rb.Append("{" + strNav + "}"); bFirst = false; } } rb.AppendLine(); rb.AppendLine(); rb.AppendLine(KPRes.OtherPlaceholders, FontStyle.Bold, null, null, ":", null); bFirst = true; foreach (string strPH in vSpecialPlaceholders) { if (strPH == VkcBreak) { rb.AppendLine(); rb.AppendLine(); bFirst = true; } else { if (!bFirst) { rb.Append(" "); } rb.Append("{" + strPH + "}"); bFirst = false; } } rb.Build(m_rtbPlaceholders); LinkifyRtf(m_rtbPlaceholders); }
public override System.Windows.Forms.Control Browse(Action<double> progressUpdateCallback = null) { RichTextBuilder builder = new RichTextBuilder(); bool indentNext = false; //builder.Append(@"{\rtf\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\par "); builder.UnderlineStyle = RichTextUnderlineStyle.Double; foreach (ScriptInstruction instruction in Instructions) { string codeName = CodeAddressName(instruction.Address); if (codeName != null) builder.AppendFormat("\n==============================\n{0}\n==============================\n", codeName); if (instruction.IsTarget) builder.IsUnderlined = true; builder.AppendFormat("{0:X}h", instruction.Address); if (instruction.IsTarget) builder.IsUnderlined = false; builder.Append(":\t"); if (indentNext) builder.Append("\t"); instruction.ToRichText(builder); //builder.Append(instruction.ToString()); builder.Append("\n"); if (instruction.IsBranch && !indentNext) builder.Append("\n"); indentNext = instruction.IsTest; } builder.Append(ExceptionEnd); var output = builder.ToString(); BetterRichTextBox box = new BetterRichTextBox() { ReadOnly = false, Multiline = true, //ScrollBars = ScrollBars.Vertical, Rtf = output, WordWrap = false, }; Font normal = box.Font; var underlined = new Font(normal, FontStyle.Underline); bool recurse = false; box.SelectionChanged += (object sender, EventArgs args) => { if (recurse) return; try { Point scrollPosition = box.ScrollPosition; int resetStart = box.SelectionStart, resetLength = box.SelectionLength; box.BeginUpdate(); recurse = true; var start = box.SelectionStart; string text = box.Text; if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1)) return; while (IsIdentifier(text, start - 1)) start--; int end = box.SelectionStart; while (IsIdentifier(text, end)) end++; string searchText = text.Substring(start, end - start); box.SelectAll(); //box.SelectionFont = normal; box.SelectionBackColor = Color.Transparent; start = 0; while (true) { start = text.IndexOf(searchText, start); if (start < 0) break; if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) { box.Select(start, searchText.Length); //box.SelectionFont = underlined; box.SelectionBackColor = Color.Yellow; } start += searchText.Length; } box.Select(resetStart, resetLength); box.ScrollPosition = scrollPosition; } finally { box.EndUpdate(); box.Invalidate(); recurse = false; } }; box.LinkClicked += (sender, args) => { throw new Exception(); }; return box; }
public override System.Windows.Forms.Control Browse(Action <double> progressUpdateCallback = null) { RichTextBuilder builder = new RichTextBuilder(); bool indentNext = false; //builder.Append(@"{\rtf\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\par "); builder.UnderlineStyle = RichTextUnderlineStyle.Double; foreach (ScriptInstruction instruction in Instructions) { string codeName = CodeAddressName(instruction.Address); if (codeName != null) { builder.AppendFormat("\n==============================\n{0}\n==============================\n", codeName); } if (instruction.IsTarget) { builder.IsUnderlined = true; } builder.AppendFormat("{0:X}h", instruction.Address); if (instruction.IsTarget) { builder.IsUnderlined = false; } builder.Append(":\t"); if (indentNext) { builder.Append("\t"); } instruction.ToRichText(builder); //builder.Append(instruction.ToString()); builder.Append("\n"); if (instruction.IsBranch && !indentNext) { builder.Append("\n"); } indentNext = instruction.IsTest; } builder.Append(ExceptionEnd); var output = builder.ToString(); BetterRichTextBox box = new BetterRichTextBox() { ReadOnly = false, Multiline = true, //ScrollBars = ScrollBars.Vertical, Rtf = output, WordWrap = false, }; Font normal = box.Font; var underlined = new Font(normal, FontStyle.Underline); bool recurse = false; box.SelectionChanged += (object sender, EventArgs args) => { if (recurse) { return; } try { Point scrollPosition = box.ScrollPosition; int resetStart = box.SelectionStart, resetLength = box.SelectionLength; box.BeginUpdate(); recurse = true; var start = box.SelectionStart; string text = box.Text; if (!IsIdentifier(text, start) && !IsIdentifier(text, start - 1)) { return; } while (IsIdentifier(text, start - 1)) { start--; } int end = box.SelectionStart; while (IsIdentifier(text, end)) { end++; } string searchText = text.Substring(start, end - start); box.SelectAll(); //box.SelectionFont = normal; box.SelectionBackColor = Color.Transparent; start = 0; while (true) { start = text.IndexOf(searchText, start); if (start < 0) { break; } if (!IsIdentifier(text, start - 1) && !IsIdentifier(text, start + searchText.Length)) { box.Select(start, searchText.Length); //box.SelectionFont = underlined; box.SelectionBackColor = Color.Yellow; } start += searchText.Length; } box.Select(resetStart, resetLength); box.ScrollPosition = scrollPosition; } finally { box.EndUpdate(); box.Invalidate(); recurse = false; } }; box.LinkClicked += (sender, args) => { throw new Exception(); }; return(box); }
/// <summary></summary> public void ToRichText(RichTextBuilder builder) { Color foregroundColor = builder.ForegroundColor; try { if (!IsValid) builder.ForegroundColor = Color.Red; switch (Type) { default: builder.Append(this); break; } } finally { builder.ForegroundColor = foregroundColor; } }