From 56971b33ce7b3b70e39b84320e3380f2d29bef56 Mon Sep 17 00:00:00 2001 From: linnan Date: Mon, 20 Dec 2021 14:29:09 +0800 Subject: [PATCH 1/3] Fix the problem that the menu is always before leaf --- Shuttle/AppDelegate.m | 81 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/Shuttle/AppDelegate.m b/Shuttle/AppDelegate.m index 2f77935..bda4a50 100644 --- a/Shuttle/AppDelegate.m +++ b/Shuttle/AppDelegate.m @@ -365,12 +365,13 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m { // go through the array and sort out the menus and the leafs into // separate bucks so we can sort them independently. NSMutableDictionary* menus = [[NSMutableDictionary alloc] init]; - NSMutableDictionary* leafs = [[NSMutableDictionary alloc] init]; +// NSMutableDictionary* leafs = [[NSMutableDictionary alloc] init]; for (NSDictionary* item in data) { if (item[@"cmd"] && item[@"name"]) { // this is a leaf - [leafs setObject:item forKey:item[@"name"]]; +// [leafs setObject:item forKey:item[@"name"]]; + [menus setObject:item forKey:item[@"name"]]; } else { // must be a menu - add all instances for (NSString* key in item) { @@ -380,50 +381,48 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m { } NSArray* menuKeys = [[menus allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; - NSArray* leafKeys = [[leafs allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; +// NSArray* leafKeys = [[leafs allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; NSInteger pos = 0; // create menus first for (NSString* key in menuKeys) { - NSMenu* subMenu = [[NSMenu alloc] init]; - NSMenuItem* menuItem = [[NSMenuItem alloc] init]; - [self separatorSortRemoval:key]; - [menuItem setTitle:menuName]; - [menuItem setSubmenu:subMenu]; - [m insertItem:menuItem atIndex:pos++]; - if (addSeparator) { - [m insertItem:[NSMenuItem separatorItem] atIndex:pos++]; - } - // build submenu - [self buildMenu:menus[key] addToMenu:subMenu]; - } - - // now create leafs - for (NSString *key in leafKeys) { - NSDictionary* cfg = leafs[key]; - NSMenuItem* menuItem = [[NSMenuItem alloc] init]; - - //Get the command we are going to run in termainal - NSString *menuCmd = cfg[@"cmd"]; - //Get the theme for this terminal session - NSString *termTheme = cfg[@"theme"]; - //Get the name for the terminal session - NSString *termTitle = cfg[@"title"]; - //Get the value of setting inTerminal - NSString *termWindow = cfg[@"inTerminal"]; - //Get the menu name will will use this as the title if title is null. - [self separatorSortRemoval:cfg[@"name"]]; - - //Place the terminal command, theme, and title into an comma delimited string - NSString *menuRepObj = [NSString stringWithFormat:@"%@¬_¬%@¬_¬%@¬_¬%@¬_¬%@", menuCmd, termTheme, termTitle, termWindow, menuName]; - - [menuItem setTitle:menuName]; - [menuItem setRepresentedObject:menuRepObj]; - [menuItem setAction:@selector(openHost:)]; - [m insertItem:menuItem atIndex:pos++]; - if (addSeparator) { - [m insertItem:[NSMenuItem separatorItem] atIndex:pos++]; + if([menus[key] isKindOfClass:[NSDictionary class]]){ + NSDictionary* cfg = menus[key]; + //Get the command we are going to run in termainal + NSString *menuCmd = cfg[@"cmd"]; + //Get the theme for this terminal session + NSString *termTheme = cfg[@"theme"]; + //Get the name for the terminal session + NSString *termTitle = cfg[@"title"]; + //Get the value of setting inTerminal + NSString *termWindow = cfg[@"inTerminal"]; + //Get the menu name will will use this as the title if title is null. + [self separatorSortRemoval:cfg[@"name"]]; + + //Place the terminal command, theme, and title into an comma delimited string + NSString *menuRepObj = [NSString stringWithFormat:@"%@¬_¬%@¬_¬%@¬_¬%@¬_¬%@", menuCmd, termTheme, termTitle, termWindow, menuName]; + + NSMenuItem* menuItem = [[NSMenuItem alloc] init]; + [menuItem setTitle:menuName]; + [menuItem setRepresentedObject:menuRepObj]; + [menuItem setAction:@selector(openHost:)]; + [m insertItem:menuItem atIndex:pos++]; + if (addSeparator) { + [m insertItem:[NSMenuItem separatorItem] atIndex:pos++]; + } + }else{ + NSMenuItem* menuItem = [[NSMenuItem alloc] init]; + NSMenu* subMenu = [[NSMenu alloc] init]; + [self separatorSortRemoval:key]; + [menuItem setTitle:menuName]; + [menuItem setSubmenu:subMenu]; + [m insertItem:menuItem atIndex:pos++]; + if (addSeparator) { + [m insertItem:[NSMenuItem separatorItem] atIndex:pos++]; + } + // build submenu + [self buildMenu:menus[key] addToMenu:subMenu]; } } } From 6dc7b64dac102964a602f3a92d54241dc43810f7 Mon Sep 17 00:00:00 2001 From: linnan Date: Mon, 20 Dec 2021 14:38:30 +0800 Subject: [PATCH 2/3] Remove unused code --- Shuttle/AppDelegate.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/Shuttle/AppDelegate.m b/Shuttle/AppDelegate.m index bda4a50..188354f 100644 --- a/Shuttle/AppDelegate.m +++ b/Shuttle/AppDelegate.m @@ -370,7 +370,6 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m { for (NSDictionary* item in data) { if (item[@"cmd"] && item[@"name"]) { // this is a leaf -// [leafs setObject:item forKey:item[@"name"]]; [menus setObject:item forKey:item[@"name"]]; } else { // must be a menu - add all instances @@ -381,7 +380,6 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m { } NSArray* menuKeys = [[menus allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; -// NSArray* leafKeys = [[leafs allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; NSInteger pos = 0; From e3029ea6c95b33e02648319c8201c27431d843cb Mon Sep 17 00:00:00 2001 From: linnan Date: Wed, 22 Dec 2021 08:58:55 +0800 Subject: [PATCH 3/3] Remove unused comment --- Shuttle/AppDelegate.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Shuttle/AppDelegate.m b/Shuttle/AppDelegate.m index 188354f..49d6469 100644 --- a/Shuttle/AppDelegate.m +++ b/Shuttle/AppDelegate.m @@ -365,7 +365,6 @@ - (void) buildMenu:(NSArray*)data addToMenu:(NSMenu *)m { // go through the array and sort out the menus and the leafs into // separate bucks so we can sort them independently. NSMutableDictionary* menus = [[NSMutableDictionary alloc] init]; -// NSMutableDictionary* leafs = [[NSMutableDictionary alloc] init]; for (NSDictionary* item in data) { if (item[@"cmd"] && item[@"name"]) {