You are viewing an older revision! See the latest version
Importing code
The mbed Compiler makes it easy to import code published on mbed.org or stored on your local machine.
Importing from mbed.org¶
The Import Wizard allows you to import programs and libraries published by mbed users. This is useful for importing code that has been packaged as a reusable library component (e.g. a class for a peripheral), so you can quickly pull in the building blocks for your project.
To import a program you have to select a shared program from the list and click the "Import" button like shown on the image above. The Import dialog will let you define the import type and name, and in the given example it would look like:
The "Import Name" field will be populated from the selected program or library. The "Import As" option allows you to change the import type regardless of the published type, thus you can import programs as libraries and vice-versa. In given the example "HelloWorld" could be imported as library in a program (see below).
The Import dialog interface would be transformed to reflect the "Import As" selection and in this case two new options will be added - "Target Path" and "New Program" both of which define the import destination.
"Target Path" defines destination programs, folders and libraries that already exist in your workspace, "New Program" will create new empty program with the specified name and import the desired library in it. Note that "Target Path" and "New Program" override each other and valid option would be the latter specified/modified.
Once the required fields are filled and validated, the "Import" button will be activated, indicating that you can import the resource.
Alternative methods¶
If you don't want to fiddle with the Import dialog options, one way to quickly import a resource is to initially select the desired destination in the navigation tree, then open the Import Wizard, and double-click the desired program or library (alternatively you can hit "Enter" key). The properties of the imported resource will be based on the nav tree selection:
- If a program, folder or library is selected, the resource will be imported as library, if "My Programs" is selected, the resource will be imported as program.
- The import name will be populated from the resource name.
- If a duplicate or other conflict is detected, the Import dialog will be opened to guide you through.
Alternatively, if you have opened the Import Wizard already and would like to quickly import a resource without changing the navigation tree selection, then you can simply drag and drop the resource from the list into your workspace. Similar to the behavior described above, the resource will be imported based on the drop target.
Multiple import¶
It's also possible to select multiple items in the Import Wizard using the Ctrl/Shift+Click combo and import them either via the Import dialog/button or drag and drop them in your workspace. This, so called batch mode, will attempt to import all selected resources even if a conflict or error occurs during import.
Importing from local machine¶
The Import Wizard also allows you to import source files and zip archive stored on your local machine. To use this method, you have to click the "Upload" tab in the Import Wizard, then click the "Browse" or "Choose File" (depending on the browser) in the very bottom and navigate the operating system file picker to the desired file or archive.
The interface allows multiple files to be added to the import list, but due to browser restrictions only one file can be picked at a time. We strongly suggest to use zip archive instead as it will allow multiple file and folders to be imported in your workspace.
If you'd like to remove a file from the list, then you can select it and click the "Remove Selected" button.
Alternative methods¶
An alternative method to import files from your local machine is to use HTML5-enabled browser and native operating system file manager, like Windows Explorer in Windows and Finder in Mac OS. You can simply select single or multiple files in the file manager and drag them directly into the browser window/tab and over the navigation tree item of your choice. Valid drop targets will be highlighted once you move the mouse over them, and once you drop the files, they would be imported in the your workspace as follows:
Archive files
- Archive files will have their contents imported in program/library container named after the zip archive name.
- If the drop target is a program, library or folder, the archive will be imported as library, if "My Programs" is the drop target, the archive will be imported as program instead.
Source non-archive files (.c, .cpp, .h, .hpp, .s)
- Source files will be imported in the drop destination without container - e.g. they will be imported as single files in the drop target.
- Source non-archive files cannot be dropped in "My Programs"
Some early versions of popular browsers like Chrome, Firefox and Opera doesn't correct support the HTML5 drag&drop, thus it's recommended to updated to the latest version. Also note the Internet Explorer browser family (up to version 10) have the HTML5 drag&drop broken in quirks mode, which means HTML5 drag&drop import is currently not possible for Internet Explorer browsers.