comparison src/netbeans.c @ 33:f6033dcbaf31

updated for version 7.0020
author vimboss
date Sun, 24 Oct 2004 19:18:58 +0000
parents ce185ac4a252
children 125e80798a85
comparison
equal deleted inserted replaced
32:41f9fd58cf13 33:f6033dcbaf31
60 #define GUARDED 10000 /* typenr for "guarded" annotation */ 60 #define GUARDED 10000 /* typenr for "guarded" annotation */
61 #define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */ 61 #define GUARDEDOFFSET 1000000 /* base for "guarded" sign id's */
62 62
63 /* The first implementation (working only with Netbeans) returned "1.1". The 63 /* The first implementation (working only with Netbeans) returned "1.1". The
64 * protocol implemented here also supports A-A-P. */ 64 * protocol implemented here also supports A-A-P. */
65 static char *ExtEdProtocolVersion = "2.2"; 65 static char *ExtEdProtocolVersion = "2.3";
66 66
67 static long pos2off __ARGS((buf_T *, pos_T *)); 67 static long pos2off __ARGS((buf_T *, pos_T *));
68 static pos_T *off2pos __ARGS((buf_T *, long)); 68 static pos_T *off2pos __ARGS((buf_T *, long));
69 static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp)); 69 static pos_T *get_off_or_lnum __ARGS((buf_T *buf, char_u **argp));
70 static long get_buf_size __ARGS((buf_T *)); 70 static long get_buf_size __ARGS((buf_T *));
71 static void netbeans_keystring __ARGS((int key, char *keystr));
72 static void special_keys __ARGS((char_u *args));
71 73
72 static void netbeans_connect __ARGS((void)); 74 static void netbeans_connect __ARGS((void));
73 static int getConnInfo __ARGS((char *file, char **host, char **port, char **password)); 75 static int getConnInfo __ARGS((char *file, char **host, char **port, char **password));
74 76
75 static void nb_init_graphics __ARGS((void)); 77 static void nb_init_graphics __ARGS((void));
100 #endif 102 #endif
101 static int cmdno; /* current command number for reply */ 103 static int cmdno; /* current command number for reply */
102 static int haveConnection = FALSE; /* socket is connected and 104 static int haveConnection = FALSE; /* socket is connected and
103 initialization is done */ 105 initialization is done */
104 static int oldFire = 1; 106 static int oldFire = 1;
105 static int exit_delay = 2; /* exit delay in seconds */
106 107
107 #ifdef FEAT_BEVAL 108 #ifdef FEAT_BEVAL
108 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA) 109 # if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
109 extern Widget textArea; 110 extern Widget textArea;
110 # endif 111 # endif
111 BalloonEval *balloonEval = NULL; 112 BalloonEval *balloonEval = NULL;
112 #endif 113 #endif
113 114
115 #ifdef FEAT_GUI_MOTIF
116 static void netbeans_Xt_connect __ARGS((void *context));
117 #else
118 # ifdef FEAT_GUI_GTK
119 static void netbeans_gtk_connect __ARGS((void));
120 # else
121 # ifdef FEAT_GUI_W32
122 static void netbeans_w32_connect __ARGS((void));
123 # endif
124 # endif
125 #endif
126
127 static int dosetvisible = FALSE;
128
114 /* 129 /*
115 * Include the debugging code if wanted. 130 * Include the debugging code if wanted.
116 */ 131 */
117 #ifdef NBDEBUG 132 #ifdef NBDEBUG
118 # include "nbdebug.c" 133 # include "nbdebug.c"
119 #endif 134 #endif
120 135
121 /* Connect back to Netbeans process */ 136 /* Connect back to Netbeans process */
122 #if defined(FEAT_GUI_MOTIF) || defined(PROTO) 137 #ifdef FEAT_GUI_MOTIF
123 void 138 static void
124 netbeans_Xt_connect(void *context) 139 netbeans_Xt_connect(void *context)
125 { 140 {
126 netbeans_connect(); 141 netbeans_connect();
127 if (sd > 0) 142 if (sd > 0)
128 { 143 {
146 sd = -1; 161 sd = -1;
147 haveConnection = FALSE; 162 haveConnection = FALSE;
148 } 163 }
149 #endif /* FEAT_MOTIF_GUI */ 164 #endif /* FEAT_MOTIF_GUI */
150 165
151 #if defined(FEAT_GUI_GTK) || defined(PROTO) 166 #ifdef FEAT_GUI_GTK
152 void 167 static void
153 netbeans_gtk_connect(void) 168 netbeans_gtk_connect(void)
154 { 169 {
155 # ifdef FEAT_BEVAL 170 # ifdef FEAT_BEVAL
156 /* 171 /*
157 * Set up the Balloon Expression Evaluation area. 172 * Set up the Balloon Expression Evaluation area.
187 sd = -1; 202 sd = -1;
188 haveConnection = FALSE; 203 haveConnection = FALSE;
189 } 204 }
190 #endif /* FEAT_GUI_GTK */ 205 #endif /* FEAT_GUI_GTK */
191 206
192 #if defined(FEAT_GUI_W32) || defined(PROTO) 207 #ifdef FEAT_GUI_W32
193 void 208 void
194 netbeans_w32_connect(void) 209 netbeans_w32_connect(void)
195 { 210 {
196 netbeans_connect(); 211 netbeans_connect();
197 if (sd > 0) 212 if (sd > 0)
410 nb_send(buf, "netbeans_connect"); 425 nb_send(buf, "netbeans_connect");
411 426
412 sprintf(buf, "0:version=0 \"%s\"\n", ExtEdProtocolVersion); 427 sprintf(buf, "0:version=0 \"%s\"\n", ExtEdProtocolVersion);
413 nb_send(buf, "externaleditor_version"); 428 nb_send(buf, "externaleditor_version");
414 429
415 nbdebug(("netbeans_connect: Connection succeeded\n"));
416
417 /* nb_init_graphics(); delay until needed */ 430 /* nb_init_graphics(); delay until needed */
418 431
419 haveConnection = TRUE; 432 haveConnection = TRUE;
420 433
421 theend: 434 theend:
837 850
838 q = (char *)skipwhite((char_u *)q); 851 q = (char *)skipwhite((char_u *)q);
839 852
840 if (nb_do_cmd(bufno, (char_u *)verb, isfunc, cmdno, (char_u *)q) == FAIL) 853 if (nb_do_cmd(bufno, (char_u *)verb, isfunc, cmdno, (char_u *)q) == FAIL)
841 { 854 {
855 #ifdef NBDEBUG
856 /*
857 * This happens because the ExtEd can send a cammand or 2 after
858 * doing a stopDocumentListen command. It doesn't harm anything
859 * so I'm disabling it except for debugging.
860 */
842 nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd)); 861 nbdebug(("nb_parse_cmd: Command error for \"%s\"\n", cmd));
843 EMSG("E629: bad return from nb_do_cmd"); 862 EMSG("E629: bad return from nb_do_cmd");
863 #endif
844 } 864 }
845 } 865 }
846 866
847 struct nbbuf_struct 867 struct nbbuf_struct
848 { 868 {
849 buf_T *bufp; 869 buf_T *bufp;
850 unsigned int fireChanges:1; 870 unsigned int fireChanges:1;
851 unsigned int initDone:1; 871 unsigned int initDone:1;
872 unsigned int insertDone:1;
852 unsigned int modified:1; 873 unsigned int modified:1;
874 int nbbuf_number;
853 char *displayname; 875 char *displayname;
854 char_u *partial_line;
855 int *signmap; 876 int *signmap;
856 short_u signmaplen; 877 short_u signmaplen;
857 short_u signmapused; 878 short_u signmapused;
858 }; 879 };
859 880
869 890
870 static int mapsigntype __ARGS((nbbuf_T *, int localsigntype)); 891 static int mapsigntype __ARGS((nbbuf_T *, int localsigntype));
871 static void addsigntype __ARGS((nbbuf_T *, int localsigntype, char_u *typeName, 892 static void addsigntype __ARGS((nbbuf_T *, int localsigntype, char_u *typeName,
872 char_u *tooltip, char_u *glyphfile, 893 char_u *tooltip, char_u *glyphfile,
873 int usefg, int fg, int usebg, int bg)); 894 int usefg, int fg, int usebg, int bg));
895 static void print_read_msg __ARGS((nbbuf_T *buf));
896 static void print_save_msg __ARGS((nbbuf_T *buf, long nchars));
874 897
875 static int curPCtype = -1; 898 static int curPCtype = -1;
876 899
877 /* 900 /*
878 * Get the Netbeans buffer number for the specified buffer. 901 * Get the Netbeans buffer number for the specified buffer.
892 * Is this a NetBeans-owned buffer? 915 * Is this a NetBeans-owned buffer?
893 */ 916 */
894 int 917 int
895 isNetbeansBuffer(buf_T *bufp) 918 isNetbeansBuffer(buf_T *bufp)
896 { 919 {
897 return bufp->b_netbeans_file; 920 return usingNetbeans && bufp->b_netbeans_file;
898 } 921 }
899 922
900 /* 923 /*
901 * NetBeans and Vim have different undo models. In Vim, the file isn't 924 * NetBeans and Vim have different undo models. In Vim, the file isn't
902 * changed if changes are undone via the undo command. In NetBeans, once 925 * changed if changes are undone via the undo command. In NetBeans, once
907 * unmodified but NetBeans thinks it IS modified. 930 * unmodified but NetBeans thinks it IS modified.
908 */ 931 */
909 int 932 int
910 isNetbeansModified(buf_T *bufp) 933 isNetbeansModified(buf_T *bufp)
911 { 934 {
912 int bufno = nb_getbufno(bufp); 935 if (usingNetbeans && bufp->b_netbeans_file)
913 936 {
914 if (bufno > 0) 937 int bufno = nb_getbufno(bufp);
915 return buf_list[bufno].modified; 938
939 if (bufno > 0)
940 return buf_list[bufno].modified;
941 else
942 return FALSE;
943 }
916 else 944 else
917 return FALSE; 945 return FALSE;
918 } 946 }
919 947
920 /* 948 /*
1002 nbdebug(("EVT: %s", buf)); 1030 nbdebug(("EVT: %s", buf));
1003 /* nb_send(buf, "netbeans_end"); avoid "write failed" messages */ 1031 /* nb_send(buf, "netbeans_end"); avoid "write failed" messages */
1004 if (sd >= 0) 1032 if (sd >= 0)
1005 sock_write(sd, buf, STRLEN(buf)); /* ignore errors */ 1033 sock_write(sd, buf, STRLEN(buf)); /* ignore errors */
1006 } 1034 }
1007
1008 /* Give NetBeans a chance to write some clean-up cmds to the socket before
1009 * we close the connection. Other clients may set the delay to zero. */
1010 if (exit_delay > 0)
1011 sleep(exit_delay);
1012 } 1035 }
1013 1036
1014 /* 1037 /*
1015 * Send a message to netbeans. 1038 * Send a message to netbeans.
1016 */ 1039 */
1047 char reply[32]; 1070 char reply[32];
1048 1071
1049 if (!haveConnection) 1072 if (!haveConnection)
1050 return; 1073 return;
1051 1074
1075 nbdebug(("REP %d: <none>\n", cmdno));
1076
1052 sprintf(reply, "%d\n", cmdno); 1077 sprintf(reply, "%d\n", cmdno);
1053
1054 nbdebug((" REPLY: %s", reply));
1055
1056 nb_send(reply, "nb_reply_nil"); 1078 nb_send(reply, "nb_reply_nil");
1057 } 1079 }
1058 1080
1059 1081
1060 /* 1082 /*
1067 char_u *reply; 1089 char_u *reply;
1068 1090
1069 if (!haveConnection) 1091 if (!haveConnection)
1070 return; 1092 return;
1071 1093
1094 nbdebug(("REP %d: %s\n", cmdno, (char *)result));
1095
1072 reply = alloc(STRLEN(result) + 32); 1096 reply = alloc(STRLEN(result) + 32);
1073 sprintf((char *)reply, "%d %s\n", cmdno, (char *)result); 1097 sprintf((char *)reply, "%d %s\n", cmdno, (char *)result);
1074
1075 nbdebug((" REPLY: %s", reply));
1076 nb_send((char *)reply, "nb_reply_text"); 1098 nb_send((char *)reply, "nb_reply_text");
1077 1099
1078 vim_free(reply); 1100 vim_free(reply);
1079 } 1101 }
1080 1102
1088 char reply[32]; 1110 char reply[32];
1089 1111
1090 if (!haveConnection) 1112 if (!haveConnection)
1091 return; 1113 return;
1092 1114
1115 nbdebug(("REP %d: %ld\n", cmdno, result));
1116
1093 sprintf(reply, "%d %ld\n", cmdno, result); 1117 sprintf(reply, "%d %ld\n", cmdno, result);
1094
1095 nbdebug(("REPLY: %s", reply));
1096
1097 nb_send(reply, "nb_reply_nr"); 1118 nb_send(reply, "nb_reply_nr");
1098 } 1119 }
1099 1120
1100 1121
1101 /* 1122 /*
1275 retval = FAIL; 1296 retval = FAIL;
1276 } 1297 }
1277 else 1298 else
1278 { 1299 {
1279 len = get_buf_size(buf->bufp); 1300 len = get_buf_size(buf->bufp);
1280 /* adjust for a partial last line */
1281 if (buf->partial_line != NULL)
1282 {
1283 nbdebug((" Adjusting buffer len for partial last line: %d\n",
1284 STRLEN(buf->partial_line)));
1285 len += STRLEN(buf->partial_line);
1286 }
1287 } 1301 }
1288 nb_reply_nr(cmdno, len); 1302 nb_reply_nr(cmdno, len);
1289 /* =====================================================================*/ 1303 /* =====================================================================*/
1290 } 1304 }
1291 else if (streq((char *)cmd, "getText")) 1305 else if (streq((char *)cmd, "getText"))
1325 { 1339 {
1326 STRCPY(p, line); 1340 STRCPY(p, line);
1327 p += STRLEN(line); 1341 p += STRLEN(line);
1328 *p++ = '\\'; 1342 *p++ = '\\';
1329 *p++ = 'n'; 1343 *p++ = 'n';
1344 vim_free(line);
1330 } 1345 }
1331 vim_free(line);
1332 } 1346 }
1333 *p++ = '\"'; 1347 *p++ = '\"';
1334 *p = '\0'; 1348 *p = '\0';
1335 } 1349 }
1336 } 1350 }
1446 { 1460 {
1447 pos_T *pos; 1461 pos_T *pos;
1448 pos_T mypos; 1462 pos_T mypos;
1449 char_u *to_free; 1463 char_u *to_free;
1450 char_u *nl; 1464 char_u *nl;
1451 int lnum; 1465 linenr_T lnum;
1452 pos_T old_w_cursor; 1466 pos_T old_w_cursor;
1453 int old_b_changed; 1467 int old_b_changed;
1454 1468
1455 if (skip >= SKIP_STOP) 1469 if (skip >= SKIP_STOP)
1456 { 1470 {
1465 args = (char_u *)cp; 1479 args = (char_u *)cp;
1466 1480
1467 /* get text to be inserted */ 1481 /* get text to be inserted */
1468 args = skipwhite(args); 1482 args = skipwhite(args);
1469 args = to_free = (char_u *)nb_unquote(args, NULL); 1483 args = to_free = (char_u *)nb_unquote(args, NULL);
1484 /*
1485 nbdebug((" CHUNK[%d]: %d bytes at offset %d\n",
1486 buf->bufp->b_ml.ml_line_count, STRLEN(args), off));
1487 */
1470 1488
1471 if (buf == NULL || buf->bufp == NULL) 1489 if (buf == NULL || buf->bufp == NULL)
1472 { 1490 {
1473 nbdebug((" null bufp in insert")); 1491 nbdebug((" null bufp in insert"));
1474 EMSG("E635: null bufp in insert"); 1492 EMSG("E635: null bufp in insert");
1475 retval = FAIL; 1493 retval = FAIL;
1476 } 1494 }
1477 else if (args != NULL) 1495 else if (args != NULL)
1478 { 1496 {
1479 /* We need to detect EOL style 1497 /*
1498 * We need to detect EOL style
1480 * because addAnno passes char-offset 1499 * because addAnno passes char-offset
1481 */ 1500 */
1482 int ff_detected = EOL_UNKNOWN; 1501 int ff_detected = EOL_UNKNOWN;
1483 int buf_was_empty = (buf->bufp->b_ml.ml_flags & ML_EMPTY); 1502 int buf_was_empty = (buf->bufp->b_ml.ml_flags & ML_EMPTY);
1503 char_u lbuf[4096]; /* size of largest insert sent by exted */
1504 int lbuf_len = 0;
1484 1505
1485 oldFire = netbeansFireChanges; 1506 oldFire = netbeansFireChanges;
1486 netbeansFireChanges = 0; 1507 netbeansFireChanges = 0;
1508 lbuf[0] = '\0';
1487 1509
1488 if (curbuf != buf->bufp) 1510 if (curbuf != buf->bufp)
1489 set_curbuf(buf->bufp, DOBUF_GOTO); 1511 set_curbuf(buf->bufp, DOBUF_GOTO);
1490 old_b_changed = buf->bufp->b_changed; 1512 old_b_changed = buf->bufp->b_changed;
1491 1513
1492 if (buf->partial_line != NULL)
1493 {
1494 nbdebug((" Combining with partial line\n"));
1495 off -= STRLEN(buf->partial_line);
1496 pos = off2pos(buf->bufp, off);
1497 if (pos && pos->col != 0)
1498 off -= pos->col; /* want start of line */
1499 buf->partial_line = vim_realloc(buf->partial_line,
1500 STRLEN(buf->partial_line) + STRLEN(args) + 1);
1501 STRCAT(buf->partial_line, args);
1502 vim_free(to_free);
1503 args = buf->partial_line;
1504 buf->partial_line = NULL;
1505 to_free = args;
1506 }
1507 pos = off2pos(buf->bufp, off); 1514 pos = off2pos(buf->bufp, off);
1508 if (pos) 1515 if (pos)
1509 { 1516 {
1510 if (pos->lnum == 0) 1517 if (pos->lnum == 0)
1511 pos->lnum = 1; 1518 pos->lnum = 1;
1512 nbdebug((" POSITION: line = %d, col = %d\n",
1513 pos->lnum, pos->col));
1514 } 1519 }
1515 else 1520 else
1516 { 1521 {
1517 /* if the given position is not found, assume we want 1522 /* if the given position is not found, assume we want
1518 * the end of the file. See setLocAndSize HACK. */ 1523 * the end of the file. See setLocAndSize HACK. */
1520 pos->col = 0; 1525 pos->col = 0;
1521 #ifdef FEAT_VIRTUALEDIT 1526 #ifdef FEAT_VIRTUALEDIT
1522 pos->coladd = 0; 1527 pos->coladd = 0;
1523 #endif 1528 #endif
1524 pos->lnum = buf->bufp->b_ml.ml_line_count; 1529 pos->lnum = buf->bufp->b_ml.ml_line_count;
1525 nbdebug((" POSITION: line = %d (EOF)\n", pos->lnum));
1526 } 1530 }
1527 lnum = pos->lnum; 1531 lnum = pos->lnum;
1528 old_w_cursor = curwin->w_cursor; 1532 old_w_cursor = curwin->w_cursor;
1529 curwin->w_cursor = *pos; 1533 curwin->w_cursor = *pos;
1530 1534
1535 if (buf->bufp->b_start_eol == FALSE && lnum > 0)
1536 {
1537 /* Append to a partial line */
1538 char_u *partial = ml_get(lnum);
1539
1540 if (partial != IObuff)
1541 STRCPY(lbuf, partial);
1542 lbuf_len = STRLEN(partial);
1543 ml_delete(lnum, FALSE);
1544 }
1545
1531 doupdate = 1; 1546 doupdate = 1;
1532 while (*args) 1547 while (*args)
1533 { 1548 {
1534 nl = (char_u *)strchr((char *)args, '\n'); 1549 nl = (char_u *)strchr((char *)args, '\n');
1535 if (!nl) 1550 if (nl)
1536 { 1551 {
1537 nbdebug((" PARTIAL[%d]: %s\n", lnum, args)); 1552 STRNCAT(lbuf, args, nl - args);
1538 break; 1553 lbuf[lbuf_len + nl - args] = '\0';
1554 args += nl - args + 1;
1539 } 1555 }
1540 /* EOL detecting. 1556 else
1541 * Not sure how to deal with '\n' on Mac 1557 {
1542 * it will fail already in nl = ... above 1558 STRCPY(lbuf, args);
1559 args += STRLEN(lbuf);
1560 }
1561
1562 /*
1563 * EOL detecting. Not sure how to deal with '\n' on Mac.
1543 */ 1564 */
1544 if (buf_was_empty && /* There is need to detect EOLs */ 1565 if (buf_was_empty && nl && *(nl - 1) != '\r')
1545 /* AND: string is empty */
1546 (args == nl
1547 /* OR hasn't '\r' at the end */
1548 || *(nl - 1) != '\r'))
1549 ff_detected = EOL_UNIX; 1566 ff_detected = EOL_UNIX;
1550 1567
1551 *nl = '\0'; 1568 /* nbdebug((" INSERT[%d]: %s\n", lnum, lbuf)); */
1552 nbdebug((" INSERT[%d]: %s\n", lnum, args)); 1569 ml_append((linenr_T)(lnum++ - 1), lbuf,
1553 ml_append((linenr_T)(lnum++ - 1), args, 1570 STRLEN(lbuf) + 1, FALSE);
1554 STRLEN(args) + 1, FALSE); 1571 lbuf[0] = '\0'; /* empty buffer */
1555 args = nl + 1; 1572 lbuf_len = 0;
1573 }
1574
1575 if (*(args - 1) == '\n')
1576 {
1577 buf->bufp->b_p_eol = TRUE;
1578 buf->bufp->b_start_eol = TRUE;
1579 }
1580 else
1581 {
1582 buf->bufp->b_p_eol = FALSE;
1583 buf->bufp->b_start_eol = FALSE;
1556 } 1584 }
1557 1585
1558 appended_lines_mark(pos->lnum - 1, lnum - pos->lnum); 1586 appended_lines_mark(pos->lnum - 1, lnum - pos->lnum);
1559 1587
1560 /* We can change initial ff without consequences 1588 /* We can change initial ff without consequences
1564 { 1592 {
1565 if (ff_detected == EOL_UNKNOWN) 1593 if (ff_detected == EOL_UNKNOWN)
1566 ff_detected = EOL_DOS; 1594 ff_detected = EOL_DOS;
1567 set_fileformat(ff_detected, OPT_LOCAL); 1595 set_fileformat(ff_detected, OPT_LOCAL);
1568 buf->bufp->b_start_ffc = *buf->bufp->b_p_ff; 1596 buf->bufp->b_start_ffc = *buf->bufp->b_p_ff;
1597 ml_delete(curbuf->b_ml.ml_line_count, FALSE);
1569 } 1598 }
1570 1599
1571 if (*args)
1572 {
1573 /*
1574 * Incomplete line, squirrel away and wait for next insert.
1575 */
1576 nbdebug((" PARTIAL-SAVED: %s\n", args));
1577 buf->partial_line = vim_realloc(buf->partial_line,
1578 STRLEN(args) + 1);
1579 STRCPY(buf->partial_line, args);
1580 }
1581 curwin->w_cursor = old_w_cursor; 1600 curwin->w_cursor = old_w_cursor;
1582 1601
1583 /* 1602 /*
1584 * XXX - GRP - Is the next line right? If I've inserted 1603 * XXX - GRP - Is the next line right? If I've inserted
1585 * text the buffer has been updated but not written. Will 1604 * text the buffer has been updated but not written. Will
1612 EMSG("E636: null buf in create"); 1631 EMSG("E636: null buf in create");
1613 return FAIL; 1632 return FAIL;
1614 } 1633 }
1615 vim_free(buf->displayname); 1634 vim_free(buf->displayname);
1616 buf->displayname = NULL; 1635 buf->displayname = NULL;
1617 nbdebug((" CREATE %d\n", bufno));
1618 1636
1619 netbeansReadFile = 0; /* don't try to open disk file */ 1637 netbeansReadFile = 0; /* don't try to open disk file */
1620 do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF); 1638 do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF);
1621 netbeansReadFile = 1; 1639 netbeansReadFile = 1;
1622 buf->bufp = curbuf; 1640 buf->bufp = curbuf;
1623 maketitle(); 1641 maketitle();
1642 buf->insertDone = FALSE;
1624 gui_update_menus(0); 1643 gui_update_menus(0);
1644 /* =====================================================================*/
1645 }
1646 else if (streq((char *)cmd, "insertDone"))
1647 {
1648 buf->bufp->b_start_eol = *args == 'T';
1649 buf->insertDone = TRUE;
1650 args += 2;
1651 buf->bufp->b_p_ro = *args == 'T';
1652 print_read_msg(buf);
1653 /* =====================================================================*/
1654 }
1655 else if (streq((char *)cmd, "saveDone"))
1656 {
1657 long savedChars = atol((char *) args);
1658 print_save_msg(buf, savedChars);
1625 /* =====================================================================*/ 1659 /* =====================================================================*/
1626 } 1660 }
1627 else if (streq((char *)cmd, "startDocumentListen")) 1661 else if (streq((char *)cmd, "startDocumentListen"))
1628 { 1662 {
1629 if (buf == NULL) 1663 if (buf == NULL)
1640 { 1674 {
1641 EMSG("E638: null buf in stopDocumentListen"); 1675 EMSG("E638: null buf in stopDocumentListen");
1642 return FAIL; 1676 return FAIL;
1643 } 1677 }
1644 buf->fireChanges = 0; 1678 buf->fireChanges = 0;
1645 if (buf->bufp != NULL 1679 if (buf->bufp != NULL)
1646 && buf->bufp->b_was_netbeans_file 1680 {
1647 && !buf->bufp->b_netbeans_file) 1681 if (buf->bufp->b_was_netbeans_file
1648 EMSGN(_("E658: NetBeans connection lost for buffer %ld"), 1682 && !buf->bufp->b_netbeans_file)
1683 EMSGN(_("E658: NetBeans connection lost for buffer %ld"),
1649 buf->bufp->b_fnum); 1684 buf->bufp->b_fnum);
1685 else
1686 {
1687 do_bufdel(DOBUF_DEL, (char_u *)"", 1, buf->bufp->b_fnum,
1688 buf->bufp->b_fnum, TRUE);
1689 /* add_to_input_buf((char_u *)"\f", 1); */
1690 vim_memset(buf, 0, sizeof(nbbuf_T));
1691 }
1692 }
1650 /* =====================================================================*/ 1693 /* =====================================================================*/
1651 } 1694 }
1652 else if (streq((char *)cmd, "setTitle")) 1695 else if (streq((char *)cmd, "setTitle"))
1653 { 1696 {
1654 if (buf == NULL) 1697 if (buf == NULL)
1656 EMSG("E639: null buf in setTitle"); 1699 EMSG("E639: null buf in setTitle");
1657 return FAIL; 1700 return FAIL;
1658 } 1701 }
1659 vim_free(buf->displayname); 1702 vim_free(buf->displayname);
1660 buf->displayname = nb_unquote(args, NULL); 1703 buf->displayname = nb_unquote(args, NULL);
1661 nbdebug((" SETTITLE %d %s\n", bufno, buf->displayname));
1662 /* =====================================================================*/ 1704 /* =====================================================================*/
1663 } 1705 }
1664 else if (streq((char *)cmd, "initDone")) 1706 else if (streq((char *)cmd, "initDone"))
1665 { 1707 {
1666 if (buf == NULL || buf->bufp == NULL) 1708 if (buf == NULL || buf->bufp == NULL)
1667 { 1709 {
1668 EMSG("E640: null buf in initDone"); 1710 EMSG("E640: null buf in initDone");
1669 return FAIL; 1711 return FAIL;
1670 } 1712 }
1671 doupdate = 1; 1713 doupdate = 1;
1672 buf->initDone = 1; 1714 buf->initDone = TRUE;
1673 if (curbuf != buf->bufp) 1715 if (curbuf != buf->bufp)
1674 set_curbuf(buf->bufp, DOBUF_GOTO); 1716 set_curbuf(buf->bufp, DOBUF_GOTO);
1675 #if defined(FEAT_AUTOCMD) 1717 #if defined(FEAT_AUTOCMD)
1676 apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp); 1718 apply_autocmds(EVENT_BUFREADPOST, 0, 0, FALSE, buf->bufp);
1677 #endif 1719 #endif
1681 /* =====================================================================*/ 1723 /* =====================================================================*/
1682 } 1724 }
1683 else if (streq((char *)cmd, "setBufferNumber") 1725 else if (streq((char *)cmd, "setBufferNumber")
1684 || streq((char *)cmd, "putBufferNumber")) 1726 || streq((char *)cmd, "putBufferNumber"))
1685 { 1727 {
1686 char_u *to_free; 1728 char_u *path;
1687 buf_T *bufp; 1729 buf_T *bufp;
1688 1730
1689 if (buf == NULL) 1731 if (buf == NULL)
1690 { 1732 {
1691 EMSG("E641: null buf in setBufferNumber"); 1733 EMSG("E641: null buf in setBufferNumber");
1692 return FAIL; 1734 return FAIL;
1693 } 1735 }
1694 to_free = (char_u *)nb_unquote(args, NULL); 1736 path = (char_u *)nb_unquote(args, NULL);
1695 if (to_free == NULL) 1737 if (path == NULL)
1696 return FAIL; 1738 return FAIL;
1697 bufp = buflist_findname(to_free); 1739 bufp = buflist_findname(path);
1698 vim_free(to_free); 1740 vim_free(path);
1699 if (bufp == NULL) 1741 if (bufp == NULL)
1700 { 1742 {
1701 EMSG2("E642: File %s not found in setBufferNumber", args); 1743 EMSG2("E642: File %s not found in setBufferNumber", args);
1702 return FAIL; 1744 return FAIL;
1703 } 1745 }
1704 buf->bufp = bufp; 1746 buf->bufp = bufp;
1747 buf->nbbuf_number = bufp->b_fnum;
1705 1748
1706 /* "setBufferNumber" has the side effect of jumping to the buffer 1749 /* "setBufferNumber" has the side effect of jumping to the buffer
1707 * (don't know why!). Don't do that for "putBufferNumber". */ 1750 * (don't know why!). Don't do that for "putBufferNumber". */
1708 if (*cmd != 'p') 1751 if (*cmd != 'p')
1709 coloncmd(":buffer %d", bufp->b_fnum); 1752 coloncmd(":buffer %d", bufp->b_fnum);
1710 else 1753 else
1711 { 1754 {
1712 buf->initDone = 1; 1755 buf->initDone = TRUE;
1713 1756
1714 /* handle any postponed key commands */ 1757 /* handle any postponed key commands */
1715 handle_key_queue(); 1758 handle_key_queue();
1716 } 1759 }
1717 1760
1729 EMSG("E643: null buf in setFullName"); 1772 EMSG("E643: null buf in setFullName");
1730 return FAIL; 1773 return FAIL;
1731 } 1774 }
1732 vim_free(buf->displayname); 1775 vim_free(buf->displayname);
1733 buf->displayname = nb_unquote(args, NULL); 1776 buf->displayname = nb_unquote(args, NULL);
1734 nbdebug((" SETFULLNAME %d %s\n", bufno, buf->displayname));
1735 1777
1736 netbeansReadFile = 0; /* don't try to open disk file */ 1778 netbeansReadFile = 0; /* don't try to open disk file */
1737 do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE, 1779 do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE,
1738 ECMD_HIDE + ECMD_OLDBUF); 1780 ECMD_HIDE + ECMD_OLDBUF);
1739 netbeansReadFile = 1; 1781 netbeansReadFile = 1;
1750 return FAIL; 1792 return FAIL;
1751 } 1793 }
1752 /* Edit a file: like create + setFullName + read the file. */ 1794 /* Edit a file: like create + setFullName + read the file. */
1753 vim_free(buf->displayname); 1795 vim_free(buf->displayname);
1754 buf->displayname = nb_unquote(args, NULL); 1796 buf->displayname = nb_unquote(args, NULL);
1755 nbdebug((" EDITFILE %d %s\n", bufno, buf->displayname));
1756 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE, 1797 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
1757 ECMD_HIDE + ECMD_OLDBUF); 1798 ECMD_HIDE + ECMD_OLDBUF);
1758 buf->bufp = curbuf; 1799 buf->bufp = curbuf;
1759 buf->initDone = 1; 1800 buf->initDone = TRUE;
1760 doupdate = 1; 1801 doupdate = 1;
1761 #if defined(FEAT_TITLE) 1802 #if defined(FEAT_TITLE)
1762 maketitle(); 1803 maketitle();
1763 #endif 1804 #endif
1764 gui_update_menus(0); 1805 gui_update_menus(0);
1769 if (buf == NULL || buf->bufp == NULL) 1810 if (buf == NULL || buf->bufp == NULL)
1770 { 1811 {
1771 /* EMSG("E645: null bufp in setVisible"); */ 1812 /* EMSG("E645: null bufp in setVisible"); */
1772 return FAIL; 1813 return FAIL;
1773 } 1814 }
1774 if (streq((char *)args, "T")) 1815 if (streq((char *)args, "T") && buf->bufp != curbuf)
1775 { 1816 {
1776 exarg_T exarg; 1817 exarg_T exarg;
1777 exarg.cmd = (char_u *)"goto"; 1818 exarg.cmd = (char_u *)"goto";
1778 exarg.forceit = FALSE; 1819 exarg.forceit = FALSE;
1820 dosetvisible = TRUE;
1779 goto_buffer(&exarg, DOBUF_FIRST, FORWARD, buf->bufp->b_fnum); 1821 goto_buffer(&exarg, DOBUF_FIRST, FORWARD, buf->bufp->b_fnum);
1780 doupdate = 1; 1822 doupdate = 1;
1823 dosetvisible = FALSE;
1781 1824
1782 /* Side effect!!!. */ 1825 /* Side effect!!!. */
1783 if (!gui.starting) 1826 if (!gui.starting)
1784 gui_mch_set_foreground(); 1827 gui_mch_set_foreground();
1785 }
1786 else
1787 {
1788 /* bury the buffer - not yet */
1789 } 1828 }
1790 /* =====================================================================*/ 1829 /* =====================================================================*/
1791 } 1830 }
1792 else if (streq((char *)cmd, "raise")) 1831 else if (streq((char *)cmd, "raise"))
1793 { 1832 {
1815 && mch_stat((char *)buf->bufp->b_ffname, &st) >= 0) 1854 && mch_stat((char *)buf->bufp->b_ffname, &st) >= 0)
1816 buf_store_time(buf->bufp, &st, buf->bufp->b_ffname); 1855 buf_store_time(buf->bufp, &st, buf->bufp->b_ffname);
1817 buf->bufp->b_changed = 0; 1856 buf->bufp->b_changed = 0;
1818 } 1857 }
1819 buf->modified = buf->bufp->b_changed; 1858 buf->modified = buf->bufp->b_changed;
1859 /* =====================================================================*/
1860 }
1861 else if (streq((char *)cmd, "setModtime"))
1862 {
1863 buf->bufp->b_mtime = atoi((char *) args);
1864 /* =====================================================================*/
1865 }
1866 else if (streq((char *)cmd, "setReadOnly"))
1867 {
1868 if (streq((char *)args, "T"))
1869 buf->bufp->b_p_ro = TRUE;
1870 else
1871 buf->bufp->b_p_ro = FALSE;
1820 /* =====================================================================*/ 1872 /* =====================================================================*/
1821 } 1873 }
1822 else if (streq((char *)cmd, "setMark")) 1874 else if (streq((char *)cmd, "setMark"))
1823 { 1875 {
1824 /* not yet */ 1876 /* not yet */
1888 gui_update_cursor(TRUE, FALSE); 1940 gui_update_cursor(TRUE, FALSE);
1889 gui_mch_flush(); 1941 gui_mch_flush();
1890 /* Quit a hit-return or more prompt. */ 1942 /* Quit a hit-return or more prompt. */
1891 if (State == HITRETURN || State == ASKMORE) 1943 if (State == HITRETURN || State == ASKMORE)
1892 { 1944 {
1893 add_to_input_buf((char_u *)"\003", 1); 1945 /* add_to_input_buf((char_u *)"\003", 1); */
1894 #ifdef FEAT_GUI_GTK 1946 #ifdef FEAT_GUI_GTK
1895 if (gtk_main_level() > 0) 1947 if (gtk_main_level() > 0)
1896 gtk_main_quit(); 1948 gtk_main_quit();
1897 #endif 1949 #endif
1898 } 1950 }
1929 nbdebug((" setStyle is obsolete!")); 1981 nbdebug((" setStyle is obsolete!"));
1930 /* =====================================================================*/ 1982 /* =====================================================================*/
1931 } 1983 }
1932 else if (streq((char *)cmd, "setExitDelay")) 1984 else if (streq((char *)cmd, "setExitDelay"))
1933 { 1985 {
1934 /* New in version 2.1. */ 1986 /* Only used in version 2.1. */
1935 cp = (char *)args;
1936 exit_delay = strtol(cp, &cp, 10);
1937 args = (char_u *)cp;
1938 /* =====================================================================*/ 1987 /* =====================================================================*/
1939 } 1988 }
1940 else if (streq((char *)cmd, "defineAnnoType")) 1989 else if (streq((char *)cmd, "defineAnnoType"))
1941 { 1990 {
1942 #ifdef FEAT_SIGNS 1991 #ifdef FEAT_SIGNS
2122 nbdebug((" no such start pos in %s, %ld\n", cmd, off)); 2171 nbdebug((" no such start pos in %s, %ld\n", cmd, off));
2123 else 2172 else
2124 { 2173 {
2125 first = *pos; 2174 first = *pos;
2126 pos = off2pos(buf->bufp, off + len - 1); 2175 pos = off2pos(buf->bufp, off + len - 1);
2127 if (pos != NULL && pos->col == 0) { 2176 if (pos != NULL && pos->col == 0)
2177 {
2128 /* 2178 /*
2129 * In Java Swing the offset is a position between 2 2179 * In Java Swing the offset is a position between 2
2130 * characters. If col == 0 then we really want the 2180 * characters. If col == 0 then we really want the
2131 * previous line as the end. 2181 * previous line as the end.
2132 */ 2182 */
2183 } 2233 }
2184 /* =====================================================================*/ 2234 /* =====================================================================*/
2185 } 2235 }
2186 else if (streq((char *)cmd, "save")) 2236 else if (streq((char *)cmd, "save"))
2187 { 2237 {
2238 /*
2239 * NOTE - This command is obsolete wrt NetBeans. Its left in
2240 * only for historical reasons.
2241 */
2188 if (buf == NULL || buf->bufp == NULL) 2242 if (buf == NULL || buf->bufp == NULL)
2189 { 2243 {
2190 nbdebug((" null bufp in %s command", cmd)); 2244 nbdebug((" null bufp in %s command", cmd));
2191 return FAIL; 2245 return FAIL;
2192 } 2246 }
2227 } 2281 }
2228 else 2282 else
2229 buf->bufp->b_netbeans_file = FALSE; 2283 buf->bufp->b_netbeans_file = FALSE;
2230 /* =====================================================================*/ 2284 /* =====================================================================*/
2231 } 2285 }
2286 else if (streq((char *)cmd, "specialKeys"))
2287 {
2288 special_keys(args);
2289 /* =====================================================================*/
2290 }
2291 else if (streq((char *)cmd, "actionMenuItem"))
2292 {
2293 /* not used yet */
2294 /* =====================================================================*/
2295 }
2232 else if (streq((char *)cmd, "version")) 2296 else if (streq((char *)cmd, "version"))
2233 { 2297 {
2234 nbdebug((" Version = %s\n", (char *) args)); 2298 /* not used yet */
2235 } 2299 }
2236 /* 2300 /*
2237 * Unrecognized command is ignored. 2301 * Unrecognized command is ignored.
2238 */ 2302 */
2239 } 2303 }
2240 if (inAtomic && doupdate) 2304 if (inAtomic && doupdate)
2241 { 2305 {
2242 needupdate = 1; 2306 needupdate = 1;
2243 doupdate = 0; 2307 doupdate = 0;
2244 } 2308 }
2309
2310 /*
2311 * Is this needed? I moved the netbeans_Xt_connect() later during startup
2312 * and it may no longer be necessary. If its not needed then needupdate
2313 * and doupdate can also be removed.
2314 */
2245 2315
2246 if (buf != NULL && buf->initDone && doupdate) 2316 if (buf != NULL && buf->initDone && doupdate)
2247 { 2317 {
2248 update_screen(NOT_VALID); 2318 update_screen(NOT_VALID);
2249 setcursor(); 2319 setcursor();
2251 gui_update_cursor(TRUE, FALSE); 2321 gui_update_cursor(TRUE, FALSE);
2252 gui_mch_flush(); 2322 gui_mch_flush();
2253 /* Quit a hit-return or more prompt. */ 2323 /* Quit a hit-return or more prompt. */
2254 if (State == HITRETURN || State == ASKMORE) 2324 if (State == HITRETURN || State == ASKMORE)
2255 { 2325 {
2256 add_to_input_buf((char_u *)"\003", 1); 2326 /* add_to_input_buf((char_u *)"\003", 1);*/
2257 #ifdef FEAT_GUI_GTK 2327 #ifdef FEAT_GUI_GTK
2258 if (gtk_main_level() > 0) 2328 if (gtk_main_level() > 0)
2259 gtk_main_quit(); 2329 gtk_main_quit();
2260 #endif 2330 #endif
2261 } 2331 }
2287 setcursor(); /* restore the cursor position */ 2357 setcursor(); /* restore the cursor position */
2288 out_flush(); /* make sure output has been written */ 2358 out_flush(); /* make sure output has been written */
2289 2359
2290 gui_update_cursor(TRUE, FALSE); 2360 gui_update_cursor(TRUE, FALSE);
2291 gui_mch_flush(); 2361 gui_mch_flush();
2362 }
2363
2364
2365 /*
2366 * Parse the specialKeys argument and issue the appropriate map commands.
2367 */
2368 static void
2369 special_keys(char_u *args)
2370 {
2371 char *save_str = nb_unquote(args, NULL);
2372 char *tok = strtok(save_str, " ");
2373 char *sep;
2374 char keybuf[64];
2375 char cmdbuf[256];
2376
2377 while (tok != NULL)
2378 {
2379 int i = 0;
2380
2381 if ((sep = strchr(tok, '-')) != NULL)
2382 {
2383 *sep = NULL;
2384 while (*tok)
2385 {
2386 switch (*tok)
2387 {
2388 case 'A':
2389 case 'M':
2390 case 'C':
2391 case 'S':
2392 keybuf[i++] = *tok;
2393 keybuf[i++] = '-';
2394 break;
2395 }
2396 tok++;
2397 }
2398 tok++;
2399 }
2400
2401 strcpy(&keybuf[i], tok);
2402 sprintf(cmdbuf, "<silent><%s> :nbkey %s<CR>", keybuf, keybuf);
2403 do_map(0, (char_u *)cmdbuf, NORMAL, FALSE);
2404 tok = strtok(NULL, " ");
2405 }
2406 vim_free(save_str);
2407 }
2408
2409
2410 void
2411 ex_nbkey(eap)
2412 exarg_T *eap;
2413 {
2414 netbeans_keystring(0, (char *)eap->arg);
2292 } 2415 }
2293 2416
2294 2417
2295 /* 2418 /*
2296 * Initialize highlights and signs for use by netbeans (mostly obsolete) 2419 * Initialize highlights and signs for use by netbeans (mostly obsolete)
2410 * length. */ 2533 * length. */
2411 if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL) 2534 if (text != NULL && text[0] != NUL && STRLEN(text) < MAXPATHL)
2412 { 2535 {
2413 p = nb_quote(text); 2536 p = nb_quote(text);
2414 if (p != NULL) 2537 if (p != NULL)
2538 {
2415 sprintf(buf, "0:balloonText=%d \"%s\"\n", cmdno, p); 2539 sprintf(buf, "0:balloonText=%d \"%s\"\n", cmdno, p);
2416 vim_free(p); 2540 vim_free(p);
2541 }
2417 nbdebug(("EVT: %s", buf)); 2542 nbdebug(("EVT: %s", buf));
2418 nb_send(buf, "netbeans_beval_cb"); 2543 nb_send(buf, "netbeans_beval_cb");
2419 } 2544 }
2420 vim_free(text); 2545 vim_free(text);
2421 } 2546 }
2427 */ 2552 */
2428 void 2553 void
2429 netbeans_startup_done(void) 2554 netbeans_startup_done(void)
2430 { 2555 {
2431 char *cmd = "0:startupDone=0\n"; 2556 char *cmd = "0:startupDone=0\n";
2557
2558 if (usingNetbeans)
2559 #ifdef FEAT_GUI_MOTIF
2560 netbeans_Xt_connect(app_context);
2561 #else
2562 # ifdef FEAT_GUI_GTK
2563 netbeans_gtk_connect();
2564 # endif
2565 #endif
2432 2566
2433 if (!haveConnection) 2567 if (!haveConnection)
2434 return; 2568 return;
2435 2569
2436 nbdebug(("EVT: %s", cmd)); 2570 nbdebug(("EVT: %s", cmd));
2459 # endif 2593 # endif
2460 # endif 2594 # endif
2461 #endif 2595 #endif
2462 } 2596 }
2463 2597
2598 /*
2599 * Tell netbeans that we're exiting. This should be called right
2600 * before calling exit.
2601 */
2602 void
2603 netbeans_send_disconnect()
2604 {
2605 char buf[128];
2606
2607 if (haveConnection)
2608 {
2609 sprintf(buf, "0:disconnect=%d\n", cmdno);
2610 nbdebug(("EVT: %s", buf));
2611 nb_send(buf, "netbeans_disconnect");
2612 }
2613 }
2614
2464 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_W32) || defined(PROTO) 2615 #if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_W32) || defined(PROTO)
2465 /* 2616 /*
2466 * Tell netbeans that the window was moved or resized. 2617 * Tell netbeans that the window was moved or resized.
2467 */ 2618 */
2468 void 2619 void
2473 if (!haveConnection) 2624 if (!haveConnection)
2474 return; 2625 return;
2475 2626
2476 sprintf(buf, "0:geometry=%d %d %d %d %d\n", 2627 sprintf(buf, "0:geometry=%d %d %d %d %d\n",
2477 cmdno, (int)Columns, (int)Rows, new_x, new_y); 2628 cmdno, (int)Columns, (int)Rows, new_x, new_y);
2478 nbdebug(("EVT: %s", buf)); 2629 /*nbdebug(("EVT: %s", buf)); happens too many times during a move */
2479 nb_send(buf, "netbeans_frame_moved"); 2630 nb_send(buf, "netbeans_frame_moved");
2480 } 2631 }
2481 #endif 2632 #endif
2482 2633
2483 /* 2634 /*
2484 * Tell netbeans the user opened a file. 2635 * Tell netbeans the user opened or activated a file.
2485 */ 2636 */
2486 void 2637 void
2487 netbeans_file_opened(char *filename) 2638 netbeans_file_activated(buf_T *bufp)
2488 { 2639 {
2640 int bufno = nb_getbufno(bufp);
2641 nbbuf_T *bp = nb_get_buf(bufno);
2489 char buffer[2*MAXPATHL]; 2642 char buffer[2*MAXPATHL];
2490 char_u *q; 2643 char_u *q;
2491 2644
2645 if (!haveConnection || dosetvisible)
2646 return;
2647
2648 q = nb_quote(bufp->b_ffname);
2649 if (q == NULL || bp == NULL || bufp == NULL)
2650 return;
2651
2652 sprintf(buffer, "%d:fileOpened=%d \"%s\" %s %s\n",
2653 bufno,
2654 bufno,
2655 (char *)q,
2656 "T", /* open in NetBeans */
2657 "F"); /* modified */
2658
2659 vim_free(q);
2660 nbdebug(("EVT: %s", buffer));
2661
2662 nb_send(buffer, "netbeans_file_opened");
2663 }
2664
2665 /*
2666 * Tell netbeans the user opened a file.
2667 */
2668 void
2669 netbeans_file_opened(buf_T *bufp)
2670 {
2671 int bufno = nb_getbufno(bufp);
2672 char buffer[2*MAXPATHL];
2673 char_u *q;
2674 nbbuf_T *bp = nb_get_buf(nb_getbufno(bufp));
2675 int bnum;
2676
2492 if (!haveConnection) 2677 if (!haveConnection)
2493 return; 2678 return;
2494 2679
2495 q = nb_quote((char_u *)filename); 2680 q = nb_quote(bufp->b_ffname);
2496 if (q == NULL) 2681 if (q == NULL)
2497 return; 2682 return;
2498 sprintf(buffer, "0:fileOpened=%d \"%s\" %s %s\n", 2683 if (bp != NULL)
2684 bnum = bufno;
2685 else
2686 bnum = 0;
2687
2688 sprintf(buffer, "%d:fileOpened=%d \"%s\" %s %s\n",
2689 bnum,
2499 0, 2690 0,
2500 (char *)q, 2691 (char *)q,
2501 "T", /* open in NetBeans */ 2692 "T", /* open in NetBeans */
2502 "F"); /* modified */ 2693 "F"); /* modified */
2503 2694
2504 vim_free(q); 2695 vim_free(q);
2505 nbdebug(("EVT: %s", buffer)); 2696 nbdebug(("EVT: %s", buffer));
2506 2697
2507 nb_send(buffer, "netbeans_file_opened"); 2698 nb_send(buffer, "netbeans_file_opened");
2508 if (p_acd && vim_chdirfile((char_u *)filename) == OK) 2699 if (p_acd && vim_chdirfile(bufp->b_ffname) == OK)
2509 shorten_fnames(TRUE); 2700 shorten_fnames(TRUE);
2510 } 2701 }
2511 2702
2512 /* 2703 /*
2513 * Tell netbeans a file was closed. 2704 * Tell netbeans a file was closed.
2522 if (!haveConnection || bufno < 0) 2713 if (!haveConnection || bufno < 0)
2523 return; 2714 return;
2524 2715
2525 if (!netbeansCloseFile) 2716 if (!netbeansCloseFile)
2526 { 2717 {
2527 nbdebug(("ignoring file_closed for %s\n", bufp->b_ffname)); 2718 nbdebug(("Ignoring file_closed for %s. File was closed from IDE\n",
2719 bufp->b_ffname));
2528 return; 2720 return;
2529 } 2721 }
2530 2722
2531 nbdebug(("netbeans_file_closed() bufno = %d, file = %s, displayname = %s\n", 2723 nbdebug(("netbeans_file_closed:\n"));
2532 bufno, bufp->b_ffname, 2724 nbdebug((" Closing bufno: %d", bufno));
2533 (nbbuf != NULL) ? nbbuf->displayname : "<>")); 2725 if (curbuf != NULL && curbuf != bufp)
2726 {
2727 nbdebug((" Curbuf bufno: %d\n", nb_getbufno(curbuf)));
2728 }
2729 else if (curbuf == bufp)
2730 {
2731 nbdebug((" curbuf == bufp\n"));
2732 }
2534 2733
2535 if (bufno <= 0) 2734 if (bufno <= 0)
2536 return; 2735 return;
2537 2736
2538 sprintf(buffer, "%d:killed=%d\n", bufno, cmdno); 2737 sprintf(buffer, "%d:killed=%d\n", bufno, cmdno);
2577 void 2776 void
2578 netbeans_inserted( 2777 netbeans_inserted(
2579 buf_T *bufp, 2778 buf_T *bufp,
2580 linenr_T linenr, 2779 linenr_T linenr,
2581 colnr_T col, 2780 colnr_T col,
2582 int oldlen,
2583 char_u *txt, 2781 char_u *txt,
2584 int newlen) 2782 int newlen)
2585 { 2783 {
2586 char_u *buf; 2784 char_u *buf;
2587 int bufno; 2785 int bufno;
2593 2791
2594 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno); 2792 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
2595 if (nbbuf == NULL) 2793 if (nbbuf == NULL)
2596 return; 2794 return;
2597 2795
2598 nbbuf->modified = 1; 2796 /* Don't mark as modified for initial read */
2797 if (nbbuf->insertDone)
2798 nbbuf->modified = 1;
2599 2799
2600 pos.lnum = linenr; 2800 pos.lnum = linenr;
2601 pos.col = col; 2801 pos.col = col;
2602
2603 off = pos2off(bufp, &pos); 2802 off = pos2off(bufp, &pos);
2604
2605 /* nbdebug(("linenr = %d, col = %d, off = %ld\n", linenr, col, off)); */
2606
2607 buf = alloc(128 + 2*newlen);
2608
2609 if (oldlen > 0)
2610 {
2611 /* some chars were replaced; send "remove" EVT */
2612 sprintf((char *)buf, "%d:remove=%d %ld %d\n",
2613 bufno, cmdno, off, oldlen);
2614 nbdebug(("EVT: %s", buf));
2615 nb_send((char *)buf, "netbeans_inserted");
2616 }
2617 else if (oldlen < 0)
2618 {
2619 /* can't happen? */
2620 nbdebug(("unexpected: oldlen < 0 in netbeans_inserted"));
2621 }
2622 2803
2623 /* send the "insert" EVT */ 2804 /* send the "insert" EVT */
2624 newtxt = alloc(newlen + 1); 2805 newtxt = alloc(newlen + 1);
2625 STRNCPY(newtxt, txt, newlen); 2806 STRNCPY(newtxt, txt, newlen);
2626 newtxt[newlen] = '\0'; 2807 newtxt[newlen] = '\0';
2627 p = nb_quote(newtxt); 2808 p = nb_quote(newtxt);
2628 if (p != NULL) 2809 if (p != NULL)
2629 { 2810 {
2811 buf = alloc(128 + 2*newlen);
2630 sprintf((char *)buf, "%d:insert=%d %ld \"%s\"\n", bufno, cmdno, off, p); 2812 sprintf((char *)buf, "%d:insert=%d %ld \"%s\"\n", bufno, cmdno, off, p);
2631 nbdebug(("EVT: %s", buf)); 2813 nbdebug(("EVT: %s", buf));
2632 nb_send((char *)buf, "netbeans_inserted"); 2814 nb_send((char *)buf, "netbeans_inserted");
2633 } 2815 vim_free(p);
2634 vim_free(p); 2816 vim_free(buf);
2817 }
2635 vim_free(newtxt); 2818 vim_free(newtxt);
2636 vim_free(buf);
2637 } 2819 }
2638 2820
2639 /* 2821 /*
2640 * Tell netbeans some bytes have been removed. 2822 * Tell netbeans some bytes have been removed.
2641 */ 2823 */
2730 } 2912 }
2731 2913
2732 2914
2733 /* 2915 /*
2734 * Send a keypress event back to netbeans. This usualy simulates some 2916 * Send a keypress event back to netbeans. This usualy simulates some
2735 * kind of function key press. 2917 * kind of function key press. This function operates on a key code.
2736 */ 2918 */
2737 void 2919 void
2738 netbeans_keycommand(int key) 2920 netbeans_keycommand(int key)
2739 { 2921 {
2922 char keyName[60];
2923
2924 netbeans_keyname(key, keyName);
2925 netbeans_keystring(key, keyName);
2926 }
2927
2928
2929 /*
2930 * Send a keypress event back to netbeans. This usualy simulates some
2931 * kind of function key press. This function operates on a key string.
2932 */
2933 static void
2934 netbeans_keystring(int key, char *keyName)
2935 {
2740 char buf[2*MAXPATHL]; 2936 char buf[2*MAXPATHL];
2741 int bufno; 2937 int bufno = nb_getbufno(curbuf);
2742 char keyName[60];
2743 long off; 2938 long off;
2744 char_u *q; 2939 char_u *q;
2745 2940
2746 if (!haveConnection) 2941 if (!haveConnection)
2747 return; 2942 return;
2748 2943
2749 /* convert key to netbeans name */
2750 netbeans_keyname(key, keyName);
2751
2752 bufno = nb_getbufno(curbuf);
2753 2944
2754 if (bufno == -1) 2945 if (bufno == -1)
2755 { 2946 {
2756 nbdebug(("got keycommand for non-NetBeans buffer, opening...\n")); 2947 nbdebug(("got keycommand for non-NetBeans buffer, opening...\n"));
2757 q = curbuf->b_ffname == NULL ? (char_u *)"" 2948 q = curbuf->b_ffname == NULL ? (char_u *)""
2829 3020
2830 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno); 3021 nbbuf = nb_bufp2nbbuf_fire(bufp, &bufno);
2831 if (nbbuf == NULL) 3022 if (nbbuf == NULL)
2832 return; 3023 return;
2833 3024
2834 nbbuf->modified = 1; 3025 /* Don't mark as modified for initial read */
3026 if (nbbuf->insertDone)
3027 nbbuf->modified = 1;
2835 3028
2836 sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, cmdno); 3029 sprintf((char *)buf, "%d:remove=%d 0 -1\n", bufno, cmdno);
2837 nbdebug(("EVT(suppressed): %s", buf)); 3030 nbdebug(("EVT(suppressed): %s", buf));
2838 /* nb_send(buf, "netbeans_deleted_all_lines"); */ 3031 /* nb_send(buf, "netbeans_deleted_all_lines"); */
2839 } 3032 }
3201 3394
3202 return offset; 3395 return offset;
3203 } 3396 }
3204 3397
3205 3398
3399 /*
3400 * This message is printed after NetBeans opens a new file. Its
3401 * similar to the message readfile() uses, but since NetBeans
3402 * doesn't normally call readfile, we do our own.
3403 */
3404 static void
3405 print_read_msg(buf)
3406 nbbuf_T *buf;
3407 {
3408 int lnum = buf->bufp->b_ml.ml_line_count;
3409 long nchars = buf->bufp->b_orig_size;
3410 char_u c;
3411
3412 msg_add_fname(buf->bufp, buf->bufp->b_ffname);
3413 c = FALSE;
3414
3415 if (buf->bufp->b_p_ro)
3416 {
3417 STRCAT(IObuff, shortmess(SHM_RO) ? _("[RO]") : _("[readonly]"));
3418 c = TRUE;
3419 }
3420 if (!buf->bufp->b_start_eol)
3421 {
3422 STRCAT(IObuff, shortmess(SHM_LAST) ? _("[noeol]") : _("[Incomplete last line]"));
3423 c = TRUE;
3424 }
3425 msg_add_lines(c, (long)lnum, nchars);
3426
3427 /* Now display it */
3428 vim_free(keep_msg);
3429 keep_msg = NULL;
3430 msg_scrolled_ign = TRUE;
3431 msg_trunc_attr(IObuff, FALSE, 0);
3432 msg_scrolled_ign = FALSE;
3433 }
3434
3435
3436 /*
3437 * Print a message after NetBeans writes the file. This message should be identical
3438 * to the standard message a non-netbeans user would see when writing a file.
3439 */
3440 static void
3441 print_save_msg(buf, nchars)
3442 nbbuf_T *buf;
3443 long nchars;
3444 {
3445 char_u c;
3446 char_u *p;
3447
3448 if (nchars >= 0)
3449 {
3450 msg_add_fname(buf->bufp, buf->bufp->b_ffname); /* fname in IObuff with quotes */
3451 c = FALSE;
3452
3453 msg_add_lines(c, buf->bufp->b_ml.ml_line_count,
3454 (long)buf->bufp->b_orig_size);
3455
3456 vim_free(keep_msg);
3457 keep_msg = NULL;
3458 msg_scrolled_ign = TRUE;
3459 p = msg_trunc_attr(IObuff, FALSE, 0);
3460 if ((msg_scrolled && !need_wait_return) || !buf->initDone)
3461 {
3462 /* Need to repeat the message after redrawing when:
3463 * - When reading from stdin (the screen will be cleared next).
3464 * - When restart_edit is set (otherwise there will be a delay
3465 * before redrawing).
3466 * - When the screen was scrolled but there is no wait-return
3467 * prompt. */
3468 set_keep_msg(p);
3469 keep_msg_attr = 0;
3470 }
3471 msg_scrolled_ign = FALSE;
3472 /* add_to_input_buf((char_u *)"\f", 1); */
3473 }
3474 else
3475 {
3476 char_u ebuf[BUFSIZ];
3477
3478 STRCPY(ebuf, (char_u *)_("E505: "));
3479 STRCAT(ebuf, IObuff);
3480 STRCAT(ebuf, (char_u *)_("is read-only (add ! to override)"));
3481 STRCPY(IObuff, ebuf);
3482 emsg(IObuff);
3483 }
3484 }
3485
3206 #endif /* defined(FEAT_NETBEANS_INTG) */ 3486 #endif /* defined(FEAT_NETBEANS_INTG) */