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 #ifndef _GOBBY_PREFERENCESDIALOG_HPP_
20 #define _GOBBY_PREFERENCESDIALOG_HPP_
21 
22 #include <gtkmm/dialog.h>
23 #include <gtkmm/frame.h>
24 #include <gtkmm/box.h>
25 #include <gtkmm/expander.h>
26 #include <gtkmm/label.h>
27 #include <gtkmm/spinbutton.h>
28 #include <gtkmm/checkbutton.h>
29 #include <gtkmm/comboboxtext.h>
30 #include <gtkmm/notebook.h>
31 #include <gtkmm/tooltips.h>
32 #include <gtkmm/liststore.h>
33 #include <gtkmm/treeview.h>
34 #include <gtkmm/cellrenderercombo.h>
35 #include <gtkmm/scrolledwindow.h>
36 #include <gtkmm/fontselection.h>
37 #include "preferences.hpp"
38 
39 namespace Gobby
40 {
41 
42 class PreferencesDialog : public Gtk::Dialog
43 {
44 public:
45 	class Page: public Gtk::Frame
46 	{
47 	public:
48 		Page();
49 
50 	protected:
51 	};
52 
53 	class Editor: public Page
54 	{
55 	public:
56 #ifndef GTKMM_DISABLE_DEPRECATED
57 		Editor(const Preferences& preferences,
58 		       Gtk::Tooltips& tooltips);
59 #else
60 		Editor(const Preferences& preferences);
61 #endif
62 
63 		void set(Preferences::Editor& editor) const;
64 
65 	protected:
66 		Gtk::VBox m_box;
67 		Gtk::Frame m_frame_tab;
68 		Gtk::Frame m_frame_indentation;
69 		Gtk::Frame m_frame_homeend;
70 
71 		Gtk::VBox m_box_tab;
72 		Gtk::HBox m_box_tab_width;
73 		Gtk::Label m_lbl_tab_width;
74 		Gtk::SpinButton m_ent_tab_width;
75 		Gtk::CheckButton m_btn_tab_spaces;
76 
77 		Gtk::VBox m_box_indentation;
78 		Gtk::CheckButton m_btn_indentation_auto;
79 
80 		Gtk::VBox m_box_homeend;
81 		Gtk::CheckButton m_btn_homeend_smart;
82 	};
83 
84 	class View: public Page
85 	{
86 	public:
87 		View(const Preferences& preferences);
88 		void set(Preferences::View& view) const;
89 
90 	protected:
91 		virtual void on_margin_display_toggled();
92 
93 		Gtk::VBox m_box;
94 		Gtk::Frame m_frame_wrap;
95 		Gtk::Frame m_frame_linenum;
96 		Gtk::Frame m_frame_curline;
97 		Gtk::Frame m_frame_margin;
98 		Gtk::Frame m_frame_bracket;
99 
100 		Gtk::VBox m_box_wrap;
101 		Gtk::CheckButton m_btn_wrap_text;
102 		Gtk::CheckButton m_btn_wrap_words;
103 
104 		Gtk::VBox m_box_linenum;
105 		Gtk::CheckButton m_btn_linenum_display;
106 
107 		Gtk::VBox m_box_curline;
108 		Gtk::CheckButton m_btn_curline_highlight;
109 
110 		Gtk::VBox m_box_margin;
111 		Gtk::CheckButton m_btn_margin_display;
112 		Gtk::HBox m_box_margin_pos;
113 		Gtk::Label m_lbl_margin_pos;
114 		Gtk::SpinButton m_ent_margin_pos;
115 
116 		Gtk::VBox m_box_bracket;
117 		Gtk::CheckButton m_btn_bracket_highlight;
118 	};
119 
120 	class Appearance: public Page
121 	{
122 	public:
123 		Appearance(const Preferences& preferences);
124 		void set(Preferences::Appearance& appearance) const;
125 
126 	protected:
127 		Gtk::VBox m_box;
128 		Gtk::Frame m_frame_toolbar;
129 		Gtk::Frame m_frame_windows;
130 
131 		Gtk::VBox m_box_toolbar;
132 		Gtk::ComboBoxText m_cmb_toolbar_style;
133 
134 		Gtk::VBox m_box_windows;
135 		Gtk::CheckButton m_btn_remember;
136 		Gtk::CheckButton m_btn_urgency_hint;
137 	};
138 
139 	class Font: public Page
140 	{
141 	public:
142 		Font(const Preferences& preferences);
143 		void set(Preferences::Font& font) const;
144 
145 	protected:
146 		void on_fontsel_realize();
147 
148 		Gtk::FontSelection m_font_sel;
149 		Glib::ustring m_init_font;
150 	};
151 
152 	class Behaviour: public Page
153 	{
154 	public:
155 		Behaviour(const Preferences& preferences);
156 		void set(Preferences::Behaviour& behaviour) const;
157 
158 	protected:
159 		Gtk::VBox m_box;
160 
161 		Gtk::Frame m_frame_documents;
162 		Gtk::VBox m_box_documents;
163 		Gtk::CheckButton m_btn_auto_open;
164 	};
165 
166 	class FileList: public Page
167 	{
168 	public:
169 		// List of languages. TODO: Should be somewhere else
170 		class LanguageColumns: public Gtk::TreeModel::ColumnRecord
171 		{
172 		public:
173 			LanguageColumns();
174 
175 			Gtk::TreeModelColumn<GtkSourceLanguage*> language;
176 			Gtk::TreeModelColumn<Glib::ustring> language_name;
177 		};
178 
179 		class FileColumns: public Gtk::TreeModel::ColumnRecord
180 		{
181 		public:
182 			FileColumns();
183 
184 			Gtk::TreeModelColumn<Glib::ustring> pattern;
185 			Gtk::TreeModelColumn<Glib::ustring> mime_type;
186 			Gtk::TreeModelColumn<Gtk::TreeIter> language;
187 		};
188 
189 		FileList(Gtk::Window& parent,
190 		         const Preferences& preferences,
191 		         GtkSourceLanguageManager* lang_mgr);
192 
193 		void set(Preferences::FileList& files) const;
194 
195 		const LanguageColumns lang_columns;
196 		const FileColumns file_columns;
197 
198 	protected:
199 		struct LangCompare
200 		{
operator ()Gobby::PreferencesDialog::FileList::LangCompare201 			bool operator()(const GtkSourceLanguage* first, const GtkSourceLanguage* second) const
202 			{
203 				return first < second;
204 			}
205 		};
206 
207 		typedef std::map<
208 			GtkSourceLanguage*,
209 			Gtk::TreeIter,
210 			LangCompare
211 		> map_type;
212 
213 		void cell_data_file_language(Gtk::CellRenderer* renderer,
214 		                             const Gtk::TreeIter& iter);
215 
216 		void on_pattern_edited(const Glib::ustring& path,
217 		                       const Glib::ustring& new_text);
218 		void on_mimetype_edited(const Glib::ustring& path,
219 		                        const Glib::ustring& new_text);
220 		void on_language_edited(const Glib::ustring& path,
221 		                        const Glib::ustring& new_text);
222 
223 		void on_selection_changed();
224 
225 		void on_file_add();
226 		void on_file_remove();
227 
228 		void set_language(const Gtk::TreeIter& row,
229 		                  GtkSourceLanguage* lang);
230 
231 		Gtk::Window& m_parent;
232 		GtkSourceLanguageManager* m_lang_mgr;
233 
234 		Gtk::CellRendererText* m_renderer_pattern;
235 		Gtk::CellRendererCombo m_renderer_lang;
236 		Gtk::CellRendererText* m_renderer_mimetype;
237 
238 		Gtk::TreeViewColumn m_viewcol_pattern;
239 		Gtk::TreeViewColumn m_viewcol_lang;
240 		Gtk::TreeViewColumn m_viewcol_mimetype;
241 
242 		Gtk::VBox m_vbox;
243 		Gtk::Label m_intro;
244 		Gtk::ScrolledWindow m_wnd;
245 		Gtk::TreeView m_view;
246 
247 		Gtk::HButtonBox m_hbox;
248 		Gtk::Button m_btn_add;
249 		Gtk::Button m_btn_remove;
250 
251 		// Map for better access to iterators to the language list
252 		map_type m_lang_map;
253 
254 		Glib::RefPtr<Gtk::ListStore> m_lang_list;
255 		Glib::RefPtr<Gtk::ListStore> m_file_list;
256 	};
257 
258 	PreferencesDialog(Gtk::Window& parent,
259 	                  const Preferences& preferences,
260 	                  GtkSourceLanguageManager* lang_mgr,
261 	                  bool local);
262 
263 	void set(Preferences& preferences) const;
264 
265 #if 0
266 	const Editor& editor() const;
267 	const View& view() const;
268 	const Appearance& appearance() const;
269 #endif
270 
271 protected:
272 	Gtk::Notebook m_notebook;
273 
274 #ifndef GTKMM_DISABLE_DEPRECATED
275 	Gtk::Tooltips m_tooltips;
276 #endif
277 
278 	Editor m_page_editor;
279 	View m_page_view;
280 	Appearance m_page_appearance;
281 	Font m_page_font;
282 	Behaviour m_page_behaviour;
283 	FileList m_page_files;
284 };
285 
286 }
287 
288 #endif // _GOBBY_PREFERENCESDIALOG_HPP_
289 
290