Skip to content

Commit 35fd9fc

Browse files
committed
feat: confirm before opening a large number of changed files
1 parent 6d43876 commit 35fd9fc

2 files changed

Lines changed: 34 additions & 16 deletions

File tree

src/extensions/default/Git/src/Panel.js

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,28 @@ define(function (require, exports) {
10161016
});
10171017
}
10181018

1019+
const OPEN_ALL_CONFIRM_THRESHOLD = 50;
1020+
1021+
function _openChangedFiles(files) {
1022+
const currentGitRoot = Preferences.get("currentGitRoot");
1023+
// addListToWorkingSet ignores files already present in any pane, so this is safe
1024+
// to run repeatedly or with some of the files already open
1025+
const fileList = files.map(function (file) {
1026+
return FileSystem.getFileForPath(currentGitRoot + file.file);
1027+
});
1028+
MainViewManager.addListToWorkingSet(MainViewManager.ACTIVE_PANE, fileList);
1029+
1030+
// if the user is already viewing one of the changed files, we don't switch the file then...
1031+
// if user is viewing a un-changed file, then we switch to the first changed file
1032+
const currentPath = MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE);
1033+
const viewingChangedFile = _.any(fileList, function (file) {
1034+
return file.fullPath === currentPath;
1035+
});
1036+
if (!viewingChangedFile) {
1037+
CommandManager.execute(Commands.FILE_OPEN, { fullPath: fileList[0].fullPath });
1038+
}
1039+
}
1040+
10191041
function openAllChangedFiles() {
10201042
return Git.status().then(function (files) {
10211043
files = _.filter(files, function (file) {
@@ -1037,23 +1059,18 @@ define(function (require, exports) {
10371059
return;
10381060
}
10391061

1040-
const currentGitRoot = Preferences.get("currentGitRoot");
1041-
// addListToWorkingSet ignores files already present in any pane, so this is safe
1042-
// to run repeatedly or with some of the files already open
1043-
const fileList = files.map(function (file) {
1044-
return FileSystem.getFileForPath(currentGitRoot + file.file);
1045-
});
1046-
MainViewManager.addListToWorkingSet(MainViewManager.ACTIVE_PANE, fileList);
1047-
1048-
// if the user is already viewing one of the changed files, we don't switch the file then...
1049-
// if user is viewing a un-changed file, then we switch to the first changed file
1050-
const currentPath = MainViewManager.getCurrentlyViewedPath(MainViewManager.ACTIVE_PANE);
1051-
const viewingChangedFile = _.any(fileList, function (file) {
1052-
return file.fullPath === currentPath;
1053-
});
1054-
if (!viewingChangedFile) {
1055-
CommandManager.execute(Commands.FILE_OPEN, { fullPath: fileList[0].fullPath });
1062+
if (files.length > OPEN_ALL_CONFIRM_THRESHOLD) {
1063+
return Utils.askQuestion(Strings.CMD_OPEN_CHANGED_FILES,
1064+
StringUtils.format(Strings.OPEN_CHANGED_FILES_CONFIRM, files.length),
1065+
{ booleanResponse: true })
1066+
.then(function (response) {
1067+
if (response === true) {
1068+
_openChangedFiles(files);
1069+
}
1070+
});
10561071
}
1072+
1073+
_openChangedFiles(files);
10571074
}).catch(function (err) {
10581075
ErrorHandler.showError(err, Strings.ERROR_OPENING_CHANGED_FILES);
10591076
});

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,6 +2171,7 @@ define({
21712171
"MERGE_RESULT": "Merge result",
21722172
"NORMALIZE_LINE_ENDINGS": "Normalize line endings (to \\n)",
21732173
"NOTHING_TO_COMMIT": "Nothing to commit, working directory clean.",
2174+
"OPEN_CHANGED_FILES_CONFIRM": "This will open {0} files in the editor. Do you want to continue?",
21742175
"OPERATION_IN_PROGRESS_TITLE": "Git operation in progress\u2026",
21752176
"ORIGIN_BRANCH": "Origin branch",
21762177
"ON_BRANCH": "'{0}' - Current Git branch",

0 commit comments

Comments
 (0)