Skip to content

Programmatically Opening Files in Brackets

JeffryBooher edited this page Oct 13, 2014 · 11 revisions

Brackets has a few different APIs for opening and managing files. This document describes best practices for opening files and examines the differences between the APIs used for opening and managing files in Brackets.

Best Practices

The best way to open a document in Brackets is to execute the command CMD_ADD_TO_WORKINGSET_AND_OPEN. This command will open the file in the specified pane, add it to the working files list and select it in the working file list. This is the preferred way to open a file.

Here's an example:

CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, {fullPath: "./view/WorkingSetView.js", paneId: "first-pane"})

API Details

COMMAND Function Notes
FILE_ADD_TO_WORKING_SET Opens a Document to the Working Files List Resolves to a Document Object. Deprecated.
CMD_ADD_TO_WORKINGSET_AND_OPEN Opens a File to the Working Files List Resolves to a File Object
FILE_OPEN Opens a Document (not to the Working Files List) Resolves to a Document Object. Deprecated.
CMD_OPEN) Opens a File (not to the Working Files List) Resolves to a File Object
API Function Notes
MainViewManager .addToWorkingSet Adds a File to the Working Files List (does not open the file) For Internal Use only
MainViewManager .addListToWorkingSet Adds an array of Files to the Working Files List (does not open anything) For Internal Use only
DocumentManager .setCurrentDocument Sets the currently view document to the document specified Deprecated
FileViewController .openAndSelectDocument opens the specified file and selects it For Internal Use only
FileViewController .openFileAndAddToWorkingSet opens the specified document and selects it Deprecated. For Internal Use only.
Clone this wiki locally