6467dcf325902f0f5bad297e26022a4ca86db8bae8b8dd558aeb3c4570bfba10784174c929557462e1cc09e92ffc69d479fd7334fd32496ba392707b20b877 1.6 KB

12345678910111213141516171819202122232425262728
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { Disposable } from '../../../../base/common/lifecycle.js';
  6. import { registerEditorContribution } from '../../../browser/editorExtensions.js';
  7. import { MessageController } from '../../message/browser/messageController.js';
  8. import * as nls from '../../../../nls.js';
  9. export class ReadOnlyMessageController extends Disposable {
  10. constructor(editor) {
  11. super();
  12. this.editor = editor;
  13. this._register(this.editor.onDidAttemptReadOnlyEdit(() => this._onDidAttemptReadOnlyEdit()));
  14. }
  15. _onDidAttemptReadOnlyEdit() {
  16. const messageController = MessageController.get(this.editor);
  17. if (messageController && this.editor.hasModel()) {
  18. if (this.editor.isSimpleWidget) {
  19. messageController.showMessage(nls.localize('editor.simple.readonly', "Cannot edit in read-only input"), this.editor.getPosition());
  20. }
  21. else {
  22. messageController.showMessage(nls.localize('editor.readonly', "Cannot edit in read-only editor"), this.editor.getPosition());
  23. }
  24. }
  25. }
  26. }
  27. ReadOnlyMessageController.ID = 'editor.contrib.readOnlyMessageController';
  28. registerEditorContribution(ReadOnlyMessageController.ID, ReadOnlyMessageController);