Skip to content

Commit

Permalink
Skyline: Some last improvements to the SkylinePreviewForm based on Im…
Browse files Browse the repository at this point in the history
…ageComparer (#3303)

Skyline: Some last improvements to the SkylinePreviewForm based on ImageComparer
- implement git revert function
- make ImageSource.disk show the modified state of the file on disk
- avoid drawing curved borders on PopupPickLists in Windows 11
- fixed race condition in RemoveAnnotationTest
  • Loading branch information
brendanx67 authored Dec 27, 2024
1 parent 7189a86 commit dbb6425
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ public static byte[] GetGitFileBinaryContent(string fullPath)
});
}

/// <summary>
/// Tells if a path has uncommitted changes with respect to the Git HEAD.
/// </summary>
/// <param name="path">The fully qualified path to a file or directory.</param>
/// <returns>True if the path has uncommitted changes, otherwise false.</returns>
public static bool IsModified(string path)
{
var output = RunGitCommand(GetPathInfo(path), "status --porcelain \"{RelativePath}\"");

// If there is any output the path has additions, deletions, or modifications
return !string.IsNullOrWhiteSpace(output);
}

/// <summary>
/// Gets a list of changed file paths under a specific directory.
/// </summary>
Expand Down
3 changes: 3 additions & 0 deletions pwiz_tools/Skyline/TestFunctional/RemoveAnnotationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ protected override void DoTest()
PropertyPath ppCarryoverProblem = ppPeptideResult.Property(AnnotationDef.ANNOTATION_PREFIX + "carryover problem");
PropertyPath ppRtSchedulingProblem =
ppPeptideResult.Property(AnnotationDef.ANNOTATION_PREFIX + "RT scheduling problem");
WaitForConditionUI(() =>
documentGrid.FindColumn(ppCarryoverProblem) != null &&
documentGrid.FindColumn(ppRtSchedulingProblem) != null);
RunUI(() =>
{
var colCarryoverProblem = documentGrid.FindColumn(ppCarryoverProblem);
Expand Down
13 changes: 13 additions & 0 deletions pwiz_tools/Skyline/TestUtil/GitFileHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public static byte[] GetGitFileBinaryContent(string fullPath)
});
}

/// <summary>
/// Tells if a path has uncommitted changes with respect to the Git HEAD.
/// </summary>
/// <param name="path">The fully qualified path to a file or directory.</param>
/// <returns>True if the path has uncommitted changes, otherwise false.</returns>
public static bool IsModified(string path)
{
var output = RunGitCommand(GetPathInfo(path), "status --porcelain \"{RelativePath}\"");

// If there is any output the path has additions, deletions, or modifications
return !string.IsNullOrWhiteSpace(output);
}

