Skip to content

Commit

Permalink
docs: add sort & its methods to API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
devvaannsh committed Oct 29, 2024
1 parent 6823a22 commit 2069587
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 9 deletions.
69 changes: 67 additions & 2 deletions docs/API-Reference/project/WorkingSetSort.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,71 @@
const WorkingSetSort = brackets.getModule("project/WorkingSetSort")
```

<a name="Sort"></a>

## Sort
**Kind**: global class

* [Sort](#Sort)
* [new Sort(commandID, compareFn, events)](#new_Sort_new)
* [.getCommandID()](#Sort+getCommandID) ⇒ <code>string</code>
* [.getCompareFn()](#Sort+getCompareFn) ⇒ <code>function</code>
* [.getEvents()](#Sort+getEvents) ⇒ <code>string</code>
* [.setChecked(value)](#Sort+setChecked)
* [.execute()](#Sort+execute)
* [.sort()](#Sort+sort)

<a name="new_Sort_new"></a>

### new Sort(commandID, compareFn, events)

| Param | Type | Description |
| --- | --- | --- |
| commandID | <code>string</code> | A valid command identifier. |
| compareFn | <code>function</code> | A valid sort function (see register for a longer explanation). |
| events | <code>string</code> | Space-separated WorkingSetSort possible events ending with ".sort". |

<a name="Sort+getCommandID"></a>

### sort.getCommandID() ⇒ <code>string</code>
The Command ID

**Kind**: instance method of [<code>Sort</code>](#Sort)
<a name="Sort+getCompareFn"></a>

### sort.getCompareFn() ⇒ <code>function</code>
The compare function

**Kind**: instance method of [<code>Sort</code>](#Sort)
<a name="Sort+getEvents"></a>

### sort.getEvents() ⇒ <code>string</code>
Gets the event that this sort object is listening to

**Kind**: instance method of [<code>Sort</code>](#Sort)
<a name="Sort+setChecked"></a>

### sort.setChecked(value)
Checks/Unchecks the command which will show a check in the menu

**Kind**: instance method of [<code>Sort</code>](#Sort)

| Param | Type |
| --- | --- |
| value | <code>boolean</code> |

<a name="Sort+execute"></a>

### sort.execute()
Performs the sort and makes it the current sort method.

**Kind**: instance method of [<code>Sort</code>](#Sort)
<a name="Sort+sort"></a>

### sort.sort()
Only performs the working set sort if this is the current sort.

**Kind**: instance method of [<code>Sort</code>](#Sort)
<a name="Commands"></a>

## Commands
Expand All @@ -11,7 +76,7 @@ Manages the workingSetList sort methods.
**Kind**: global variable
<a name="get"></a>

## get(command) ⇒ [<code>Sort</code>](#new_Sort_new)
## get(command) ⇒ [<code>Sort</code>](#Sort)
Retrieves a Sort object by id

**Kind**: global function
Expand All @@ -38,7 +103,7 @@ Enables/Disables Automatic Sort depending on the value.

<a name="register"></a>

## register(command, compareFn, events) ⇒ [<code>Sort</code>](#new_Sort_new)
## register(command, compareFn, events) ⇒ [<code>Sort</code>](#Sort)
Registers a working set sort method.

**Kind**: global function
Expand Down
29 changes: 22 additions & 7 deletions src/project/WorkingSetSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ define(function (require, exports, module) {

/**
* List of sorting method objects
*
* @private
* @type {Array.<Sort>}
*/
var _sorts = [];

/**
* Denotes the current sort method object
*
* @private
* @type {Sort}
*/
var _currentSort = null;

/**
* Denotes if automatic sorting is enabled or not
*
* @private
* @type {boolean}
*/
Expand All @@ -73,27 +76,31 @@ define(function (require, exports, module) {

/**
* Events which the sort command will listen for to trigger a sort
*
* @constant {string}
* @private
*/
var _SORT_EVENT_NAMES = "workingSetAdd workingSetAddList";

/**
* Preference name
*
* @constant {string}
* @private
*/
var _WORKING_SET_SORT_PREF = "workingSetSortMethod";

/**
* Legacy preference name
*
* @constant {string}
* @private
*/
var _LEGACY_SORT_PREF = "currentSort";

/**
* Retrieves a Sort object by id
*
* @param {(string|Command)} command A command ID or a command object.
* @return {?Sort}
*/
Expand All @@ -114,6 +121,7 @@ define(function (require, exports, module) {

/**
* Converts the old brackets working set sort preference into the modern paneview sort preference
*
* @private
* @param {!string} sortMethod - sort preference to convert
* @return {?string} new sort preference string or undefined if an sortMethod is not found
Expand Down Expand Up @@ -142,6 +150,7 @@ define(function (require, exports, module) {

/**
* Removes the sort listeners.
*
* @private
*/
function _removeListeners() {
Expand All @@ -150,6 +159,7 @@ define(function (require, exports, module) {

/**
* Enables/Disables Automatic Sort depending on the value.
*
* @param {boolean} enable True to enable, false to disable.
*/
function setAutomatic(enable) {
Expand All @@ -167,6 +177,7 @@ define(function (require, exports, module) {

/**
* Adds the current sort MainViewManager listeners.
*
* @private
*/
function _addListeners() {
Expand All @@ -184,6 +195,7 @@ define(function (require, exports, module) {

/**
* Sets the current sort method and checks it on the context menu.
*
* @private
* @param {Sort} newSort
*/
Expand All @@ -204,7 +216,6 @@ define(function (require, exports, module) {


/**
* @private
* @constructor
* @param {string} commandID A valid command identifier.
* @param {function(File, File): number} compareFn A valid sort
Expand All @@ -220,7 +231,7 @@ define(function (require, exports, module) {

/**
* The Command ID
* @private
*
* @return {string}
*/
Sort.prototype.getCommandID = function () {
Expand All @@ -229,7 +240,7 @@ define(function (require, exports, module) {

/**
* The compare function
* @private
*
* @return {function(File, File): number}
*/
Sort.prototype.getCompareFn = function () {
Expand All @@ -238,7 +249,7 @@ define(function (require, exports, module) {

/**
* Gets the event that this sort object is listening to
* @private
*
* @return {string}
*/
Sort.prototype.getEvents = function () {
Expand All @@ -247,7 +258,7 @@ define(function (require, exports, module) {

/**
* Checks/Unchecks the command which will show a check in the menu
* @private
*
* @param {boolean} value
*/
Sort.prototype.setChecked = function (value) {
Expand All @@ -259,7 +270,6 @@ define(function (require, exports, module) {

/**
* Performs the sort and makes it the current sort method.
* @private
*/
Sort.prototype.execute = function () {
_setCurrentSort(this);
Expand All @@ -268,7 +278,6 @@ define(function (require, exports, module) {

/**
* Only performs the working set sort if this is the current sort.
* @private
*/
Sort.prototype.sort = function () {
if (_currentSort === this) {
Expand All @@ -281,6 +290,7 @@ define(function (require, exports, module) {

/**
* Registers a working set sort method.
*
* @param {(string|Command)} command A command ID or a command object
* @param {function(File, File): number} compareFn The function that
* will be used inside JavaScript's sort function. The return a value
Expand Down Expand Up @@ -330,6 +340,7 @@ define(function (require, exports, module) {

/**
* Command Handler for CMD_WORKING_SORT_TOGGLE_AUTO
*
* @private
*/
function _handleToggleAutoSort() {
Expand All @@ -338,6 +349,7 @@ define(function (require, exports, module) {

/**
* Command Handler for CMD_WORKINGSET_SORT_BY_*
*
* @private
* @param {!string} commandId identifies the sort method to use
*/
Expand Down Expand Up @@ -385,13 +397,15 @@ define(function (require, exports, module) {

/**
* Initialize default values for sorting preferences
*
* @private
*/
PreferencesManager.stateManager.definePreference("automaticSort", "boolean", false);

/**
* Define a default sort method that's empty so that we
* just convert and use the legacy sort method
*
* @private
*/
PreferencesManager.stateManager.definePreference(_WORKING_SET_SORT_PREF, "string", "");
Expand All @@ -414,6 +428,7 @@ define(function (require, exports, module) {

/**
* Initialize items dependent on extensions/workingSetList
*
* @private
*/
AppInit.appReady(function () {
Expand Down

0 comments on commit 2069587

Please sign in to comment.