This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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.
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"});
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. |
When opening a file, you generally construct a call to CommandManager.execute
along with its commandData
. It's the commandData
which provides various options when opening the file:
Member | Meaning | Notes |
---|---|---|
fullPath | Path to the file to open | Required. Must be canonical. |
index | Index in the working set to put the file | Optional. For internal use. |
silent | Suppress error messages | Optional |
forceRedraw | Forces the working set view to redraw | Optional. |
paneId | Pane in which to open the file | Optional or undefined. May MainViewManger.ACTIVE_PANE or a valid pane id. |
options | Options to use when creating the view of the file | Optional. |
Options to use when creating the view of the file
Member | Meaning | Notes |
---|---|---|
noPaneActivate | open the file in the specified pane but don't activate it | |
noPaneRedundancyCheck | don't check to see if the document is open in another pane | For internal use. |
CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, {fullPath: "./view/WorkingSetView.js", paneId: "first-pane"})