AmendHub

Download:

jcs

/

wallops

/

amendments

/

76

chatter: Implement Cmd+W to close a query tab or part a channel


jcs made amendment 76 2 months ago
--- chatter.c Mon Sep 9 16:49:01 2024 +++ chatter.c Tue Sep 10 09:32:08 2024 @@ -78,6 +78,7 @@ chatter_init(const char *server, const unsigned short xfree(&chatter); return NULL; } + chatter->focusable = focusable; width = screenBits.bounds.right - screenBits.bounds.left - padding; width = MIN(width, 640); @@ -128,7 +129,6 @@ chatter_init(const char *server, const unsigned short focusable->update_menu = chatter_update_menu; focusable->resume = chatter_resume; focusable_add(focusable); - chatter->focusable = focusable; chatter_update_menu(focusable); @@ -254,7 +254,7 @@ chatter_add_tab(struct chatter *chatter, Rect *win_bou if (conn) chatter_reveal_shadow(chatter); - + return tab; } @@ -404,6 +404,8 @@ chatter_focus_tab(struct chatter *chatter, struct chat DrawControls(chatter->win); chatter_draw_tab_bar(chatter); + + chatter_update_menu(chatter->focusable); } void @@ -956,6 +958,15 @@ chatter_menu(struct focusable *focusable, short menu, TEPaste(chatter->input_te); return true; } + break; + case VIEW_MENU_ID: + switch (item) { + case VIEW_MENU_CLOSE_ID: + if (chatter->current_tab->query_nick[0] || + chatter->current_tab->channel) + chatter_close_tab(chatter, chatter->current_tab); + return true; + } } return false; @@ -971,7 +982,13 @@ chatter_update_menu(struct focusable *focusable) HLock(tab->messages_te); EnableItem(view_menu, VIEW_MENU_HIDE_ID); - + + if (chatter->current_tab->query_nick[0] || + chatter->current_tab->channel) + EnableItem(view_menu, VIEW_MENU_CLOSE_ID); + else + DisableItem(view_menu, VIEW_MENU_CLOSE_ID); + EnableItem(edit_menu, EDIT_MENU_PASTE_ID); if ((*(chatter->input_te))->selStart != (*(chatter->input_te))->selEnd) { @@ -1304,6 +1321,11 @@ chatter_close_tab(struct chatter *chatter, struct chat chatter_focus_tab(chatter, next_tab); chatter_reveal_shadow(chatter); + + if (tab->channel) + irc_part_channel(tab->conn, tab->channel); + + chatter_update_menu(chatter->focusable); } void --- chatter.h Sun Sep 8 21:38:55 2024 +++ chatter.h Tue Sep 10 08:49:49 2024 @@ -46,6 +46,7 @@ #define VIEW_MENU_ID 131 #define VIEW_MENU_HIDE_ID 1 +#define VIEW_MENU_CLOSE_ID 2 #define WAIT_TYPE_NONE (1 << 0) #define WAIT_TYPE_BACKGROUND (1 << 1) --- irc.c Mon Sep 9 16:32:40 2024 +++ irc.c Tue Sep 10 09:16:30 2024 @@ -928,11 +928,12 @@ irc_process_input(struct irc_connection *conn, struct return; } if (strcasecmp(arg0, "close") == 0) { - if (conn->chatter->current_tab->query_nick[0]) + if (conn->chatter->current_tab->query_nick[0] || + conn->chatter->current_tab->channel) chatter_close_tab(conn->chatter, conn->chatter->current_tab); else chatter_printf(conn->chatter, conn, NULL, - "not a query window", + "cannot close server tab, use /disconnect", arg0); return; } @@ -1118,6 +1119,12 @@ irc_quit_with_message(struct irc_connection *conn, cha else irc_printf(conn, "QUIT :%s %s on a %s\r\n", PROGRAM_NAME, get_version(false), gestalt_machine_type()); +} + +void +irc_part_channel(struct irc_connection *conn, struct irc_channel *channel) +{ + irc_printf(conn, "PART %s\r\n", channel->name); } void --- irc.h Sun Sep 8 21:23:00 2024 +++ irc.h Tue Sep 10 09:17:34 2024 @@ -109,5 +109,7 @@ void irc_abort(struct irc_connection *conn); void irc_close(struct irc_connection *conn); void irc_process_input(struct irc_connection *conn, struct irc_channel *channel, char *query_nick, char *input); - +void irc_part_channel(struct irc_connection *conn, + struct irc_channel *channel); + #endif \ No newline at end of file --- main.c Mon Sep 9 08:44:37 2024 +++ main.c Tue Sep 10 09:29:25 2024 @@ -334,12 +334,13 @@ handle_menu(long menu_id) ret = true; break; #endif - default: - if (nfocusables && focusables[0]->visible && focusables[0]->menu) - ret = focusables[0]->menu(focusables[0], HiWord(menu_id), - LoWord(menu_id)); } + if (!ret && nfocusables && focusables[0]->visible && + focusables[0]->menu) + ret = focusables[0]->menu(focusables[0], HiWord(menu_id), + LoWord(menu_id)); + HiliteMenu(0); return ret; } @@ -383,9 +384,10 @@ update_menu(void) } } - if (hidden) + if (hidden) { SetItem(view_menu, VIEW_MENU_HIDE_ID, "\pShow Windows"); - else + DisableItem(view_menu, VIEW_MENU_CLOSE_ID); + } else SetItem(view_menu, VIEW_MENU_HIDE_ID, "\pHide Windows"); if (nfocusables && focusables[0]->visible && @@ -397,6 +399,8 @@ update_menu(void) DisableItem(edit_menu, EDIT_MENU_CUT_ID); DisableItem(edit_menu, EDIT_MENU_COPY_ID); DisableItem(edit_menu, EDIT_MENU_PASTE_ID); + + DisableItem(view_menu, VIEW_MENU_HIDE_ID); } void --- wallops.π.r Thu Sep 5 10:11:44 2024 +++ wallops.π.r Tue Sep 10 09:36:37 2024 @@ -20,7 +20,8 @@ data 'MENU' (130) { data 'MENU' (131) { $"0083 0000 0000 0000 0000 FFFF FFFF 0456" /* .É.............V */ $"6965 770C 4869 6465 2057 696E 646F 7773" /* iew.Hide Windows */ - $"0048 0000 00" /* .H... */ + $"0048 0000 0943 6C6F 7365 2054 6162 0057" /* .H..∆Close Tab.W */ + $"0000 00" /* ... */ }; data 'MBAR' (128) {