Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/extensions/default/CloseOthers/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/

/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this file have the Adobe license since it will be part of the core now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems true. all other extensions holding Adobe License. Once i get feedback from @JeffryBooher for coding standard, and if he say any other changes, i'll give next commit with Adobe License update.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Every non thirdparty js file has it. Make sure to use the year 2013 when adding it.

/*global define, $, brackets, window, document */

define(function (require, exports, module) {
"use strict";

var Menus = brackets.getModule("command/Menus"),
CommandManager = brackets.getModule("command/CommandManager"),
Commands = brackets.getModule("command/Commands"),
dm = brackets.getModule("document/DocumentManager"),
settings = JSON.parse(require("text!settings.json")),
working_set_cmenu = Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_MENU);

function handleClose(mode) {

var targetIndex = dm.findInWorkingSet(dm.getCurrentDocument().file.fullPath),
workingSet = dm.getWorkingSet().slice(0);

CommandManager.execute(Commands.FILE_CLOSE_ALL, {promptOnly: true}).done(function () {

var start = (mode === "close_below") ? (targetIndex + 1) : 0,
end = (mode === "close_above") ? (targetIndex) : (workingSet.length),
i;

if (mode === "close_others") {
workingSet.splice(targetIndex, 1);
}

for (i = start; i < end; i++) {
dm.removeFromWorkingSet(workingSet[i]);
}
});
}

if (settings.close_below) {
CommandManager.register("Close Others Below", "file.close_below", function () {
handleClose("close_below");
});
working_set_cmenu.addMenuItem("file.close_below", "", Menus.AFTER, Commands.FILE_CLOSE);
}

if (settings.close_others) {
CommandManager.register("Close Others", "file.close_others", function () {
handleClose("close_others");
});
working_set_cmenu.addMenuItem("file.close_others", "", Menus.AFTER, Commands.FILE_CLOSE);
}

if (settings.close_above) {
CommandManager.register("Close Others Above", "file.close_above", function () {
handleClose("close_above");
});
working_set_cmenu.addMenuItem("file.close_above", "", Menus.AFTER, Commands.FILE_CLOSE);
}
});
5 changes: 5 additions & 0 deletions src/extensions/default/CloseOthers/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"close_others": true,
"close_above": true,
"close_below": true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default i have enabled "Close Others" only. If user wish they can enable other two options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say we enable them all then let the user turn them off if they wish.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These settings will be hard to change, since these are saved in the core code, which is replaced with each update. And working with git, it will show this as file that was modified.

Would it be ok to have these preferences as menu items? Or we should leave them like this until the Preference Dialog is done, so we can add them there? Having submenus will really help for this things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next i planned to add "Close Others", "Close Others Above", "Close Others Below" as dynamically, based on user selection. I am not sure, whether there is an option to add context menus dynamically. If i succeed with that, then there won't be settings.json. Until i feel it is good to be there. Most of the users don't use settings.json, until they know it.