|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import { DisposableStore } from 'vs/base/common/lifecycle';
|
7 |
| -import { isEqual } from 'vs/base/common/resources'; |
| 7 | +import { basename, isEqual } from 'vs/base/common/resources'; |
8 | 8 | import Severity from 'vs/base/common/severity';
|
9 | 9 | import { URI } from 'vs/base/common/uri';
|
10 | 10 | import { ITextModelService } from 'vs/editor/common/services/resolverService';
|
@@ -234,50 +234,79 @@ class MergeEditorCloseHandler implements IEditorCloseHandler {
|
234 | 234 | return ConfirmResult.SAVE;
|
235 | 235 | }
|
236 | 236 |
|
237 |
| - const actions: string[] = [ |
238 |
| - someAreDirty ? localize('unhandledConflicts.saveAndIgnore', "Save & Continue with Conflicts") : localize('unhandledConflicts.ignore', "Continue with Conflicts"), |
239 |
| - localize('unhandledConflicts.discard', "Discard Merge Changes"), |
240 |
| - localize('unhandledConflicts.cancel', "Cancel"), |
241 |
| - ]; |
| 237 | + const result = someAreDirty |
| 238 | + ? await this._confirmDirty(handler) |
| 239 | + : await this._confirmNoneDirty(handler); |
| 240 | + |
| 241 | + if (result !== ConfirmResult.CANCEL) { |
| 242 | + // save or ignore: in both cases we tell the inputs to ignore unhandled conflicts |
| 243 | + // for the dirty state computation. |
| 244 | + for (const input of handler) { |
| 245 | + input._ignoreUnhandledConflicts = true; |
| 246 | + } |
| 247 | + } |
| 248 | + |
| 249 | + return result; |
| 250 | + } |
| 251 | + |
| 252 | + private async _confirmDirty(handler: MergeEditorCloseHandler[]): Promise<ConfirmResult> { |
| 253 | + const isMany = handler.length > 1; |
| 254 | + |
| 255 | + const message = isMany |
| 256 | + ? localize('messageN', 'Do you want to save the changes you made to {0} files?', handler.length) |
| 257 | + : localize('message1', 'Do you want to save the changes you made to {0}?', basename(handler[0]._model.resultTextModel.uri)); |
| 258 | + |
242 | 259 | const options = {
|
243 | 260 | cancelId: 2,
|
244 |
| - detail: handler.length > 1 |
245 |
| - ? localize('unhandledConflicts.detailN', 'Merge conflicts in {0} editors will remain unhandled.', handler.length) |
246 |
| - : localize('unhandledConflicts.detail1', 'Merge conflicts in this editor will remain unhandled.') |
| 261 | + detail: isMany |
| 262 | + ? localize('detailN', "The files contain unhandled conflicts. Your changes will be lost if you don't save them.") |
| 263 | + : localize('detail1', "The file contains unhandled conflicts. Your changes will be lost if you don't save them.") |
247 | 264 | };
|
248 | 265 |
|
249 |
| - const { choice } = await this._dialogService.show( |
250 |
| - Severity.Info, |
251 |
| - localize('unhandledConflicts.msg', 'Do you want to continue with unhandled conflicts?'), // 1 |
252 |
| - actions, |
253 |
| - options |
254 |
| - ); |
| 266 | + const actions: string[] = [ |
| 267 | + localize('saveWithConflict', "Save with Conflicts"), |
| 268 | + localize('discard', "Don't save"), |
| 269 | + localize('cancel', "Cancel"), |
| 270 | + ]; |
| 271 | + |
| 272 | + const { choice } = await this._dialogService.show(Severity.Info, message, actions, options); |
255 | 273 |
|
256 | 274 | if (choice === options.cancelId) {
|
257 | 275 | // cancel: stay in editor
|
258 | 276 | return ConfirmResult.CANCEL;
|
| 277 | + } else if (choice === 0) { |
| 278 | + // save with conflicts |
| 279 | + return ConfirmResult.SAVE; |
| 280 | + } else { |
| 281 | + // discard changes |
| 282 | + return ConfirmResult.DONT_SAVE; |
259 | 283 | }
|
| 284 | + } |
260 | 285 |
|
261 |
| - // save or revert: in both cases we tell the inputs to ignore unhandled conflicts |
262 |
| - // for the dirty state computation. |
263 |
| - for (const input of handler) { |
264 |
| - input._ignoreUnhandledConflicts = true; |
265 |
| - } |
| 286 | + private async _confirmNoneDirty(handler: MergeEditorCloseHandler[]): Promise<ConfirmResult> { |
| 287 | + const isMany = handler.length > 1; |
266 | 288 |
|
267 |
| - if (choice === 0) { |
268 |
| - // conflicts: continue with remaining conflicts |
269 |
| - return ConfirmResult.SAVE; |
| 289 | + const message = isMany |
| 290 | + ? localize('conflictN', 'Do you want to close with conflicts in {0} files?', handler.length) |
| 291 | + : localize('conflict1', 'Do you want to close with conflicts in {0}?', basename(handler[0]._model.resultTextModel.uri)); |
270 | 292 |
|
271 |
| - } else if (choice === 1) { |
272 |
| - // discard: undo all changes and save original (pre-merge) state |
273 |
| - for (const input of handler) { |
274 |
| - input._model.discardMergeChanges(); |
275 |
| - } |
276 |
| - return ConfirmResult.SAVE; |
| 293 | + const options = { |
| 294 | + cancelId: 1, |
| 295 | + detail: isMany |
| 296 | + ? localize('detailNotDirtyN', "The files contain unhandled conflicts.") |
| 297 | + : localize('detailNotDirty1', "The file contains unhandled conflicts.") |
| 298 | + }; |
| 299 | + |
| 300 | + const actions = [ |
| 301 | + localize('closeWithConflicts', "Close with Conflicts"), |
| 302 | + localize('cancel', "Cancel"), |
| 303 | + ]; |
277 | 304 |
|
| 305 | + const { choice } = await this._dialogService.show(Severity.Info, message, actions, options); |
| 306 | + if (choice === options.cancelId) { |
| 307 | + return ConfirmResult.CANCEL; |
278 | 308 | } else {
|
279 |
| - // don't save |
280 |
| - return ConfirmResult.DONT_SAVE; |
| 309 | + return ConfirmResult.SAVE; |
281 | 310 | }
|
282 | 311 | }
|
283 | 312 | }
|
0 commit comments