mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-01 17:56:51 +13:00
fixed #1196: Added %t and %pn file naming support for region capture too
This commit is contained in:
parent
abf0ab210a
commit
97487517fe
9 changed files with 67 additions and 6 deletions
|
@ -193,6 +193,11 @@ public override void Prepare()
|
|||
}
|
||||
}
|
||||
|
||||
public override WindowInfo GetWindowInfo()
|
||||
{
|
||||
return AreaManager.FindSelectedWindowInfo(CurrentPosition);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
|
|
@ -245,6 +245,11 @@ public virtual Image GetRegionImage()
|
|||
return ShapeCaptureHelpers.GetRegionImage(SurfaceImage, regionFillPath, regionDrawPath, Config);
|
||||
}
|
||||
|
||||
public virtual WindowInfo GetWindowInfo()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Close(SurfaceResult result)
|
||||
{
|
||||
Result = result;
|
||||
|
|
|
@ -342,6 +342,21 @@ public SimpleWindowInfo FindSelectedWindow()
|
|||
return null;
|
||||
}
|
||||
|
||||
public WindowInfo FindSelectedWindowInfo(Point mousePosition)
|
||||
{
|
||||
if (Windows != null)
|
||||
{
|
||||
SimpleWindowInfo windowInfo = Windows.FirstOrDefault(x => x.IsWindow && x.Rectangle.Contains(InputManager.MousePosition));
|
||||
|
||||
if (windowInfo != null)
|
||||
{
|
||||
return windowInfo.WindowInfo;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void surface_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
|
|
|
@ -32,6 +32,15 @@ public class SimpleWindowInfo
|
|||
{
|
||||
public IntPtr Handle { get; set; }
|
||||
public Rectangle Rectangle { get; set; }
|
||||
public bool IsWindow { get; set; }
|
||||
|
||||
public WindowInfo WindowInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return new WindowInfo(Handle);
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleWindowInfo(IntPtr handle)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,21 @@ public Process Process
|
|||
}
|
||||
}
|
||||
|
||||
public string ProcessName
|
||||
{
|
||||
get
|
||||
{
|
||||
Process process = Process;
|
||||
|
||||
if (process != null)
|
||||
{
|
||||
return process.ProcessName;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle Rectangle
|
||||
{
|
||||
get
|
||||
|
|
|
@ -91,6 +91,7 @@ private bool CheckHandle(IntPtr handle, bool isWindow)
|
|||
|
||||
if (isWindow)
|
||||
{
|
||||
windowInfo.IsWindow = true;
|
||||
windowInfo.Rectangle = CaptureHelpers.GetWindowRectangle(handle);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1926,8 +1926,8 @@ private void CaptureActiveWindow(TaskSettings taskSettings, bool autoHideForm =
|
|||
|
||||
img.Tag = new ImageTag
|
||||
{
|
||||
ActiveWindowTitle = activeWindowTitle,
|
||||
ActiveProcessName = activeProcessName
|
||||
WindowTitle = activeWindowTitle,
|
||||
ProcessName = activeProcessName
|
||||
};
|
||||
|
||||
return img;
|
||||
|
@ -2011,6 +2011,17 @@ private void CaptureRegion(CaptureType captureType, TaskSettings taskSettings, b
|
|||
using (screenshot)
|
||||
{
|
||||
img = surface.GetRegionImage();
|
||||
|
||||
WindowInfo windowInfo = surface.GetWindowInfo();
|
||||
|
||||
if (windowInfo != null)
|
||||
{
|
||||
img.Tag = new ImageTag
|
||||
{
|
||||
WindowTitle = windowInfo.Text,
|
||||
ProcessName = windowInfo.ProcessName
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (surface.Result == SurfaceResult.Fullscreen)
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace ShareX
|
|||
{
|
||||
public class ImageTag
|
||||
{
|
||||
public string ActiveWindowTitle { get; set; }
|
||||
public string ActiveProcessName { get; set; }
|
||||
public string WindowTitle { get; set; }
|
||||
public string ProcessName { get; set; }
|
||||
}
|
||||
}
|
|
@ -160,8 +160,8 @@ public static string GetFilename(TaskSettings taskSettings, string extension = n
|
|||
|
||||
if (imageTag != null)
|
||||
{
|
||||
nameParser.WindowText = imageTag.ActiveWindowTitle;
|
||||
nameParser.ProcessName = imageTag.ActiveProcessName;
|
||||
nameParser.WindowText = imageTag.WindowTitle;
|
||||
nameParser.ProcessName = imageTag.ProcessName;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue