Detect Editor Gadget Modified

Just starting out? Need help? Post your questions and find answers here.
mbecerra
User
User
Posts: 15
Joined: Mon Feb 28, 2005 4:59 am

Detect Editor Gadget Modified

Post by mbecerra »

I am trying to create a simple text editor and am having a bit of difficulty. I want to check to see if the text in the editor gadget was modified and if so set a flag. I tried to use KeyboardPushed(#PB_KEY_ALL) but was told i couldn't since that is for games and multimedia, and required OpenScreen() or OpenWindowedScreen(). Any assistence in this matter would be greatly appreciated.

PureTextED
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Detect Editor Gadget Modified

Post by rsts »

User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Detect Editor Gadget Modified

Post by skywalk »

If the extra overhead isn't a problem, look to the ScintillaGadget. 8)
There is so much functionality built-in and all OS supported.
Though, my simple use of #WM_LBUTTONUP, #WM_KEYUP may not work in Linux/MacOS.
But there is always the ScintillaCallBack(Gadget, *scinotify.SCNotification)

Code: Select all

EnableExplicit
#WIN = 0
#MNU = 1
#SCI = 2
#STB = 3
Define.i ri,wW,wH,wWo,wHo,ev,evM,evG,evT
Define.s Txt$
If OpenWindow(#WIN, 0, 0, 400, 400, "ScintillaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)  
  If CreateMenu(#MNU, WindowID(0))    
    MenuTitle("File")
    MenuItem(#MNU+1, "Save")
  EndIf
  If CreateStatusBar(#STB, WindowID(#WIN))
    AddStatusBarField(#PB_Ignore) ; autosize this field    
    StatusBarText(#STB,0," ")
  EndIf
  If InitScintilla()
    ScintillaGadget(#SCI, 5, 5, 300, 70, #Null)
    ScintillaSendMessage(#SCI, #SC_EOL_CRLF, 0, 0)
    ScintillaSendMessage(#SCI, #SCI_STYLESETFORE, 0, RGB(255, 0, 0))            
    Txt$ = "Enter / select text here..." + #CRLF$ + #CRLF$
    ScintillaSendMessage(#SCI, #SCI_SETTEXT, 0, @Txt$)            
    Txt$ = "Make changes and Click 'File - Save' to clear the change status." + #CRLF$
    ScintillaSendMessage(#SCI, #SCI_APPENDTEXT, Len(Txt$), @Txt$)
    ScintillaSendMessage(#SCI, #SCI_SETSAVEPOINT, 0, 0)        
  EndIf    
Else  
  End
EndIf

Repeat
  ev = WaitWindowEvent() 
  Select ev
  Case #PB_Event_SizeWindow
    wW = WindowWidth(#WIN)
    wH = WindowHeight(#WIN)    
    wWo = GadgetX(#SCI)
    wHo = GadgetY(#SCI) + MenuHeight() + StatusBarHeight(#STB)
    ResizeGadget(#SCI,#PB_Ignore,#PB_Ignore,ww-wWo,wh-wHo)    
  Case #PB_Event_Gadget 
    evG = EventGadget()
    evT = EventType()
    Select eVG
    Case #SCI            
      If ScintillaSendMessage(#SCI, #SCI_GETMODIFY, 0, 0)
        SetWindowTitle(#WIN,"ScintillaGadget*")  ; append '*' showing user modified contents.        
        ScintillaSendMessage(#SCI, #SCI_SETSAVEPOINT, 0, 0)        
      EndIf
    EndSelect  
  Case #WM_LBUTTONUP, #WM_KEYUP
    ; This gets len of all text...
    ;ri = ScintillaSendMessage(#SCI, #SCI_GETLENGTH, 0, 0)   : Txt$ = Space(ri+1)
    ; This gets the len of selected text... 
    ri = ScintillaSendMessage(#SCI, #SCI_GETSELTEXT, 0, 0): Txt$ = Space(ri+1)
    ri = ScintillaSendMessage(#SCI, #SCI_GETSELTEXT, 0, @Txt$)
    If ri
      If Len(Txt$) > 25
        Txt$ = RemoveString(Left(Txt$,22) + " ~...~" + Right(Txt$,3), #CRLF$)            
      EndIf          
      StatusBarText(#STB, 0, "Selected Text -> '" + Txt$ + "'")
    Else
      StatusBarText(#STB, 0, " ")
    EndIf      
  Case #PB_Event_Menu
    evM = EventMenu()
    If evM = #MNU+1
      ScintillaSendMessage(#SCI, #SCI_SETSAVEPOINT, 0, 0)              
      SetWindowTitle(#WIN,"ScintillaGadget")  
    EndIf    
  Case #PB_Event_CloseWindow
    Break 
  EndSelect
ForEver
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
C64
Enthusiast
Enthusiast
Posts: 151
Joined: Sat Dec 18, 2010 4:40 am

Re: Detect Editor Gadget Modified

Post by C64 »

mbecerra wrote:I want to check to see if the text in the editor gadget was modified
Check if GetGadgetText(#editor) is different to the previous check.
Post Reply