Skip to content

Commit 797ed3f

Browse files
committed
Removed string for collapse custom region menu.
Set alwaysUseIndentFold preference to be false by default Addresses adobe#10848 - changes to preference files are now updated live in brackets without needing to restart
1 parent a66855e commit 797ed3f

File tree

9 files changed

+162
-27
lines changed

9 files changed

+162
-27
lines changed

src/extensions/default/CodeFolding/Prefs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define(function (require, exports, module) {
2020
{name: strings.MIN_FOLD_SIZE, description: strings.MIN_FOLD_SIZE_HELP});
2121
prefs.definePreference("saveFoldStates", "boolean", true,
2222
{name: strings.SAVE_FOLD_STATES, description: strings.SAVE_FOLD_STATES_HELP});
23-
prefs.definePreference("alwaysUseIndentFold", "boolean", true,
23+
prefs.definePreference("alwaysUseIndentFold", "boolean", false,
2424
{name: strings.ALWAYS_USE_INDENT_FOLD, description: strings.ALWAYS_USE_INDENT_FOLD_HELP});
2525
prefs.definePreference("enableRegionFolding", "boolean", false,
2626
{name: strings.ENABLE_REGION_FOLDING, description: strings.ENABLE_REGION_FOLDING});
@@ -113,4 +113,6 @@ define(function (require, exports, module) {
113113

114114
module.exports.clearAllFolds = clearAllFolds;
115115

116+
module.exports.prefBase = prefs;
117+
116118
});

src/extensions/default/CodeFolding/foldhelpers/foldcode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ define(function (require, exports, module) {
2424
if (typeof pos === "number") {
2525
pos = CodeMirror.Pos(pos, 0);
2626
}
27+
2728
var finder = options.rangeFinder || CodeMirror.fold.auto,
2829
minSize = options.minFoldSize || prefs.getSetting("minFoldSize"),
2930
range,
@@ -121,7 +122,7 @@ define(function (require, exports, module) {
121122
});
122123

123124
CodeMirror.defineExtension("isFolded", function (line) {
124-
return this._lineFolds[line];
125+
return this._lineFolds && this._lineFolds[line];
125126
});
126127

127128
/**

src/extensions/default/CodeFolding/foldhelpers/foldgutter.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,15 @@ define(function (require, exports, module) {
312312
});
313313
}
314314

315+
function remove(cm) {
316+
var gutters = cm.getOption("gutters").slice(0);
317+
var index = gutters.indexOf("CodeMirror-foldgutter");
318+
gutters.splice(index, 1);
319+
cm.setOption("gutters", gutters);
320+
CodeMirror.defineOption("foldGutter", false, null);
321+
}
315322

323+
exports.remove = remove;
316324
exports.init = init;
317325
exports.clearGutter = clearGutter;
318326
exports.updateInViewport = updateInViewport;

src/extensions/default/CodeFolding/main.js

Lines changed: 149 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ define(function (require, exports, module) {
4545
EXPAND = "codefolding.expand",
4646
EXPAND_ALL = "codefolding.expand.all",
4747
gutterName = "CodeMirror-foldgutter",
48-
COLLAPSE_CUSTOM_REGIONS = "codefolding.collapse.customregions";
48+
codeFoldingMenuDivider = "codefolding.divider",
49+
collapseKey = "Ctrl-Alt-[",
50+
expandKey = "Ctrl-Alt-]",
51+
collapseAllKey = "Alt-1",
52+
expandAllKey = "Shift-Alt-1";
4953

5054
ExtensionUtils.loadStyleSheet(module, "main.less");
5155

@@ -210,8 +214,12 @@ define(function (require, exports, module) {
210214
_lineFolds = _lineFolds || {};
211215
cm._lineFolds = _lineFolds;
212216
var gutters = cm.getOption("gutters").slice(0);
217+
213218
var lnIndex = gutters.indexOf("CodeMirror-linenumbers");
214-
gutters.splice(lnIndex + 1, 0, gutterName);
219+
//reuse any existing fold gutter
220+
if (gutters.indexOf(gutterName) < 0) {
221+
gutters.splice(lnIndex + 1, 0, gutterName);
222+
}
215223
cm.setOption("gutters", gutters);
216224
cm.setOption("foldGutter", {onGutterClick: onGutterClick});
217225

@@ -244,6 +252,11 @@ define(function (require, exports, module) {
244252
if (previous) {
245253
saveLineFolds(previous);
246254
}
255+
} else {
256+
if (current && current._codeMirror) {
257+
CodeMirror.commands.unfoldAll(current._codeMirror);
258+
foldGutter.remove(current._codeMirror);
259+
}
247260
}
248261
}
249262

@@ -254,11 +267,119 @@ define(function (require, exports, module) {
254267
saveLineFolds(EditorManager.getCurrentFullEditor());
255268
}
256269

270+
/**
271+
* Utility function to check if the code folding menu options exist in the menu
272+
*/
273+
function menuExists(id) {
274+
var viewMenu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);
275+
return Menus.getMenuItem(viewMenu._getMenuItemId(id));
276+
}
277+
278+
/**
279+
* Create the codefolding menu items and register key bindings if they dont already exist
280+
*/
281+
function createMenuItems() {
282+
//register commands
283+
if (!CommandManager.get(COLLAPSE_ALL)) {
284+
CommandManager.register(Strings.COLLAPSE_ALL, COLLAPSE_ALL, collapseAll);
285+
}
286+
287+
if (!CommandManager.get(EXPAND_ALL)) {
288+
CommandManager.register(Strings.EXPAND_ALL, EXPAND_ALL, expandAll);
289+
}
290+
291+
if (!CommandManager.get(COLLAPSE)) {
292+
CommandManager.register(Strings.COLLAPSE_CURRENT, COLLAPSE, collapseCurrent);
293+
}
294+
295+
if (!CommandManager.get(EXPAND)) {
296+
CommandManager.register(Strings.EXPAND_CURRENT, EXPAND, expandCurrent);
297+
}
298+
299+
//create menus
300+
if (!menuExists(codeFoldingMenuDivider)) {
301+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuDivider(Menus.LAST, codeFoldingMenuDivider);
302+
}
303+
304+
if (!menuExists(COLLAPSE_ALL)) {
305+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE_ALL);
306+
}
307+
308+
if (!menuExists(EXPAND_ALL)) {
309+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND_ALL);
310+
}
311+
312+
if (!menuExists(COLLAPSE)) {
313+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE);
314+
}
315+
316+
if (!menuExists(EXPAND)) {
317+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND);
318+
}
319+
//register keybindings
320+
if (KeyBindingManager.getKeyBindings(COLLAPSE_ALL).length === 0) {
321+
KeyBindingManager.addBinding(COLLAPSE_ALL, collapseAllKey);
322+
}
323+
if (KeyBindingManager.getKeyBindings(EXPAND_ALL).length === 0) {
324+
KeyBindingManager.addBinding(EXPAND_ALL, expandAllKey);
325+
}
326+
if (KeyBindingManager.getKeyBindings(COLLAPSE).length === 0) {
327+
KeyBindingManager.addBinding(COLLAPSE, collapseKey);
328+
}
329+
if (KeyBindingManager.getKeyBindings(EXPAND).length === 0) {
330+
KeyBindingManager.addBinding(EXPAND, expandKey);
331+
}
332+
}
333+
334+
/**
335+
* Remove the codefolding menu items and removeany key bindings attributed to them
336+
*/
337+
function removeMenuItems() {
338+
//remove keybindings
339+
if (KeyBindingManager.getKeyBindings(COLLAPSE).length > 0) {
340+
KeyBindingManager.removeBinding(collapseKey);
341+
}
342+
343+
if (KeyBindingManager.getKeyBindings(EXPAND).length > 0) {
344+
KeyBindingManager.removeBinding(expandKey);
345+
}
346+
347+
if (KeyBindingManager.getKeyBindings(COLLAPSE_ALL).length > 0) {
348+
KeyBindingManager.removeBinding(collapseAllKey);
349+
}
350+
351+
if (KeyBindingManager.getKeyBindings(EXPAND_ALL).length > 0) {
352+
KeyBindingManager.removeBinding(expandAllKey);
353+
}
354+
355+
//remove menus
356+
if (menuExists(codeFoldingMenuDivider)) {
357+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuDivider(codeFoldingMenuDivider);
358+
}
359+
360+
if (menuExists(COLLAPSE)) {
361+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(COLLAPSE);
362+
}
363+
364+
if (menuExists(EXPAND)) {
365+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(EXPAND);
366+
}
367+
368+
if (menuExists(COLLAPSE_ALL)) {
369+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(COLLAPSE_ALL);
370+
}
371+
372+
if (menuExists(EXPAND_ALL)) {
373+
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(EXPAND_ALL);
374+
}
375+
}
376+
257377
/**
258378
Initialise the extension
259379
*/
260380
function init() {
261381
if (!prefs.getSetting("enabled")) {
382+
removeMenuItems();
262383
return;
263384
}
264385
foldCode.init();
@@ -287,27 +408,12 @@ define(function (require, exports, module) {
287408
init();
288409
});
289410

290-
CommandManager.register(Strings.COLLAPSE_ALL, COLLAPSE_ALL, collapseAll);
291-
CommandManager.register(Strings.EXPAND_ALL, EXPAND_ALL, expandAll);
292-
293-
CommandManager.register(Strings.COLLAPSE_CURRENT, COLLAPSE, collapseCurrent);
294-
CommandManager.register(Strings.EXPAND_CURRENT, EXPAND, expandCurrent);
295-
296-
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuDivider();
297-
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE);
298-
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND);
299-
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE_ALL);
300-
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND_ALL);
301-
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE_CUSTOM_REGIONS);
302-
303-
KeyBindingManager.addBinding(COLLAPSE, "Ctrl-Alt-[");
304-
KeyBindingManager.addBinding(EXPAND, "Ctrl-Alt-]");
305-
KeyBindingManager.addBinding(COLLAPSE_ALL, "Alt-1");
306-
KeyBindingManager.addBinding(EXPAND_ALL, "Shift-Alt-1");
411+
createMenuItems();
307412

