1 /* gobby - A GTKmm driven libobby client
2  * Copyright (C) 2005, 2006 0x539 dev group
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (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 GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this program; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #include <sstream>
20 #include <gtkmm/separator.h>
21 #include <obby/format_string.hpp>
22 #include <obby/local_buffer.hpp>
23 #include "common.hpp"
24 #include "statusbar.hpp"
25 
StatusBar(Header & header,const Folder & folder)26 Gobby::StatusBar::StatusBar(Header& header, const Folder& folder):
27 	m_header(header)
28 {
29 	pack_end(m_bar_position, Gtk::PACK_SHRINK);
30 	pack_end(m_bar_language, Gtk::PACK_SHRINK);
31 
32 	m_bar_position.set_size_request(200, -1);
33 	m_bar_language.set_size_request(200, -1);
34 
35 	set_has_resize_grip(false);
36 	m_bar_language.set_has_resize_grip(false);
37 
38 	push(_("Not connected"));
39 
40 	folder.document_cursor_moved_event().connect(
41 		sigc::mem_fun(*this, &StatusBar::update_cursor) );
42 	folder.document_language_changed_event().connect(
43 		sigc::mem_fun(*this, &StatusBar::update_language) );
44 	folder.tab_switched_event().connect(
45 		sigc::mem_fun(*this, &StatusBar::update_from_document) );
46 }
47 
update_language(DocWindow & wnd)48 void Gobby::StatusBar::update_language(DocWindow& wnd)
49 {
50 	// Selected language
51 	m_bar_language.pop();
52 	if(wnd.get_language() )
53 	{
54 		Glib::ustring name =
55 			gtk_source_language_get_name(wnd.get_language());
56 		obby::format_string str(_("Selected language: %0%") );
57 		str << name.raw();
58 		m_bar_language.push(str.str() );
59 	}
60 	else
61 	{
62 		m_bar_language.push(_("No language selected") );
63 	}
64 }
65 
update_cursor(DocWindow & wnd)66 void Gobby::StatusBar::update_cursor(DocWindow& wnd)
67 {
68 	unsigned int row, col;
69 	wnd.get_cursor_position(row, col);
70 
71 	m_bar_position.pop();
72 	obby::format_string str(_("Line: %0%, Column: %1%"));
73 	str << (row + 1) << (col + 1);
74 	m_bar_position.push(str.str() );
75 }
76 
update_from_document(DocWindow & wnd)77 void Gobby::StatusBar::update_from_document(DocWindow& wnd)
78 {
79 	update_language(wnd);
80 	update_cursor(wnd);
81 }
82 
update_connection(const Glib::ustring & str)83 void Gobby::StatusBar::update_connection(const Glib::ustring& str)
84 {
85 	// TODO: Do this in obby_start!
86 	pop();
87 	push(str);
88 }
89 
obby_start(LocalBuffer & buf)90 void Gobby::StatusBar::obby_start(LocalBuffer& buf)
91 {
92 }
93 
obby_end()94 void Gobby::StatusBar::obby_end()
95 {
96 	pop();
97 	m_bar_language.pop();
98 	m_bar_position.pop();
99 
100 	push(_("Not connected"));
101 }
102 
obby_user_join(const obby::user & user)103 void Gobby::StatusBar::obby_user_join(const obby::user& user)
104 {
105 }
106 
obby_user_part(const obby::user & user)107 void Gobby::StatusBar::obby_user_part(const obby::user& user)
108 {
109 }
110 
obby_document_insert(LocalDocumentInfo & document)111 void Gobby::StatusBar::obby_document_insert(LocalDocumentInfo& document)
112 {
113 }
114 
obby_document_remove(LocalDocumentInfo & document)115 void Gobby::StatusBar::obby_document_remove(LocalDocumentInfo& document)
116 {
117 	// Last document that is closed?
118 	if(document.get_buffer().document_count() == 1)
119 	{
120 		// Clear document-related statusbar items
121 		m_bar_language.pop();
122 		m_bar_position.pop();
123 	}
124 }
125 
on_show()126 void Gobby::StatusBar::on_show()
127 {
128 	Gtk::Statusbar::on_show();
129 	//m_sep.hide();
130 }
131 
132