Skip to content

Commit 5dd3d7f

Browse files
committed
Fixed bugs in Path Control contextual click handling
1 parent 21b2c8f commit 5dd3d7f

5 files changed

Lines changed: 79 additions & 11 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### 13/11/2025 - Version 3.4.1
66

77
* New application icon
8+
* Fix path bar contextual menu handling
89
* Minor UI and bug fixes
910
* Some code modernization
1011

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
* Fix checking Regex and Case Insensitive in filter field options
44
* Preserve selection between refreshes (preserve expanded items between refreshes?)
5-
* Fix path bar folders contextual click
65
* Show full command (w/args) for process (ala ps -ef) in Info Panel
76
* Highlight matching part of string when filtering (option in filter field popup)
87
* Store authentication privileges and use them to run command line tool "/usr/bin/file" for Info Dialog

resources/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<key>CFBundleSignature</key>
2424
<string>????</string>
2525
<key>CFBundleVersion</key>
26-
<string>361</string>
26+
<string>362</string>
2727
<key>LSApplicationCategoryType</key>
2828
<string>public.app-category.utilities</string>
2929
<key>LSMinimumSystemVersion</key>

source/Util/NSPathControl+ContextMenu.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
/*
2+
Copyright (c) 2018-2025, Sveinbjorn Thordarson <sveinbjorn@sveinbjorn.org>
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice, this
12+
list of conditions and the following disclaimer in the documentation and/or other
13+
materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its contributors may
16+
be used to endorse or promote products derived from this software without specific
17+
prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
132
#import <Cocoa/Cocoa.h>
233

334
NS_ASSUME_NONNULL_BEGIN

source/Util/NSPathControl+ContextMenu.m

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
1+
/*
2+
Copyright (c) 2018-2025, Sveinbjorn Thordarson <sveinbjorn@sveinbjorn.org>
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
2. Redistributions in binary form must reproduce the above copyright notice, this
12+
list of conditions and the following disclaimer in the documentation and/or other
13+
materials provided with the distribution.
14+
15+
3. Neither the name of the copyright holder nor the names of its contributors may
16+
be used to endorse or promote products derived from this software without specific
17+
prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
131
#import "NSPathControl+ContextMenu.h"
232
#import "NSWorkspace+Additions.h"
3-
#import "IconUtils.h"
33+
#import <objc/runtime.h>
34+
35+
static const char * kFilePathAssociatedObjectKey = "filePath";
436

537
@implementation NSPathControl (ContextMenu)
638

39+
// Generate contextual menu for a Ctrl-clicked item in the Path Control
740
- (NSMenu *)menuForEvent:(NSEvent *)event {
8-
941
NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
1042
NSRect frame = [self bounds];
1143
NSPathCell *cell = (NSPathCell *)[self cell];
@@ -23,7 +55,7 @@ - (NSMenu *)menuForEvent:(NSEvent *)event {
2355

2456
NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
2557

26-
// Open
58+
// Open (with default app)
2759
NSMenuItem *openItem = [[NSMenuItem alloc] initWithTitle:@"Open" action:@selector(openPath:) keyEquivalent:@""];
2860
[openItem setTarget:self];
2961
[openItem setRepresentedObject:path];
@@ -38,11 +70,15 @@ - (NSMenu *)menuForEvent:(NSEvent *)event {
3870
}
3971
[menu addItem:openItem];
4072

41-
// Open With
73+
// Open With submenu
4274
NSMenuItem *openWithItem = [[NSMenuItem alloc] initWithTitle:@"Open With" action:nil keyEquivalent:@""];
4375
NSMenu *openWithMenu = [[NSMenu alloc] init];
76+
objc_setAssociatedObject(openWithMenu, kFilePathAssociatedObjectKey, path, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
4477
[openWithItem setSubmenu:openWithMenu];
45-
[[NSWorkspace sharedWorkspace] openWithMenuForFile:path target:self action:@selector(openPathWithApplication:) menu:openWithMenu];
78+
[[NSWorkspace sharedWorkspace] openWithMenuForFile:path
79+
target:self
80+
action:@selector(openPathWithApplication:)
81+
menu:openWithMenu];
4682
[menu addItem:openWithItem];
4783

4884
[menu addItem:[NSMenuItem separatorItem]];
@@ -53,12 +89,13 @@ - (NSMenu *)menuForEvent:(NSEvent *)event {
5389
[showItem setRepresentedObject:path];
5490
[menu addItem:showItem];
5591

56-
// Get Info
57-
NSMenuItem *getInfoItem = [[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(showPathInfoInFinder:) keyEquivalent:@""];
92+
// Get Info in Finder
93+
NSMenuItem *getInfoItem = [[NSMenuItem alloc] initWithTitle:@"Show Info in Finder" action:@selector(showPathInfoInFinder:) keyEquivalent:@""];
5894
[getInfoItem setTarget:self];
5995
[getInfoItem setRepresentedObject:path];
6096
[menu addItem:getInfoItem];
6197

98+
// Separator
6299
[menu addItem:[NSMenuItem separatorItem]];
63100

64101
// Copy Path
@@ -78,8 +115,8 @@ - (void)openPath:(id)sender {
78115
}
79116

80117
- (void)openPathWithApplication:(id)sender {
81-
NSString *appPath = [sender representedObject];
82-
NSString *filePath = [[[sender menu] supermenu] representedObject];
118+
NSString *appPath = [sender toolTip];
119+
NSString *filePath = objc_getAssociatedObject([sender menu], kFilePathAssociatedObjectKey);
83120
[[NSWorkspace sharedWorkspace] openFile:filePath withApplication:appPath];
84121
}
85122

0 commit comments

Comments
 (0)