allow to customize editor placeholder attributes appcode/142.3519 clion/142.3518
authorDmitry Batrak <Dmitry.Batrak@jetbrains.com>
Sun, 26 Jul 2015 14:22:22 +0000 (17:22 +0300)
committerDmitry Batrak <Dmitry.Batrak@jetbrains.com>
Sun, 26 Jul 2015 14:22:22 +0000 (17:22 +0300)
platform/lang-impl/src/com/intellij/injected/editor/EditorWindowImpl.java
platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorEx.java
platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorImpl.java

index 4b6e61600f20150b201dfa1dd20b3d47e8ae6c92..75bb3fa40e5e81f615ea826825e4665fb48c0594 100644 (file)
@@ -832,6 +832,11 @@ public class EditorWindowImpl extends UserDataHolderBase implements EditorWindow
     myDelegate.setPlaceholder(text);
   }
 
+  @Override
+  public void setPlaceholderAttributes(@Nullable TextAttributes attributes) {
+    myDelegate.setPlaceholderAttributes(attributes);
+  }
+
   @Override
   public void setShowPlaceholderWhenFocused(boolean show) {
     myDelegate.setShowPlaceholderWhenFocused(show);
index 0b182c39ec6cae284803bb0bc59f9a971a86d168..c61b6d24cc3c0c169e5589ac3b331a10ed8adbce 100644 (file)
@@ -228,6 +228,14 @@ public interface EditorEx extends Editor {
    */
   void setPlaceholder(@Nullable CharSequence text);
 
+  /**
+   * Sets text attributes for a placeholder. Font style and color are currently supported. 
+   * <code>null</code> means default values should be used.
+   * 
+   * @see #setPlaceholder(CharSequence)
+   */
+  void setPlaceholderAttributes(@Nullable TextAttributes attributes);
+  
   /**
    * Controls whether <code>'placeholder text'</code> is visible when editor is focused.
    *
index 3425a6bc0e28642cc9b606b4e9f503548eac63c4..322b4149108bce1e84a034cb199c6daabb39aaf8 100644 (file)
@@ -282,6 +282,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
 
   @Nullable
   private CharSequence myPlaceholderText;
+  @Nullable private TextAttributes myPlaceholderAttributes;
   private int myLastPaintedPlaceholderWidth;
   private boolean myShowPlaceholderWhenFocused;
 
@@ -2244,6 +2245,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
     myPlaceholderText = text;
   }
 
+  @Override
+  public void setPlaceholderAttributes(@Nullable TextAttributes attributes) {
+    myPlaceholderAttributes = attributes;
+  }
+
   public CharSequence getPlaceholder() {
     return myPlaceholderText;
   }
@@ -3086,8 +3092,11 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
       hintText = SwingUtilities.layoutCompoundLabel(g.getFontMetrics(), hintText.toString(), null, 0, 0, 0, 0,
                                                     myEditorComponent.getBounds(), new Rectangle(), new Rectangle(), 0);
       myLastPaintedPlaceholderWidth = drawString(
-        g, hintText, 0, hintText.length(), new Point(0, 0), clip, null, null, Font.PLAIN,
-        myFoldingModel.getPlaceholderAttributes().getForegroundColor(), PAINT_NO_WHITESPACE
+        g, hintText, 0, hintText.length(), new Point(0, 0), clip, null, null, 
+        myPlaceholderAttributes == null ? Font.PLAIN : myPlaceholderAttributes.getFontType(),
+        myPlaceholderAttributes == null ? myFoldingModel.getPlaceholderAttributes().getForegroundColor() : 
+                                          myPlaceholderAttributes.getForegroundColor(), 
+        PAINT_NO_WHITESPACE
       );
       flushCachedChars(g);
       return true;