Author Topic: CSED - Modification  (Read 31157 times)

0 Members and 1 Guest are viewing this topic.

Offline Gary Beene

  • Jr. Member
  • **
  • Posts: 96
  • User-Rate: +3/-0
CSED - Modification
« on: October 17, 2013, 02:31:56 AM »
I was looking at CSED and wanted to see if I could modify it highlight the name of a function/method, then have CSED jump to that function/method - regardless of which file/TAB it is in.  Perhaps a context menu with "GoTo Function Under Cursor", or something like that.   I don't see that feature  right now.

Has anyone already done a mod like that?

Doesn't seem like it would be terribly hard, but it's always best to see if the job's already been done!

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: CSED - Modification
« Reply #1 on: October 17, 2013, 03:46:47 AM »
I remember that I implemented it in the old SED editor. There was also a shortcut key to go back. That editor had more features than CSED, but as it was my first SDK application it was not as well structured as CSED. Besides, there were apportations of several people that later left the project and was a nightmare to me to update the code with each new version of PB. I write CSED from scratch and decided to implement only the features that I use and allow others to use it to make their own versions if they wish.

I also used CSED to test my CWindows class and wrappers and the beta versions of the new compilers. It was the first PB application to be fully unicode and High DPI aware.

Offline Gary Beene

  • Jr. Member
  • **
  • Posts: 96
  • User-Rate: +3/-0
