/****************************** Module Header ******************************* * * Module Name: charops.e * * Copyright (c) Netlabs EPM Distribution Project 2002 * * $Id$ * * =========================================================================== * * This file is part of the Netlabs EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * Netlabs EPM Distribution. This library is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * ****************************************************************************/ ; --------------------------------------------------------------------------- ; Adjust mark and overlay mark defproc pCommon_Adjust_Overlay( letter) --call checkmark() -- Disabled to allow overlay between two files mt = marktype() if mt = '' then sayerror NO_MARK__MSG stop endif if leftstr( mt, 1) <> 'B' then -- Change to block mark getmark firstline, lastline, firstcol, lastcol, mkfileid if leftstr( mt, 1) = 'C' & firstline <> lastline then sayerror CHAR_ONE_LINE__MSG stop endif call pSet_Mark( firstline, lastline, firstcol, lastcol, 'BLOCK', mkfileid) endif if letter = 'A' then -- If the marked file is another one, create also a new undo state for it getfileid fid if fid <> mkfileid then display -14 activatefile mkfileid NextCmdAltersText() activatefile fid display 14 endif adjustblock elseif letter = 'O' then overlay_block endif if mt <> 'BLOCK' then -- Restore mark type getmark firstline, lastline, firstcol, lastcol, mkfileid call pSet_Mark( firstline, lastline, firstcol, lastcol, mt, mkfileid) -- Strip trailing spaces for line mark if leftstr( mt, 1) = 'L' then 'Strip' firstline lastline endif endif ; --------------------------------------------------------------------------- ; Changed to not return rc, but to just set it. rc is a default universal var. defproc pCopy_Mark SavedLine = .line fRestoreLine = 0 mktype = marktype() copyrc = 0 -- Standard is to place marked lines below the cursor. -- With LineInsert = 'A', it can be placed above. if mktype = 'LINE' then KeyPath = '\NEPMD\User\Mark\LineInsert' LineInsert = QueryConfigKey( KeyPath) if LineInsert = 'A' then .lineg = .line - 1 fRestoreLine = 1 endif endif do once = 1 to 1 getmark mkfirstline, mklastline, mkfirstcol, mklastcol, mkfid rc = 0 copymark copyrc = rc if copyrc then leave endif call ChangeBmAttrInMark( 'COPY', mkfirstline, mklastline, mkfirstcol, mklastcol, mkfid) enddo if fRestoreLine then .lineg = SavedLine endif rc = copyrc return ; --------------------------------------------------------------------------- defproc pMove_Mark SavedLine = .line fRestoreLine = 0 mktype = marktype() moverc = 0 -- Standard is to place marked lines below the cursor. -- With LineInsert = 'A', it can be placed above. if mktype = 'LINE' then KeyPath = '\NEPMD\User\Mark\LineInsert' LineInsert = QueryConfigKey( KeyPath) if LineInsert = 'A' then .lineg = .line - 1 fRestoreLine = 1 endif endif do once = 1 to 1 getmark mkfirstline, mklastline, mkfirstcol, mklastcol, mkfid rc = 0 movemark moverc = rc if moverc then leave endif call ChangeBmAttrInMark( 'MOVE', mkfirstline, mklastline, mkfirstcol, mklastcol, mkfid) enddo if fRestoreLine then .lineg = SavedLine endif rc = moverc return ; --------------------------------------------------------------------------- defproc pDelete_Mark if cursor_in_mark() then getmark first_line, last_line, first_col, last_col, mark_fid mark_type = marktype() if mark_type = 'LINE' then --.line = first_line -- go to begin of mark and keep .col (done automatically) elseif mark_type = 'CHAR' then .line = first_line -- go to begin of mark .col = first_col elseif mark_type = 'BLOCK' then .col = first_col -- go to begin of mark and keep .line endif endif call DelBookmarkInRegion() deletemark return ; --------------------------------------------------------------------------- ; Return 1 if cursor is in mark or just after it. Else return 0. defproc Cursor_In_Mark rc = 0 getmark first_line, last_line, first_col, last_col, mark_fid getfileid cur_fid mark_type = marktype() cur_line = .line cur_col = .col if mark_fid = cur_fid then if mark_type = 'LINE' then if cur_line >= first_line and cur_line <= last_line then rc = 1 endif elseif mark_type = 'CHAR' then if cur_line > first_line and cur_line < last_line then rc = 1 elseif first_line <> last_line and cur_line = first_line and cur_col >= first_col then rc = 1 elseif first_line <> last_line and cur_line = last_line and cur_col <= last_col + 1 then rc = 1 elseif first_line = last_line and cur_line = first_line and cur_col >= first_col and cur_col <= last_col + 1 then rc = 1 endif elseif mark_type = 'BLOCK' then if cur_line >= first_line and cur_line <= last_line then if cur_col >= first_col and cur_col <= last_col + 1 then rc = 1 endif endif endif endif --sayerror 'Cursor in mark: 'rc return rc ; --------------------------------------------------------------------------- ; Changed to allow for multiple chars and added option to fill left-aligned, ; with padded spaces. All mark types are supported. For line mark, the lines ; up their line ends are filled, not up to column 1600 (excluding). defproc pFill_Mark call CheckMark() getmark markfirstline, marklastline, markfirstcol, marklastcol, markfid mt = marktype() NewValue = arg( 1) if NewValue == '' then Title = FILL__MSG Buttons = '/~Tiled/~Left-Aligned/'CANCEL__MSG OldEntry = '' DefaultButton = 1 HelpId = 0 HelpId = 0 Text = 'Enter a fill string:' ret = EntryBox( Title, Buttons, OldEntry, '', 255, -- Length atoi( DefaultButton)''atoi( HelpId)''GethWndC( APP_HANDLE) || Text) parse value ret with Button 2 NewValue \0 if Button = \3 | NewValue == '' then -- Cancel return elseif Button = \1 then -- Tiled fTiled = 1 elseif Button = \2 then -- Left-aligned fTiled = 0 endif else fTiled = arg( 2) if not wordpos( fTiled, '0 1') then fTiled = 1 endif endif call NextCmdAltersText() do Line = markfirstline to marklastline if mt = 'CHAR' then if Line = markfirstline & Line = marklastline then StartCol = markfirstcol EndCol = marklastcol elseif Line = markfirstline then StartCol = markfirstcol EndCol = -1 elseif Line = marklastline then StartCol = 1 EndCol = marklastcol else StartCol = 1 EndCol = -1 endif elseif mt = 'BLOCK' then StartCol = markfirstcol EndCol = marklastcol elseif mt = 'LINE' then StartCol = 1 EndCol = -1 endif LineStr = textline( Line) if EndCol = -1 | EndCol >= 1599 then SearchStr = substr( LineStr, StartCol) FillLen = length( SearchStr) else FillLen = Max( 0, EndCol - StartCol + 1) SearchStr = substr( LineStr, StartCol, FillLen) -- Ensure that string has chars within FillLen. Pad the fill area -- with spaces if mark is beyond line end. Otherwise Replace -- would only replace the existing chars in mark. SavedInsertState = insertstate() if not SavedInsertState then SwitchInsertState( '1') endif pSave_Pos( SavedPos) LineStrLen = length( LineStr) .lineg = Line .col = StartCol do forever if .col > EndCol then leave endif if .col > LineStrLen then keyin ' ' else .col = .col + 1 endif enddo pRestore_Pos( SavedPos) if not SavedInsertState then SwitchInsertState( '0') endif endif if fTiled then -- Tiled FillChars = '' i = 0 do forever i = i + 1 FillChars = FillChars''NewValue if length( FillChars) >= FillLen then leave endif enddo FillChars = leftstr( FillChars, FillLen) else -- Left-aligned, padded with spaces FillChars = NewValue FillChars = leftstr( FillChars, FillLen) endif -- Use normal search to avoid escaping. rcx = SearchReplaceLine( SearchStr, FillChars, 1, '', Line, StartCol, EndCol) enddo return