Android Code Snippet [B4X][Library] A solution to easily add your own code snippets?

EDIT:
How wonderful, can you please give us an full example with b4xpages?
Attached MySnippets.b4xlib and instructions about how you can add your own code snippets (see them after the line of asterisks in this post)
Watch the animated gif in post #7 to see how to use this library.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------

A little while ago I wrote:

A great feature: you can add comment lines to your methods (Subs) that contain code that you can copy and paste; even many lines of code.

B4X:
' This routine is useful to...
' Example:
'<code>
' here many "ready" code lines that can be easily copied and pasted by just one click.
'</code>
Public Sub DoSomething
End Sub

I love it!

An idea is coming to my mind (on which to study a little) ...

If I developed a library (B4Xlib?) that contained fake methods (Subs) for the sole purpose of getting source code from them, code snippets?

I might have a class for each category of snippets.

In case my headache goes away and I don't decide to go and buy a guillotine to get rid of the cervical headache problem once and for all 😄:mad: , I'll do some implementation tests.

******************************************************************************************************************************************************

How to add snippets to this MySnippets.b4xlib library.



Method A:

Directly using 7zip (or similar), without the need to unzip the library.
Just open the library with 7zip, double-click on a class file name, your default text editor will open, add/modify this file and save it.
(*) You can also create a new "category class" (using your text editor or one B4X IDE) and then drag it on 7zip - again having it open as just written.


Method B:

Using the B4XPages project attached, MySnippetsClasses. Edit its classes, add snippet-routines (take as example Erel's Sub TextToBitmap, which is in clsB4XViews class),
(*) add a new "category class".


(*) If you create a new "category class", you must declare and create an instance of it in the "platform main class", as in:

1611881760857.png


clsB4A is one of the four "platform main class" (there are: clsB4J, clsB4I and clsB4X).
For example, if you create a "category class" that contains animation snippets, you could create a clsAnimations class, then you should:

Add to Sub Class_Globals:
Public Animations As clsAnimations

Add to Public Sub Intialize:
Animations.Initialize


Note that I haven't B4i. If you open B4i MySnippetsClasses project, you should add (menu Project - Add Existing Modules) to it the clsB4I*.bas (select "Copy to project folder") and the clsB4X*.bas (select "Link - relative path").


///////////////////////////////////////////
Note:
if you use 7zip as suggested in "method A", this (MySnippets.b4xlib) can be a useful library, but a well done tool, perhaps developed with B4J, with which to manage a SQLite database of snippets would probably be a better choice. I think some already exist on this site.
///////////////////////////////////////////


It is not unlikely that this is all a bit too abstruse and that I will attach the wrong files. After all it's late at night, it's about 2:30 A.M. and... I'm already sleeping, while typing 😄😴

If you want, you can also throw everything in your trash: luckily for you it's free :)
 

Attachments

  • MySnippetsClasses.zip
    22.3 KB · Views: 135
  • MySnippets.b4xlib
    7.8 KB · Views: 122
Last edited:

Claudio Oliveira

Active Member
Licensed User
Sounds like a good idea. 🤔
Not sure about the best way (if there's one at all) to implement this, but the idea sounds pretty good to me...
Watching this thread.
 

mangojack

Well-Known Member
Licensed User
In anatomy, cervical is an adjective that has two meanings: of or pertaining to any neck. of or pertaining to the female cervix: i.e., the neck of the uterus.

? :oops:
 

LucaMs

Expert
Licensed User
You can make is simpler. Put all the methods in gSnippets directly:
B4X:
'B4X methods

....


#If B4A
'B4A methods
#Else If B4i
'B4i methods
#Else If B4J
'B4J methods
#End If
I use it but to supply and show only the class (instance, of course) of the specific language (and always the B4X class).
... and have a class for each category.

Too much stuff? Maybe, but it seems (to me 😄 ) well organized.
When I need to add a new snippet, I open the b4xlib with 7zip, open the related class, add, save and done.
 
Last edited:
Top