Changeset 1411 for trunk/dll/dircnrs.c


Ignore:
Timestamp:
Mar 29, 2009, 10:33:07 PM (16 years ago)
Author:
Steven Levine
Message:

Rework extended container search to use common logic
Update docs to match code
Shift now reverses configured state of extended container search enable
Backslash optional in not ambiguous

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/dircnrs.c

    r1402 r1411  
    12261226        if ((shiftstate & KC_CTRL) == KC_CTRL)
    12271227          PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_MKDIR, 0), MPVOID);
     1228        // Alt-Insert - create file
    12281229        else if ((shiftstate & KC_ALT) == KC_ALT)
    12291230          PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_CREATE, 0), MPVOID);
     
    12391240      case VK_HOME:
    12401241        if ((shiftstate & KC_CTRL) == KC_CTRL && dcd) {
    1241 
    12421242          CHAR s[CCHMAXPATH], *p;
    1243 
    12441243          strcpy(s, dcd->directory);
    12451244          p = strchr(s, '\\');
     
    12591258          PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DELETE, 0), MPVOID);
    12601259        break;
    1261       }
    1262     }
    1263     if (shiftstate || fNoSearch)
    1264       break;
    1265     if (SHORT1FROMMP(mp1) & KC_CHAR) {
    1266 
    1267       ULONG thistime, len;
    1268       SEARCHSTRING srch;
    1269       PCNRITEM pci;
    1270 
    1271       if (!dcd)
    1272         break;
    1273       switch (SHORT1FROMMP(mp2)) {
    1274       case '\x1b':
    1275       case '\r':
    1276       case '\n':
    1277         dcd->lasttime = 0;
    1278         *dcd->szCommonName = 0;
    1279         break;
    1280       default:
    1281         thistime = WinQueryMsgTime(WinQueryAnchorBlock(hwnd));
    1282         if (thistime > dcd->lasttime + 1250)
    1283           *dcd->szCommonName = 0;
    1284         dcd->lasttime = thistime;
    1285         if (SHORT1FROMMP(mp2) == ' ' && !dcd->szCommonName)
    1286           break;
    1287       KbdRetry:
    1288         len = strlen(dcd->szCommonName);
    1289         if (len >= CCHMAXPATH - 1) {
    1290           *dcd->szCommonName = 0;
    1291           len = 0;
    1292         }
    1293         dcd->szCommonName[len] = toupper(SHORT1FROMMP(mp2));
    1294         dcd->szCommonName[len + 1] = 0;
    1295         memset(&srch, 0, sizeof(SEARCHSTRING));
    1296         srch.cb = (ULONG) sizeof(SEARCHSTRING);
    1297         srch.pszSearch = (PSZ) dcd->szCommonName;
    1298         srch.fsPrefix = TRUE;
    1299         srch.fsCaseSensitive = FALSE;
    1300         srch.usView = CV_ICON;
    1301         pci = WinSendMsg(hwnd, CM_SEARCHSTRING, MPFROMP(&srch),
    1302                          MPFROMLONG(CMA_FIRST));
    1303         if (pci && (INT) pci != -1) {
    1304 
    1305           USHORT attrib = CRA_CURSORED;
    1306 
    1307           /* make found item current item */
    1308           if (!stricmp(pci->pszFileName, dcd->szCommonName))
    1309             attrib |= CRA_SELECTED;
    1310           WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
    1311                      MPFROM2SHORT(TRUE, attrib));
    1312           /* make sure that record shows in viewport */
    1313           ShowCnrRecord(hwnd, (PMINIRECORDCORE) pci);
    1314           return (MRESULT) TRUE;
    1315         }
    1316         else {
    1317           if (SHORT1FROMMP(mp2) == ' ') {
    1318             dcd->szCommonName[len] = 0;
    1319             break;
    1320           }
    1321           *dcd->szCommonName = 0;
    1322           dcd->lasttime = 0;
    1323           if (len)                      // retry as first letter if no match
    1324             goto KbdRetry;
    1325         }
    1326         break;
    1327       }
    1328     }
    1329     break;
     1260      } // switch
     1261    }
     1262
     1263    if (SearchContainer(hwnd, msg, mp1, mp2))
     1264      return (MRESULT)TRUE;             // Avoid default handler
     1265    break;                              // Let default handler see key too
    13301266
    13311267  case WM_MOUSEMOVE:
     
    15071443            if (fSplitStatus && hwndStatus2) {
    15081444              CommaFmtULL(tb, sizeof(tb), pci->cbFile + pci->easize, ' ');
    1509               if (!fMoreButtons) {
    1510                 DateFormat(szDate, pci->date);
     1445              if (!fMoreButtons) {
     1446                DateFormat(szDate, pci->date);
    15111447                sprintf(s, " %s  %s %02u%s%02u%s%02u  [%s]  %s",
    15121448                        tb,
    15131449                        szDate,
    1514                         pci->time.hours,
    1515                         TimeSeparator,
    1516                         pci->time.minutes,
    1517                         TimeSeparator,
     1450                        pci->time.hours,
     1451                        TimeSeparator,
     1452                        pci->time.minutes,
     1453                        TimeSeparator,
    15181454                        pci->time.seconds,
    1519                         pci->pszDispAttr, pci->pszFileName);
    1520               }
     1455                        pci->pszDispAttr, pci->pszFileName);
     1456              }
    15211457              else {
    15221458                *tf = 0;
     
    15331469              WinSetWindowText(hwndStatus2, NullStr);
    15341470            if (fMoreButtons) {
    1535               WinSetWindowText(hwndName, pci->pszFileName);
    1536               DateFormat(szDate, pci->date);
     1471              WinSetWindowText(hwndName, pci->pszFileName);
     1472              DateFormat(szDate, pci->date);
    15371473              sprintf(s, "%s %02u%s%02u%s%02u",
    1538                       szDate,
    1539                       pci->time.hours, TimeSeparator,
    1540                       pci->time.minutes, TimeSeparator,
    1541                       pci->time.seconds);
     1474                      szDate,
     1475                      pci->time.hours, TimeSeparator,
     1476                      pci->time.minutes, TimeSeparator,
     1477                      pci->time.seconds);
    15421478              WinSetWindowText(hwndDate, s);
    15431479              WinSetWindowText(hwndAttr, pci->pszDispAttr);
     
    28352771                Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    28362772                          GetPString(IDS_CANTFINDDIRTEXT),
    2837                           pci->pszFileName);
    2838                 if (!fErrorBeepOff)
     2773                          pci->pszFileName);
     2774                if (!fErrorBeepOff)
    28392775                  DosBeep(250,100);
    28402776                driveserial[toupper(*pci->pszFileName) - 'A'] = -1;
     
    33313267                if (fSplitStatus && hwndStatus2) {
    33323268                  CommaFmtULL(tb, sizeof(tb), pci->cbFile + pci->easize, ' ');
    3333                   if (!fMoreButtons) {
    3334                     CHAR date[11];
    3335 
    3336                     DateFormat(date, pci->date);
     3269                  if (!fMoreButtons) {
     3270                    CHAR date[11];
     3271
     3272                    DateFormat(date, pci->date);
    33373273                    sprintf(s, " %s  %s %02u%s%02u%s%02u  [%s]  %s",
    33383274                            tb, date, pci->time.hours, TimeSeparator,
     
    33523288                  WinSetWindowText(hwndStatus2, s);
    33533289                }
    3354                 if (fMoreButtons) {
    3355                   CHAR szDate[DATE_BUF_BYTES];
    3356 
    3357                   WinSetWindowText(hwndName, pci->pszFileName);
    3358                   DateFormat(szDate, pci->date);
     3290                if (fMoreButtons) {
     3291                  CHAR szDate[DATE_BUF_BYTES];
     3292
     3293                  WinSetWindowText(hwndName, pci->pszFileName);
     3294                  DateFormat(szDate, pci->date);
    33593295                  sprintf(s, "%s %02u%s%02u%s%02u",
    3360                           szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
     3296                          szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
    33613297                          TimeSeparator, pci->time.seconds);
    33623298                  WinSetWindowText(hwndDate, s);
     
    35873523}
    35883524
     3525/**
     3526 * Search container for matching text
     3527 * @return TRUE if key completely handled here
     3528 */
     3529
     3530MRESULT EXPENTRY SearchContainer(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     3531{
     3532  DIRCNRDATA *dcd = INSTDATA(hwnd);
     3533  ULONG thistime;
     3534  UINT len;
     3535  SEARCHSTRING srch;
     3536  PCNRITEM pci;
     3537  USHORT key;
     3538
     3539  if (!dcd)
     3540    return FALSE;
     3541
     3542  // Just to be safe, caller has probably already checked
     3543  if (SHORT1FROMMP(mp1) & KC_KEYUP)
     3544    return FALSE;
     3545
     3546  // Just to be safe, caller has probably already cached
     3547  shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
     3548
     3549  // If not plain character or suppressed
     3550  // Shift toggles configured setting
     3551  if (shiftstate & (KC_ALT | KC_CTRL) || (shiftstate & KC_SHIFT ? !fNoSearch : fNoSearch))
     3552    return FALSE;
     3553
     3554  if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
     3555    key = SHORT2FROMMP(mp2);
     3556    if (key == VK_BACKSPACE)
     3557      key = '\x8';
     3558    else if (key == VK_ESC)
     3559      key = '\x1b';
     3560    else
     3561      return FALSE;
     3562  }
     3563  else if (SHORT1FROMMP(mp1) & KC_CHAR)
     3564    key = SHORT1FROMMP(mp2);
     3565  else
     3566    return FALSE;
     3567
     3568  thistime = WinQueryMsgTime(WinQueryAnchorBlock(hwnd));
     3569  if (thistime > dcd->lasttime + 1500)
     3570    *dcd->szCommonName = 0;             // 1.5 seconds
     3571  dcd->lasttime = thistime;
     3572
     3573  switch (key) {
     3574  case '\x1b':                  // Esc
     3575    *dcd->szCommonName = 0;
     3576    break;
     3577  default:
     3578    if (key == ' ' && !*dcd->szCommonName)
     3579      break;                    // Let PM see space to allow select toggle
     3580    len = strlen(dcd->szCommonName);
     3581    if (key == '\x8') {
     3582      // Backspace
     3583      if (len) {
     3584        len--;
     3585        dcd->szCommonName[len] = 0;     // Chop
     3586      }
     3587    }
     3588    else {
     3589      if (len >= CCHMAXPATH - 1) {
     3590        if (!fErrorBeepOff)
     3591          DosBeep(250,100);
     3592          // WinAlarm(hwnd,WA_WARNING);
     3593      }
     3594      else {
     3595        dcd->szCommonName[len] = toupper(key);
     3596        dcd->szCommonName[len + 1] = 0;
     3597      }
     3598    }
     3599    // Case insensitive search
     3600    memset(&srch, 0, sizeof(SEARCHSTRING));
     3601    srch.cb = (ULONG) sizeof(SEARCHSTRING);
     3602    srch.pszSearch = (PSZ) dcd->szCommonName;
     3603    srch.fsPrefix = TRUE;
     3604    srch.fsCaseSensitive = FALSE;
     3605    srch.usView = CV_ICON;
     3606    pci = WinSendMsg(hwnd, CM_SEARCHSTRING, MPFROMP(&srch),
     3607                     MPFROMLONG(CMA_FIRST));
     3608    if (pci && (INT) pci != -1) {
     3609      /* Got match make found item current item */
     3610      USHORT attrib = CRA_CURSORED;
     3611      if (!stricmp(pci->pszDisplayName, dcd->szCommonName))
     3612        attrib |= CRA_SELECTED;
     3613      WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
     3614                 MPFROM2SHORT(TRUE, attrib));
     3615      /* make sure that record shows in viewport */
     3616      ShowCnrRecord(hwnd, (PMINIRECORDCORE) pci);
     3617      return (MRESULT)TRUE;
     3618    }
     3619    else {
     3620      if (key == ' ')
     3621        return FALSE;                   // Let PM see space to toggle select
     3622      // No match
     3623      // Erase non-matching last character, len is not yet incremented
     3624      dcd->szCommonName[len] = 0;
     3625      if (len == 0 && key != '\\') {
     3626        // Let's see if user forgot leading backslash
     3627        // key = SHORT1FROMMP(mp2);
     3628        if (SearchContainer(hwnd, msg, mp1, MPFROM2SHORT('\\', 0))) {
     3629          if (SearchContainer(hwnd, msg, mp1, mp2))
     3630            return (MRESULT)TRUE;
     3631        }
     3632      }
     3633#if 0 // 15 Mar 09 SHL fixme to not hang
     3634      if (!fErrorBeepOff)
     3635        DosBeep(250,100);
     3636        // WinAlarm(hwnd,WA_WARNING);
     3637#endif
     3638    }
     3639  } // switch
     3640
     3641  return FALSE;                         // Let PM see key
     3642}
     3643
    35893644HWND StartDirCnr(HWND hwndParent, CHAR * directory, HWND hwndRestore,
    35903645                 ULONG flags)
Note: See TracChangeset for help on using the changeset viewer.