FindText Scintilla flag
BlitzMax Forums/Brucey's Modules/FindText Scintilla flag
| ||
Rem bbdoc: Find some text in the document. End Rem Method FindText:Int(minPos:Int, maxPos:Int, text:String, flags:Int) Return bmx_wxscintilla_findtext(wxObjectPtr, minPos, maxPos, text, flags) End MethodIs there any flag for: WHOLEWORD and MATCHCASE? Const wxSCI_WHOLEWORD:Int = 2 Const wxSCI_MATCHCASE:Int = 4 |
| ||
You can try to make a constant or variable with a content of:Const wxSCI_BOTH:Int = wxSCI_WHOLEWORD | wxSCI_MATCHCASE ...and pass that to Find function. -Henri |
| ||
Of course this means you could call it that way: FindText(minPos, maxPos, wxSCI_WHOLEWORD | wxSCI_MATCHCASE) bye Ron |
| ||
sorry I can't find any flag that sort out wholeword or matchcase I test binary number: 1, 2, 4, 8, 16, 32, 64, 128, 256 it find all In my mind I need to let the function FindText find the text and I need to sort it out manually, but I am confident that Scintilla have a function already for this (or BlitzMax)! Maybe I am wrong that the flag has anything to do with finding wholeword or matchcase? Const wxSCI_WHOLEWORD:Int = 2 Const wxSCI_MATCHCASE:Int = 4 It look like these 2 constant is not for the function FindText |
| ||
It does indeed work as I just tested it and the results were exactly what should be. If you want to test it yourself then here's something to try out: EDIT: You might want to back the file first if you ever want to revert back to original. 1. Open up the scintilla.bmx in the samples folder 2. Add these imports on top of file under import wx.wxFrame Import wx.wxDialog Import wx.wxPanel Import wx.wxTextCtrl Import wx.wxStaticLine Import wx.wxStaticText Import wx.wxStdDialogButtonSizer Import wx.wxButton Import brl.standardio 2. Modify the Edit-type by adding line ConnectAny(wxEVT_KEY_DOWN, OnKeyDown)...somewhere in the bottom of OnInit() method. Now add a new function somewhere inside Edit type called Function OnKeyDown(ev:wxEvent) Local key_ev:wxKeyEvent = wxKeyEvent(ev) Local keyCode:Int = key_ev.GetKeyCode() Local lv:Edit = Edit(ev.sink) If Not lv Then Notify "LV not found!!";Return Local key:String = Chr(keyCode) If key = "F" Then If key_ev.ControlDown() Then Local txt:String = EntryDlg("Find","Find") If txt Then Print lv.FindText(0, 100, txt, wxSCI_WHOLEWORD | wxSCI_MATCHCASE) EndIf EndIf EndIf ev.skip() EndFunctionThis gets executed when you press any key. 3. Finally add this function and type in the bottom of whole file Function EntryDlg:String(text:String, title:String) Local dial:TEntryDialog = New TEntryDialog.Create(text, title) Local value:String = dial.GetString() dial.Free() Return value EndFunction Type TEntryDialog Extends wxDialog Field m_panel:wxPanel Field m_label1:wxStaticText Field m_field1:wxTextCtrl Field m_staticline:wxStaticLine Field m_sdbSizer:wxStdDialogButtonSizer Field m_sdbSizerCancel:wxButton Field m_sdbSizerOK:wxButton Field text:String Field value:String Field ret:Int Method Create:TEntryDialog(txt:String, title:String) text = txt Return TEntryDialog(Super.Create_(Null, wxID_ANY, title, -1, -1, -1, -1, wxDEFAULT_DIALOG_STYLE)) End Method Method OnInit() Local bSizer1:wxBoxSizer = New wxBoxSizer.Create(wxVERTICAL) Local bSizer2:wxBoxSizer = New wxBoxSizer.Create(wxVERTICAL) Local bSizer3:wxBoxSizer = New wxBoxSizer.Create(wxHORIZONTAL) m_sdbSizer = New wxStdDialogButtonSizer.CreateSizer() m_sdbSizerOK = New wxButton.Create(Self, wxID_OK) m_sdbSizerCancel = New wxButton.Create(Self, wxID_CANCEL) m_panel = New wxPanel.Create(Self, wxID_ANY,,,,, wxTAB_TRAVERSAL) m_panel.SetForegroundColour(New wxColour.Create(0,0,0)) m_panel.SetBackgroundColour(New wxColour.Create(255,255,255)) m_staticline = New wxStaticLine.Create(Self, wxID_ANY,,,,, wxLI_HORIZONTAL) m_label1 = New wxStaticText.Create(m_panel, wxID_ANY, text) m_label1.Wrap(-1) m_field1 = New wxTextCtrl.Create(m_panel, wxID_ANY, "",,,200,,0) bSizer2.AddCustomSpacer(0, 15, 1, wxEXPAND, 5) bSizer3.Add(m_label1, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5) bSizer3.Add(m_field1, 0, wxRIGHT|wxLEFT, 5) bSizer2.AddSizer(bSizer3, 1, wxEXPAND, 5) bSizer2.AddCustomSpacer(0, 15, 1, wxEXPAND, 5) bSizer1.Add(m_panel, 1, wxEXPAND, 5) bSizer1.Add(m_staticline, 0, wxEXPAND, 5) m_sdbSizer.AddButton( m_sdbSizerOK) m_sdbSizer.AddButton( m_sdbSizerCancel) bSizer1.AddSizer(m_sdbSizer, 0, wxEXPAND|wxTOP|wxBOTTOM, 10) m_panel.SetSizer(bSizer2) m_panel.Layout() bSizer2.Fit(m_panel) m_sdbSizer.Realize() SetSizer(bSizer1) Layout() bSizer1.Fit(Self) Center(wxBOTH) m_sdbSizerCancel.ConnectAny(wxEVT_COMMAND_BUTTON_CLICKED, OnCancel, Null, Self) m_sdbSizerOK.ConnectAny(wxEVT_COMMAND_BUTTON_CLICKED, OnOk, Null, Self) m_sdbSizerOK.SetDefault() m_field1.SetFocus() Centre() ret = ShowModal() If ret Then value = m_field1.GetValue() Else value = "" EndIf End Method Method GetString:String() Return value EndMethod Function OnCancel(ev:wxEvent) Local d:TEntryDialog = TEntryDialog(ev.sink) d.EndModal(False) End Function Function OnOk(ev:wxEvent) Local d:TEntryDialog = TEntryDialog(ev.sink) d.EndModal(True) End Function End Type Now you have find functionality which can be activated by pressing CTRL + F . Try changing the constant in OnKeyDown()-function to see the effects. If text is found then starting position is printed in MaxIDE console and if no matching text is found then -1 is printed. -Henri |
| ||
The problem might be: I test binary number: 1, 2, 4, 8, 16, 32, 64, 128, 256 it find all 1 | 2 does not mean: "if res =1 or res = 2". 1 | 2 = 3 1 | 4 = 5 1 | 2 | 4 = 7 2 | 4 = 6 So you would have needed to check for 1-256 to check for all possibilities. bye Ron |
| ||
I use this extra check if search text = selected find text _MatchCase = 0 no check, 1 check matchcase Method checkStr:Int(_Txt:String, _MatchCase:Int) If Not _MatchCase Then Return 1 If GetSelectedText() = _Txt Then Return 1 End MethodStill find wholeword for another day Derron: I see my laziness so I test up to: 0 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216The best would be if FindText could check for the matchcase and wholeword! flags in: Method FindText:Int(minPos:Int, maxPos:Int, text:String, flags:Int) Don't work as I understand it anyhow! By the way FindText is a scintilla Method (maybe there is many FindText that look the same) I was eager to test Henri example, specially when I never use wxBoxSizer I gone far in my project and never understand the power of wxBoxSizer yet I guess it's why I could not convert my project to the aui.bmx example some month ago! I still don't have a toolbar yet ^^ unfortunately I could not make Henri's example to run Local lv:Edit = Edit(ev.sink)I search all file for Edit but it look like I don't have Edit installed in my BlitzMax |
| ||
Method checkStr:Int(_Txt:String, _MatchCase:Int) If Not _MatchCase Then Return 1 If GetSelectedText() = _Txt Then Return 1 End Method Why not Method checkStr:Int(_Txt:String, _MatchCase:Int) If not _MatchCase Then Return GetSelectedText() = _Txt Return GetSelectedText().ToLower() = _Txt.ToLower() End Method -- which does check ignoring the case or not ignoring it. Derron: I see my laziness so I test up to: [...] Like said, if you set multiple flags, the resulting bitmask will not be power of 2 ... Flags = Flag1 | Flag2 = 3 Flags = 1 | 2 = 3 See the example I posted in my reply above. More exactly: you check 0, 1, 2, 4, 8 ... but you never checked "3" (flag 1 and flag 2 enabled) bye Ron |
| ||
here's a working example - a mix of the scintilla sample, and Henri's find dialog, with an additional set of check boxes so that you may experiment by toggling the flags : Try experimenting with the word "Thre", and adjust the flags to see how the find result reflects the changes. The flags themselves are defined in consts.bmx, in the wscintilla.mod folder. |
| ||
Thank thee very much, that example was a gold mine for me |
| ||
I search all file for Edit but it look like I don't have Edit installed in my BlitzMax "Edit" is a Type defined in the scintilla sample. If you had followed Henri's instructions, you'd have found it there :-) |
| ||
When I run the Henri/Brucey example it didn't find anything, then I start expect it's my computer that is mocking with me! So I god forbid restart my computer, that is against my religion and then the example code start finding text miraculous. I revert my own find and now it work, maybe I need restart my computer at least every month or so? The funny part in this story is that: Const wxSCI_WHOLEWORD:Int = 2 Const wxSCI_MATCHCASE:Int = 4was working the whole time ^^ Sometime laziness has it's drawbacks! |