jcs
/wallops
/amendments
/99
*: Add Window menu, move Hide/Show to it, add each chatter
This allows Cmd+1, Cmd+2, etc. to switch between chatter windows.
jcs made amendment 99 2 months ago
--- chatter.c Thu Sep 12 13:44:49 2024
+++ chatter.c Thu Sep 12 21:59:44 2024
@@ -132,6 +132,12 @@ chatter_init(const char *server, const unsigned short
chatter_update_menu(focusable);
chatter_draw_tab_bar(chatter);
+ snprintf(title, sizeof(title), "Disconnected");
+ CtoPstr(title);
+ InsMenuItem(window_menu, title, WINDOW_MENU_N_ID + focusable->id);
+ SetItemCmd(window_menu, WINDOW_MENU_N_ID + focusable->id,
+ '1' + focusable->id);
+
chatter_printf(chatter, NULL, NULL,
"$B***$0 Welcome to %s %s",
PROGRAM_NAME, get_version(false));
@@ -440,6 +446,8 @@ chatter_close(struct focusable *focusable)
return false;
}
+ DelMenuItem(window_menu, WINDOW_MENU_N_ID + focusable->id);
+
SLIST_FOREACH_SAFE(conn, &irc_connections_list, list, tconn) {
if (conn->chatter == chatter) {
irc_close_connection(conn);
@@ -473,23 +481,32 @@ void
chatter_update_titlebar(struct chatter *chatter)
{
Str255 curtitle;
- char title[64];
+ char title[64], menu_title[64];
struct chatter_tab *tab = chatter->current_tab;
- if (!tab->conn || tab->conn->state <= IRC_STATE_DISCONNECTED)
+ if (!tab->conn || tab->conn->state <= IRC_STATE_DISCONNECTED) {
snprintf(title, sizeof(title), "%s: Disconnected", PROGRAM_NAME);
- else if (tab->conn->state == IRC_STATE_CONNECTING)
+ strlcpy(menu_title, "Disconnected", sizeof(menu_title));
+ } else if (tab->conn->state == IRC_STATE_CONNECTING) {
snprintf(title, sizeof(title), "%s: Connecting to %s",
PROGRAM_NAME, tab->conn->hostname);
- else
+ strlcpy(menu_title, tab->conn->hostname, sizeof(menu_title));
+ } else {
snprintf(title, sizeof(title), "%s: %s@%s", PROGRAM_NAME,
tab->conn->nick, tab->conn->hostname);
+ snprintf(menu_title, sizeof(menu_title),
+ "%s@%s", tab->conn->nick, tab->conn->hostname);
+ }
GetWTitle(chatter->win, &curtitle);
PtoCstr(curtitle);
if (strcmp((char *)&curtitle, title) != 0)
SetWTitle(chatter->win, CtoPstr(title));
+
+ CtoPstr(menu_title);
+ SetItem(window_menu, WINDOW_MENU_N_ID + chatter->focusable->id,
+ menu_title);
}
void
@@ -981,18 +998,21 @@ chatter_update_menu(struct focusable *focusable)
{
struct chatter *chatter = (struct chatter *)(focusable->cookie);
struct chatter_tab *tab = chatter->current_tab;
-
+
+ if (!chatter)
+ return;
+
HLock(chatter->input_te);
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(window_menu, WINDOW_MENU_HIDE_ID);
+
EnableItem(edit_menu, EDIT_MENU_PASTE_ID);
if ((*(chatter->input_te))->selStart != (*(chatter->input_te))->selEnd) {
@@ -1037,7 +1057,8 @@ chatter_key_down(struct focusable *focusable, EventRec
TEIdle(chatter->input_te);
HUnlock(te->hText);
HUnlock(chatter->input_te);
- irc_process_input(tab->conn, tab->channel, tab->query_nick, input);
+ irc_process_input(tab->conn, tab->channel,
+ (tab->query_nick[0] ? tab->query_nick : NULL), input);
xfree(&input);
} else {
TEKey(k, chatter->input_te);
--- chatter.h Thu Sep 12 13:45:03 2024
+++ chatter.h Thu Sep 12 21:27:39 2024
@@ -48,15 +48,18 @@
#define EDIT_MENU_PASTE_ID 3
#define VIEW_MENU_ID 131
-#define VIEW_MENU_HIDE_ID 1
-#define VIEW_MENU_CLOSE_ID 2
-#define VIEW_MENU_IGNORE_ID 3
+#define VIEW_MENU_CLOSE_ID 1
+#define VIEW_MENU_IGNORE_ID 2
#define IGNORE_MENU_ID 132
#define IGNORE_MENU_JOINS_ID 1
#define IGNORE_MENU_QUITS_ID 2
#define IGNORE_MENU_NICKS_ID 3
+#define WINDOW_MENU_ID 133
+#define WINDOW_MENU_HIDE_ID 1
+#define WINDOW_MENU_N_ID 3
+
#define WAIT_TYPE_NONE (1 << 0)
#define WAIT_TYPE_BACKGROUND (1 << 1)
#define WAIT_TYPE_FOREGROUND (1 << 2)
@@ -94,7 +97,8 @@ struct chatter {
struct chatter_tab *current_tab;
};
-extern MenuHandle apple_menu, file_menu, edit_menu, view_menu, ignore_menu;
+extern MenuHandle apple_menu, file_menu, edit_menu, view_menu, ignore_menu,
+ window_menu;
void notify(void);
void cancel_notification(void);
--- main.c Thu Sep 12 13:12:44 2024
+++ main.c Thu Sep 12 21:39:10 2024
@@ -24,7 +24,8 @@
NMRec notification = { 0 };
struct settings settings;
-MenuHandle apple_menu, file_menu, edit_menu, view_menu, ignore_menu;
+MenuHandle apple_menu, file_menu, edit_menu, view_menu, ignore_menu,
+ window_menu;
#ifdef MALLOC_DEBUG
MenuHandle debug_menu;
@@ -83,6 +84,8 @@ main(void)
if (!(ignore_menu = GetMenu(IGNORE_MENU_ID)))
panic("no ignore menu");
InsertMenu(ignore_menu, -1);
+ if (!(window_menu = GetMenu(WINDOW_MENU_ID)))
+ panic("no window menu");
update_menu();
#ifdef MALLOC_DEBUG
debug_menu = NewMenu(DEBUG_MENU_DUMP_ID, "\pDebug");
@@ -155,11 +158,9 @@ main(void)
focusable_close(found_focusable);
break;
case inContent:
- if (event_win != FrontWindow()) {
- if (found_focusable) {
- cancel_notification();
- focusable_show(found_focusable);
- }
+ if (event_win != FrontWindow() && found_focusable) {
+ cancel_notification();
+ focusable_show(found_focusable);
}
if (found_focusable && found_focusable->mouse_down)
found_focusable->mouse_down(found_focusable, &event);
@@ -272,35 +273,6 @@ handle_menu(long menu_id)
}
break;
case VIEW_MENU_ID:
- switch (LoWord(menu_id)) {
- case VIEW_MENU_HIDE_ID: {
- Str255 text;
- struct focusable **tfocusables = NULL;
-
- /* hiding and showing adjusts order, so duplicate order */
- tfocusables = xmalloc(sizeof(struct focusable *) * nfocusables);
- memcpy(tfocusables, focusables, sizeof(struct focusable *) *
- nfocusables);
-
- GetItem(view_menu, VIEW_MENU_HIDE_ID, &text);
- if (memcmp((char *)text + 1, "Hide", 4) == 0) {
- for (n = 0; n < nfocusables; n++) {
- if (tfocusables[n]->visible)
- focusable_hide(tfocusables[n]);
- }
- } else {
- for (n = 0; n < nfocusables; n++) {
- if (!tfocusables[n]->visible)
- focusable_show(tfocusables[n]);
- }
- }
-
- xfree(&tfocusables);
- update_menu();
- ret = true;
- break;
- }
- }
break;
case IGNORE_MENU_ID: {
short current;
@@ -332,6 +304,48 @@ handle_menu(long menu_id)
ret = true;
break;
}
+ case WINDOW_MENU_ID:
+ switch (LoWord(menu_id)) {
+ case WINDOW_MENU_HIDE_ID: {
+ Str255 text;
+ struct focusable **tfocusables = NULL;
+
+ /* hiding and showing adjusts order, so duplicate order */
+ tfocusables = xmalloc(sizeof(struct focusable *) * nfocusables);
+ memcpy(tfocusables, focusables, sizeof(struct focusable *) *
+ nfocusables);
+
+ GetItem(window_menu, WINDOW_MENU_HIDE_ID, &text);
+ if (memcmp((char *)text + 1, "Hide", 4) == 0) {
+ for (n = 0; n < nfocusables; n++) {
+ if (tfocusables[n]->visible)
+ focusable_hide(tfocusables[n]);
+ }
+ } else {
+ for (n = 0; n < nfocusables; n++) {
+ if (!tfocusables[n]->visible)
+ focusable_show(tfocusables[n]);
+ }
+ }
+
+ xfree(&tfocusables);
+ update_menu();
+ ret = true;
+ break;
+ }
+ default:
+ if (LoWord(menu_id) >= WINDOW_MENU_N_ID) {
+ for (n = 0; n < nfocusables; n++) {
+ if (focusables[n]->id == LoWord(menu_id) -
+ WINDOW_MENU_N_ID) {
+ focusable_show(focusables[n]);
+ break;
+ }
+ }
+ ret = true;
+ }
+ }
+ break;
#ifdef MALLOC_DEBUG
case DEBUG_MENU_DUMP_ID:
switch (LoWord(menu_id)) {
@@ -416,21 +430,23 @@ update_menu(void)
}
}
- EnableItem(view_menu, VIEW_MENU_HIDE_ID);
-
- if (hidden) {
- SetItem(view_menu, VIEW_MENU_HIDE_ID, "\pShow Windows");
- DisableItem(view_menu, VIEW_MENU_CLOSE_ID);
- } else
- SetItem(view_menu, VIEW_MENU_HIDE_ID, "\pHide Windows");
+ EnableItem(view_menu, WINDOW_MENU_HIDE_ID);
+ if (hidden)
+ DisableItem(view_menu, VIEW_MENU_CLOSE_ID);
+
CheckItem(ignore_menu, IGNORE_MENU_JOINS_ID,
!!(settings.ignores & IGNORE_JOINS));
CheckItem(ignore_menu, IGNORE_MENU_QUITS_ID,
!!(settings.ignores & IGNORE_QUITS));
CheckItem(ignore_menu, IGNORE_MENU_NICKS_ID,
!!(settings.ignores & IGNORE_NICKS));
-
+
+ if (hidden)
+ SetItem(window_menu, WINDOW_MENU_HIDE_ID, "\pShow Windows");
+ else
+ SetItem(window_menu, WINDOW_MENU_HIDE_ID, "\pHide Windows");
+
if (nfocusables && focusables[0]->visible &&
focusables[0]->update_menu) {
focusables[0]->update_menu(focusables[0]);
@@ -441,7 +457,7 @@ update_menu(void)
DisableItem(edit_menu, EDIT_MENU_COPY_ID);
DisableItem(edit_menu, EDIT_MENU_PASTE_ID);
- DisableItem(view_menu, VIEW_MENU_HIDE_ID);
+ DisableItem(window_menu, WINDOW_MENU_HIDE_ID);
}
void
--- wallops.π.r Wed Sep 11 11:00:51 2024
+++ wallops.π.r Thu Sep 12 21:48:58 2024
@@ -19,9 +19,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 0943 6C6F 7365 2054 6162 0057" /* .H..∆Close Tab.W */
- $"0000 0649 676E 6F72 6500 1B84 0000" /* ...Ignore..Ñ.. */
+ $"6965 7709 436C 6F73 6520 5461 6200 5700" /* iew∆Close Tab.W. */
+ $"0006 4967 6E6F 7265 001B 8400 00" /* ..Ignore..Ñ.. */
};
data 'MENU' (132) {
@@ -32,8 +31,14 @@ data 'MENU' (132) {
$"00" /* . */
};
+data 'MENU' (133) {
+ $"0085 0000 0000 0000 0000 FFFF FFFB 0657" /* .Ö.............W */
+ $"696E 646F 770C 4869 6465 2057 696E 646F" /* indow.Hide Windo */
+ $"7773 0048 0000 012D 0000 0000 00" /* ws.H...-..... */
+};
+
data 'MBAR' (128) {
- $"0004 0080 0081 0082 0083" /* ...Ä.Å.Ç.É */
+ $"0005 0080 0081 0082 0083 0085" /* ...Ä.Å.Ç.É.Ö */
};
data 'ALRT' (128) {
@@ -57,17 +62,17 @@ data 'DITL' (129, "CONNECT_DITL") {
$"0000 0000 00BE 0096 00D0 00B4 0500 0000" /* .....æ.ñ.–.¥.... */
$"0000 00DC 0096 00EC 00F4 1000 0000 0000" /* .....ñ.......... */
$"000A 000A 001A 0055 8807 5365 7276 6572" /* .......Uà.Server */
- $"3A0C 0000 0000 0028 000A 0038 005E 880C" /* :......(...8.^à. */
+ $"3A72 0000 0000 0028 000A 0038 005E 880C" /* :r.....(...8.^à. */
$"5365 7276 6572 2050 6F72 743A 0000 0000" /* Server Port:.... */
$"0046 000A 0056 0089 8810 5365 7276 6572" /* .F...V.âà.Server */
$"2050 6173 7377 6F72 643A 0000 0000 0064" /* Password:.....d */
- $"000A 0074 0055 8805 4E69 636B 3A06 0000" /* ...t.Uà.Nick:... */
+ $"000A 0074 0055 8805 4E69 636B 3A3A 0000" /* ...t.Uà.Nick::.. */
$"0000 0082 000A 0092 0055 8806 4964 656E" /* ...Ç...í.Uà.Iden */
$"743A 0000 0000 00A0 000A 00B0 0055 880A" /* t:.....†...∞.Uà. */
$"5265 616C 204E 616D 653A 0000 0000 00BE" /* Real Name:.....æ */
$"000A 00CE 0055 880A 4869 6465 204D 4F54" /* ...Œ.Uà.Hide MOT */
$"443A 0000 0000 00DC 000A 00ED 0072 880D" /* D:...........rଠ*/
- $"4A6F 696E 2043 6861 6E6E 656C 3A00" /* Join Channel:. */
+ $"4A6F 696E 2043 6861 6E6E 656C 3A6E" /* Join Channel:n */
};
data 'DITL' (130, "ABOUT_DITL", purgeable, preload) {