Re: CSED - Modification
« Reply #2 on: October 17, 2013, 04:26:41 PM »
Jose,
I downloaded v1.03 (that's the latest, yes) and tried to compile with PBWin10.

This line fails (line #963 in CSED.bas):
Code: [Select]
If hwndClient Then AfxShowFileProperties(hwnd, AfxGetWindowText(MdiGetActive(hwndClient))), %TRUE)
Looking at your afxshell.inc file, the AfxShowFileProperties requires only 2 arguments, but you have 3 in the CSED.bas code.

It looks like the %True show be removed. Is that true?

Offline Pierre Bellisle

  • Jr. Member
  • **
  • Posts: 82
  • User-Rate: +11/-7
Re: CSED - Modification
« Reply #3 on: October 17, 2013, 04:48:36 PM »
Hey Gary,

I got this...

••• CSED103_Source\CSED.BAS
IF hwndClient THEN AfxShowFileProperties(hwnd, AfxGetWindowText(MdiGetActive(hwndClient)), %TRUE)

••• José\Windows API Headers\2.05\AfxShell.inc
FUNCTION AfxShowFileProperties (BYVAL hwnd AS DWORD, BYREF wszFileName AS WSTRINGZ, OPTIONAL BYVAL bDisplayError AS LONG) AS LONG

••• José\Windows API Headers\3.1.0.4\AfxShell.inc
FUNCTION AfxShowFileProperties (BYVAL hwnd AS DWORD, BYREF wszFileName AS WSTRINGZ) AS LONG

So I guess it's true that %true should be thrown away...   ;D
« Last Edit: October 17, 2013, 04:58:45 PM by Pierre Bellisle »

Offline Gary Beene

  • Jr. Member
  • **
  • Posts: 96
  • User-Rate: +3/-0
Re: CSED - Modification
« Reply #4 on: October 17, 2013, 05:03:57 PM »
Howdy Pierre!
Always good to hear from you!

I compiled it successfully without the %TRUE. I'll watch for any obnoxious behaviour.  But based on what 2.05 says it was for, looks like its a no-impact change!

Offline Pierre Bellisle

  • Jr. Member
  • **
  • Posts: 82
  • User-Rate: +11/-7
Re: CSED - Modification
« Reply #5 on: October 17, 2013, 05:52:45 PM »
According to 2.05 this was a flag to generate a messagebox in case of a ShellExecuteEx error,
like "File not found", "Path not found", "Access denied", etc.

So, no big deal I guess....

Pierre

« Last Edit: October 17, 2013, 06:01:13 PM by Pierre Bellisle »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: CSED - Modification
« Reply #6 on: October 17, 2013, 05:53:20 PM »
There are not side effects. Just remove the %TRUE parameter.

Offline Theo Gottwald

  • Administrator
  • Hero Member
  • *****
  • Posts: 919
  • User-Rate: +30/-4
    • it-berater
Re: CSED - Modification
« Reply #7 on: October 17, 2013, 11:11:25 PM »
Gary, there are a few more bits that you can change in CSED.
I remember that i changed a setting that influences the quality of the font-drawing.
Possibly Jose remembers the exact parameters. It had to do with the scintilla control.


Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: CSED - Modification
« Reply #8 on: October 17, 2013, 11:47:20 PM »
In the file CSED_SCI.INC, after

Code: [Select]
' ========================================================================================
' Set Scintilla Edit Control's options
' ========================================================================================
SUB CSED_SetScintillaOptions (BYVAL hSci AS DWORD, BYVAL strFileExt AS STRING)

   LOCAL bitsNeeded AS LONG   ' // Number of bits needed by the lexer for styling

   ' // Get direct pointer for faster access
   LOCAL pSci AS DWORD   ' // Scintilla's direct pointer
   pSci = SCI_GetDirectPointer(hSci)
   IF pSci = 0 THEN EXIT SUB


add

Code: [Select]
   ' // If Vista/Windows 7, use Direct Write for higher quality antialiased drawing
   IF AfxGetWindowsVersion => 6 THEN
      SCIP_SetBufferedDraw(pSci, 0)
      SCIP_SetTechnology(pSci, %SC_TECHNOLOGY_DIRECTWRITE)
   END IF

But you need to download the latest version of SciLexer.dll. Older versions were buggy and it did not worked.

Offline Gary Beene

  • Jr. Member
  • **
  • Posts: 96
  • User-Rate: +3/-0
Re: CSED - Modification
« Reply #9 on: October 18, 2013, 01:37:40 AM »
I've completed the mod (well, still testing, but good so far). Other than some code to add a new context menu, "Find Procedure", I was able to keep the change down to a single function which I placed in csed.bas

User action is like this:
1. Highlight text (a function/sub/method/fastproc name)
2. Right click and select a new context menu item , "Find Procedure"
3. Click the menu item to search open files for a procedure by the name of the selected text
4. If found, matching TAB/text is selected/highlighted. Document scrolls to the matching procedure.
5. If not found, a MsgBox pops up with "Procedure NOT found ..." + selectedtext

There's no Find Next - I assume there's only one procedure by the selected name.

Here's the function I added. It's called when the context menu is selected. I pulled the basic enumeration code from CSED_TabCtrl.INC, then added the search lines from some code I already had on hand.

Jose, the pSed.hEdit values seems to get updated by the enumeration code (MDIActive, I'd guess). Is that right?

If there's any obvious problem with this code being compatible with the rest of the CSED code, please let me know! 

Code: [Select]
Sub LocateProcedure_BEENE(temp$)        'temp$ is highlighted text
   Local i,j,iResult,nTAB As Long, hMDI As Dword
   Local vPath As Variant, tmp$, FindStructure As SCI_TextToFind

   'strings to look for--------------------------------
   tmp$ = LTrim$(LCase$(temp$))
   Dim target(6) As StringZ * 65
   target(0) = "sub " + tmp$               : target(1) = "function " + tmp$
   target(2) = "static sub " + tmp$        : target(3) = "static function " + tmp$
   target(4) = "callback function " + tmp$ : target(5) = "fastproc function " + tmp$
   target(6) = "method " + tmp$

   'enumerate Edit windows-----------------------------
   AfxDisableWindowRedraw pSed.hwndClient                   'disable redraw
   hMDI = GetWindow(pSed.hwndClient, %GW_Child)
   While hMDI
      vPath = AfxGetWindowText(hMdi)                        'get path from the collection
      nTab = CSED_GetTabNumberFromPath(Variant$$(vPath))    'get TAB number from Path
      TabCtrl_SetCurSel(pSed.hTabMdi, nTab)                 'select the TAB
      MDIActivate(pSed.hwndClient, hMdi)                    'activate this MDI child window
      '---highlight search string, if found, in newly activated TAB edit control ----------
         For j = 0 To UBound(target)
            FindStructure.Chrg.cpMin = 0
            FindStructure.Chrg.cpMax = SendMessage(pSed.hEdit,%SCI_GetLength,0,0)
            FindStructure.lpstrText = VarPtr(target(j))
            iResult = SendMessage (pSed.hEdit, %SCI_FindText, 0, VarPtr(FindStructure))
            If iResult > -1 Then
               SendMessage pSed.hEdit, %SCI_SetSel, FindStructure.ChrgText.cpMin, FindStructure.ChrgText.cpMax
               AfxEnableWindowRedraw pSed.hwndClient        'enable redraw
               If pSed.hEdit Then RedrawWindow pSed.hEdit, ByVal %NULL, %NULL, %RDW_ERASE Or %RDW_FRAME Or %RDW_INVALIDATE
               Exit Loop
            End If
         Next j
      '-----------------------------------------------------------------
      hMDI = GetWindow(hMDI, %GW_HWNDNEXT)
   Wend
   If iResult = - 1 Then MsgBox "Procedure NOT found ...  " + tmp$, %MB_Ok + %MB_IconExclamation, "Search for Procedure"
End Sub
« Last Edit: October 18, 2013, 11:23:02 PM by Gary Beene »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: CSED - Modification
« Reply #10 on: October 18, 2013, 01:49:16 AM »
When you call pSed.hEdit, you always get the handle of the active scintilla control, because it does not return you an stored value, but is a property that retrieves it by calling GetDlgItem(MdiGetActive(m_hwndClient), %IDC_EDIT).

Offline Gary Beene

  • Jr. Member
  • **
  • Posts: 96
  • User-Rate: +3/-0
Re: CSED - Modification
« Reply #11 on: October 18, 2013, 03:59:07 AM »
Jose,
Thanks for that explanation. Now that you describe where hEdit comes from, I can see that in your code.

It occurred to me that there should be a simpler way to enumerate the TABs/Scintilla controls than what I used up above, one that doesn't require the use of the vpath approach.

This snippet is what I'm thinking ...
Code: [Select]
   TABCount = SendMessage(pSed.hTabMdi, %TCM_GetItemCount,0,0)
   For i = 0 To TabCount
      TabCtrl_SetCurSel(pSed.hTabMdi, i)       'select the TAB
      hMDI = ?????                             '<---- how to get hMDI of i-th TAB
      MDIActivate(pSed.hwndClient, hMdi)       'activate this MDI child window
      '--- search/highlight code goes here
   Next i
But I haven't been able to figure out the line that gets the hMDI value in each pass of the loop.  Would you point me in the right direction? 
« Last Edit: October 18, 2013, 04:46:10 AM by Gary Beene »

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
Re: CSED - Modification
« Reply #12 on: October 18, 2013, 05:52:21 AM »
I'm afraid not. The scintilla controls are not children of the tab controls. Therefore, selecting a tab does not activate any window. To get hMdi you have to call MdiGetActive, but as the active window has not changed, you will always get the same handle (the one of the last activated MDI child window) no mather of which tab you select.

Offline Paul Squires

  • Jr. Member
  • **
  • Posts: 90
  • User-Rate: +11/-5
    • PlanetSquires
Re: CSED - Modification
« Reply #13 on: October 18, 2013, 01:03:06 PM »
Just a suggestion:
Instead of highlighting the text and then selecting from a menu to search for the procedure, try getting the word at the current cursor position and then select the find procedure from the menu. Eliminating the need to highlight the word first is common in most editors/IDE's.
Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor
http://www.planetsquires.com

Offline Aslan Babakhanov

  • Newbie
  • *
  • Posts: 24
  • User-Rate: +5/-3
Re: CSED - Modification
« Reply #14 on: October 18, 2013, 01:51:56 PM »
BTW, this option is available in QB (4.5, 7.1) ide's. You just move cursor to the sub/function name and pressing F2, then immediately getting in to the list of subroutines with highlighted function/sub. You only need to press ENTER key to jump. If I'm not mistaken, that worked even with included files. Say you have main.bas and two included files incl1.inc and incl2.inc. Function AAA placed in incl2.inc file and called from main.bas. You move cursor to AAA sub in main.bas and pressing F2 - Ide immediately showing the list of all subs and moving cursor to the AAA sub in incl2.inc file... Pretty easy and helpful, if you want to tap onto desired sub right from cursor, without touching the mouse.