*/
#include <assert.h>
+#include <ctype.h>
#include <stdlib.h>
#include "putty.h"
union control *okbutton, *cancelbutton;
struct sesslist sesslist;
int midsession;
+ char filterstr[SAVEDSESSION_LEN];
+ int filteritems[2048];
};
/*
void *dlg, Config *cfg, int *maybe_launch)
{
int i = dlg_listbox_index(ssd->listbox, dlg);
+ /* If filterstr is set, we need to pick the i item out
+ * of filteritems.
+ */
+ if (strlen(ssd->filterstr)) {
+ i = ssd->filteritems[i];
+ }
int isdef;
if (i < 0) {
dlg_beep(dlg);
if (ctrl == ssd->editbox) {
dlg_editbox_set(ctrl, dlg, savedsession);
} else if (ctrl == ssd->listbox) {
- int i;
+ int i, j = 0, k;
+ char checkstr[SAVEDSESSION_LEN];
dlg_update_start(ctrl, dlg);
dlg_listbox_clear(ctrl, dlg);
- for (i = 0; i < ssd->sesslist.nsessions; i++)
+ for (i = 0; i < ssd->sesslist.nsessions; i++) {
+ /* Loop to build listbox content:
+ * We only put the item into it when it matches
+ * the given string in ssd->filterstr.
+ */
+ for (k = 0; k < SAVEDSESSION_LEN; k++) {
+ checkstr[k] = tolower(ssd->sesslist.sessions[i][k]);
+ }
+ if (!strstr(checkstr, ssd->filterstr))
+ continue;
+ ssd->filteritems[j++] = i;
dlg_listbox_add(ctrl, dlg, ssd->sesslist.sessions[i]);
+ }
dlg_update_done(ctrl, dlg);
}
} else if (event == EVENT_VALCHANGE) {
- int top, bottom, halfway, i;
+ int i;
if (ctrl == ssd->editbox) {
dlg_editbox_get(ctrl, dlg, savedsession,
SAVEDSESSION_LEN);
- top = ssd->sesslist.nsessions;
- bottom = -1;
- while (top-bottom > 1) {
- halfway = (top+bottom)/2;
- i = strcmp(savedsession, ssd->sesslist.sessions[halfway]);
- if (i <= 0 ) {
- top = halfway;
- } else {
- bottom = halfway;
- }
- }
- if (top == ssd->sesslist.nsessions) {
- top -= 1;
- }
- dlg_listbox_select(ssd->listbox, dlg, top);
+ /*
+ * Save string that was typed into the textbox and
+ * save it into ssd->filterstr. We convert the string
+ * to lowercase for a case insensitive matching.
+ */
+ for (i = 0; i < SAVEDSESSION_LEN; i++) {
+ ssd->filterstr[i] = tolower(savedsession[i]);
+ }
+ // Refreshing listbox.
+ dlg_refresh(ssd->listbox, dlg);
}
} else if (event == EVENT_ACTION) {
int mbl = FALSE;
"Load, save or delete a stored session");
ctrl_columns(s, 2, 75, 25);
get_sesslist(&ssd->sesslist, TRUE);
- ssd->editbox = ctrl_editbox(s, "Saved Sessions", 'e', 100,
+ ssd->editbox = ctrl_editbox(s, "Saved Sessions / Search", 'e', 100,
HELPCTX(session_saved),
sessionsaver_handler, P(ssd), P(NULL));
ssd->editbox->generic.column = 0;