Skip to content

Commit

Permalink
Handle reopening last tab from main window
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthoPakPak committed Jan 8, 2019
1 parent 7cb8b96 commit d32bb66
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "FastFinder/Helper/FinderLogicHelper.m"
timestampString = "568674331.018504"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "137"
endingLineNumber = "137"
landmarkName = "-getFinderWindowFromWindows:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "FastFinder/Helper/FinderLogicHelper.m"
timestampString = "568674331.019065"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "131"
endingLineNumber = "131"
landmarkName = "-getFinderWindowFromWindows:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "FastFinder/Helper/FinderLogicHelper.m"
timestampString = "568674331.0194139"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "107"
endingLineNumber = "107"
landmarkName = "-show:finder:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "FastFinder/Helper/FinderLogicHelper.m"
timestampString = "568674331.01974"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "92"
endingLineNumber = "92"
landmarkName = "-show:finder:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "FastFinder/Helper/FinderLogicHelper.m"
timestampString = "568674331.020051"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "97"
endingLineNumber = "97"
landmarkName = "-show:finder:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
11 changes: 6 additions & 5 deletions FastFinder/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -836,7 +837,7 @@
<rect key="frame" x="44" y="5" width="361" height="28"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" id="oCa-qL-jbv">
<font key="font" metaFont="system" size="11"/>
<font key="font" metaFont="smallSystem"/>
<string key="title">You can reopen this window at any moment by opening FastFinder
from Spotlight or your Application folder</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
Expand Down Expand Up @@ -921,10 +922,10 @@ Animation is currently experimental and can cause quick glitch do to how MacOS h
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Nyb-ZY-c8Z">
<rect key="frame" x="167" y="247" width="19" height="14"/>
<rect key="frame" x="167" y="247" width="50" height="14"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="0.1" id="XMp-re-cIW">
<font key="font" metaFont="system" size="11"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="0.1" id="XMp-re-cIW">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand All @@ -942,7 +943,7 @@ Animation is currently experimental and can cause quick glitch do to how MacOS h
<rect key="frame" x="103" y="13" width="148" height="14"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Credits : Anthonin Cocagne" id="evw-x8-xEh">
<font key="font" metaFont="system" size="11"/>
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
Expand Down
76 changes: 56 additions & 20 deletions FastFinder/Helper/FinderLogicHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//CONFIGURATION

//for first launch
static CGFloat const DEFAULT_FINDER_HEIGHT = 500;
static CGFloat const DEFAULT_FINDER_HEIGHT = 550;


@implementation FinderLogicHelper {
Expand All @@ -26,6 +26,7 @@ @implementation FinderLogicHelper {
CGFloat screenHeight;
CGFloat screenWidth;

NSInteger idOfMainVisorFinderWindow;
NSInteger idOfVisorFinderWindow;
CGFloat lastFinderHeight;
}
Expand Down Expand Up @@ -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;

Expand All @@ -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…
Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions FastFinder/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<string>0.1.1</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit d32bb66

Please sign in to comment.