Date: 02-16-2022
Return to Index
created by gbSnippets
'By default, Scintilla provides undo/redo support of actions that change the
'document. Sequences of typing or deletion are combined by Scinitilla into
'single undo/redo actions. Caret movement, selection changes, and view
'scrolling actions are not saved.
'By default, undo/redo will continue as long as memory is available.
'Saving undo/redo actions can be stopped and restarted, all saved actions can be
'deleted, and actions taken by code can be added to the undo/redo list. You
'also test to see if undo/redo actions are available (useful to enable/disable
'toolbar or menu Undo/Redo buttons. You can also define the start/end of a series
'of actions that you want treated as a single undo/redo action.
'One clarification might be useful. To create a point where undo will no longer
'look backwards, use SCI_EmptyUndoBuffer. While SCI_SetSavePoint might seem to
'indicate a point at which undo cannot go past, but all it really does is set
'a point at which Scintilla sends a notification to the container app - undo
'actions continue to move through prior changes.
'Primary Code:
'Undo
SendMessage hSci, %SCI_Undo, 0,0
'Redo
SendMessage hSci, %SCI_Redo, 0,0
'Start/Stop
SendMessage hSci, %SCI_SetUndoCollection, 1,0 'turn on saving of undo/redo actions
SendMessage hSci, %SCI_SetUndoCollection, 0,0 'turn off saving of undo/redo actions
'Clear the undo/redo action list
SendMessage hSci, %SCI_EmptyUndoBuffer, 0,0
'Set a save point
SendMessage hSci, %SCI_SetSavePoint, 0,0
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "scintilla_gb.inc"
%ID_Sci = 1000 : %ID_BtnA = 1001 : %ID_BtnB = 1002 : %ID_BtnC = 1003
Global hDlg, hSci, hLib As DWord
Function PBMain() As Long
hLib = LoadLibrary("SCILEXER.DLL")
Dialog New Pixels, 0, "Scintilla Example",300,300,300,150, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %ID_BtnA, "Undo", 10,10,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnB, "Redo", 10,40,70,20, %WS_Child Or %WS_Visible
Control Add Button, hDlg, %ID_BtnC, "SetSavePoint", 10,70,70,20, %WS_Child Or %WS_Visible
Control Add "Scintilla", hDlg, %ID_Sci, "", 100,10,180,130, %WS_Child Or %WS_Visible
Control Handle hDlg, %ID_Sci To hSci 'get handle to Scintilla window
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local txt As String
txt = "Select Case var$ 'first line" + $CrLf + "End Select 'last line" + Chr$(0)
Select Case CB.Msg
Case %WM_InitDialog
InitializeScintilla
PostMessage hSci, %SCI_SetSel, 0,0 'unselect initially
SendMessage hSci, %SCI_EmptyUndoBuffer, 0,0
Case %WM_Command
Select Case CB.Ctl
Case %ID_BtnA : TestA
Case %ID_BtnB : TestB
Case %ID_BtnC : TestC
End Select
Case %WM_Size
Control Set Size hDlg, %ID_Sci, Lo(Word, CB.lParam)-110, Hi(Word, CB.lParam)-20
Case %WM_Destroy
If hLib Then FreeLibrary hLib 'free the Scintilla library
End Select
End Function
Sub InitializeScintilla
Local txt As String
txt = "If x = 2 Then" + $CrLf + " 'do nothing" + $Crlf
txt = txt + "Else" + $crlf + " x = 0" + $crlf + "End If" + Chr$(0)
SendMessage hSci, %SCI_SetText, 0, StrPTR(txt)
SendMessage hSci, %SCI_SetMarginWidthN, 0, 20
End Sub
Sub TestA
SendMessage hSci, %SCI_Undo, 0,0
End Sub
Sub TestB
SendMessage hSci, %SCI_Redo, 0,0
End Sub
Sub TestC
SendMessage hSci, %SCI_EmptyUndoBuffer, 0,0
End Sub
'gbs_00649
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm