jacobslusser / ScintillaNET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.
MIT License
964 stars 242 forks source link

ReadOnly Mode Visual Studio Properties Panel Issue #510

Open Chadt54 opened 3 years ago

Chadt54 commented 3 years ago

In Visual Studio, in the Properties Panel for the control, if you have the ReadOnly mode set to True, then you can't change or set the "Text" property in the Properties panel.

VPKSoft commented 3 years ago

Changind the Scintilla Text property setter from this:

  set
  {
      if (string.IsNullOrEmpty(value))
      {
          DirectMessage(NativeMethods.SCI_CLEARALL);
      }
      else if (value.Contains("\0"))
      {
          DirectMessage(NativeMethods.SCI_CLEARALL);
          AppendText(value);
      }
      else
      {
          fixed (byte* bp = Helpers.GetBytes(value, Encoding, zeroTerminated: true)) 
              DirectMessage(NativeMethods.SCI_SETTEXT, IntPtr.Zero, new IntPtr(bp));
      }
  }

into this:

  set
  {
      var previousReadOnly = DesignMode ? ReadOnly : false;

      // Allow Text property change in read-only mode when  designer is active.
      if (previousReadOnly && DesignMode)
      {
          DirectMessage(NativeMethods.SCI_SETREADONLY, IntPtr.Zero);
      }

      if (string.IsNullOrEmpty(value))
      {
          DirectMessage(NativeMethods.SCI_CLEARALL);
      }
      else if (value.Contains("\0"))
      {
          DirectMessage(NativeMethods.SCI_CLEARALL);
          AppendText(value);
      }
      else
      {
          fixed (byte* bp = Helpers.GetBytes(value, Encoding, zeroTerminated: true)) 
              DirectMessage(NativeMethods.SCI_SETTEXT, IntPtr.Zero, new IntPtr(bp));
      }

      // Allow Text property change in read-only mode when  designer is active.
      if (previousReadOnly && DesignMode)
      {
          DirectMessage(NativeMethods.SCI_SETREADONLY, new IntPtr(1));
      }
  }

I can only make the change to my own fork as a PR is on the way and the official doesn't currently seem to be in active development.

Chadt54 commented 3 years ago

Wow! Fast turn around! Thank you!

Currently, I'm ok with dealing with the workaround of disabling the readonly mode for a quick second to edit the text property, but just wanted to post the issue to here to make sure the bug is known and can be fixed in the future (but it got fixed immediately! haha).

So, glad I could help! and thanks again for the fast turn around :)