Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: blueshake on July 20, 2009, 05:02:45 am

Title: indentation guilds highlight
Post by: blueshake on July 20, 2009, 05:02:45 am
Hello :
     I found that indentation guilds can not highlight in codeblock.So I did a little work for it .
Code
Index: sdk/cbeditor.cpp
===================================================================
--- sdk/cbeditor.cpp (revision 5678)
+++ sdk/cbeditor.cpp (working copy)
@@ -2269,7 +2269,12 @@
         ch == _T('}') || ch == _T(']') || ch == _T(')'))
     {
         if (newPos != wxSCI_INVALID_POSITION)
+           {
                 control->BraceHighlight(currPos, newPos);
+                int currColum = control->GetColumn(currPos);
+                int newColum = control->GetColumn(newPos);
+                control->SetHighlightGuide((currColum < newColum) ? currColum :newColum);
+           }
         else
             control->BraceBadLight(currPos);
     }


[attachment deleted by admin]
Title: Re: indentation guilds highlight
Post by: ollydbg on July 20, 2009, 08:55:54 am
Really Cool!
I would test it in my local copy.
I suggest you can file a "patch" in the berlios page.
Title: Re: indentation guilds highlight
Post by: geiermeier on July 20, 2009, 08:59:32 am
Now that someone mentions it, this is really a missing feature. I've been using my finger on the screen to memorize indentations a lot of times with CB. I hope the colour will be customizable?
Title: Re: indentation guilds highlight
Post by: blueshake on July 20, 2009, 09:17:51 am
it's a shame to say that I don't know how to make a patch actually .even I read the the article about it in wiki.the color can be changed if you change the brace highlight color .
Title: Re: indentation guilds highlight
Post by: ollydbg on July 20, 2009, 09:30:20 am
◎blueshake

1, register a user in BerliOS
2, add a patch entry in this page
http://developer.berlios.de/patch/?group_id=5358

 :D
Title: Re: indentation guilds highlight
Post by: danselmi on July 20, 2009, 03:14:10 pm

Is it possible to highlight the indentation guides even when they are not shown normally?
Title: Re: indentation guilds highlight
Post by: blueshake on July 20, 2009, 03:36:47 pm
it can be shown in this way .but it seems that it don't show if the line has no indentation .see the pictures in attach .

[attachment deleted by admin]
Title: Re: indentation guilds highlight
Post by: killerbot on July 20, 2009, 05:31:49 pm
I have applied the 'not yet created patch' to trunk : rev 5695
Title: Re: indentation guilds highlight
Post by: ollydbg on July 21, 2009, 03:41:40 am
I have applied the 'not yet created patch' to trunk : rev 5695

I update to rev 5695, but no indent line will displayed when matching brace was highlight... :(



[attachment deleted by admin]
Title: Re: indentation guilds highlight
Post by: blueshake on July 21, 2009, 04:54:54 am
setting ->Editor ->General setting show indentation guides .Turn it on .
Title: Re: indentation guilds highlight
Post by: ollydbg on July 21, 2009, 05:03:58 am
setting ->Editor ->General setting show indentation guides .Turn it on .
thanks, but I found that the line is too short. not connect between two braces.
see the attachment.


[attachment deleted by admin]
Title: Re: indentation guilds highlight
Post by: blueshake on July 21, 2009, 05:16:00 am
it don't  show because it have no indentation in the line . add indentation in the line ,it will show ,I
don't konw why .
Title: Re: indentation guilds highlight
Post by: ollydbg on July 21, 2009, 01:03:40 pm
hi, if this file was opened in Notepad++, the line shows quite well. see the screen shot:


[attachment deleted by admin]
Title: Re: indentation guilds highlight
Post by: ollydbg on July 21, 2009, 01:35:26 pm
Also, I found the indentation guids line will "break" after I save my cpp file. see the screen shot below:

The first image was before saving.
The second image was captured after saving

[attachment deleted by admin]
Title: Re: indentation guilds highlight
Post by: oBFusCATed on July 21, 2009, 02:23:36 pm
This is because C::B removes the whites spaces at the end of the line, so this is not a new case...
Title: Re: indentation guilds highlight
Post by: ollydbg on July 21, 2009, 04:00:24 pm
This is because C::B removes the whites spaces at the end of the line, so this is not a new case...
Thanks for you explanation.
But can we learn from notepad++. they do a better job :D
Title: Re: indentation guilds highlight
Post by: rhf on July 21, 2009, 04:15:00 pm

But can we learn from notepad++. they do a better job :D
[/quote]
@ollydbg
On my machine it appears that notepad++ does the same thing if the Edit option "Trim Trailing Space" is used.
Title: Re: indentation guilds highlight
Post by: kisoft on July 21, 2009, 04:16:13 pm
Settings/Editor: uncheck "Strip trailing blanks".
Title: Re: indentation guilds highlight
Post by: ollydbg on July 21, 2009, 04:46:26 pm
Thanks to rhf and kisoft.
Yes, if I unckeck "Trim Trailing Space", there's no difference after "save".

But it is still strange, seems NotePad++ can show quite well compare with CB.(Note, they open the same cpp file)

you can see my reply#10 and reply#12.
Title: Re: indentation guilds highlight
Post by: rhf on July 21, 2009, 06:35:14 pm
But it is still strange, seems NotePad++ can show quite well compare with CB.(Note, they open the same cpp file)
Yes, it appears to be a lighter shade and not as distracting - which I would prefer. Perhaps there is a font setting or something to set this.
Title: Re: indentation guilds highlight
Post by: ollydbg on July 23, 2009, 04:21:25 am
I found the reason why the indent line will break.

First, if we check "show indent line" in the editor dialog. This function will be called.
src\sdk\wxscintilla\src\wxscintilla.cpp line 1301
Code
void wxScintilla::SetIndentationGuides (int indentView)
{
    SendMsg(SCI_SETINDENTATIONGUIDES, indentView, 0);  //Set breakpoint here
}

So, I set a breakpoint there, and found the parameter indentView = 1.

Refer to the scintilla document:
Quote
SCI_SETINDENTATIONGUIDES(int indentView)
SCI_GETINDENTATIONGUIDES
Indentation guides are dotted vertical lines that appear within indentation white space every indent size columns. They make it easy to see which constructs line up especially when they extend over multiple pages. Style STYLE_INDENTGUIDE (37) is used to specify the foreground and background colour of the indentation guides.

There are 4 indentation guide views. SC_IV_NONE turns the feature off but the other 3 states determine how far the guides appear on empty lines.
SC_IV_NONE    No indentation guides are shown.
SC_IV_REAL    Indentation guides are shown inside real indentation white space.
SC_IV_LOOKFORWARD    Indentation guides are shown beyond the actual indentation up to the level of the next non-empty line. If the previous non-empty line was a fold header then indentation guides are shown for one more level of indent than that line. This setting is good for Python.
SC_IV_LOOKBOTH    Indentation guides are shown beyond the actual indentation up to the level of the next non-empty line or previous non-empty line whichever is the greater. This setting is good for most languages.

and
In the scr/sdk/wxscintilla/src/scintilla/include/Scintilla.h line 215
Code
#define SC_IV_NONE 0
#define SC_IV_REAL 1
#define SC_IV_LOOKFORWARD 2
#define SC_IV_LOOKBOTH 3

So, the SC_IV_REAL will be used, which will cause a indentation line break.

So, I suggest that we can use:
SC_IV_LOOKFORWARD or SC_IV_LOOKBOTH.



By the way, I'd thank rhf for his help to find the reason!!!



Title: Re: indentation guilds highlight
Post by: ollydbg on July 23, 2009, 08:24:47 am
hi, this is the patch to get a continuous indentation guilds line.

Code
Index: cbeditor.cpp
===================================================================
--- cbeditor.cpp (revision 5697)
+++ cbeditor.cpp (working copy)
@@ -41,6 +41,8 @@
 #include "encodingdetector.h"
 #include "projectfileoptionsdlg.h"
 
+#include "wxscintilla/src/scintilla/include/Scintilla.h"
+
 const wxString g_EditorModified = _T("*");
 
 #define ERROR_MARKER          1
@@ -1081,7 +1083,7 @@
     }
 
     control->SetUseTabs(mgr->ReadBool(_T("/use_tab"), false));
-    control->SetIndentationGuides(mgr->ReadBool(_T("/show_indent_guides"), false));
+    control->SetIndentationGuides(mgr->ReadBool(_T("/show_indent_guides"), false)!=false?SC_IV_LOOKBOTH:SC_IV_NONE);
     control->SetTabIndents(mgr->ReadBool(_T("/tab_indents"), true));
     control->SetBackSpaceUnIndents(mgr->ReadBool(_T("/backspace_unindents"), true));
     control->SetWrapMode(mgr->ReadBool(_T("/word_wrap"), false));
@@ -2853,7 +2855,8 @@
     cbStyledTextCtrl* control = GetControl();
     int pos = control->PositionFromPoint(wxPoint(event.GetX(), event.GetY()));
     int style = control->GetStyleAt(pos);
-    NotifyPlugins(cbEVT_EDITOR_TOOLTIP, style, wxEmptyString, event.GetX(), event.GetY());
+    if(IsContextMenuOpened()==false)
+        NotifyPlugins(cbEVT_EDITOR_TOOLTIP, style, wxEmptyString, event.GetX(), event.GetY());
     OnScintillaEvent(event);
 }

Also, this patch disable the tooltip message if a context menu was opened.
Title: Re: indentation guilds highlight
Post by: Jenna on July 23, 2009, 08:26:38 am
Fixed in trunk (r5698) and (together with indendation-guide highlight) in cc-branch (r5699).

Thanks ollydbg.

By the way, if you quote from source-code, it would be nice to also know the filename and if possible the line in the file.

EDIT:

just the indendation-guide fix.
My changes and your post crossed each other.
Title: Re: indentation guilds highlight
Post by: ollydbg on July 23, 2009, 08:46:40 am
Ok, I know, and I have modified my previous posts.

Your patch is better than mine, it can avoid include another header "Scintilla.h", because the indentation guilds type was also defined in "include\wxscintilla\include\wx\wxscintilla.h" Line 186
Code
#define wxSTI_IV_NONE 0
#define wxSTI_IV_REAL 1
#define wxSTI_IV_LOOKFORWARD 2
#define wxSTI_IV_LOOKBOTH 3
:D
Title: Re: indentation guilds highlight
Post by: blueshake on July 23, 2009, 10:07:01 am
nice work. :D
Title: Re: indentation guilds highlight
Post by: rhf on July 23, 2009, 02:23:23 pm
@ollydbg and jens.

Well done, guys!

I would still like to see dimmer indentation guide lines, similar to what notepad++ uses.
I think it involves the setting of STYLE_INDENTGUIDE, but I don't know how to do it.

Thanks again,
Bob
Title: Re: indentation guilds highlight
Post by: blueshake on July 23, 2009, 02:36:43 pm
Style STYLE_INDENTGUIDE  is used to specify the foreground and background colour of the indentation guides.
Title: Re: indentation guilds highlight
Post by: ollydbg on July 23, 2009, 03:50:08 pm
@ollydbg and jens.

Well done, guys!

I would still like to see dimmer indentation guide lines, similar to what notepad++ uses.
I think it involves the setting of STYLE_INDENTGUIDE, but I don't know how to do it.

Thanks again,
Bob



Firstly, you can find in the scintilla document
http://www.scintilla.org/ScintillaDoc.html#BuildingScintilla

Quote
Style definition

While the style setting messages mentioned above change the style numbers associated with text, these messages define how those style numbers are interpreted visually. There are 256 lexer styles that can be set, numbered 0 to STYLE_MAX (255). Unless you use SCI_SETSTYLEBITS to change the number of style bits, styles 0 to 31 are used to set the text attributes. There are also some predefined numbered styles starting at 32, The following STYLE_* constants are defined.

STYLE_INDENTGUIDE    37    This style sets the foreground and background colours used when drawing the indentation guides.
note: we are only interest in STYLE_INDENTGUIDE    37
Secondly, you can see the similar definition macros in, note: we are only interest in STYLE_INDENTGUIDE    37

include\wxscintilla\include\wx\wxscintilla.h line 131
Code
// Styles in range 32..38 are predefined for parts of the UI and are not used as normal styles.
// Style 39 is for future use.
#define wxSCI_STYLE_DEFAULT 32
#define wxSCI_STYLE_LINENUMBER 33
#define wxSCI_STYLE_BRACELIGHT 34
#define wxSCI_STYLE_BRACEBAD 35
#define wxSCI_STYLE_CONTROLCHAR 36
#define wxSCI_STYLE_INDENTGUIDE 37
#define wxSCI_STYLE_CALLTIP 38
#define wxSCI_STYLE_LASTPREDEFINED 39
#define wxSCI_STYLE_MAX 255

So, in wxScintilla, they use wxSCI_STYLE_INDENTGUIDE.

Thirdly, I found the code in

sdk\wxscintilla\src\wxscintilla.cpp line 667

Code
// Set the foreground colour of a style.
void wxScintilla::StyleSetForeground (int style, const wxColour& fore)
{
    SendMsg(SCI_STYLESETFORE, style, wxColourAsLong(fore));
}

Forthly, I think you can do this in the function below:

sdk\editorcolourset.cpp line 434

Code
void EditorColourSet::Apply(HighlightLanguage lang, cbStyledTextCtrl* control)
{
    ......

    control->StyleSetForeground(wxSCI_STYLE_INDENTGUIDE, Dimmer color like comment text);
    ......

 
}


Finally, there is only one last question:
How can I get the "Dimmer color like comment text" value?

Any  comments?
Title: Re: indentation guilds highlight
Post by: ollydbg on July 24, 2009, 07:32:27 am
hi, add this statement will let the indentation guild line become green.

sdk\editorcolourset.cpp Line 463

Code
    control->StyleSetForeground(wxSCI_STYLE_INDENTGUIDE,wxColour(0xFF00));

But I still don't know how to use a predefined color... :(
Title: Re: indentation guilds highlight
Post by: blueshake on July 24, 2009, 07:47:14 am
it works. :D
in this file gdicmn.h
Code
#define wxBLACK       wxStockGDI::GetColour(wxStockGDI::COLOUR_BLACK)
#define wxBLUE        wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE)
#define wxCYAN        wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN)
#define wxGREEN       wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN)
#define wxLIGHT_GREY  wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY)
#define wxRED         wxStockGDI::GetColour(wxStockGDI::COLOUR_RED)
#define wxWHITE       wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)

or add a option in setting???
Title: Re: indentation guilds highlight
Post by: blueshake on July 24, 2009, 07:50:16 am
I just test the wxLIGHT_GREY
Code
control->StyleSetForeground(wxSCI_STYLE_INDENTGUIDE, *wxLIGHT_GREY);

@rhf
Is this the style you talk about?

[attachment deleted by admin]
Title: Re: indentation guilds highlight
Post by: ollydbg on July 24, 2009, 02:08:19 pm
I think He(rhf) would like "a dimmer indentation guide lines", I personally prefer the indentation guide line color = color of comment text.

But I don't know how to get that color value from predefined user color option. :(
Title: Re: indentation guilds highlight
Post by: blueshake on July 24, 2009, 03:47:57 pm
maybe it is relative to mset.m_Colours in line 467 in editorcolourset.cpp.but I am not sure.
Title: Re: indentation guilds highlight
Post by: rhf on July 24, 2009, 04:39:04 pm
@ollydbg and blueshake,

Following your suggestions, I added the following to sdk\editorcolourset.cpp in Line 463:
Code
 control->StyleSetForeground(wxSCI_STYLE_INDENTGUIDE, *wxLIGHT_GREY);

This worked beautifully, doing exactly what I wanted, and it even changes color when the braces are highlighted.

Well done and thanks,
Bob
Title: Re: indentation guilds highlight
Post by: ollydbg on July 24, 2009, 04:57:14 pm
hi, I have found a better way, that is: I can set the indentation guild line's color =C++ Comment color.
By default, it was a gray line.

You can add these code in

sdk\editorcolourset.cpp  line 506-509.

Code
        if (opt->name == _T("Comment (normal)") )
        {
            control->StyleSetForeground(wxSCI_STYLE_INDENTGUIDE,opt->fore);
        }

Title: Re: indentation guilds highlight
Post by: rhf on July 24, 2009, 10:50:31 pm
You can add these code in
sdk\editorcolourset.cpp  line 506-509.
Code
        if (opt->name == _T("Comment (normal)") )
        {
            control->StyleSetForeground(wxSCI_STYLE_INDENTGUIDE,opt->fore);
        }
Very good, ollydbg, it is indeed a more general solution than using the fixed setting in my reply #33 above. Now if someone could just add "Indentation guideline" to the Configure editor Syntax highlighting list, everyone could use their own settings, and we would not have to use up one of the existing highlight options. I tried to do this but couldn't figure it out.
Title: Re: indentation guilds highlight
Post by: Jenna on July 24, 2009, 11:13:12 pm
Now if someone could just add "Indentation guideline" to the Configure editor Syntax highlighting list, everyone could use their own settings, and we would not have to use up one of the existing highlight options. I tried to do this but couldn't figure it out.

If I see it right the list is created from the lexer's content, so it can not easily be added to the list, without changing all lexers.

<Edit>
On the other hand that would be not such a hard work, because the style for the indendation guide already exists, so adding :
Code
				<Style name="Indendation guide"
index="37"
fg="55,55,55"/>
to sdk/resources/lexers/lexer_cpp.xml (and running update[.bat] afterwards to copy the changed file to the right place) makes the indendation guide's colour configurable at next start.
</Edit>

By the way the keyword "Comment (normal)" does not exist for all languages.

And the highlight-colour is always the same as used for matching braces:
Quote from: wxScintilla docu
void SetHighlightGuide (int column)
int GetHighlightGuide()


When brace highlighting occurs, the indentation guide corresponding to the braces may be highlighted with the brace highlighting style, wxSCI_STYLE_BRACELIGHT (34). Set column to 0 to cancel this highlight.
Quote from: sdk/wxscintilla/src/scintilla/src/Editor.cxx:2918
      pixmapIndentGuideHighlight->FillRectangle(rcIG, vs.styles[STYLE_BRACELIGHT].back.allocated);
      pixmapIndentGuideHighlight->PenColour(vs.styles[STYLE_BRACELIGHT].fore.allocated);

That means the highlight-style can never be different from the matching-braces highlight-style without patching scintillas-sources.
Title: Re: indentation guilds highlight
Post by: ollydbg on July 25, 2009, 03:18:33 am


<Edit>
On the other hand that would be not such a hard work, because the style for the indendation guide already exists, so adding :
Code
				<Style name="Indendation guide"
index="37"
fg="55,55,55"/>
to sdk/resources/lexers/lexer_cpp.xml (and running update[.bat] afterwards to copy the changed file to the right place) makes the indentation guide's colour configurable at next start.

Really good  catch!
Thanks jens!!!
That also make its color configurable in Editor->Syntax highlighting dialog.

Edit
If I change indentation guide's colour, will it be saved in my "F:\cb_svn\src\output\share\CodeBlocks\lexers\lexer_cpp.xml" ?

It seems even I close CB, this xml file leaves unchanged. But the next time I run CB, the color do persist.


So, where does the customized color configuration be saved?
Thanks.

Edit2
Well, I find the answer myself. the customized color setting was saved in "default.conf". :D

Code
<editor>
<colour_sets>
               .........
<cc>
<style20>
<FORE>
<colour r="255" g="0" b="0" />
</FORE>
                ........

</colour_sets>
Title: Re: indentation guilds highlight
Post by: rhf on July 25, 2009, 03:39:02 pm
Thanks to all of you guys! This is nice work.

By the way Jens, yesterday I tried exactly the same mod to lexer_cpp.xml that you suggest in your Reply #36 and nothing happened - because, Duh!, I never ran update.

I really like having control over the style of the guide that this gives me.
Title: Re: indentation guilds highlight
Post by: Jenna on July 25, 2009, 04:06:30 pm
Thanks to all of you guys! This is nice work.

By the way Jens, yesterday I tried exactly the same mod to lexer_cpp.xml that you suggest in your Reply #36 and nothing happened - because, Duh!, I never ran update.

I really like having control over the style of the guide that this gives me.

You should also be able to change the used lexer-xml directly.

On linux it's in /usr/share/codeblocks/lexers and on windows in <C::B-installation-directory>\share\CodeBlocks\lexers.

Or better create a subdirectory lexers in C::B's conf-dir copy the lexer-xml you want to change inside and change it (only tested on linux).

This has the advantage, that an update will not overwrite it, but of course the disadvantage that an update will not overwrite it
... even if some essentials have changed.
Title: Re: indentation guilds highlight
Post by: rhf on July 25, 2009, 05:25:21 pm
OK. Thanks, Jens.
Title: Re: indentation guilds highlight
Post by: rhf on July 26, 2009, 05:55:13 pm
Hi Jens,

Regarding your suggestion in Reply #36 above:

...  so adding :
Code
				<Style name="Indentation guide"
index="37"
fg="55,55,55"/>
to sdk/resources/lexers/lexer_cpp.xml (and running update[.bat] afterwards to copy the changed file to the right place) makes the indendation guide's colour configurable at next start.

I suppose it was obvious to everyone but me that this change to lexer_cpp.xml gives the user control over the guide syntax highlighting without any code changes at all to sdk\editorcolourset.cpp.  Since the Indentation guides checkbox has been added to Configure editor -> General settings in the trunk, it seems reasonable to add this change to the trunk as well.
Title: Re: indentation guilds highlight
Post by: ollydbg on July 28, 2009, 04:14:27 pm
Quote
Since the Indentation guides checkbox has been added to Configure editor -> General settings in the trunk, it seems reasonable to add this change to the trunk as well.
I suggest this change should be added in trunk soon. :D
Title: Re: indentation guilds highlight
Post by: Jenna on July 28, 2009, 04:34:58 pm
Quote
Since the Indentation guides checkbox has been added to Configure editor -> General settings in the trunk, it seems reasonable to add this change to the trunk as well.
I suggest this change should be added in trunk soon. :D

The indendation guide checkbox is there since a long time, so I don't see the relationship.
At the moment (wx)Scintilla uses the default foreground-color for the indendation-guide, so I don't think it's an absolute must to make the style configurable.
There might be other changes (or issues) with a higher priority.
Title: Re: indentation guilds highlight
Post by: ollydbg on July 28, 2009, 04:44:41 pm
There might be other changes (or issues) with a higher priority.
Yes, other more important issues need to be fixed. You are a hard working dev!
Title: Re: indentation guilds highlight
Post by: rhf on July 28, 2009, 04:58:21 pm
There might be other changes (or issues) with a higher priority.
Yes, other more important issues need to be fixed. You are a hard working dev!
I agree also. If I could help, perhaps by sending you a patch, I would be glad to do so.
Thanks again for your good work.