fixed #1196: Added %t and %pn file naming support for region capture too

This commit is contained in:
Jaex 2015-12-17 14:00:20 +02:00
parent abf0ab210a
commit 97487517fe
9 changed files with 67 additions and 6 deletions

View file

@ -193,6 +193,11 @@ public override void Prepare()
}
}
public override WindowInfo GetWindowInfo()
{
return AreaManager.FindSelectedWindowInfo(CurrentPosition);
}
protected override void Update()
{
base.Update();

View file

@ -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;

View file

@ -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)

View file

@ -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)
{

View file

@ -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

View file

@ -91,6 +91,7 @@ private bool CheckHandle(IntPtr handle, bool isWindow)
if (isWindow)
{
windowInfo.IsWindow = true;
windowInfo.Rectangle = CaptureHelpers.GetWindowRectangle(handle);
}
else

View file

@ -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)

View file

@ -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; }
}
}

View file

@ -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;
}
}