New feature - code snippets

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4J_WAPEwMg5gr.gif


Code snippets are added into b4xlibs. You can create an empty b4xlib just for snippets.
Each snippet is a text file, for example:
B4X:
'Loads the remote media into the given panel and sets the background color.
$MediaManager$.SetMediaWithExtra($Panel$, "https://www.b4x.com/images/Logo_on-dark.png", "", _
    CreateMap($MediaManager$.REQUEST_BACKGROUND: xui.Color_Black))
 

Sandman

Expert
Licensed User
Longtime User
Does the IDE match the filenames for the snippets, or where does the "Code_SimpleMedia..." come from?
 

LucaMs

Expert
Licensed User
Longtime User
I really hope I'm not the only one who doesn't understand how it works ?

Creating a bank of code snippets is a matter of:
1. Putting all snippets (text files) in a folder named Snippets.
2. Zipping the folder and renaming it to CodeSnippets.b4xlib (or any other name).
So will I be able to have a single library with all my snippets? And, if so, how should/could I group them, for example by genre (graphics, strings, web, ...), to select one in the best, most direct way?
 

AnandGupta

Expert
Licensed User
Longtime User
I really hope I'm not the only one who doesn't understand how it works ?


So will I be able to have a single library with all my snippets? And, if so, how should/could I group them, for example by genre (graphics, strings, web, ...), to select one in the best, most direct way?
Agree. I am also lost to understand it and its uses in new way.
Please give we us some light.
 

Filippo

Expert
Licensed User
Longtime User
I really hope I'm not the only one who doesn't understand how it works ?
This is, in my opinion, a superfluous library.
This is always possible with a code module.
Just put all code-snipped in the module. I use it in every new app as a general module.
The only advantage would be that you can save different layouts in this library.
 

Mashiane

Expert
Licensed User
Longtime User
I just googled the code that Erel is using from the forum..


MindBlowing... will just wait until the suspense is over... ;)
 

OliverA

Expert
Licensed User
Longtime User
This is always possible with a code module.
Just put all code-snipped in the module. I use it in every new app as a general module.
These are code snippets, not complete methods. Think of it as keyboard shortcuts that expand to more complete code. Or macros/macro expansion. I've seen this requested before...
 

stevel05

Expert
Licensed User
Longtime User
You can store lines of code that you use regularly, or can't remember completely and copy it into your code with a few keystrokes. It could be a java class name, or 1 or more lines or a full sub. Whatever you like.
 

AnandGupta

Expert
Licensed User
Longtime User
You can store lines of code that you use regularly, or can't remember completely and copy it into your code with a few keystrokes. It could be a java class name, or 1 or more lines or a full sub. Whatever you like.
Ahh.. so it is like snippets managers made available by members, but instead of using another B4J jar or exe, we get it inside the ide itself. So no copy+paste or drag+paste required. Okay.
 

hatzisn

Expert
Licensed User
Longtime User
I really hope I'm not the only one who doesn't understand how it works ?


So will I be able to have a single library with all my snippets? And, if so, how should/could I group them, for example by genre (graphics, strings, web, ...), to select one in the best, most direct way?

You are not!!!
 

hatzisn

Expert
Licensed User
Longtime User
I suppose I have not paid that much attention. My doubt was if I could add more than one code snippets in the given (everytime) library in a single file. But it is already mentioned. We cannot.
 

hatzisn

Expert
Licensed User
Longtime User
Re-read post#2. you can put as many snippets as you like in one library (file), and have as many (files) libraries as you like, with different names.

Sorry, my bad, by saying file I meant the text file in the b4xlib file with snippets and with the "given (everytime) library" I meant f.e. JsonObject or XMLSax etc. So my question was if we want to add more than one code snippets for JsonObject f.e. can we put them all in a single txt file or several txts one for each code snippet? It is already answered as I understand. That is one snippet per txt.
 
Top