[q-lang-cvs] qcalc qcalc.q,1.170,1.171
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-22 01:50:24
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv20558 Modified Files: qcalc.q Log Message: more bugfixes and optimizations to better handle asynchronous messages Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.170 retrieving revision 1.171 diff -C2 -d -r1.170 -r1.171 *** qcalc.q 21 Nov 2007 02:58:54 -0000 1.170 --- qcalc.q 22 Nov 2007 01:50:18 -0000 1.171 *************** *** 633,646 **** @1 ! /* Override qt_invoke to reject any "unsafe" callbacks (i.e., everything ! except abort) during evaluations. XXXFIXME: We should actually queue ! callbacks (and execute them later in the callback routine) if we're in a ! local event loop here. */ qt_invoke OBJ SLOT ARGS - = _FAIL_ if is_recursive and then neq SLOT abort; // Use this for debugging if debug_invoke doesn't work (see below). // = printf "qt_invoke: %s %s %s\n" (str OBJ,str SLOT,str ARGS) || // fail if neq SLOT timer; @0 --- 633,657 ---- @1 ! /* Override qt_invoke to reject or queue "unsafe" callbacks during ! evaluations. */ ! ! def WL = [abort,eval,gui_update,popup,text_changed,linenumbermsg,indent], ! BL1 = [eval,gui_update], BL2 = [timer]; qt_invoke OBJ SLOT ARGS // Use this for debugging if debug_invoke doesn't work (see below). // = printf "qt_invoke: %s %s %s\n" (str OBJ,str SLOT,str ARGS) || // fail if neq SLOT timer; + // Blacklist #1: these are always inhibited in recursive mode. + = true if is_recursive and then any (eq SLOT) BL1; + // Blacklist #2: these are always inhibited in local mode. + = true if not is_global and then any (eq SLOT) BL2; + // All other callbacks are deferred in local mode unless they're on the + // whitelist. These will be executed later from the timer. Also note that + // while eval and gui_update are on the whitelist and hence passed through + // here (unless in recursive mode), in local mode these callbacks will + // simply queue a corresponding GUI update request for later processing. + = post MSGS '(SLOT OBJ (qt_data OBJ) ARGS || true) || true + if not is_global and then all (neq SLOT) WL; @0 *************** *** 696,701 **** abort _ _ _ = ABORTED := true; ! about _ _ _ if is_global: ! = aboutbox $ sprintf "<h1>QCalc - A Q spreadsheet</h1>\n\ \n\ --- 707,711 ---- abort _ _ _ = ABORTED := true; ! about _ _ _ = aboutbox $ sprintf "<h1>QCalc - A Q spreadsheet</h1>\n\ \n\ *************** *** 731,736 **** = qt_assistant PAGE; ! help A _ _ _ = assistant (which "doc/qcalc.html"++A) if is_global; ! manual A _ _ _ = assistant (which "doc/qdoc.html"++A) if is_global; /* Timer processing. */ --- 741,746 ---- = qt_assistant PAGE; ! help A _ _ _ = assistant (which "doc/qcalc.html"++A); ! manual A _ _ _ = assistant (which "doc/qdoc.html"++A); /* Timer processing. */ *************** *** 738,749 **** set_status B A = qt A "setEnabled" B if B<>qt A "isEnabled" (); ! timer _ _ _ = // set_status EDITING EDIT_ACCEPT || ! // set_status EDITING EDIT_CANCEL || ! // set_status (not EDITING) EDIT_EDIT || ! // set_status HAVE_TEXT EDIT_PASTE || ! set_status HAVE_UNDO EDIT_UNDO || set_status HAVE_REDO EDIT_REDO || ! if not is_recursive then digest_loop ! where HAVE_TABLE = (qt TABW "currentPageIndex" () = 0), EDITING = qt TABLE "isEditing" (), --- 748,754 ---- set_status B A = qt A "setEnabled" B if B<>qt A "isEnabled" (); ! timer _ _ _ = set_status HAVE_UNDO EDIT_UNDO || set_status HAVE_REDO EDIT_REDO || ! digest_loop where HAVE_TABLE = (qt TABW "currentPageIndex" () = 0), EDITING = qt TABLE "isEditing" (), *************** *** 758,768 **** not null (get REDO_LIST) else ! qt EDIT "isRedoAvailable" () ! // where HAVE_TEXT = neg null $ qt CLIP "text" $ ! // qt_val "QClipboard" "Clipboard" ! if is_global; ! digest_loop = digest S || digest_loop where S = get MSGS if #MSGS>0; ! = do_queued_updates otherwise; /* State of the inferior Q process: 0 = uninitialized or exited, 1 = --- 763,780 ---- not null (get REDO_LIST) else ! qt EDIT "isRedoAvailable" (); ! digest_loop = digest_loop_at time || do_queued_updates; ! ! /* Make sure that we eventually return from the loop in local mode, so that ! qcalc doesn't get locked in a local loop, which might otherwise happen if ! there's a lot of asynchronous messages to process. */ ! ! digest_loop_at T0 ! = digest S || digest_loop_at T0 ! where S = get MSGS ! if (#MSGS>0) and then ! (is_global or else (time-T0<=0.5)); ! = () otherwise; /* State of the inferior Q process: 0 = uninitialized or exited, 1 = *************** *** 889,894 **** if RES where RES = waitmsg "Compiling..." || init_interp, ! _ = highlight_rebuild_cache ! if is_global; init_interp = TASK := (TMP|NEW_TASK) || --- 901,905 ---- if RES where RES = waitmsg "Compiling..." || init_interp, ! _ = highlight_rebuild_cache; init_interp = TASK := (TMP|NEW_TASK) || *************** *** 959,963 **** // KLUDGE: Qt/Q cannot pass the QPoint parameter right now, so we read // QCursor::pos() instead. ! popup _ _ (I,J) = qt POPUP "exec" $ qt "QCursor" "pos" () if is_global; /* Manage table items. We derive our own QTableItems here, as we need to --- 970,974 ---- // KLUDGE: Qt/Q cannot pass the QPoint parameter right now, so we read // QCursor::pos() instead. ! popup _ _ (I,J) = qt POPUP "exec" $ qt "QCursor" "pos" (); /* Manage table items. We derive our own QTableItems here, as we need to *************** *** 1162,1165 **** --- 1173,1180 ---- otherwise; + clean_cell (I,J) + = clear_cell (I,J) if is_gui_elem (I,J); + = set_pixmap (I,J) NULLPM otherwise; + init_wrap (I,J) = qt IT "setWordWrap" $ not member (get EVAL) (I,J) if not is_nil IT *************** *** 1198,1204 **** /* Editing table cells and evaluation. */ ! eval _ _ (I,J) ! where (I,J) = real_index (I,J) ! if is_global and then not is_recursive: = process_gui2 (I,J) X || digest_loop where X:QtObject = gui_elem (I,J); --- 1213,1219 ---- /* Editing table cells and evaluation. */ ! eval S D (I,J) = eval2 S D (real_index (I,J)); ! eval2 _ _ (I,J) ! if is_global: = process_gui2 (I,J) X || digest_loop where X:QtObject = gui_elem (I,J); *************** *** 1206,1214 **** where X:QtObject = finish_edit true (I,J) || gui_elem (I,J); ! = (); ! where (I,J) = real_index (I,J) ! if not is_global and then not is_recursive: = queue_update (I,J) if is_gui_elem (I,J); - = (); /* FIXME: If we created a GUI object in the edited cell, it will be destroyed --- 1221,1226 ---- where X:QtObject = finish_edit true (I,J) || gui_elem (I,J); ! if not is_global: = queue_update (I,J) if is_gui_elem (I,J); /* FIXME: If we created a GUI object in the edited cell, it will be destroyed *************** *** 1239,1243 **** edit _ _ () where (I,J) = real_current_cell ! if qt TABW "currentPageIndex" () = 0 if is_global: = // nuke the current cell clear_cell (I,J) || --- 1251,1255 ---- edit _ _ () where (I,J) = real_current_cell ! if qt TABW "currentPageIndex" () = 0: = // nuke the current cell clear_cell (I,J) || *************** *** 1254,1258 **** edit _ _ (I,J,1) where (I,J) = real_index (I,J) ! if qt TABW "currentPageIndex" () = 0 if is_global: = if not qt TABLE "isEditing" () then edit_cell (I,J) --- 1266,1270 ---- edit _ _ (I,J,1) where (I,J) = real_index (I,J) ! if qt TABW "currentPageIndex" () = 0: = if not qt TABLE "isEditing" () then edit_cell (I,J) *************** *** 1260,1264 **** accept _ _ _ ! where _ = LAST_EDIT := (), (I,J) = real_current_cell if is_global: = doprocess (I,J) || digest_loop if is_gui_elem (I,J); --- 1272,1276 ---- accept _ _ _ ! where _ = LAST_EDIT := (), (I,J) = real_current_cell: = doprocess (I,J) || digest_loop if is_gui_elem (I,J); *************** *** 1274,1278 **** accept2 S D A where _ = LAST_EDIT := (), (I,J) = real_current_cell, N = num_rows ! if is_global and then (qt TABW "currentPageIndex" () = 0): = gui_enter (I,J) X where X:QtObject = gui_elem (I,J); --- 1286,1290 ---- accept2 S D A where _ = LAST_EDIT := (), (I,J) = real_current_cell, N = num_rows ! if qt TABW "currentPageIndex" () = 0: = gui_enter (I,J) X where X:QtObject = gui_elem (I,J); *************** *** 1288,1297 **** qt TABLE "isEditing" () and then (qt TABW "currentPageIndex" () = 0) ! where _ = LAST_EDIT := (), (I,J) = real_current_cell ! if is_global; gui_update X (I,J) _ ! where (I,J) = real_index (I,J) ! if not is_recursive and then not is_nil X: = if (I,J)<>real_current_cell then set_current_cell (I,J) || process_gui2 (I,J) X || digest_loop --- 1300,1307 ---- qt TABLE "isEditing" () and then (qt TABW "currentPageIndex" () = 0) ! where _ = LAST_EDIT := (), (I,J) = real_current_cell; gui_update X (I,J) _ ! where (I,J) = real_index (I,J) if not is_nil X: = if (I,J)<>real_current_cell then set_current_cell (I,J) || process_gui2 (I,J) X || digest_loop *************** *** 1309,1315 **** activate _ _ (I,J) ! = updatemsg (I,J) if check_editing || is_global; ! clicked _ _ (I,J) if is_global: = check_editing || fail if neq current_edited (real_index (I,J)); --- 1319,1325 ---- activate _ _ (I,J) ! = check_editing || updatemsg (I,J); ! clicked _ _ (I,J) = check_editing || fail if neq current_edited (real_index (I,J)); *************** *** 1454,1458 **** edit_undo _ _ _ = undo || updatemsg current_cell where _ = check_editing ! if (qt TABW "currentPageIndex" () = 0) and then is_global; = qt EDIT "undo" () if qt TABW "currentPageIndex" () = 1; --- 1464,1468 ---- edit_undo _ _ _ = undo || updatemsg current_cell where _ = check_editing ! if qt TABW "currentPageIndex" () = 0; = qt EDIT "undo" () if qt TABW "currentPageIndex" () = 1; *************** *** 1460,1468 **** edit_redo _ _ _ = redo || updatemsg current_cell where _ = check_editing ! if (qt TABW "currentPageIndex" () = 0) and then is_global; = qt EDIT "redo" () if qt TABW "currentPageIndex" () = 1; ! merge_cells _ _ _ if is_global: = EDITED := true || update_title || save_undo (I,J;N,M) where (I,J) = real_index (I,J), (N,M) = cell_span (I,J) --- 1470,1478 ---- edit_redo _ _ _ = redo || updatemsg current_cell where _ = check_editing ! if qt TABW "currentPageIndex" () = 0; = qt EDIT "redo" () if qt TABW "currentPageIndex" () = 1; ! merge_cells _ _ _ = EDITED := true || update_title || save_undo (I,J;N,M) where (I,J) = real_index (I,J), (N,M) = cell_span (I,J) *************** *** 1475,1479 **** if qt TABW "currentPageIndex" () = 0; ! dissociate_cells _ _ _ if is_global: = do dissociate_cell $ get_spans $ cat SEL where SEL = check_editing || sel_cellvals selection --- 1485,1489 ---- if qt TABW "currentPageIndex" () = 0; ! dissociate_cells _ _ _ = do dissociate_cell $ get_spans $ cat SEL where SEL = check_editing || sel_cellvals selection *************** *** 1506,1510 **** (N,M) = (max 1 N,max 1 M); ! insert_row _ _ _ if is_global: = adjust_rows (N+2) || EDITED := true || update_title || --- 1516,1520 ---- (N,M) = (max 1 N,max 1 M); ! insert_row _ _ _ = adjust_rows (N+2) || EDITED := true || update_title || *************** *** 1523,1527 **** if qt TABW "currentPageIndex" () = 0; ! delete_row _ _ _ if is_global: = EDITED := true || update_title || --- 1533,1537 ---- if qt TABW "currentPageIndex" () = 0; ! delete_row _ _ _ = EDITED := true || update_title || *************** *** 1544,1548 **** if qt TABW "currentPageIndex" () = 0; ! insert_col _ _ _ if is_global: = adjust_cols (N+2) || EDITED := true || update_title || --- 1554,1558 ---- if qt TABW "currentPageIndex" () = 0; ! insert_col _ _ _ = adjust_cols (N+2) || EDITED := true || update_title || *************** *** 1561,1565 **** if qt TABW "currentPageIndex" () = 0; ! delete_col _ _ _ if is_global: = EDITED := true || update_title || --- 1571,1575 ---- if qt TABW "currentPageIndex" () = 0; ! delete_col _ _ _ = EDITED := true || update_title || *************** *** 1634,1638 **** where SEL = check_editing || selection, CELLS = sel_cells SEL ! if (qt TABW "currentPageIndex" () = 0) and then is_global; = qt EDIT "del" () if qt TABW "currentPageIndex" () = 1; --- 1644,1648 ---- where SEL = check_editing || selection, CELLS = sel_cells SEL ! if qt TABW "currentPageIndex" () = 0; = qt EDIT "del" () if qt TABW "currentPageIndex" () = 1; *************** *** 1646,1650 **** X = sel_cellvals SEL, S = sel_cellcvals SEL, CELLS = sel_cells SEL ! if (qt TABW "currentPageIndex" () = 0) and then is_global; = qt EDIT "cut" () if qt TABW "currentPageIndex" () = 1; --- 1656,1660 ---- X = sel_cellvals SEL, S = sel_cellcvals SEL, CELLS = sel_cells SEL ! if qt TABW "currentPageIndex" () = 0; = qt EDIT "cut" () if qt TABW "currentPageIndex" () = 1; *************** *** 1653,1657 **** where SEL = check_editing || selection, X = sel_cellvals SEL, S = sel_cellcvals SEL ! if (qt TABW "currentPageIndex" () = 0) and then is_global; = qt EDIT "copy" () if qt TABW "currentPageIndex" () = 1; --- 1663,1667 ---- where SEL = check_editing || selection, X = sel_cellvals SEL, S = sel_cellcvals SEL ! if qt TABW "currentPageIndex" () = 0; = qt EDIT "copy" () if qt TABW "currentPageIndex" () = 1; *************** *** 1663,1667 **** where SEL = check_editing || selection, (I0,J0;I1,J1;I2,J2) = SEL ! if (qt TABW "currentPageIndex" () = 0) and then is_global; paste _ _ _ = EDITED := get EDITED or else not null SEL || --- 1673,1677 ---- where SEL = check_editing || selection, (I0,J0;I1,J1;I2,J2) = SEL ! if qt TABW "currentPageIndex" () = 0; paste _ _ _ = EDITED := get EDITED or else not null SEL || *************** *** 1679,1683 **** N = foldl max (MIN_ROWS-1) (map fst CELLS) + 1, M = foldl max (MIN_COLS-1) (map snd CELLS) + 1 ! if (qt TABW "currentPageIndex" () = 0) and then is_global; = qt EDIT "paste" () if qt TABW "currentPageIndex" () = 1; --- 1689,1693 ---- N = foldl max (MIN_ROWS-1) (map fst CELLS) + 1, M = foldl max (MIN_COLS-1) (map snd CELLS) + 1 ! if qt TABW "currentPageIndex" () = 0; = qt EDIT "paste" () if qt TABW "currentPageIndex" () = 1; *************** *** 1695,1699 **** SEL = map (translate (DI,DJ)) SEL, CELLS = map (flip (flip sub 0) 1) SEL ! if (qt TABW "currentPageIndex" () = 0) and then is_global; fill _ _ _ = EDITED := true || update_title || --- 1705,1709 ---- SEL = map (translate (DI,DJ)) SEL, CELLS = map (flip (flip sub 0) 1) SEL ! if qt TABW "currentPageIndex" () = 0; fill _ _ _ = EDITED := true || update_title || *************** *** 1707,1711 **** VALS = sel_cellvals SEL, CELLS = map (flip (flip sub 0) 1) $ cat VALS ! if (qt TABW "currentPageIndex" () = 0) and then is_global; fill_vals SEL --- 1717,1721 ---- VALS = sel_cellvals SEL, CELLS = map (flip (flip sub 0) 1) $ cat VALS ! if qt TABW "currentPageIndex" () = 0; fill_vals SEL *************** *** 1932,1936 **** where FONT = qt_new "QFont" (); ! choose_font _ _ _ if is_global: = do (flip set_font FONT) (if qt TABW "currentPageIndex" () = 0 then [TABLE] --- 1942,1946 ---- where FONT = qt_new "QFont" (); ! choose_font _ _ _ = do (flip set_font FONT) (if qt TABW "currentPageIndex" () = 0 then [TABLE] *************** *** 1982,1987 **** save S D A = save_as S D A if eq (get FILENAME) (); ! save _ _ _ if is_global: ! = EDITED := false || qt EDIT "setModified" false || update_title || fprintf F --- 1992,1996 ---- save S D A = save_as S D A if eq (get FILENAME) (); ! save _ _ _ = EDITED := false || qt EDIT "setModified" false || update_title || fprintf F *************** *** 2027,2032 **** = D otherwise; ! save_as X D A if is_global: ! = FILENAME := S || save X D A if not isfile (fopen S "r") or else (question --- 2036,2040 ---- = D otherwise; ! save_as X D A = FILENAME := S || save X D A if not isfile (fopen S "r") or else (question *************** *** 2039,2045 **** special deps X; load _ _ _ ! if not null NAME ! where NAME:String = open_dg ! if check_editing || check_edited if is_global: = () where () = open_file NAME; = msgbox $ sprintf --- 2047,2052 ---- special deps X; load _ _ _ ! if not null NAME where NAME:String = open_dg ! if check_editing || check_edited: = () where () = open_file NAME; = msgbox $ sprintf *************** *** 2052,2056 **** recent_file I _ _ _ if not null NAME where NAME:String = get FILES!(I-1) ! if check_editing || check_edited if is_global: = () where () = open_file NAME; = msgbox $ sprintf --- 2059,2063 ---- recent_file I _ _ _ if not null NAME where NAME:String = get FILES!(I-1) ! if check_editing || check_edited: = () where () = open_file NAME; = msgbox $ sprintf *************** *** 2175,2179 **** ROWS = [0..num_rows-1], COLS = [0..num_cols-1] ! if check_editing || check_edited if is_global; /* Encoding tag. FIXME: This currently requires nl_langinfo to get the system --- 2182,2186 ---- ROWS = [0..num_rows-1], COLS = [0..num_cols-1] ! if check_editing || check_edited; /* Encoding tag. FIXME: This currently requires nl_langinfo to get the system *************** *** 2203,2208 **** OPT_CELLS = qt OPTIONS_CELLS "selectedId" (), FROM = qt PRT "fromPage" (), TO = qt PRT "toPage" () ! where ALL = selection_all, SEL = selection ! if is_global: = doprint PRT OPT_CONTENTS (FROM,TO) $ format_as_text OPT_CELLS (I1,J1;I2,J2) --- 2210,2214 ---- OPT_CELLS = qt OPTIONS_CELLS "selectedId" (), FROM = qt PRT "fromPage" (), TO = qt PRT "toPage" () ! where ALL = selection_all, SEL = selection: = doprint PRT OPT_CONTENTS (FROM,TO) $ format_as_text OPT_CELLS (I1,J1;I2,J2) *************** *** 2213,2217 **** where (_,_;I1,J1;I2,J2) = ALL; = doprint PRT OPT_CONTENTS (FROM,TO) ""; ! if is_global: = statusmsg "Print aborted"; --- 2219,2223 ---- where (_,_;I1,J1;I2,J2) = ALL; = doprint PRT OPT_CONTENTS (FROM,TO) ""; ! otherwise: = statusmsg "Print aborted"; *************** *** 2451,2455 **** bail_out _ _ _ = qt APP "exit" 1 ! if check_editing || check_edited if is_global; edited = get EDITED or else qt EDIT "isModified" (); --- 2457,2461 ---- bail_out _ _ _ = qt APP "exit" 1 ! if check_editing || check_edited; edited = get EDITED or else qt EDIT "isModified" (); *************** *** 3551,3555 **** doprocess (I,J) = insert_cells (I,J) || cell_setval (I,J) () || ! if is_gui_elem (I,J) then clear_cell (I,J) || // do the necessary reevaluations if check_interp then compute V --- 3557,3561 ---- doprocess (I,J) = insert_cells (I,J) || cell_setval (I,J) () || ! clean_cell (I,J) || // do the necessary reevaluations if check_interp then compute V *************** *** 3579,3588 **** process1 (I,J,S) ! = if is_gui_elem (I,J) then clear_cell (I,J) || insert_cells (I,J) || insert_eval (I,J;S,'X,DEPS) || cell_setval (I,J) () where ("=",S) = (hd S,trim (tl S)), 'X = parse S, DEPS = deps 'X; ! = if is_gui_elem (I,J) then clear_cell (I,J) || set_cell (I,J) S || insert_cells (I,J) || delete_eval (I,J) || --- 3585,3594 ---- process1 (I,J,S) ! = clean_cell (I,J) || insert_cells (I,J) || insert_eval (I,J;S,'X,DEPS) || cell_setval (I,J) () where ("=",S) = (hd S,trim (tl S)), 'X = parse S, DEPS = deps 'X; ! = clean_cell (I,J) || set_cell (I,J) S || insert_cells (I,J) || delete_eval (I,J) || *************** *** 3603,3612 **** = cell_setval (I,J) () || check_deps CHK (I,J) if is_qt_object S; ! = if is_gui_elem (I,J) then clear_cell (I,J) || insert_cells (I,J) || insert_eval (I,J;S,'X,DEPS) || cell_setval (I,J) () || check_deps CHK (I,J) where ("=",S) = (hd S,trim (tl S)), 'X = parse S, DEPS = deps 'X; ! = if is_gui_elem (I,J) then clear_cell (I,J) || set_cell (I,J) S1 || cell_setval (I,J) S0 || --- 3609,3618 ---- = cell_setval (I,J) () || check_deps CHK (I,J) if is_qt_object S; ! = clean_cell (I,J) || insert_cells (I,J) || insert_eval (I,J;S,'X,DEPS) || cell_setval (I,J) () || check_deps CHK (I,J) where ("=",S) = (hd S,trim (tl S)), 'X = parse S, DEPS = deps 'X; ! = clean_cell (I,J) || set_cell (I,J) S1 || cell_setval (I,J) S0 || |