Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8029 from adobe/randy/replace-in
Browse files Browse the repository at this point in the history
Add Replace in... to context menus
  • Loading branch information
njx committed Jun 13, 2014
2 parents 1917878 + 737b27a commit f6d3efc
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,18 @@ define(function (require, exports, module) {

// FIND
exports.CMD_FIND = "cmd.find"; // FindReplace.js _launchFind()
exports.CMD_FIND_IN_FILES = "cmd.findInFiles"; // FindInFiles.js _doFindInFiles()
exports.CMD_FIND_IN_SELECTED = "cmd.findInSelected"; // FindInFiles.js _doFindInSubtree()
exports.CMD_FIND_IN_SUBTREE = "cmd.findInSubtree"; // FindInFiles.js _doFindInSubtree()
exports.CMD_FIND_IN_FILES = "cmd.findInFiles"; // FindInFilesUI.js _showFindBar()
exports.CMD_FIND_IN_SELECTED = "cmd.findInSelected"; // FindInFilesUI.js _showFindBarForSubtree()
exports.CMD_FIND_IN_SUBTREE = "cmd.findInSubtree"; // FindInFilesUI.js _showFindBarForSubtree()
exports.CMD_FIND_NEXT = "cmd.findNext"; // FindReplace.js _findNext()
exports.CMD_FIND_PREVIOUS = "cmd.findPrevious"; // FindReplace.js _findPrevious()
exports.CMD_FIND_ALL_AND_SELECT = "cmd.findAllAndSelect"; // FindReplace.js _findAllAndSelect()
exports.CMD_ADD_NEXT_MATCH = "cmd.addNextMatch"; // FindReplace.js _expandAndAddNextToSelection()
exports.CMD_SKIP_CURRENT_MATCH = "cmd.skipCurrentMatch"; // FindReplace.js _skipCurrentMatch()
exports.CMD_REPLACE = "cmd.replace"; // FindReplace.js _replace()
exports.CMD_REPLACE_IN_FILES = "cmd.replaceInFiles"; // FindInFiles.js _doReplaceInFiles()
exports.CMD_REPLACE_IN_FILES = "cmd.replaceInFiles"; // FindInFilesUI.js _showReplaceBar()
exports.CMD_REPLACE_IN_SELECTED = "cmd.replaceInSelected"; // FindInFilesUI.js _showReplaceBarForSubtree()
exports.CMD_REPLACE_IN_SUBTREE = "cmd.replaceInSubtree"; // FindInFilesUI.js _showReplaceBarForSubtree()

// VIEW
exports.VIEW_HIDE_SIDEBAR = "view.hideSidebar"; // SidebarView.js toggle()
Expand Down
3 changes: 3 additions & 0 deletions src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ define(function (require, exports, module) {
menu.addMenuDivider();
menu.addMenuItem(Commands.CMD_REPLACE);
menu.addMenuItem(Commands.CMD_REPLACE_IN_FILES);
menu.addMenuItem(Commands.CMD_REPLACE_IN_SELECTED);

/*
* View menu
Expand Down Expand Up @@ -206,6 +207,7 @@ define(function (require, exports, module) {
project_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS);
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.CMD_FIND_IN_SUBTREE);
project_cmenu.addMenuItem(Commands.CMD_REPLACE_IN_SUBTREE);
project_cmenu.addMenuDivider();
project_cmenu.addMenuItem(Commands.FILE_REFRESH);

Expand All @@ -217,6 +219,7 @@ define(function (require, exports, module) {
working_set_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_OS);
working_set_cmenu.addMenuDivider();
working_set_cmenu.addMenuItem(Commands.CMD_FIND_IN_SUBTREE);
working_set_cmenu.addMenuItem(Commands.CMD_REPLACE_IN_SUBTREE);
working_set_cmenu.addMenuDivider();
working_set_cmenu.addMenuItem(Commands.FILE_CLOSE);

Expand Down
2 changes: 2 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ define({
"CMD_FIND_IN_SUBTREE" : "Find in\u2026",
"CMD_REPLACE" : "Replace",
"CMD_REPLACE_IN_FILES" : "Replace in Files",
"CMD_REPLACE_IN_SELECTED" : "Replace in Selected File/Folder",
"CMD_REPLACE_IN_SUBTREE" : "Replace in\u2026",

// View menu commands
"VIEW_MENU" : "View",
Expand Down
23 changes: 17 additions & 6 deletions src/search/FindInFilesUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ define(function (require, exports, module) {
if (_findBar) {
_findBar.close();
}

_findBar = new FindBar({
navigator: false,
replace: showReplace,
replaceAllOnly: showReplace,
scope: true,
initialQuery: initialString,
queryPlaceholder: Strings.CMD_FIND_IN_SUBTREE,
queryPlaceholder: (showReplace ? Strings.CMD_REPLACE_IN_SUBTREE : Strings.CMD_FIND_IN_SUBTREE),
scopeLabel: FindUtils.labelForScope(scope)
});
_findBar.open();
Expand Down Expand Up @@ -348,6 +348,15 @@ define(function (require, exports, module) {
_showFindBar(selectedEntry);
}

/**
* @private
* Search within the file/subtree defined by the sidebar selection
*/
function _showReplaceBarForSubtree() {
var selectedEntry = ProjectManager.getSelectedItem();
_showFindBar(selectedEntry, true);
}

/**
* @private
* Close the open search bar, if any. For unit tests.
Expand Down Expand Up @@ -375,10 +384,12 @@ define(function (require, exports, module) {
$(ProjectManager).on("beforeProjectClose", function () { _resultsView.close(); });

// Initialize: command handlers
CommandManager.register(Strings.CMD_FIND_IN_FILES, Commands.CMD_FIND_IN_FILES, _showFindBar);
CommandManager.register(Strings.CMD_REPLACE_IN_FILES, Commands.CMD_REPLACE_IN_FILES, _showReplaceBar);
CommandManager.register(Strings.CMD_FIND_IN_SELECTED, Commands.CMD_FIND_IN_SELECTED, _showFindBarForSubtree);
CommandManager.register(Strings.CMD_FIND_IN_SUBTREE, Commands.CMD_FIND_IN_SUBTREE, _showFindBarForSubtree);
CommandManager.register(Strings.CMD_FIND_IN_FILES, Commands.CMD_FIND_IN_FILES, _showFindBar);
CommandManager.register(Strings.CMD_REPLACE_IN_FILES, Commands.CMD_REPLACE_IN_FILES, _showReplaceBar);
CommandManager.register(Strings.CMD_FIND_IN_SELECTED, Commands.CMD_FIND_IN_SELECTED, _showFindBarForSubtree);
CommandManager.register(Strings.CMD_REPLACE_IN_SELECTED, Commands.CMD_REPLACE_IN_SELECTED, _showReplaceBarForSubtree);
CommandManager.register(Strings.CMD_FIND_IN_SUBTREE, Commands.CMD_FIND_IN_SUBTREE, _showFindBarForSubtree);
CommandManager.register(Strings.CMD_REPLACE_IN_SUBTREE, Commands.CMD_REPLACE_IN_SUBTREE, _showReplaceBarForSubtree);

// Public exports
exports.searchAndShowResults = searchAndShowResults;
Expand Down
48 changes: 48 additions & 0 deletions test/spec/FindInFiles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,54 @@ define(function (require, exports, module) {
});
});

it("should do a search in folder, replace all from find bar", function () {
openTestProjectCopy(defaultSourcePath);
var dirEntry = FileSystem.getDirectoryForPath(defaultSourcePath + "/css/");
openSearchBar(null, true);
executeReplace("foo", "bar", true);

waitsFor(function () {
return FindInFiles._searchDone;
}, "search finished");

// Click the "Replace" button in the search panel - this should kick off the replace
runs(function () {
$(".replace-checked").click();
});

waitsFor(function () {
return FindInFiles._replaceDone;
}, "replace finished");
expectInMemoryFiles({
inMemoryFiles: ["/css/foo.css"],
inMemoryKGFolder: "simple-case-insensitive-only-foo.css"
});
});

it("should do a search in file, replace all from find bar", function () {
openTestProjectCopy(defaultSourcePath);
var dirEntry = FileSystem.getDirectoryForPath(defaultSourcePath + "/css/foo.css");
openSearchBar(null, true);
executeReplace("foo", "bar", true);

waitsFor(function () {
return FindInFiles._searchDone;
}, "search finished");

// Click the "Replace" button in the search panel - this should kick off the replace
runs(function () {
$(".replace-checked").click();
});

waitsFor(function () {
return FindInFiles._replaceDone;
}, "replace finished");
expectInMemoryFiles({
inMemoryFiles: ["/css/foo.css"],
inMemoryKGFolder: "simple-case-insensitive-only-foo.css"
});
});

it("should do a regexp search/replace from find bar", function () {
openTestProjectCopy(defaultSourcePath);
openSearchBar(null, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bar.txt file

This file should *not* show up in certain searches
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* bar.css */
body {
margin: 0;
}
h1, barter {
padding: 2px auto;
}
ul.bar {
list-style: none;
}
.bar {
font-size: large;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>bar</title>
<link rel="stylesheet" href="css/bar.css">
<script src="bar.js"></script>
</head>

<body>

<h1>bar</h1>
<p>Intro to bar</p>
<ul class="bar">
<li>bar</li>
<li>bar</li>
<li>baz</li>
</ul>
<p class="bar">It's all about the bar</p>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Test comment */
define(function (require, exports, module) {
var bar = require("modules/bar"),
Bar = require("modules/Bar"),
Baz = require("modules/Baz");

function callbar() {

bar();

}

}

0 comments on commit f6d3efc

Please sign in to comment.