Thread: [q-lang-cvs] qcalc qcalc.q,1.141,1.142
Brought to you by:
agraef
|
From: Albert G. <ag...@us...> - 2007-11-13 10:52:58
|
Update of /cvsroot/q-lang/qcalc In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv27368 Modified Files: qcalc.q Log Message: make cell spans move when inserting and deleting rows and columns; handle this with undo/redo, too Index: qcalc.q =================================================================== RCS file: /cvsroot/q-lang/qcalc/qcalc.q,v retrieving revision 1.141 retrieving revision 1.142 diff -C2 -d -r1.141 -r1.142 *** qcalc.q 13 Nov 2007 10:03:06 -0000 1.141 --- qcalc.q 13 Nov 2007 10:52:54 -0000 1.142 *************** *** 1377,1381 **** dissociate_cells _ _ _ if is_global: ! = do dissociate_cell $ get_spans SEL where SEL = check_editing || sel_cellvals selection if qt TABW "currentPageIndex" () = 0; --- 1377,1381 ---- dissociate_cells _ _ _ if is_global: ! = do dissociate_cell $ get_spans $ cat SEL where SEL = check_editing || sel_cellvals selection if qt TABW "currentPageIndex" () = 0; *************** *** 1386,1398 **** where IT = get_table_item (I,J); ! get_spans SEL = sort indexcmp SP ! where (I,J,V) = unzip3 $ cat SEL, K = zip I J, K = map real_index K, ! SP = filter is_spanned $ keys $ hdict $ zip K V; insert_row _ _ _ if is_global: = adjust_rows (N+2) || EDITED := true || ! update_title || process_sel SEL || ! save_undo CELLS || updatemsg (I,J) || digest_loop --- 1386,1417 ---- where IT = get_table_item (I,J); ! get_spans SEL = sort indexcmp SEL ! where (I,J,V) = unzip3 SEL, K = zip I J, K = map real_index K, ! SEL = filter is_spanned $ keys $ hdict $ zip K V; ! ! move_spans (DI,DJ) SEL ! = do clear_span SEL || ! dowith set_span (map (translate (DI,DJ)) SEL) SP ! where SP = map cell_span SEL; ! ! clear_span (I,J) ! = qt IT "setSpan" (1,1) ! if not is_nil IT ! where IT = qt TABLE "item" (I,J); ! ! set_span (I,J) (N,M) ! = spanned_table_item (I,J) (N,M) ! if (N>1) or else (M>1) ! where (I1,J1) = (max 0 I,max 0 J), ! (N,M) = (N-I1+I,M-J1+J), (I,J) = (I1,J1), ! (N,M) = (max 1 N,max 1 M); insert_row _ _ _ if is_global: = adjust_rows (N+2) || EDITED := true || ! update_title || ! move_spans (1,0) (get_spans SEL) || ! process_sel SEL || ! save_undo (1,0,CELLS) || updatemsg (I,J) || digest_loop *************** *** 1408,1413 **** delete_row _ _ _ if is_global: = EDITED := true || ! update_title || process_sel SEL || ! adjust_rows N || save_undo CELLS || updatemsg (I,J) || digest_loop --- 1427,1435 ---- delete_row _ _ _ if is_global: = EDITED := true || ! update_title || ! move_spans (-1,0) (get_spans SEL) || ! process_sel SEL || ! adjust_rows N || ! save_undo (-1,0,CELLS) || updatemsg (I,J) || digest_loop *************** *** 1423,1428 **** insert_col _ _ _ if is_global: = adjust_cols (N+2) || EDITED := true || ! update_title || process_sel SEL || ! save_undo CELLS || updatemsg (I,J) || digest_loop --- 1445,1452 ---- insert_col _ _ _ if is_global: = adjust_cols (N+2) || EDITED := true || ! update_title || ! move_spans (0,1) (get_spans SEL) || ! process_sel SEL || ! save_undo (0,1,CELLS) || updatemsg (I,J) || digest_loop *************** *** 1438,1443 **** delete_col _ _ _ if is_global: = EDITED := true || ! update_title || process_sel SEL || ! adjust_cols N || save_undo CELLS || updatemsg (I,J) || digest_loop --- 1462,1470 ---- delete_col _ _ _ if is_global: = EDITED := true || ! update_title || ! move_spans (0,-1) (get_spans SEL) || ! process_sel SEL || ! adjust_cols N || ! save_undo (0,-1,CELLS) || updatemsg (I,J) || digest_loop *************** *** 1615,1618 **** --- 1642,1648 ---- /* Helper functions for processing selections. */ + translate (DI,DJ) (I,J) + = (I+DI,J+DJ); + translate (DI,DJ) (I,J,S) = (I+DI,J+DJ,sprintf "= %s" (translate (DI,DJ) S)) *************** *** 2612,2615 **** --- 2642,2656 ---- /* Undo/redo. **************************************************************/ + /* We currently process three different kinds of actions: + + - a list L of changed values (I,J,S); these are used by most editing + operations + + - a list L as above, with associated moving spans, denoted (DI,DJ,L); + these are used by the row/column insertion/deletion operations + + - a pair (I,J;N,M), denoting a change of cell (I,J) to the given row/column + span; these are used by the cell merge and dissociate operations */ + def LAST_SAVE = ref 0, SPANS = ref emptyhdict; *************** *** 2638,2641 **** --- 2679,2689 ---- where L = undo_cellvals L; + save_undo (DI,DJ,L:List) + = //printf "*** save undo: %s\n" (str (DI,DJ,L)) || + if #get UNDO_LIST < get LAST_SAVE then LAST_SAVE := 0 || + UNDO_LIST := [(DI,DJ,L)|get UNDO_LIST] || REDO_LIST := [] + if not null L + where L = undo_cellvals L; + merge_undo (I,J) = merge_undo [(I,J)]; *************** *** 2648,2651 **** --- 2696,2706 ---- where L = filter (neg is_gui_elem.fst) $ undo_cellvals L; + merge_undo L:List + = //printf "*** merge undo: %s ++ %s\n" (str (DI,DJ,L0),str L) || + UNDO_LIST := [(I,J,L0++L)|UL] + where [(I,J,L0:List)|UL] = get UNDO_LIST + if not null L + where L = filter (neg is_gui_elem.fst) $ undo_cellvals L; + undo_cellvals (I,J) = [undo_cellval (I,J)]; *************** *** 2663,2666 **** --- 2718,2728 ---- = (1,1) otherwise; + undo_filter (I,J;N,M) + = []; + undo_filter (DI,DJ,L:List) + = L; + undo_filter L:List + = L; + undo = //printf "*** undo: %s\n" (str W) || adjust_table (N,M) || *************** *** 2670,2674 **** digest_loop where D = foldl (foldl insert) emptyhdict $ ! filter islist $ reverse UL, W = map (undo_cell D.fst) L, N = foldl max (MIN_ROWS-1) --- 2732,2736 ---- digest_loop where D = foldl (foldl insert) emptyhdict $ ! map undo_filter $ reverse UL, W = map (undo_cell D.fst) L, N = foldl max (MIN_ROWS-1) *************** *** 2680,2683 **** --- 2742,2763 ---- where [L:List|UL] = get UNDO_LIST; + undo = //printf "*** undo: %s\n" (str (DI,DJ,W)) || + adjust_table (N,M) || + move_spans (-DI,-DJ) (get_spans W) || + process_sel W || + UNDO_LIST := UL || REDO_LIST := [(DI,DJ,L)|get REDO_LIST] || + EDITED := (#UL<>get LAST_SAVE) || update_title || + digest_loop + where D = foldl (foldl insert) emptyhdict $ + map undo_filter $ reverse UL, + W = map (undo_cell D.fst) L, + N = foldl max (MIN_ROWS-1) + (map fst $ filter (neg null.trd) W) + 1, + M = foldl max (MIN_COLS-1) + (map snd $ filter (neg null.trd) W) + 1, + W = filter (valid_cell (N,M)) W + if not null UL + where [(DI,DJ,L:List)|UL] = get UNDO_LIST; + undo = //printf "*** undo: %s\n" (str (I,J;N,M)) || set_current_cell (I,J) || spanned_table_item (I,J) (N1,M1) || *************** *** 2704,2707 **** --- 2784,2804 ---- W = filter (valid_cell (N,M)) W; + redo = //printf "*** redo: %s\n" (str (DI,DJ,W)) || + adjust_table (N,M) || + move_spans (DI,DJ) (get_spans W) || + process_sel W || + UNDO_LIST := [(DI,DJ,L)|UL] || REDO_LIST := RL || + EDITED := (#UL+1<>get LAST_SAVE) || update_title || + digest_loop + where [(DI,DJ,L:List)|RL] = get REDO_LIST, + UL = get UNDO_LIST, + (KEYS,VALS) = unzip L, + W = zipwith append KEYS VALS, + N = foldl max (MIN_ROWS-1) + (map fst $ filter (neg null.trd) W) + 1, + M = foldl max (MIN_COLS-1) + (map snd $ filter (neg null.trd) W) + 1, + W = filter (valid_cell (N,M)) W; + redo = //printf "*** redo: %s\n" (str (I,J;N,M)) || set_current_cell (I,J) || spanned_table_item (I,J) (N,M) || |