2
* Copyright (C) 2010 Neil Jagdish Patel
4
* This library is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License
6
* version 3.0 as published by the Free Software Foundation.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License version 3.0 for more details.
13
* You should have received a copy of the GNU Lesser General Public
14
* License along with this library. If not, see
15
* <http://www.gnu.org/licenses/>.
17
* Authored by Neil Jagdish Patel <neil.patel@canonical.com>
22
public class Entry : Gtk.VBox
24
private Service service;
26
private InputTextView text_view;
35
this.service = new Service ();
37
this.text_view = new InputTextView (this.service);
38
this.add (this.text_view);
39
this.text_view.show ();
43
public class InputTextView : Gtk.TextView
45
public Service service { get; construct; }
47
private Gdk.Color base_color;
48
private Gdk.Color error_color;
50
bool last_was_shortened = false;
52
public InputTextView (Service service)
54
Object (service:service,
59
wrap_mode:Gtk.WrapMode.WORD_CHAR,
63
pixels_below_lines:2);
68
this.base_color = this.get_style ().base[Gtk.StateType.NORMAL];
69
Gdk.Color.parse ("indianred", out this.error_color);
71
this.get_buffer ().changed.connect (this.on_text_changed);
72
this.get_buffer ().insert_text.connect (this.on_text_inserted);
74
//this.set_sensitive (this.service.is_connected ());
77
private void on_text_changed ()
79
var chars = this.get_buffer ().get_char_count ();
81
this.modify_base (Gtk.StateType.NORMAL,
82
chars > 140 ? this.error_color : this.base_color);
85
private void on_text_inserted (Gtk.TextIter iter, string text, int len)
87
if (this.last_was_shortened == false
90
&& text[0:4] == "http")
92
var buf = this.get_buffer ();
93
Signal.stop_emission_by_name (buf, "insert-text") ;
94
var shrt = this.service.shorten (text);
95
this.last_was_shortened = true;
96
buf.insert (iter, shrt, -1);
100
this.last_was_shortened = false;