From d32bb660192b03dccc09a2a3affa405f21ffb9bd Mon Sep 17 00:00:00 2001 From: Cocagne Anthonin Date: Tue, 8 Jan 2019 22:09:04 +0100 Subject: [PATCH] Handle reopening last tab from main window --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 86 ++++++++++++++++++- FastFinder/Base.lproj/Main.storyboard | 11 +-- FastFinder/Helper/FinderLogicHelper.m | 76 +++++++++++----- FastFinder/Info.plist | 4 +- 4 files changed, 147 insertions(+), 30 deletions(-) diff --git a/FastFinder.xcworkspace/xcuserdata/antho.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/FastFinder.xcworkspace/xcuserdata/antho.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 5ba990a..f0036b0 100644 --- a/FastFinder.xcworkspace/xcuserdata/antho.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/FastFinder.xcworkspace/xcuserdata/antho.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -74,14 +74,94 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "FastFinder/ViewController/SettingsViewController.m" - timestampString = "565384919.423647" + timestampString = "568674219.037619" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "86" - endingLineNumber = "86" + startingLineNumber = "94" + endingLineNumber = "94" landmarkName = "-didChangeAnimationVelocity:" landmarkType = "7"> + + + + + + + + + + + + + + + + + + + + diff --git a/FastFinder/Base.lproj/Main.storyboard b/FastFinder/Base.lproj/Main.storyboard index 3bb5be0..abc75b2 100644 --- a/FastFinder/Base.lproj/Main.storyboard +++ b/FastFinder/Base.lproj/Main.storyboard @@ -1,6 +1,7 @@ + @@ -836,7 +837,7 @@ - + You can reopen this window at any moment by opening FastFinder from Spotlight or your Application folder @@ -921,10 +922,10 @@ Animation is currently experimental and can cause quick glitch do to how MacOS h - + - - + + @@ -942,7 +943,7 @@ Animation is currently experimental and can cause quick glitch do to how MacOS h - + diff --git a/FastFinder/Helper/FinderLogicHelper.m b/FastFinder/Helper/FinderLogicHelper.m index a3c4479..1b4ecfc 100644 --- a/FastFinder/Helper/FinderLogicHelper.m +++ b/FastFinder/Helper/FinderLogicHelper.m @@ -17,7 +17,7 @@ //CONFIGURATION //for first launch -static CGFloat const DEFAULT_FINDER_HEIGHT = 500; +static CGFloat const DEFAULT_FINDER_HEIGHT = 550; @implementation FinderLogicHelper { @@ -26,6 +26,7 @@ @implementation FinderLogicHelper { CGFloat screenHeight; CGFloat screenWidth; + NSInteger idOfMainVisorFinderWindow; NSInteger idOfVisorFinderWindow; CGFloat lastFinderHeight; } @@ -87,6 +88,18 @@ -(void) show:(BOOL)show finder:(FinderApplication*)finder { } else { NSLog(@"Hide finder"); + //experimental : reopen last closed window/tab; unfortunately, there is no way to distinguish tabs from window… + if ([self frontmostWindowIsTabOfMainWindow:finderWindows]) { + idOfVisorFinderWindow = ((FinderWindow*)finderWindows[0]).id; //show tab of main window + } else { //frontmost window isn't mainWindow nor a tab of mainWindow +// ((FinderWindow*)finderWindows[0]).index++; + for (int i = 0; i < [self getMainWindow:finderWindows].index; i++) { + ((FinderWindow*)finderWindows[i]).index++; //send all windows which are above mainWindow to back + } + [self getMainWindow:finderWindows].index = 1; //send mainWindow to front + idOfVisorFinderWindow = idOfMainVisorFinderWindow; //restore main window + } + finderWindow = [self getFinderWindowFromWindows:finderWindows]; CGFloat finderHeight = finderWindow.bounds.size.height; @@ -97,6 +110,8 @@ -(void) show:(BOOL)show finder:(FinderApplication*)finder { if (animated) { [self animateOffsetWindow:finderWindow directionUp:NO completionHandler:^{ //if the frontmost window (not finder one) at the time of making the shortcut takes the whole screen (window.bounds == screen.bounds) + +// finder.frontmost = NO; //use this to allow working "Show in Finder" but experience is not as well as with finder.visible finder.visible = NO; //this is what causes the glitch that is visible when there is no other window behind, because when you reactivate the finder after hiding it, it restores position //if the frontmost window (not finder one) at the time of making the shortcut does NOT take the whole screen (window.bounds != screen.bounds), but the problem of this version is that the fact of not setting finder visible=NO, causes that if we click manually on Finder dock icon, it stays at its position on bottom… @@ -114,24 +129,8 @@ -(FinderWindow*) getFinderWindowFromWindows:(SBElementArray*)finderWindows { FinderWindow *finderWindow = nil; if (finderWindows.count > 1) { - for (FinderWindow *finderWin in finderWindows) { - //NSLog(@"win : %@", finderWin.properties); //this can cause glitch… - - if (finderWin.id == idOfVisorFinderWindow) { - finderWindow = finderWin; - finderWindow.index = 1; //set this window the frontmost one - } - } - - //don't really know why i have to do this a second time, but without this it doesn't work - if (finderWindow.id != idOfVisorFinderWindow) { - NSLog(@"Window isn't the good one, searching for the good one…"); - for (FinderWindow *finderWin in finderWindows) { - if (finderWin.id == idOfVisorFinderWindow) { - finderWindow = finderWin; - } - } - } + finderWindow = [self getMainWindow:finderWindows]; + finderWindow.index = 1; } if (finderWindow == nil) { @@ -147,11 +146,13 @@ -(FinderWindow*) getFinderWindowFromWindows:(SBElementArray*)finderWindows { // [self runCommand:@"osascript -e \"tell application \"Finder\" to make new Finder window\""]; } + idOfMainVisorFinderWindow = finderWindow.id; + idOfVisorFinderWindow = finderWindow.id; } // NSLog(@"Window : id:%ld, name:%@, index:%ld, idOfVisorFinderWindow:%ld", finderWindow.id, finderWindow.name, finderWindow.index, idOfVisorFinderWindow); - idOfVisorFinderWindow = finderWindow.id; + //idOfVisorFinderWindow = finderWindow.id; return finderWindow; } @@ -186,7 +187,42 @@ - (void)animateOffsetWindow:(FinderWindow *)finderWindow directionUp:(BOOL)direc } +-(FinderWindow*) getMainWindow:(SBElementArray*)finderWindows { + FinderWindow *mainWindow; + for (FinderWindow *finderWin in finderWindows) { + //NSLog(@"win : %@", finderWin.properties); //this can cause glitch… + + if (finderWin.id == idOfVisorFinderWindow) { + mainWindow = finderWin; + break; + } + } + + //don't really know why i have to do this a second time, but without this it doesn't work + if (mainWindow.id != idOfVisorFinderWindow) { + NSLog(@"Window isn't the good one, searching for the good one…"); + for (FinderWindow *finderWin in finderWindows) { + if (finderWin.id == idOfVisorFinderWindow) { + NSLog(@"Window finally found !"); + mainWindow = finderWin; + break; + } + } + } + + return mainWindow; +} +-(BOOL) frontmostWindowIsTabOfMainWindow:(SBElementArray*)finderWindows { + FinderWindow *frontmostWindow = (FinderWindow*)finderWindows[0]; + FinderWindow *mainWindow = [self getMainWindow:finderWindows]; + + if (CGRectEqualToRect(frontmostWindow.bounds, mainWindow.bounds) && CGPointEqualToPoint(frontmostWindow.position, mainWindow.position)) { + return YES; + } + + return NO; +} #pragma mark - Misc diff --git a/FastFinder/Info.plist b/FastFinder/Info.plist index 331360a..60d8a70 100644 --- a/FastFinder/Info.plist +++ b/FastFinder/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.1 + 0.1.1 CFBundleVersion - 1 + 2 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion