Author Topic: Creating User Defined Labels  (Read 4725 times)

Theno

  • Guest
Creating User Defined Labels
« on: April 19, 2010, 08:07:04 PM »
Hi friends,

I created two labels for my own use. But I want to share it with friends here to help them to create their own labels. I got help from Stefan's topic here and messages about TODO. I think he must get the most hard-working member of the forum prize :) And also thanks to Alex for his never ending support ;)

http://forum.hippoedit.com/index.php/topic,621.0.html

What I did here different from Stefan's example is defining it as a scope to show in hierarchy bar and also created another block that behaves like another comment block. Also my labels name and description are separated from "-" character so you can write different thing to the both parts.

First we create our block.
You can do it without creating another block, with using an existing block. But since we don't want these strings executed on our code page, they must be inside a comment block, or a block that will behave like a comment block too as I did.

Code: [Select]
<Style id="remark" name="Remarks" image="13" bold="0" italic="1" underline="0" overview="0" clr="Format tag" bkclr="#FFFFFFFF">
        <Blocks>
                <Block open="''" close="\n"/>
        </Blocks>
</Style>

I created a style named remark and I said HE that you will use this style only inside the characters that I specified as a block. In asp '(apos) and \n(new line) is a comment block. So I created ''(2apos) and \n(new line) as my new block. So I can colorize my new block other than my comment style though it still behaves like a comment.

Second we create our labels.

Code: [Select]
   
<Label group="Block" match="Block:\s*((\w*\s?)+)\s+-\s+(.*?)($|/)" name="\1" descr="\3" image="14" scope="1">
        <Containers open="remark"/>
</Label>
<Label group="TODO" match="TODO:\s*((\w*\s?)+)\s+-\s+(.*?)($|/)" name="\1" descr="\3" image="15" scope="1">
        <Containers open="remark"/>
</Label>

My labels name are Block and TODO, they are actually equal as syntax and working the only difference is I gave different images to them to easily separate and navigate to them.

We define the labels by giving a name to the group attribute. In match attribute we must specify the regex to find the string that we want to make a label. Here our regex is like this.

TODO:\s*((\w*\s?)+)\s+-\s+(.*?)($|/)

\s : space characters
\w : any word character
. : any character
$ : end of line
| : logical or
- : same character itself
/ : same character itself

* : several (0 or more) of the previous
+ : more than 1 (1 or more) of the previous (there must be at least 1)
? : 0 or 1 of the previous

So this sentence says; First find "TODO:" string. Then it can be followed by several space characters (\s*), then there can be several word characters (\w*) followed by 0 or 1 space characters (\s?) - this means a word - and there can be more than 1 words like this (+) and this part creates our \1 definition. And they can be followed by 1 or more space characters (\s+) till "-" character is found. Again after "-" character there can be at least one space characters (\s+) after this, search for any characters that can be several  (.*) and there can be 0 or 1 of them (?). And this part creates our \3 definition. Search like this till the end of line ($) or "/" character is found ($|/).

I hope it is understandable :)
For more information on Regex you can check these links.
http://forum.hippoedit.com/index.php/topic,90.0.html
http://regexlib.com/CheatSheet.aspx

Also if you want to get info about Boost regular expression library which is used by HE by default, please check the links below.
http://www.boost.org/doc/libs/1_42_0/libs/regex/doc/html/boost_regex/syntax.html
http://regexlib.com/RETester.aspx

I also gave each label different images (image="14" and image="15"). These images are shown in the navigation bar. So when I look at the navigation bar I can easily separate them.

And lastly we create our scopes to be shown in the hierarchy bar.

Code: [Select]
<Scope open="Block" close="/" separator="true">
     <Containers open="remark"/>
</Scope>
<Scope open="TODO" close="/" separator="true">
     <Containers open="remark"/>
</Scope>

Here we say He that, when you see "Block" string followed by a "/" character create a scope between them. And draw a separator line under it when it is a block (not a single line) (separator="true"). And lastly use this scopes just inside the "remark" style that we created earlier (<Containers open="remark"/>).

So from now on when you write something like this on your page it will be formatted like we defined above.

''Block: Variable Definition - Defines the used variables /

or

''Block: Variable Definition - Defines the used variables
''
''
''/

They both will be shown in navigation bar in hierarchy bar and they will also be a scope till "/" character.

I tried to explain as much as I can. You can create you own labels as described here too. Please check the ss to see these in action.

Thanks...
« Last Edit: April 20, 2010, 10:42:37 PM by Theno »

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2222
  • Karma: +37/-3
    • HippoEDIT
Re: Creating User Defined Labels
« Reply #1 on: April 20, 2010, 03:15:38 PM »
Hi Theno,

Incredible, this is much better then I can explain and in much more details that I am able to provide without a stress :)
Very good+useful post! Everything is correct and follows HE design.

You can also add these two about regular expression links maybe:
- HE uses Boost regular expression library. Here you can get complete documentation about regular expression syntax and possibilities for Boost.Regexp and so for HippoEDIT also.
- Regular expression tester from RegexLib.

Best regards,
Alex.
P.S: I have not checked your files yet, will do this today evening.

Theno

  • Guest
Re: Creating User Defined Labels
« Reply #2 on: April 20, 2010, 10:39:35 PM »
Hi Alex,

Quote
Incredible, this is much better then I can explain and in much more details that I am able to provide without a stress

Thanks I tried to do my best :) I hope users benefit from them.

By the way, I wonder how HE does adding comments (apos) automatically at the beginning of the new line when you press enter. I didn't see a definition in the code templates for this. I want to add it to my labels too so it will put (2apos) automatically when I press enter, to the new line.

Quote
You can also add these two about regular expression links maybe:

I added the links to the first post.

Thanks...

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2222
  • Karma: +37/-3
    • HippoEDIT
Re: Creating User Defined Labels
« Reply #3 on: April 20, 2010, 11:02:45 PM »
Hi Theno,

Quote
By the way, I wonder how HE does adding comments (apos) automatically at the beginning of the new line when you press enter. I didn't see a definition in the code templates for this. I want to add it to my labels too so it will put (2apos) automatically when I press enter, to the new line.
there is no way...
Such behavior is hard coded for comment style only (as commenting commands) and the is no way currently to enable it for other styles and this is not an easy change.


Best regards,
Alex.

Theno

  • Guest
Re: Creating User Defined Labels
« Reply #4 on: April 20, 2010, 11:47:59 PM »
Ok I see I thought so too, thanks...