Mercurial > hg
comparison mcabber/src/screen.c @ 503:ddec224c2318
MUC: nickname completion
This patch adds nickname completion in a room (at the beginning of a line).
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 31 Oct 2005 22:35:35 +0100 |
parents | baa812f04f24 |
children | 5a2132ba2220 |
comparison
equal
deleted
inserted
replaced
502:3134b4960cdb | 503:ddec224c2318 |
---|---|
1361 check_offset(-1); | 1361 check_offset(-1); |
1362 } | 1362 } |
1363 | 1363 |
1364 // which_row() | 1364 // which_row() |
1365 // Tells which row our cursor is in, in the command line. | 1365 // Tells which row our cursor is in, in the command line. |
1366 // -1 -> normal text | 1366 // -2 -> normal text |
1367 // -1 -> room: nickname completion | |
1367 // 0 -> command | 1368 // 0 -> command |
1368 // 1 -> parameter 1 (etc.) | 1369 // 1 -> parameter 1 (etc.) |
1369 // If > 0, then *p_row is set to the beginning of the row | 1370 // If > 0, then *p_row is set to the beginning of the row |
1370 static int which_row(char **p_row) | 1371 static int which_row(const char **p_row) |
1371 { | 1372 { |
1372 int row = -1; | 1373 int row = -1; |
1373 char *p; | 1374 char *p; |
1374 int quote = FALSE; | 1375 int quote = FALSE; |
1375 | 1376 |
1376 // Not a command? | 1377 // Not a command? |
1377 if ((ptr_inputline == inputLine) || (inputLine[0] != '/')) | 1378 if ((ptr_inputline == inputLine) || (inputLine[0] != '/')) { |
1378 return -1; | 1379 if (!current_buddy) return -2; |
1380 if (buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_ROOM) { | |
1381 *p_row = inputLine; | |
1382 return -1; | |
1383 } | |
1384 return -2; | |
1385 } | |
1379 | 1386 |
1380 // This is a command | 1387 // This is a command |
1381 row = 0; | 1388 row = 0; |
1382 for (p = inputLine ; p < ptr_inputline ; p++) { | 1389 for (p = inputLine ; p < ptr_inputline ; p++) { |
1383 if (quote) { | 1390 if (quote) { |
1420 // Function called when tab is pressed. | 1427 // Function called when tab is pressed. |
1421 // Initiate or continue a completion... | 1428 // Initiate or continue a completion... |
1422 static void scr_handle_tab(void) | 1429 static void scr_handle_tab(void) |
1423 { | 1430 { |
1424 int nrow; | 1431 int nrow; |
1425 char *row; | 1432 const char *row; |
1426 const char *cchar; | 1433 const char *cchar; |
1427 guint compl_categ; | 1434 guint compl_categ; |
1428 | 1435 |
1429 nrow = which_row(&row); | 1436 nrow = which_row(&row); |
1430 | 1437 |
1431 // a) No completion if no leading slash ('cause not a command) | 1438 // a) No completion if no leading slash ('cause not a command), |
1439 // unless this is a room (then, it is a nickname completion) | |
1432 // b) We can't have more than 2 parameters (we use 2 flags) | 1440 // b) We can't have more than 2 parameters (we use 2 flags) |
1433 if (nrow < 0 || (nrow == 3 && !completion_started) || nrow > 3) return; | 1441 if ((nrow == -2) || (nrow == 3 && !completion_started) || nrow > 3) |
1434 | 1442 return; |
1435 if (nrow == 0) { // Command completion | 1443 |
1444 if (nrow == 0) { // Command completion | |
1436 row = &inputLine[1]; | 1445 row = &inputLine[1]; |
1437 compl_categ = COMPL_CMD; | 1446 compl_categ = COMPL_CMD; |
1438 } else { // Other completion, depending on the command | 1447 } else if (nrow == -1) { // Nickname completion |
1448 compl_categ = COMPL_RESOURCE; | |
1449 } else { // Other completion, depending on the command | |
1439 int alias = FALSE; | 1450 int alias = FALSE; |
1440 cmd *com; | 1451 cmd *com; |
1441 char *xpline = expandalias(inputLine); | 1452 char *xpline = expandalias(inputLine); |
1442 com = cmd_get(xpline); | 1453 com = cmd_get(xpline); |
1443 if (xpline != inputLine) { | 1454 if (xpline != inputLine) { |