/// <summary>
/// Gets a list of changed file paths under a specific directory.
/// </summary>
Expand Down
40 changes: 40 additions & 0 deletions pwiz_tools/Skyline/TestUtil/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pwiz_tools/Skyline/TestUtil/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@
<data name="DiskFailure" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\DiskFailure.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="filechanged" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\filechanged.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="fileunchanged" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fileunchanged.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="fileunknown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fileunknown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="gitsource" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\gitsource.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down Expand Up @@ -163,6 +172,9 @@
<data name="textbutton" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\textbutton.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="undo" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\undo.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="webdestination" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\webdestination.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pwiz_tools/Skyline/TestUtil/Resources/undo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions pwiz_tools/Skyline/TestUtil/ScreenshotPreviewForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 65 additions & 5 deletions pwiz_tools/Skyline/TestUtil/ScreenshotPreviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ private void UpdatePreviewImages()
{
lock (_lock)
{
UpdateImageSourceButtons();
helpTip.SetToolTip(oldScreenshotLabel, _oldScreenshot.FileLoaded);
SetPreviewSize(labelOldSize, _oldScreenshot);
SetPreviewImage(oldScreenshotPictureBox, _oldScreenshot, _diff);
Expand Down Expand Up @@ -896,28 +897,49 @@ private void PauseAtNextScreenshot()

private bool SaveScreenshot()
{
if (File.Exists(_fileToSave) && !FileEx.IsWritable(_fileToSave))
string filePath = _fileToSave;
if (File.Exists(filePath) && !IsWritable(filePath))
{
ShowMessage(LineSeparate(string.Format("The file {0} is locked.", _fileToSave),
"Check that it is not open in another program such as TortoiseIDiff."));
return false;
}
try
{
string screenshotDir = Path.GetDirectoryName(_fileToSave) ?? string.Empty;
string screenshotDir = Path.GetDirectoryName(filePath) ?? string.Empty;
Assume.IsFalse(string.IsNullOrEmpty(screenshotDir)); // Because ReSharper complains about possible null
Directory.CreateDirectory(screenshotDir);

_newScreenshot.Image.Save(_fileToSave);
_newScreenshot.Image.Save(filePath);
return true;
}
catch (Exception e)
{
PreviewMessageDlg.ShowWithException(this, string.Format("Failed to save screenshot {0}", _fileToSave), e);
PreviewMessageDlg.ShowWithException(this, string.Format("Failed to save screenshot {0}", filePath), e);
return false;
}
}

private void Revert()
{
string filePath = _fileToSave;
if (File.Exists(filePath) && !IsWritable(filePath))
{
ShowMessage(LineSeparate(string.Format("The file {0} is locked.", filePath),
"Check that it is not open in another program such as TortoiseIDiff."));
return;
}
try
{
GitFileHelper.RevertFileToHead(filePath);
RefreshOldScreenshot();
}
catch (Exception e)
{
ShowMessageWithException(string.Format("Failed to revert screenshot {0}", filePath), e);
}
}

private void SaveAndContinue()
{
if (SaveScreenshot())
Expand Down Expand Up @@ -1056,7 +1078,28 @@ private void UpdateImageSourceButtons()
break;
case ImageSource.disk:
default:
buttonImageSource.Image = Resources.save;
bool? changed = null;
var filePath = _fileToSave;
if (File.Exists(filePath))
{
try
{
changed = GitFileHelper.IsModified(filePath);
}
catch (Exception)
{
// Ignore and leave changed null
}
}

if (!changed.HasValue)
{
buttonImageSource.Image = Resources.fileunknown;
}
else
{
buttonImageSource.Image = changed.Value ? Resources.filechanged : Resources.fileunchanged;
}
helpTip.SetToolTip(buttonImageSource, _defaultImageSourceTipText);
break;
}
Expand Down Expand Up @@ -1094,6 +1137,11 @@ private void toolStripSaveAndContinue_Click(object sender, EventArgs e)
SaveAndContinue();
}

private void toolStripRevert_Click(object sender, EventArgs e)
{
Revert();
}

private void toolStripGotoWeb_Click(object sender, EventArgs e)
{
GotoLink();
Expand Down Expand Up @@ -1192,6 +1240,13 @@ private void ScreenshotPreviewForm_KeyDown(object sender, KeyEventArgs e)
e.Handled = true;
}
break;
case Keys.Z:
if (e.Control)
{
Revert();
e.Handled = true;
}
break;
}
}

Expand All @@ -1207,6 +1262,11 @@ private void CopyBitmap(Bitmap bitmap)
}
}

public static bool IsWritable(string path)
{
return FileEx.IsWritable(path);
}

private string LineSeparate(params string[] lines)
{
return TextUtil.LineSeparate(lines);
Expand Down
9 changes: 7 additions & 2 deletions pwiz_tools/Skyline/TestUtil/ScreenshotProcessingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ public static class ScreenshotProcessingExtensions

public static Bitmap CleanupBorder(this Bitmap bmp, bool toolWindow = false)
{
bool isWindows11 = IsWindows11();
if (!toolWindow)
{
return bmp.CleanupBorder(new Rectangle(0, 0, bmp.Width, bmp.Height), 8);
return bmp.CleanupBorder(new Rectangle(0, 0, bmp.Width, bmp.Height), isWindows11 ? 8 : 0);
}
else if (!IsWindows11())
else if (!isWindows11)
{
// Floating dockable forms have only a transparent border at the top
return bmp.CleanupBorder(new Rectangle(0, 0, bmp.Width, 1), 0);
Expand Down Expand Up @@ -77,6 +78,10 @@ private static Bitmap CleanupBorder(this Bitmap bmp, Color? color, Rectangle rec
// All white border means it is actually a graph so don't draw anything on it
if (bestBorderColor.ToArgb() == Color.White.ToArgb())
return bmp;
// If there is supposed to be a corner curve but there is just one color, avoid
// drawing a curved corner on top of the otherwise rectangular border.
if (cornerRadius != 0 && colorCounts.Count == 1)
return bmp;
return bmp.CleanupBorderInternal(color ?? bestBorderColor, rect, cornerRadius);
}

Expand Down
4 changes: 4 additions & 0 deletions pwiz_tools/Skyline/TestUtil/TestUtil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@
<None Include="Resources\noscreenshot.png" />
<None Include="Resources\hand-cur.bmp" />
<None Include="Resources\gitsource.png" />
<None Include="Resources\fileunchanged.png" />
<None Include="Resources\filechanged.png" />
<None Include="Resources\fileunknown.png" />
<None Include="Resources\undo.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit dbb6425

Please sign in to comment.