/SparkleShare/SparkleEntry.cs

http://github.com/hbons/SparkleShare · C# · 106 lines · 63 code · 27 blank · 16 comment · 7 complexity · 42e3036ba62a996f30b3667bd4c8f9d4 MD5 · raw file

  1. // SparkleShare, a collaboration and sharing tool.
  2. // Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General private License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General private License for more details.
  13. //
  14. // You should have received a copy of the GNU General private License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. using Gtk;
  17. // TODO: Remove with Gtk3
  18. namespace SparkleShare {
  19. public class SparkleEntry : Entry {
  20. private string example_text;
  21. private bool example_text_active;
  22. public SparkleEntry ()
  23. {
  24. ExampleTextActive = true;
  25. FocusGrabbed += delegate { OnEntered (); };
  26. ClipboardPasted += delegate { OnEntered (); };
  27. FocusOutEvent += delegate {
  28. if (Text.Equals ("") || Text == null)
  29. ExampleTextActive = true;
  30. if (ExampleTextActive)
  31. UseExampleText ();
  32. };
  33. }
  34. private void OnEntered ()
  35. {
  36. if (ExampleTextActive) {
  37. ExampleTextActive = false;
  38. Text = "";
  39. UseNormalTextColor ();
  40. }
  41. }
  42. public bool ExampleTextActive {
  43. get {
  44. return this.example_text_active;
  45. }
  46. set {
  47. this.example_text_active = value;
  48. if (this.example_text_active)
  49. UseSecondaryTextColor ();
  50. else
  51. UseNormalTextColor ();
  52. }
  53. }
  54. public string ExampleText
  55. {
  56. get {
  57. return this.example_text;
  58. }
  59. set {
  60. this.example_text = value;
  61. if (this.example_text_active)
  62. UseExampleText ();
  63. }
  64. }
  65. private void UseExampleText ()
  66. {
  67. Text = this.example_text;
  68. UseSecondaryTextColor ();
  69. }
  70. private void UseSecondaryTextColor ()
  71. {
  72. ModifyText (StateType.Normal, Style.Foreground (StateType.Insensitive));
  73. }
  74. private void UseNormalTextColor ()
  75. {
  76. ModifyText (StateType.Normal, Style.Foreground (StateType.Normal));
  77. }
  78. }
  79. }