mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
If a new session was saved from Change Settings, a side-effect on Windows was
that the global `sesslist' got out of sync with the saved-sessions submenu, causing the latter to launch the wrong sessions. Also, Change Settings wasn't getting a fresh session list, so if the set of sessions had changed since session startup it wouldn't reflect that (at least until a session was saved). Fixed (on all platforms). Therefore, since the global sesslist didn't seem to be useful, I've got rid of it; config.c creates one as needed, as do the frontends. (Not tried compiling Mac changes.) Also, we now build the saved-sessions submenu on demand on Windows and Unix. (This should probably also be done on the Mac.) [originally from svn r5609]
This commit is contained in:
parent
a068889389
commit
52a17ab04a
32
config.c
32
config.c
@ -278,7 +278,7 @@ static void sshbug_handler(union control *ctrl, void *dlg,
|
||||
struct sessionsaver_data {
|
||||
union control *editbox, *listbox, *loadbutton, *savebutton, *delbutton;
|
||||
union control *okbutton, *cancelbutton;
|
||||
struct sesslist *sesslist;
|
||||
struct sesslist sesslist;
|
||||
int midsession;
|
||||
};
|
||||
|
||||
@ -297,10 +297,10 @@ static int load_selected_session(struct sessionsaver_data *ssd,
|
||||
dlg_beep(dlg);
|
||||
return 0;
|
||||
}
|
||||
isdef = !strcmp(ssd->sesslist->sessions[i], "Default Settings");
|
||||
load_settings(ssd->sesslist->sessions[i], !isdef, cfg);
|
||||
isdef = !strcmp(ssd->sesslist.sessions[i], "Default Settings");
|
||||
load_settings(ssd->sesslist.sessions[i], !isdef, cfg);
|
||||
if (!isdef) {
|
||||
strncpy(savedsession, ssd->sesslist->sessions[i],
|
||||
strncpy(savedsession, ssd->sesslist.sessions[i],
|
||||
SAVEDSESSION_LEN);
|
||||
savedsession[SAVEDSESSION_LEN-1] = '\0';
|
||||
} else {
|
||||
@ -344,8 +344,8 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
|
||||
int i;
|
||||
dlg_update_start(ctrl, dlg);
|
||||
dlg_listbox_clear(ctrl, dlg);
|
||||
for (i = 0; i < ssd->sesslist->nsessions; i++)
|
||||
dlg_listbox_add(ctrl, dlg, ssd->sesslist->sessions[i]);
|
||||
for (i = 0; i < ssd->sesslist.nsessions; i++)
|
||||
dlg_listbox_add(ctrl, dlg, ssd->sesslist.sessions[i]);
|
||||
dlg_update_done(ctrl, dlg);
|
||||
}
|
||||
} else if (event == EVENT_VALCHANGE) {
|
||||
@ -376,9 +376,9 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
|
||||
dlg_beep(dlg);
|
||||
return;
|
||||
}
|
||||
isdef = !strcmp(ssd->sesslist->sessions[i], "Default Settings");
|
||||
isdef = !strcmp(ssd->sesslist.sessions[i], "Default Settings");
|
||||
if (!isdef) {
|
||||
strncpy(savedsession, ssd->sesslist->sessions[i],
|
||||
strncpy(savedsession, ssd->sesslist.sessions[i],
|
||||
SAVEDSESSION_LEN);
|
||||
savedsession[SAVEDSESSION_LEN-1] = '\0';
|
||||
} else {
|
||||
@ -392,8 +392,8 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
|
||||
sfree(errmsg);
|
||||
}
|
||||
}
|
||||
get_sesslist(ssd->sesslist, FALSE);
|
||||
get_sesslist(ssd->sesslist, TRUE);
|
||||
get_sesslist(&ssd->sesslist, FALSE);
|
||||
get_sesslist(&ssd->sesslist, TRUE);
|
||||
dlg_refresh(ssd->editbox, dlg);
|
||||
dlg_refresh(ssd->listbox, dlg);
|
||||
} else if (!ssd->midsession &&
|
||||
@ -402,9 +402,9 @@ static void sessionsaver_handler(union control *ctrl, void *dlg,
|
||||
if (i <= 0) {
|
||||
dlg_beep(dlg);
|
||||
} else {
|
||||
del_settings(ssd->sesslist->sessions[i]);
|
||||
get_sesslist(ssd->sesslist, FALSE);
|
||||
get_sesslist(ssd->sesslist, TRUE);
|
||||
del_settings(ssd->sesslist.sessions[i]);
|
||||
get_sesslist(&ssd->sesslist, FALSE);
|
||||
get_sesslist(&ssd->sesslist, TRUE);
|
||||
dlg_refresh(ssd->listbox, dlg);
|
||||
}
|
||||
} else if (ctrl == ssd->okbutton) {
|
||||
@ -819,8 +819,8 @@ static void portfwd_handler(union control *ctrl, void *dlg,
|
||||
}
|
||||
}
|
||||
|
||||
void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
|
||||
int midsession, int protocol, int protcfginfo)
|
||||
void setup_config_box(struct controlbox *b, int midsession,
|
||||
int protocol, int protcfginfo)
|
||||
{
|
||||
struct controlset *s;
|
||||
struct sessionsaver_data *ssd;
|
||||
@ -904,7 +904,7 @@ void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
|
||||
midsession ? "Save the current session settings" :
|
||||
"Load, save or delete a stored session");
|
||||
ctrl_columns(s, 2, 75, 25);
|
||||
ssd->sesslist = sesslist;
|
||||
get_sesslist(&ssd->sesslist, TRUE);
|
||||
ssd->editbox = ctrl_editbox(s, "Saved Sessions", 'e', 100,
|
||||
HELPCTX(session_saved),
|
||||
sessionsaver_handler, P(ssd), P(NULL));
|
||||
|
@ -66,7 +66,6 @@ static void mac_config(int midsession)
|
||||
{
|
||||
Session *s;
|
||||
WinInfo *wi;
|
||||
static struct sesslist sesslist;
|
||||
Str255 mactitle;
|
||||
char *str;
|
||||
|
||||
@ -90,9 +89,8 @@ static void mac_config(int midsession)
|
||||
else
|
||||
s->settings_window = GetNewWindow(wSettings, NULL, (WindowPtr)-1);
|
||||
|
||||
get_sesslist(&sesslist, TRUE);
|
||||
s->ctrlbox = ctrl_new_box();
|
||||
setup_config_box(s->ctrlbox, &sesslist, midsession, 0, 0);
|
||||
setup_config_box(s->ctrlbox, midsession, 0, 0);
|
||||
|
||||
s->settings_ctrls.data = &s->temp_cfg;
|
||||
if (midsession)
|
||||
|
@ -80,7 +80,6 @@ struct alert_queue {
|
||||
{
|
||||
NSOutlineView *treeview;
|
||||
struct controlbox *ctrlbox;
|
||||
struct sesslist sl;
|
||||
void *dv;
|
||||
Config cfg;
|
||||
}
|
||||
|
@ -123,10 +123,8 @@
|
||||
int hmin = 0;
|
||||
int panelht = 0;
|
||||
|
||||
get_sesslist(&sl, TRUE);
|
||||
|
||||
ctrlbox = ctrl_new_box();
|
||||
setup_config_box(ctrlbox, &sl, FALSE /*midsession*/, aCfg.protocol,
|
||||
setup_config_box(ctrlbox, FALSE /*midsession*/, aCfg.protocol,
|
||||
0 /* protcfginfo */);
|
||||
unix_setup_config_box(ctrlbox, FALSE /*midsession*/);
|
||||
|
||||
|
4
putty.h
4
putty.h
@ -980,8 +980,8 @@ void cmdline_error(char *, ...);
|
||||
* Exports from config.c.
|
||||
*/
|
||||
struct controlbox;
|
||||
void setup_config_box(struct controlbox *b, struct sesslist *sesslist,
|
||||
int midsession, int protocol, int protcfginfo);
|
||||
void setup_config_box(struct controlbox *b, int midsession,
|
||||
int protocol, int protcfginfo);
|
||||
|
||||
/*
|
||||
* Exports from minibidi.c.
|
||||
|
@ -1956,7 +1956,6 @@ int do_config_box(const char *title, Config *cfg, int midsession,
|
||||
GtkTreeItem *treeitemlevels[8];
|
||||
GtkTree *treelevels[8];
|
||||
struct dlgparam dp;
|
||||
struct sesslist sl;
|
||||
struct Shortcuts scs;
|
||||
|
||||
struct selparam *selparams = NULL;
|
||||
@ -1964,8 +1963,6 @@ int do_config_box(const char *title, Config *cfg, int midsession,
|
||||
|
||||
dlg_init(&dp);
|
||||
|
||||
get_sesslist(&sl, TRUE);
|
||||
|
||||
listitemheight = get_listitemheight();
|
||||
|
||||
for (index = 0; index < lenof(scs.sc); index++) {
|
||||
@ -1975,7 +1972,7 @@ int do_config_box(const char *title, Config *cfg, int midsession,
|
||||
window = gtk_dialog_new();
|
||||
|
||||
ctrlbox = ctrl_new_box();
|
||||
setup_config_box(ctrlbox, &sl, midsession, cfg->protocol, protcfginfo);
|
||||
setup_config_box(ctrlbox, midsession, cfg->protocol, protcfginfo);
|
||||
unix_setup_config_box(ctrlbox, midsession);
|
||||
gtk_setup_config_box(ctrlbox, midsession, window);
|
||||
|
||||
@ -2161,7 +2158,6 @@ int do_config_box(const char *title, Config *cfg, int midsession,
|
||||
|
||||
gtk_main();
|
||||
|
||||
get_sesslist(&sl, FALSE);
|
||||
dlg_cleanup(&dp);
|
||||
sfree(selparams);
|
||||
|
||||
|
@ -3226,6 +3226,33 @@ void saved_session_freedata(GtkMenuItem *item, gpointer data)
|
||||
sfree(str);
|
||||
}
|
||||
|
||||
static void update_savedsess_menu(GtkMenuItem *menuitem, gpointer data)
|
||||
{
|
||||
struct gui_data *inst = (struct gui_data *)data;
|
||||
struct sesslist sesslist;
|
||||
int i;
|
||||
|
||||
gtk_container_foreach(GTK_CONTAINER(inst->sessionsmenu),
|
||||
(GtkCallback)gtk_widget_destroy, NULL);
|
||||
|
||||
get_sesslist(&sesslist, TRUE);
|
||||
for (i = 1; i < sesslist.nsessions; i++) {
|
||||
GtkWidget *menuitem =
|
||||
gtk_menu_item_new_with_label(sesslist.sessions[i]);
|
||||
gtk_container_add(GTK_CONTAINER(inst->sessionsmenu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
gtk_object_set_data(GTK_OBJECT(menuitem), "user-data",
|
||||
dupstr(sesslist.sessions[i]));
|
||||
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
|
||||
GTK_SIGNAL_FUNC(saved_session_menuitem),
|
||||
inst);
|
||||
gtk_signal_connect(GTK_OBJECT(menuitem), "destroy",
|
||||
GTK_SIGNAL_FUNC(saved_session_freedata),
|
||||
inst);
|
||||
}
|
||||
get_sesslist(&sesslist, FALSE); /* free up */
|
||||
}
|
||||
|
||||
void update_specials_menu(void *frontend)
|
||||
{
|
||||
struct gui_data *inst = (struct gui_data *)frontend;
|
||||
@ -3505,28 +3532,10 @@ int pt_main(int argc, char **argv)
|
||||
gtk_widget_hide(inst->restartitem);
|
||||
MKMENUITEM("Duplicate Session", dup_session_menuitem);
|
||||
if (saved_sessions) {
|
||||
struct sesslist sesslist;
|
||||
int i;
|
||||
|
||||
inst->sessionsmenu = gtk_menu_new();
|
||||
|
||||
get_sesslist(&sesslist, TRUE);
|
||||
for (i = 1; i < sesslist.nsessions; i++) {
|
||||
menuitem = gtk_menu_item_new_with_label(sesslist.sessions[i]);
|
||||
gtk_container_add(GTK_CONTAINER(inst->sessionsmenu), menuitem);
|
||||
gtk_widget_show(menuitem);
|
||||
gtk_object_set_data(GTK_OBJECT(menuitem), "user-data",
|
||||
dupstr(sesslist.sessions[i]));
|
||||
gtk_signal_connect(GTK_OBJECT(menuitem), "activate",
|
||||
GTK_SIGNAL_FUNC(saved_session_menuitem),
|
||||
inst);
|
||||
gtk_signal_connect(GTK_OBJECT(menuitem), "destroy",
|
||||
GTK_SIGNAL_FUNC(saved_session_freedata),
|
||||
inst);
|
||||
}
|
||||
get_sesslist(&sesslist, FALSE);
|
||||
|
||||
MKMENUITEM("Saved Sessions", NULL);
|
||||
/* sessionsmenu will be updated when it's invoked */
|
||||
/* XXX is this the right way to do dynamic menus in Gtk? */
|
||||
MKMENUITEM("Saved Sessions", update_savedsess_menu);
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem),
|
||||
inst->sessionsmenu);
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ static int nevents = 0, negsize = 0;
|
||||
|
||||
extern Config cfg; /* defined in window.c */
|
||||
|
||||
struct sesslist sesslist; /* exported to window.c */
|
||||
|
||||
#define PRINTER_DISABLED_STRING "None (printing disabled)"
|
||||
|
||||
void force_normal(HWND hwnd)
|
||||
@ -649,7 +647,7 @@ int do_config(void)
|
||||
int ret;
|
||||
|
||||
ctrlbox = ctrl_new_box();
|
||||
setup_config_box(ctrlbox, &sesslist, FALSE, 0, 0);
|
||||
setup_config_box(ctrlbox, FALSE, 0, 0);
|
||||
win_setup_config_box(ctrlbox, &dp.hwnd, (help_path != NULL), FALSE);
|
||||
dp_init(&dp);
|
||||
winctrl_init(&ctrls_base);
|
||||
@ -661,11 +659,9 @@ int do_config(void)
|
||||
dp.data = &cfg;
|
||||
dp.shortcuts['g'] = TRUE; /* the treeview: `Cate&gory' */
|
||||
|
||||
get_sesslist(&sesslist, TRUE);
|
||||
ret =
|
||||
SaneDialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL,
|
||||
GenericMainDlgProc);
|
||||
get_sesslist(&sesslist, FALSE);
|
||||
|
||||
ctrl_free_box(ctrlbox);
|
||||
winctrl_cleanup(&ctrls_panel);
|
||||
@ -683,7 +679,7 @@ int do_reconfig(HWND hwnd, int protcfginfo)
|
||||
backup_cfg = cfg; /* structure copy */
|
||||
|
||||
ctrlbox = ctrl_new_box();
|
||||
setup_config_box(ctrlbox, &sesslist, TRUE, cfg.protocol, protcfginfo);
|
||||
setup_config_box(ctrlbox, TRUE, cfg.protocol, protcfginfo);
|
||||
win_setup_config_box(ctrlbox, &dp.hwnd, (help_path != NULL), TRUE);
|
||||
dp_init(&dp);
|
||||
winctrl_init(&ctrls_base);
|
||||
|
@ -78,6 +78,7 @@ static void init_fonts(int, int);
|
||||
static void another_font(int);
|
||||
static void deinit_fonts(void);
|
||||
static void set_input_locale(HKL);
|
||||
static void update_savedsess_menu(void);
|
||||
|
||||
static int is_full_screen(void);
|
||||
static void make_full_screen(void);
|
||||
@ -121,10 +122,11 @@ static struct {
|
||||
int specials_submenu_pos;
|
||||
} popup_menus[2];
|
||||
enum { SYSMENU, CTXMENU };
|
||||
static HMENU savedsess_menu;
|
||||
|
||||
Config cfg; /* exported to windlg.c */
|
||||
|
||||
extern struct sesslist sesslist; /* imported from windlg.c */
|
||||
static struct sesslist sesslist; /* for saved-session menu */
|
||||
|
||||
struct agent_callback {
|
||||
void (*callback)(void *, void *, int);
|
||||
@ -741,23 +743,17 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
* Set up the session-control options on the system menu.
|
||||
*/
|
||||
{
|
||||
HMENU s, m;
|
||||
int i, j;
|
||||
HMENU m;
|
||||
int j;
|
||||
char *str;
|
||||
|
||||
popup_menus[SYSMENU].menu = GetSystemMenu(hwnd, FALSE);
|
||||
popup_menus[CTXMENU].menu = CreatePopupMenu();
|
||||
AppendMenu(popup_menus[CTXMENU].menu, MF_ENABLED, IDM_PASTE, "&Paste");
|
||||
|
||||
s = CreateMenu();
|
||||
savedsess_menu = CreateMenu();
|
||||
get_sesslist(&sesslist, TRUE);
|
||||
/* skip sesslist.sessions[0] == Default Settings */
|
||||
for (i = 1;
|
||||
i < ((sesslist.nsessions <= MENU_SAVED_MAX+1) ? sesslist.nsessions
|
||||
: MENU_SAVED_MAX+1);
|
||||
i++)
|
||||
AppendMenu(s, MF_ENABLED, IDM_SAVED_MIN + (i-1)*MENU_SAVED_STEP,
|
||||
sesslist.sessions[i]);
|
||||
update_savedsess_menu();
|
||||
|
||||
for (j = 0; j < lenof(popup_menus); j++) {
|
||||
m = popup_menus[j].menu;
|
||||
@ -768,7 +764,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
|
||||
AppendMenu(m, MF_SEPARATOR, 0, 0);
|
||||
AppendMenu(m, MF_ENABLED, IDM_NEWSESS, "Ne&w Session...");
|
||||
AppendMenu(m, MF_ENABLED, IDM_DUPSESS, "&Duplicate Session");
|
||||
AppendMenu(m, MF_POPUP | MF_ENABLED, (UINT) s, "Sa&ved Sessions");
|
||||
AppendMenu(m, MF_POPUP | MF_ENABLED, (UINT) savedsess_menu,
|
||||
"Sa&ved Sessions");
|
||||
AppendMenu(m, MF_ENABLED, IDM_RECONF, "Chan&ge Settings...");
|
||||
AppendMenu(m, MF_SEPARATOR, 0, 0);
|
||||
AppendMenu(m, MF_ENABLED, IDM_COPYALL, "C&opy All to Clipboard");
|
||||
@ -895,6 +892,23 @@ char *do_select(SOCKET skt, int startup)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Refresh the saved-session submenu from `sesslist'.
|
||||
*/
|
||||
static void update_savedsess_menu(void)
|
||||
{
|
||||
int i;
|
||||
while (DeleteMenu(savedsess_menu, 0, MF_BYPOSITION)) ;
|
||||
/* skip sesslist.sessions[0] == Default Settings */
|
||||
for (i = 1;
|
||||
i < ((sesslist.nsessions <= MENU_SAVED_MAX+1) ? sesslist.nsessions
|
||||
: MENU_SAVED_MAX+1);
|
||||
i++)
|
||||
AppendMenu(savedsess_menu, MF_ENABLED,
|
||||
IDM_SAVED_MIN + (i-1)*MENU_SAVED_STEP,
|
||||
sesslist.sessions[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Update the Special Commands submenu.
|
||||
*/
|
||||
@ -1888,6 +1902,16 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
||||
show_mouseptr(1);
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
case WM_INITMENUPOPUP:
|
||||
if ((HMENU)wParam == savedsess_menu) {
|
||||
/* About to pop up Saved Sessions sub-menu.
|
||||
* Refresh the session list. */
|
||||
get_sesslist(&sesslist, FALSE); /* free */
|
||||
get_sesslist(&sesslist, TRUE);
|
||||
update_savedsess_menu();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
case WM_SYSCOMMAND:
|
||||
switch (wParam & ~0xF) { /* low 4 bits reserved to Windows */
|
||||
|
Loading…
Reference in New Issue
Block a user