public override void Run() { //IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; ITextEditorControlProvider viewContent = WorkbenchSingleton.ActiveControl as ITextEditorControlProvider; if (viewContent == null || !(viewContent is ITextEditorControlProvider)) { return; } TextEditorControl textarea = ((ITextEditorControlProvider)viewContent).TextEditorControl; using (SharpDevelopColorDialog cd = new SharpDevelopColorDialog()) { if (cd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainForm) == DialogResult.OK) { string ext = Path.GetExtension(textarea.FileName).ToLowerInvariant(); string colorstr; if (ext == ".cs" || ext == ".vb" || ext == ".boo") { if (cd.Color.IsKnownColor) { colorstr = "Color." + cd.Color.ToKnownColor().ToString(); } else if (cd.Color.A < 255) { colorstr = "Color.FromArgb(0x" + cd.Color.ToArgb().ToString("x") + ")"; } else { colorstr = string.Format("Color.FromArgb({0}, {1}, {2})", cd.Color.R, cd.Color.G, cd.Color.B); } } else { if (cd.Color.IsKnownColor) { colorstr = cd.Color.ToKnownColor().ToString(); } else if (cd.Color.A < 255) { colorstr = "#" + cd.Color.ToArgb().ToString("X"); } else { colorstr = string.Format("#{0:X2}{1:X2}{2:X2}", cd.Color.R, cd.Color.G, cd.Color.B); } } textarea.Document.Insert(textarea.ActiveTextAreaControl.Caret.Offset, colorstr); int lineNumber = textarea.Document.GetLineNumberForOffset(textarea.ActiveTextAreaControl.Caret.Offset); textarea.ActiveTextAreaControl.Caret.Column += colorstr.Length; textarea.Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, new TextLocation(0, lineNumber))); textarea.Document.CommitUpdate(); } } }
void SelectCustomColour(ColorPickerComboBox comboBox) { using (SharpDevelopColorDialog colorDialog = new SharpDevelopColorDialog()) { colorDialog.FullOpen = true; colorDialog.Color = comboBox.SelectedColor; if (colorDialog.ShowDialog() == DialogResult.OK) { comboBox.SelectedColor = colorDialog.Color; } } }
public override void Run() { IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; if (viewContent == null || !(viewContent is ITextEditorProvider)) { return; } ITextEditor textEditor = ((ITextEditorProvider)viewContent).TextEditor; using (SharpDevelopColorDialog cd = new SharpDevelopColorDialog()) { if (cd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window) == DialogResult.OK) { string ext = Path.GetExtension(textEditor.FileName).ToLowerInvariant(); string colorstr; if (ext == ".cs" || ext == ".vb" || ext == ".boo") { if (cd.Color.IsKnownColor) { colorstr = "Color." + cd.Color.ToKnownColor().ToString(); } else if (cd.Color.A < 255) { colorstr = "Color.FromArgb(0x" + cd.Color.ToArgb().ToString("x") + ")"; } else { colorstr = string.Format("Color.FromArgb({0}, {1}, {2})", cd.Color.R, cd.Color.G, cd.Color.B); } } else { if (cd.Color.IsKnownColor) { colorstr = cd.Color.ToKnownColor().ToString(); } else if (cd.Color.A < 255) { colorstr = "#" + cd.Color.ToArgb().ToString("X"); } else { colorstr = string.Format("#{0:X2}{1:X2}{2:X2}", cd.Color.R, cd.Color.G, cd.Color.B); } } textEditor.SelectedText = colorstr; textEditor.Select(textEditor.SelectionStart + textEditor.SelectionLength, 0); } } }
public override void Run() { ITextEditor textEditor = SD.GetActiveViewContentService <ITextEditor>(); if (textEditor == null) { return; } using (SharpDevelopColorDialog cd = new SharpDevelopColorDialog()) { if (cd.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) { string ext = Path.GetExtension(textEditor.FileName).ToLowerInvariant(); string colorstr; if (ext == ".cs" || ext == ".vb" || ext == ".boo") { if (cd.Color.IsKnownColor) { colorstr = "Color." + cd.Color.ToKnownColor().ToString(); } else if (cd.Color.A < 255) { colorstr = "Color.FromArgb(0x" + cd.Color.ToArgb().ToString("x") + ")"; } else { colorstr = string.Format("Color.FromArgb({0}, {1}, {2})", cd.Color.R, cd.Color.G, cd.Color.B); } } else { if (cd.Color.IsKnownColor) { colorstr = cd.Color.ToKnownColor().ToString(); } else if (cd.Color.A < 255) { colorstr = "#" + cd.Color.ToArgb().ToString("X"); } else { colorstr = string.Format("#{0:X2}{1:X2}{2:X2}", cd.Color.R, cd.Color.G, cd.Color.B); } } textEditor.SelectedText = colorstr; textEditor.Select(textEditor.SelectionStart + textEditor.SelectionLength, 0); } } }
public void TwoCustomColors() { int[] colors = new int[] { 10, 20 }; Assert.AreEqual("10|20", SharpDevelopColorDialog.CustomColorsToString(colors)); }
public void OneCustomColor() { int[] colors = new int[] { 10 }; Assert.AreEqual("10", SharpDevelopColorDialog.CustomColorsToString(colors)); }
public void NullIntColorsArray() { Assert.AreEqual(String.Empty, SharpDevelopColorDialog.CustomColorsToString(null)); }
public void FirstColorIsInvalid() { int[] colors = SharpDevelopColorDialog.CustomColorsFromString("Test|20"); Assert.AreEqual(1, colors.Length); Assert.AreEqual(20, colors[0]); }
public void OneColorInString() { int[] colors = SharpDevelopColorDialog.CustomColorsFromString("34"); Assert.AreEqual(1, colors.Length); Assert.AreEqual(34, colors[0]); }
public void EmptyString() { Assert.IsNull(SharpDevelopColorDialog.CustomColorsFromString(String.Empty)); }
public void NullString() { Assert.IsNull(SharpDevelopColorDialog.CustomColorsFromString(null)); }