@@ -48,7 +48,7 @@ public partial class MainWindow : FluentWindow
4848 private Services . RecentProjectsManager ? recentProjectsManager ;
4949 private string ? currentProjectId ;
5050 private System . Timers . Timer ? autoSaveTimer ;
51- private readonly int AutoSaveIntervalMs = ( int ) TimeSpan . FromSeconds ( 3 ) . TotalMilliseconds ;
51+ private readonly int AutoSaveIntervalMs = ( int ) TimeSpan . FromSeconds ( 5 ) . TotalMilliseconds ;
5252
5353 private static readonly List < FormatItem > _formats =
5454 [
@@ -91,6 +91,7 @@ public MainWindow()
9191 AspectRatioTransformPreview . RatioItem = selectedAspectRatio ;
9292
9393 InitializeProjectManager ( ) ;
94+ UpdateOpenedFileNameText ( ) ;
9495 }
9596
9697 private void DrawPolyLine ( )
@@ -576,6 +577,9 @@ await Task.Run(async () =>
576577
577578 // Create a new project ID for this image
578579 currentProjectId = Guid . NewGuid ( ) . ToString ( ) ;
580+
581+ // Update the ReOpenFileButton to show the current file name
582+ UpdateOpenedFileNameText ( ) ;
579583 }
580584
581585 private void OpenFolderButton_Click ( object sender , RoutedEventArgs e )
@@ -1490,6 +1494,8 @@ private async Task LoadMeasurementPackageAsync(string fileName)
14901494 currentProjectId = package . Metadata . ProjectId ;
14911495 else
14921496 currentProjectId = Guid . NewGuid ( ) . ToString ( ) ;
1497+
1498+ UpdateOpenedFileNameText ( ) ;
14931499 }
14941500
14951501 public async void LoadMeasurementsPackageFromFile ( string filePath )
@@ -1591,4 +1597,69 @@ protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
15911597
15921598 base . OnClosing ( e ) ;
15931599 }
1600+
1601+ private void UpdateOpenedFileNameText ( )
1602+ {
1603+ if ( string . IsNullOrEmpty ( openedFileName ) )
1604+ {
1605+ ReOpenFileText . Text = "Image/Project Name" ;
1606+ CloseFileIcon . Visibility = Visibility . Collapsed ;
1607+ }
1608+ else
1609+ {
1610+ ReOpenFileText . Text = openedFileName ;
1611+
1612+ if ( openedPackage is not null )
1613+ ReOpenFileText . Text = $ " { openedPackage . Metadata . OriginalFilename } ";
1614+ CloseFileIcon . Visibility = Visibility . Visible ;
1615+ }
1616+ }
1617+
1618+ private void CloseFileIcon_MouseDown ( object sender , MouseButtonEventArgs e )
1619+ {
1620+ e . Handled = true ; // Prevent the click from bubbling to the button
1621+ ResetApplicationState ( ) ;
1622+ }
1623+
1624+ private void ResetApplicationState ( )
1625+ {
1626+ // Stop the autosave timer
1627+ autoSaveTimer ? . Stop ( ) ;
1628+ AutosaveCurrentState ( ) ;
1629+
1630+ // Clear the image
1631+ MainImage . Source = null ;
1632+ imagePath = null ;
1633+ openedFileName = string . Empty ;
1634+ openedPackage = null ;
1635+ savedPath = null ;
1636+
1637+ // Reset the title
1638+ wpfuiTitleBar . Title = "Magick Crop & Measure by TheJoeFin" ;
1639+
1640+ // Reset UI elements
1641+ RemoveMeasurementControls ( ) ;
1642+ HideTransformControls ( ) ;
1643+ HideCroppingControls ( ) ;
1644+ HideResizeControls ( ) ;
1645+ BottomBorder . Visibility = Visibility . Collapsed ;
1646+ WelcomeMessageModal . Visibility = Visibility . Visible ;
1647+ OpenFolderButton . IsEnabled = false ;
1648+ Save . IsEnabled = false ;
1649+
1650+ // Reset the canvas transform
1651+ if ( ShapeCanvas . RenderTransform is MatrixTransform matTrans )
1652+ {
1653+ matTrans . Matrix = new Matrix ( ) ;
1654+ }
1655+
1656+ // Reset undo/redo
1657+ undoRedo . Clear ( ) ;
1658+
1659+ // Create a new project ID
1660+ currentProjectId = Guid . NewGuid ( ) . ToString ( ) ;
1661+
1662+ // Update the button state
1663+ UpdateOpenedFileNameText ( ) ;
1664+ }
15941665}
0 commit comments