/SparkleShare/SparkleEntry.cs
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 17 18using Gtk; 19 20// TODO: Remove with Gtk3 21namespace SparkleShare { 22 23 public class SparkleEntry : Entry { 24 25 26 private string example_text; 27 private bool example_text_active; 28 29 30 public SparkleEntry () 31 { 32 ExampleTextActive = true; 33 34 FocusGrabbed += delegate { OnEntered (); }; 35 ClipboardPasted += delegate { OnEntered (); }; 36 37 FocusOutEvent += delegate { 38 if (Text.Equals ("") || Text == null) 39 ExampleTextActive = true; 40 41 if (ExampleTextActive) 42 UseExampleText (); 43 }; 44 } 45 46 47 private void OnEntered () 48 { 49 if (ExampleTextActive) { 50 ExampleTextActive = false; 51 Text = ""; 52 UseNormalTextColor (); 53 } 54 } 55 56 57 public bool ExampleTextActive { 58 get { 59 return this.example_text_active; 60 } 61 62 set { 63 this.example_text_active = value; 64 65 if (this.example_text_active) 66 UseSecondaryTextColor (); 67 else 68 UseNormalTextColor (); 69 } 70 } 71 72 73 public string ExampleText 74 { 75 get { 76 return this.example_text; 77 } 78 79 set { 80 this.example_text = value; 81 82 if (this.example_text_active) 83 UseExampleText (); 84 } 85 } 86 87 88 private void UseExampleText () 89 { 90 Text = this.example_text; 91 UseSecondaryTextColor (); 92 } 93 94 95 private void UseSecondaryTextColor () 96 { 97 ModifyText (StateType.Normal, Style.Foreground (StateType.Insensitive)); 98 } 99 100 101 private void UseNormalTextColor () 102 { 103 ModifyText (StateType.Normal, Style.Foreground (StateType.Normal)); 104 } 105 } 106}