Skip to main content

MainViewManager

Import :

const MainViewManager = brackets.getModule("view/MainViewManager")

view/MainViewManager

MainViewManager manages the arrangement of all open panes as well as provides the controller logic behind all views in the MainView (e.g. ensuring that a file doesn't appear in 2 lists)

Each pane contains one or more views wich are created by a view factory and inserted into a pane list. There may be several panes managed by the MainViewManager with each pane containing a list of views. The panes are always visible and the layout is determined by the MainViewManager and the user.

Currently we support only 2 panes.

All of the WorkingSet APIs take a paneId Argument. This can be an actual pane Id, ALL_PANES (in most cases) or ACTIVE_PANE. ALL_PANES may not be supported for some APIs. See the API for details.

This module dispatches several events:

  • activePaneChange - When the active pane changes. There will always be an active pane. (e, newPaneId:string, oldPaneId:string)
  • currentFileChange -- When the user has switched to another pane, file, document. When the user closes a view and there are no other views to show the current file will be null. (e, newFile:File, newPaneId:string, oldFile:File, oldPaneId:string)
  • paneLayoutChange -- When Orientation changes. (e, orientation:string)
  • paneCreate -- When a pane is created (e, paneId:string)
  • paneDestroy -- When a pane is destroyed (e, paneId:string)

To listen for working set changes, you must listen to all of these events:

  • workingSetAdd -- When a file is added to the working set (e, fileAdded:File, index:number, paneId:string)
  • workingSetAddList -- When multiple files are added to the working set (e, fileAdded:Array."File", paneId:string)
  • workingSetMove - When a File has moved to a different working set (e, File:FILE, sourcePaneId:string, destinationPaneId:string)
  • workingSetRemove -- When a file is removed from the working set (e, fileRemoved:File, suppressRedraw:boolean, paneId:string)
  • workingSetRemoveList -- When multiple files are removed from the working set (e, filesRemoved:Array."File", paneId:string)
  • workingSetSort -- When a pane's view array is reordered without additions or removals. (e, paneId:string)
  • workingSetUpdate -- When changes happen due to system events such as a file being deleted. listeners should discard all working set info and rebuilt it from the pane by calling getWorkingSet() (e, paneId:string)
  • _workingSetDisableAutoSort -- When the working set is reordered by manually dragging a file. (e, paneId:string) For Internal Use Only.

To listen for events, do something like this: (see EventDispatcher for details on this pattern) MainViewManager.on("eventname", handler);

view/MainViewManager.EVENT_CURRENT_FILE_CHANGE : string

Event current file change

Kind: inner constant of view/MainViewManager

view/MainViewManager.ALL_PANES

Special paneId shortcut that can be used to specify that all panes should be targeted by the API. Not all APIs support this constnant. Check the API documentation before use.

Kind: inner constant of view/MainViewManager

view/MainViewManager.ACTIVE_PANE

Special paneId shortcut that can be used to specify that the API should target the focused pane only. All APIs support this shortcut.

Kind: inner constant of view/MainViewManager

view/MainViewManager.isExclusiveToPane(File) ⇒ Object

Checks whether a file is listed exclusively in the provided pane

Kind: inner method of view/MainViewManager

ParamTypeDescription
FileFilethe file

view/MainViewManager.getActivePaneId() ⇒ string

Retrieves the currently active Pane Id

Kind: inner method of view/MainViewManager
Returns: string - Active Pane's ID.

view/MainViewManager.focusActivePane()

Focuses the current pane. If the current pane has a current view, then the pane will focus the view.

Kind: inner method of view/MainViewManager

view/MainViewManager.setActivePaneId(paneId)

Switch active pane to the specified pane id (or ACTIVE_PANE/ALL_PANES, in which case this call does nothing).

Kind: inner method of view/MainViewManager

ParamTypeDescription
paneIdstringthe id of the pane to activate

view/MainViewManager.getCurrentlyViewedFile(paneId) ⇒ File

Retrieves the currently viewed file of the specified paneId

Kind: inner method of view/MainViewManager
Returns: File - File object of the currently viewed file, or null if there isn't one or there's no such pane

ParamTypeDescription
paneIdstringthe id of the pane in which to retrieve the currently viewed file

view/MainViewManager.getCurrentlyViewedEditor(paneId) ⇒ Editor

Retrieves the currently viewed editor of the specified paneId

Kind: inner method of view/MainViewManager
Returns: Editor - currently editor, or null if there isn't one or there's no such pane

ParamTypeDescription
paneIdstringthe id of the pane in which to retrieve the currently viewed editor

view/MainViewManager.getAllViewedEditors() ⇒ Object

Gets an array of editors open in panes with their pane IDs. Can return an empty array if no editors are open.

Kind: inner method of view/MainViewManager
Returns: Object - An array of objects, each containing an editor and its corresponding pane ID.

view/MainViewManager.getCurrentlyViewedPath(paneId) ⇒ string

Retrieves the currently viewed path of the pane specified by paneId

Kind: inner method of view/MainViewManager
Returns: string - the path of the currently viewed file or null if there isn't one

ParamTypeDescription
paneIdstringthe id of the pane in which to retrieve the currently viewed path

view/MainViewManager.cacheScrollState(paneId)

Caches the specified pane's current scroll state If there was already cached state for the specified pane, it is discarded and overwritten

Kind: inner method of view/MainViewManager

ParamTypeDescription
paneIdstringid of the pane in which to cache the scroll state, ALL_PANES or ACTIVE_PANE

view/MainViewManager.restoreAdjustedScrollState(paneId, heightDelta)

Restores the scroll state from cache and applies the heightDelta The view implementation is responsible for applying or ignoring the heightDelta. This is used primarily when a modal bar opens to keep the editor from scrolling the current page out of view in order to maintain the appearance. The state is removed from the cache after calling this function.

Kind: inner method of view/MainViewManager

ParamTypeDescription
paneIdstringid of the pane in which to adjust the scroll state, ALL_PANES or ACTIVE_PANE
heightDeltanumberdelta H to apply to the scroll state

view/MainViewManager.getWorkingSet(paneId) ⇒ Array.<File>

Retrieves the WorkingSet for the given paneId not including temporary views

Kind: inner method of view/MainViewManager

ParamTypeDescription
paneIdstringid of the pane in which to get the view list, ALL_PANES or ACTIVE_PANE

view/MainViewManager.getAllOpenFiles() ⇒ array.<File>

Retrieves the list of all open files including temporary views

Kind: inner method of view/MainViewManager
Returns: array.<File> - the list of all open files in all open panes

view/MainViewManager.getPaneIdList() ⇒ array.<string>

Retrieves the list of all open pane ids

Kind: inner method of view/MainViewManager
Returns: array.<string> - the list of all open panes

view/MainViewManager.getWorkingSetSize(paneId) ⇒ number

Retrieves the size of the selected pane's view list

Kind: inner method of view/MainViewManager
Returns: number - the number of items in the specified pane

ParamTypeDescription
paneIdstringid of the pane in which to get the workingset size. Can use ALL_PANES or ACTIVE_PANE

view/MainViewManager.getPaneTitle(paneId) ⇒ string

Retrieves the title to display in the workingset view

Kind: inner method of view/MainViewManager
Returns: string - title

ParamTypeDescription
paneIdstringid of the pane in which to get the title

view/MainViewManager.getPaneCount() ⇒ number

Retrieves the number of panes

Kind: inner method of view/MainViewManager

view/MainViewManager.findInAllWorkingSets(fullPath) ⇒ Object

Finds all instances of the specified file in all working sets. If there is a temporary view of the file, it is not part of the result set

Kind: inner method of view/MainViewManager
Returns: Object - an array of paneId/index records

ParamTypeDescription
fullPathstringpath of the file to find views of

view/MainViewManager.findInOpenPane(fullPath) ⇒ Object

Returns the pane IDs and editors (if present) of the given file in any open and viewable pane. If the same file is open in multiple panes, all matching panes will be returned. If not found in any panes, an empty array will be returned.

Kind: inner method of view/MainViewManager
Returns: Object - An array of objects, each containing the pane ID and the corresponding editor, if present.

ParamTypeDescription
fullPathstringThe full path of the file to search for.

view/MainViewManager.findInWorkingSet(paneId, fullPath) ⇒ number

Gets the index of the file matching fullPath in the workingset

Kind: inner method of view/MainViewManager
Returns: number - index, -1 if not found.

ParamTypeDescription
paneIdstringid of the pane in which to search or ALL_PANES or ACTIVE_PANE
fullPathstringfull path of the file to search for

view/MainViewManager.findInWorkingSetByAddedOrder(paneId, fullPath) ⇒ number

Gets the index of the file matching fullPath in the added order workingset

Kind: inner method of view/MainViewManager
Returns: number - index, -1 if not found.

ParamTypeDescription
paneIdstringid of the pane in which to search or ALL_PANES or ACTIVE_PANE
fullPathstringfull path of the file to search for

view/MainViewManager.findInWorkingSetByMRUOrder(paneId, fullPath) ⇒ number

Gets the index of the file matching fullPath in the MRU order workingset

Kind: inner method of view/MainViewManager
Returns: number - index, -1 if not found.

ParamTypeDescription
paneIdstringid of the pane in which to search or ALL_PANES or ACTIVE_PANE
fullPathstringfull path of the file to search for

view/MainViewManager.addToWorkingSet(paneId, file, [index], [forceRedraw])

Adds the given file to the end of the workingset, if it is not already there. This API does not create a view of the file, it just adds it to the working set Views of files in the working set are persisted and are not destroyed until the user closes the file using FILE_CLOSE; Views are created using FILE_OPEN and, when opened, are made the current view. If a File is already opened then the file is just made current and its view is shown.

Kind: inner method of view/MainViewManager

ParamTypeDescription
paneIdstringThe id of the pane in which to add the file object to or ACTIVE_PANE
fileFileThe File object to add to the workingset
[index]numberPosition to add to list (defaults to last); -1 is ignored
[forceRedraw]booleanIf true, a workingset change notification is always sent (useful if suppressRedraw was used with removeView() earlier)

view/MainViewManager.addListToWorkingSet(paneId, fileList)

Adds the given file list to the end of the workingset.

Kind: inner method of view/MainViewManager

ParamTypeDescription
paneIdstringThe id of the pane in which to add the file object to or ACTIVE_PANE
fileListArray.<File>Array of files to add to the pane

view/MainViewManager.switchPaneFocus()

Switch between panes

Kind: inner method of view/MainViewManager

view/MainViewManager.traverseToNextViewByMRU(direction) ⇒ Object

Get the next or previous file in the MRU list.

Kind: inner method of view/MainViewManager
Returns: Object - The File object of the next item in the traversal order or null if there aren't any files to traverse. May return current file if there are no other files to traverse.

ParamTypeDescription
directionnumberMust be 1 or -1 to traverse forward or backward

view/MainViewManager.traverseToNextViewInListOrder(direction) ⇒ Object

Get the next or previous file in list order.

Kind: inner method of view/MainViewManager
Returns: Object - The File object of the next item in the traversal order or null if there aren't any files to traverse. May return current file if there are no other files to traverse.

ParamTypeDescription
directionnumberMust be 1 or -1 to traverse forward or backward

view/MainViewManager.beginTraversal()

Indicates that traversal has begun. Can be called any number of times.

Kind: inner method of view/MainViewManager

view/MainViewManager.endTraversal()

Un-freezes the MRU list after one or more beginTraversal() calls. Whatever file is current is bumped to the front of the MRU list.

Kind: inner method of view/MainViewManager

view/MainViewManager.setLayoutScheme(rows, columns)

Changes the layout scheme

Kind: inner method of view/MainViewManager
Summay: Rows or Columns may be 1 or 2 but both cannot be 2. 1x2, 2x1 or 1x1 are the legal values

ParamTypeDescription
rowsnumber(may be 1 or 2)
columnsnumber(may be 1 or 2)

view/MainViewManager.getLayoutScheme() ⇒ Object

Retrieves the current layout scheme.

Kind: inner method of view/MainViewManager
Returns: Object - - An object containing the number of rows and columns in the layout.