macOS Finder Service to open a directory in a new kitty tab or window
This commit is contained in:
parent
fb4123a6f2
commit
8177cfac2a
@ -264,6 +264,10 @@ class Boss:
|
|||||||
cwd_from = w.child.pid_for_cwd if w is not None else None
|
cwd_from = w.child.pid_for_cwd if w is not None else None
|
||||||
self._new_os_window(args, cwd_from)
|
self._new_os_window(args, cwd_from)
|
||||||
|
|
||||||
|
def new_os_window_with_wd(self, wd):
|
||||||
|
special_window = SpecialWindow(None, cwd=wd)
|
||||||
|
self._new_os_window(special_window)
|
||||||
|
|
||||||
def add_child(self, window):
|
def add_child(self, window):
|
||||||
self.child_monitor.add_child(window.id, window.child.pid, window.child.child_fd, window.screen)
|
self.child_monitor.add_child(window.id, window.child.pid, window.child.child_fd, window.screen)
|
||||||
self.window_id_map[window.id] = window
|
self.window_id_map[window.id] = window
|
||||||
@ -937,6 +941,10 @@ class Boss:
|
|||||||
cwd_from = w.child.pid_for_cwd if w is not None else None
|
cwd_from = w.child.pid_for_cwd if w is not None else None
|
||||||
self._create_tab(args, cwd_from=cwd_from)
|
self._create_tab(args, cwd_from=cwd_from)
|
||||||
|
|
||||||
|
def new_tab_with_wd(self, wd):
|
||||||
|
special_window = SpecialWindow(None, cwd=wd)
|
||||||
|
self._new_tab(special_window)
|
||||||
|
|
||||||
def _new_window(self, args, cwd_from=None):
|
def _new_window(self, args, cwd_from=None):
|
||||||
tab = self.active_tab
|
tab = self.active_tab
|
||||||
if tab is not None:
|
if tab is not None:
|
||||||
|
|||||||
@ -869,6 +869,7 @@ process_pending_closes(ChildMonitor *self) {
|
|||||||
// via the mouse causes a crash because of the way autorelease pools work in
|
// via the mouse causes a crash because of the way autorelease pools work in
|
||||||
// glfw/cocoa. So we use a flag instead.
|
// glfw/cocoa. So we use a flag instead.
|
||||||
static unsigned int cocoa_pending_actions = 0;
|
static unsigned int cocoa_pending_actions = 0;
|
||||||
|
static char *cocoa_pending_actions_wd = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
set_cocoa_pending_action(CocoaPendingAction action) {
|
set_cocoa_pending_action(CocoaPendingAction action) {
|
||||||
@ -877,6 +878,12 @@ set_cocoa_pending_action(CocoaPendingAction action) {
|
|||||||
// Unjam it so the pending action is processed right now.
|
// Unjam it so the pending action is processed right now.
|
||||||
unjam_event_loop();
|
unjam_event_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
set_cocoa_pending_action_with_wd(CocoaPendingAction action, const char *wd) {
|
||||||
|
cocoa_pending_actions_wd = strdup(wd);
|
||||||
|
set_cocoa_pending_action(action);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
@ -893,7 +900,11 @@ main_loop(ChildMonitor *self, PyObject *a UNUSED) {
|
|||||||
if (cocoa_pending_actions) {
|
if (cocoa_pending_actions) {
|
||||||
if (cocoa_pending_actions & PREFERENCES_WINDOW) { call_boss(edit_config_file, NULL); }
|
if (cocoa_pending_actions & PREFERENCES_WINDOW) { call_boss(edit_config_file, NULL); }
|
||||||
if (cocoa_pending_actions & NEW_OS_WINDOW) { call_boss(new_os_window, NULL); }
|
if (cocoa_pending_actions & NEW_OS_WINDOW) { call_boss(new_os_window, NULL); }
|
||||||
|
if (cocoa_pending_actions & NEW_OS_WINDOW_WITH_WD) { call_boss(new_os_window_with_wd, "s", cocoa_pending_actions_wd); }
|
||||||
|
if (cocoa_pending_actions & NEW_TAB_WITH_WD) { call_boss(new_tab_with_wd, "s", cocoa_pending_actions_wd); }
|
||||||
cocoa_pending_actions = 0;
|
cocoa_pending_actions = 0;
|
||||||
|
free(cocoa_pending_actions_wd);
|
||||||
|
cocoa_pending_actions_wd = NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
parse_input(self);
|
parse_input(self);
|
||||||
|
|||||||
@ -187,6 +187,38 @@ cocoa_send_notification(PyObject *self UNUSED, PyObject *args) {
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface ServiceProvider : NSObject
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ServiceProvider
|
||||||
|
|
||||||
|
- (void)openTab:(NSPasteboard*)pasteboard
|
||||||
|
userData:(NSString *) UNUSED userData error:(NSError **) UNUSED error {
|
||||||
|
[self openFilesFromPasteboard:pasteboard type:NEW_TAB_WITH_WD];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)openOSWindow:(NSPasteboard*)pasteboard
|
||||||
|
userData:(NSString *) UNUSED userData error:(NSError **) UNUSED error {
|
||||||
|
[self openFilesFromPasteboard:pasteboard type:NEW_OS_WINDOW_WITH_WD];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)openFilesFromPasteboard:(NSPasteboard *)pasteboard type:(int)type {
|
||||||
|
NSDictionary *options = [NSDictionary dictionaryWithObject:@YES forKey:NSPasteboardURLReadingFileURLsOnlyKey];
|
||||||
|
NSArray *filePathArray = [pasteboard readObjectsForClasses:[NSArray arrayWithObject:[NSURL class]] options:options];
|
||||||
|
for (NSURL *url in filePathArray) {
|
||||||
|
NSString *path = [url path];
|
||||||
|
BOOL isDirectory = NO;
|
||||||
|
if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) {
|
||||||
|
if (!isDirectory) {
|
||||||
|
path = [path stringByDeletingLastPathComponent];
|
||||||
|
}
|
||||||
|
set_cocoa_pending_action_with_wd(type, [path UTF8String]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
// global menu {{{
|
// global menu {{{
|
||||||
void
|
void
|
||||||
cocoa_create_global_menu(void) {
|
cocoa_create_global_menu(void) {
|
||||||
@ -278,6 +310,9 @@ cocoa_create_global_menu(void) {
|
|||||||
@selector(applicationDockMenu:),
|
@selector(applicationDockMenu:),
|
||||||
(IMP)get_dock_menu,
|
(IMP)get_dock_menu,
|
||||||
"@@:@");
|
"@@:@");
|
||||||
|
|
||||||
|
|
||||||
|
[NSApp setServicesProvider:[[[ServiceProvider alloc] init] autorelease]];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@ -206,9 +206,13 @@ void send_prerendered_sprites_for_window(OSWindow *w);
|
|||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
void get_cocoa_key_equivalent(int, int, unsigned short*, int*);
|
void get_cocoa_key_equivalent(int, int, unsigned short*, int*);
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PREFERENCES_WINDOW = 1, NEW_OS_WINDOW = 2
|
PREFERENCES_WINDOW = 1,
|
||||||
|
NEW_OS_WINDOW = 2,
|
||||||
|
NEW_OS_WINDOW_WITH_WD = 4,
|
||||||
|
NEW_TAB_WITH_WD = 8
|
||||||
} CocoaPendingAction;
|
} CocoaPendingAction;
|
||||||
void set_cocoa_pending_action(CocoaPendingAction action);
|
void set_cocoa_pending_action(CocoaPendingAction action);
|
||||||
|
void set_cocoa_pending_action_with_wd(CocoaPendingAction action, const char *wd);
|
||||||
bool application_quit_requested();
|
bool application_quit_requested();
|
||||||
void request_application_quit();
|
void request_application_quit();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
14
setup.py
14
setup.py
@ -724,6 +724,20 @@ Categories=System;TerminalEmulator;
|
|||||||
NSSupportsAutomaticGraphicsSwitching=True,
|
NSSupportsAutomaticGraphicsSwitching=True,
|
||||||
LSApplicationCategoryType='public.app-category.utilities',
|
LSApplicationCategoryType='public.app-category.utilities',
|
||||||
LSEnvironment={'KITTY_LAUNCHED_BY_LAUNCH_SERVICES': '1'},
|
LSEnvironment={'KITTY_LAUNCHED_BY_LAUNCH_SERVICES': '1'},
|
||||||
|
NSServices=[
|
||||||
|
{
|
||||||
|
'NSMenuItem': {'default': 'New ' + appname + ' Tab Here'},
|
||||||
|
'NSMessage': 'openTab',
|
||||||
|
'NSRequiredContext': {'NSTextContent': 'FilePath'},
|
||||||
|
'NSSendTypes': ['NSFilenamesPboardType', 'public.plain-text'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'NSMenuItem': {'default': 'New ' + appname + ' Window Here'},
|
||||||
|
'NSMessage': 'openOSWindow',
|
||||||
|
'NSRequiredContext': {'NSTextContent': 'FilePath'},
|
||||||
|
'NSSendTypes': ['NSFilenamesPboardType', 'public.plain-text'],
|
||||||
|
},
|
||||||
|
],
|
||||||
)
|
)
|
||||||
with open('Info.plist', 'wb') as fp:
|
with open('Info.plist', 'wb') as fp:
|
||||||
plistlib.dump(pl, fp)
|
plistlib.dump(pl, fp)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user