308413
var editor = EditorManager.getCurrentFullEditor();
309414
if (editor) {
310415
var cm = editor._codeMirror;
416+
createGutter(editor);
311417
if (prefs.getSetting("fadeFoldButtons")) {
312418
foldGutter.clearGutter(cm);
313419
} else {
@@ -316,5 +422,28 @@ define(function (require, exports, module) {
316422
}
317423
}
318424

319-
AppInit.appReady(init);
425+
/**
426+
* Register change listener for the preferences file.
427+
*/
428+
function watchPrefsForChanges() {
429+
prefs.prefBase.on("change", function (e, data) {
430+
if (data.ids.indexOf("enabled") > -1) {
431+
if (prefs.getSetting("enabled")) {
432+
init();
433+
} else {
434+
var editor = EditorManager.getCurrentFullEditor();
435+
if (editor && editor._codeMirror && CodeMirror.commands.unfoldAll) {
436+
CodeMirror.commands.unfoldAll(editor._codeMirror);
437+
foldGutter.remove(editor._codeMirror);
438+
}
439+
removeMenuItems();
440+
}
441+
}
442+
});
443+
}
444+
445+
AppInit.appReady(function () {
446+
init();
447+
watchPrefsForChanges();
448+
});
320449
});

src/nls/fi/strings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ define({
631631
"EXPAND_ALL" : "Laajenna kaikki",
632632
"COLLAPSE_CURRENT" : "Pienennä nykyinen",
633633
"EXPAND_CURRENT" : "Laajenna nykyinen",
634-
"COLLAPSE_CUSTOM_REGIONS" : "Pienennä mukautetut alueet",
635634
"MIN_FOLD_SIZE" : "Pienin laskostuksen koko",
636635
"MIN_FOLD_SIZE_HELP" : "Pienin sallittu laskostettavan alueen rivimäärä",
637636
"ENABLE_REGION_FOLDING" : "Ota mukautetun alueen laskostus käyttöön",

src/nls/nl/strings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ define({
462462
"EXPAND_ALL" : "Alles uitklappen",
463463
"COLLAPSE_CURRENT" : "Huidige inklappen",
464464
"EXPAND_CURRENT" : "Huidige uitklappen",
465-
"COLLAPSE_CUSTOM_REGIONS" : "Aangepaste regio's inklappen",
466465
"MIN_FOLD_SIZE" : "Minimale vouwgrootte",
467466
"MIN_FOLD_SIZE_HELP" : "Minimaal aantal regels om toe te staan in een vouwreeks",
468467
"ENABLE_REGION_FOLDING" : "Aangepaste regio's inschakelen",

src/nls/pt-br/strings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,6 @@ define({
632632
"EXPAND_ALL" : "Expandir Tudo",
633633
"COLLAPSE_CURRENT" : "Dobrar Posição Atual",
634634
"EXPAND_CURRENT" : "Expandir Posição Atual",
635-
"COLLAPSE_CUSTOM_REGIONS" : "Dobrar Regiões Personalizadas",
636635
"MIN_FOLD_SIZE" : "Tamanha Mínimo",
637636
"MIN_FOLD_SIZE_HELP" : "Número Mínimo de linhas necessário para o dobramento",
638637
"ENABLE_REGION_FOLDING" : "Regiões Personalizadas de Dobramento",

src/nls/root/strings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ define({
637637
"EXPAND_ALL" : "Expand All",
638638
"COLLAPSE_CURRENT" : "Collapse Current",
639639
"EXPAND_CURRENT" : "Expand Current",
640-
"COLLAPSE_CUSTOM_REGIONS" : "Collapse Custom Regions",
641640
"MIN_FOLD_SIZE" : "Minimum fold size",
642641
"MIN_FOLD_SIZE_HELP" : "Minimum number of lines to allow in a fold range",
643642
"ENABLE_REGION_FOLDING" : "Enable custom region folding",

src/nls/ru/strings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ define({
572572
"EXPAND_ALL" : "Развернуть все",
573573
"COLLAPSE_CURRENT" : "Свернуть текущий",
574574
"EXPAND_CURRENT" : "Развернуть текущий",
575-
"COLLAPSE_CUSTOM_REGIONS" : "Свернуть текущий region",
576575
"MIN_FOLD_SIZE" : "Минимальный размер сворачивания",
577576
"MIN_FOLD_SIZE_HELP" : "Минимальное число строк для сворачивания",
578577
"ENABLE_REGION_FOLDING" : "Включить сворачивание для region`ов",

0 commit comments

Comments
 (0)