mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
Added support to paste text with ctrl + v in region capture
This commit is contained in:
parent
f9ec01a2c1
commit
f432754b87
3 changed files with 40 additions and 10 deletions
|
@ -1129,4 +1129,4 @@ public static Cursor CreateCursor(byte[] data)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,11 +34,11 @@ public class TextDrawingShape : RectangleDrawingShape
|
|||
public override ShapeType ShapeType { get; } = ShapeType.DrawingText;
|
||||
|
||||
public string Text { get; set; }
|
||||
public TextDrawingOptions Options { get; set; }
|
||||
public TextDrawingOptions TextOptions { get; set; }
|
||||
|
||||
public override void OnConfigLoad()
|
||||
{
|
||||
Options = AnnotationOptions.TextOptions.Copy();
|
||||
TextOptions = AnnotationOptions.TextOptions.Copy();
|
||||
BorderColor = AnnotationOptions.TextBorderColor;
|
||||
BorderSize = AnnotationOptions.TextBorderSize;
|
||||
FillColor = AnnotationOptions.TextFillColor;
|
||||
|
@ -46,7 +46,7 @@ public override void OnConfigLoad()
|
|||
|
||||
public override void OnConfigSave()
|
||||
{
|
||||
AnnotationOptions.TextOptions = Options;
|
||||
AnnotationOptions.TextOptions = TextOptions;
|
||||
AnnotationOptions.TextBorderColor = BorderColor;
|
||||
AnnotationOptions.TextBorderSize = BorderSize;
|
||||
AnnotationOptions.TextFillColor = FillColor;
|
||||
|
@ -58,9 +58,9 @@ public override void OnDraw(Graphics g)
|
|||
|
||||
if (!string.IsNullOrEmpty(Text) && Rectangle.Width > 10 && Rectangle.Height > 10)
|
||||
{
|
||||
using (Font font = new Font(Options.Font, Options.Size, Options.Style))
|
||||
using (Brush textBrush = new SolidBrush(Options.Color))
|
||||
using (StringFormat sf = new StringFormat { Alignment = Options.AlignmentHorizontal, LineAlignment = Options.AlignmentVertical })
|
||||
using (Font font = new Font(TextOptions.Font, TextOptions.Size, TextOptions.Style))
|
||||
using (Brush textBrush = new SolidBrush(TextOptions.Color))
|
||||
using (StringFormat sf = new StringFormat { Alignment = TextOptions.AlignmentHorizontal, LineAlignment = TextOptions.AlignmentVertical })
|
||||
{
|
||||
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
||||
g.DrawString(Text, font, textBrush, Rectangle, sf);
|
||||
|
@ -83,7 +83,7 @@ private void UpdateText()
|
|||
{
|
||||
Manager.PauseForm();
|
||||
|
||||
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, Options))
|
||||
using (TextDrawingInputBox inputBox = new TextDrawingInputBox(Text, TextOptions))
|
||||
{
|
||||
inputBox.ShowDialog();
|
||||
Text = inputBox.InputText;
|
||||
|
@ -92,5 +92,22 @@ private void UpdateText()
|
|||
|
||||
Manager.ResumeForm();
|
||||
}
|
||||
|
||||
public void SetTextWithAutoSize(string text)
|
||||
{
|
||||
Point pos = InputManager.MousePosition0Based;
|
||||
|
||||
Size size;
|
||||
|
||||
using (Font font = new Font(TextOptions.Font, TextOptions.Size, TextOptions.Style))
|
||||
{
|
||||
size = Helpers.MeasureText(text, font).Offset(30);
|
||||
}
|
||||
|
||||
Point location = new Point(pos.X - size.Width / 2, pos.Y - size.Height / 2);
|
||||
|
||||
Rectangle = new Rectangle(location, size);
|
||||
Text = text;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -999,7 +999,7 @@ private void form_KeyDown(object sender, KeyEventArgs e)
|
|||
CurrentShapeType = ShapeType.DrawingPixelate;
|
||||
break;
|
||||
case Keys.Control | Keys.V:
|
||||
AddImageFromClipboard();
|
||||
PasteFromClipboard();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1690,7 +1690,7 @@ public void OrderStepShapes()
|
|||
}
|
||||
}
|
||||
|
||||
private void AddImageFromClipboard()
|
||||
private void PasteFromClipboard()
|
||||
{
|
||||
if (Clipboard.ContainsImage())
|
||||
{
|
||||
|
@ -1706,6 +1706,19 @@ private void AddImageFromClipboard()
|
|||
SelectCurrentShape();
|
||||
}
|
||||
}
|
||||
else if (Clipboard.ContainsText())
|
||||
{
|
||||
string text = Clipboard.GetText();
|
||||
|
||||
if (!string.IsNullOrEmpty(text))
|
||||
{
|
||||
CurrentShapeType = ShapeType.DrawingText;
|
||||
TextDrawingShape shape = (TextDrawingShape)CreateShape(ShapeType.DrawingText);
|
||||
shape.SetTextWithAutoSize(text.Trim());
|
||||
AddShape(shape);
|
||||
SelectCurrentShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCurrentShapeChanged(BaseShape shape)
|
||||
|
|
Loading…
Reference in a new issue