Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(667)

Side by Side Diff: ui/gtk3/switcher.vala

Issue 339170043: ui/gtk3: Translate input method name in ibus (Closed)
Patch Set: Created 6 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gtk3/panel.vala ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* vim:set et sts=4 sw=4: 1 /* vim:set et sts=4 sw=4:
2 * 2 *
3 * ibus - The Input Bus 3 * ibus - The Input Bus
4 * 4 *
5 * Copyright(c) 2011-2016 Peng Huang <shawn.p.huang@gmail.com> 5 * Copyright(c) 2011-2016 Peng Huang <shawn.p.huang@gmail.com>
6 * Copyright(c) 2015-2017 Takao Fujiwara <takao.fujiwara1@gmail.com> 6 * Copyright(c) 2015-2017 Takao Fujiwara <takao.fujiwara1@gmail.com>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version. 11 * version 2.1 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details. 16 * Lesser General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Lesser General Public 18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software 19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 * USA 21 * USA
22 */ 22 */
23 23
24 class Switcher : Gtk.Window { 24 class Switcher : Gtk.Window {
25 private class IBusEngineButton : Gtk.Button { 25 private class IBusEngineButton : Gtk.Button {
26 public IBusEngineButton(IBus.EngineDesc engine, Switcher switcher) { 26 public IBusEngineButton(IBus.EngineDesc engine, Switcher switcher) {
27 GLib.Object(); 27 GLib.Object();
28 28
29 this.longname = engine.get_longname(); 29 var longname = engine.get_longname();
30 var textdomain = engine.get_textdomain();
31 this.transname = GLib.dgettext(textdomain, longname);
30 32
31 var name = engine.get_name(); 33 var name = engine.get_name();
32 34
33 if (name.length < 4 || name[0:4] != "xkb:") { 35 if (name.length < 4 || name[0:4] != "xkb:") {
34 IconWidget icon = new IconWidget(engine.get_icon(), 36 IconWidget icon = new IconWidget(engine.get_icon(),
35 Gtk.IconSize.DIALOG); 37 Gtk.IconSize.DIALOG);
36 icon.set_halign(Gtk.Align.CENTER); 38 icon.set_halign(Gtk.Align.CENTER);
37 icon.set_valign(Gtk.Align.CENTER); 39 icon.set_valign(Gtk.Align.CENTER);
38 add(icon); 40 add(icon);
39 } else { 41 } else {
(...skipping 11 matching lines...) Expand all
51 int fixed_width, fixed_height; 53 int fixed_width, fixed_height;
52 Gtk.icon_size_lookup(Gtk.IconSize.DIALOG, 54 Gtk.icon_size_lookup(Gtk.IconSize.DIALOG,
53 out fixed_width, 55 out fixed_width,
54 out fixed_height); 56 out fixed_height);
55 label.set_size_request(fixed_width, fixed_height); 57 label.set_size_request(fixed_width, fixed_height);
56 58
57 add(label); 59 add(label);
58 } 60 }
59 } 61 }
60 62
61 public string longname { get; set; } 63 public string transname { get; set; }
62 64
63 public override bool draw(Cairo.Context cr) { 65 public override bool draw(Cairo.Context cr) {
64 base.draw(cr); 66 base.draw(cr);
65 if (is_focus) { 67 if (is_focus) {
66 cr.save(); 68 cr.save();
67 cr.rectangle( 69 cr.rectangle(
68 0, 0, get_allocated_width(), get_allocated_height()); 70 0, 0, get_allocated_width(), get_allocated_height());
69 cr.set_source_rgba(0.0, 0.0, 1.0, 0.1); 71 cr.set_source_rgba(0.0, 0.0, 1.0, 0.1);
70 cr.fill(); 72 cr.fill();
71 cr.restore(); 73 cr.restore();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 KeybindingManager.get_primary_modifier( 146 KeybindingManager.get_primary_modifier(
145 state & KeybindingManager.MODIFIER_FILTER); 147 state & KeybindingManager.MODIFIER_FILTER);
146 m_selected_engine = m_result = index; 148 m_selected_engine = m_result = index;
147 m_input_context_path = input_context_path; 149 m_input_context_path = input_context_path;
148 m_result_engine = null; 150 m_result_engine = null;
149 151
150 update_engines(engines); 152 update_engines(engines);
151 /* Let gtk recalculate the window size. */ 153 /* Let gtk recalculate the window size. */
152 resize(1, 1); 154 resize(1, 1);
153 155
154 m_label.set_text(m_buttons[index].longname); 156 m_label.set_text(m_buttons[index].transname);
155 m_buttons[index].grab_focus(); 157 m_buttons[index].grab_focus();
156 158
157 Gdk.Device device = event.get_device(); 159 Gdk.Device device = event.get_device();
158 if (device == null) { 160 if (device == null) {
159 var display = get_display(); 161 var display = get_display();
160 var device_manager = display.get_device_manager(); 162 var device_manager = display.get_device_manager();
161 /* The macro VALA_X_Y supports even numbers. 163 /* The macro VALA_X_Y supports even numbers.
162 * http://git.gnome.org/browse/vala/commit/?id=294b374af6 164 * http://git.gnome.org/browse/vala/commit/?id=294b374af6
163 */ 165 */
164 #if VALA_0_16 166 #if VALA_0_16
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 257 }
256 258
257 m_engines = engines; 259 m_engines = engines;
258 int max_label_width = 0; 260 int max_label_width = 0;
259 261
260 for (int i = 0; i < m_engines.length; i++) { 262 for (int i = 0; i < m_engines.length; i++) {
261 var index = i; 263 var index = i;
262 var engine = m_engines[i]; 264 var engine = m_engines[i];
263 var button = new IBusEngineButton(engine, this); 265 var button = new IBusEngineButton(engine, this);
264 var longname = engine.get_longname(); 266 var longname = engine.get_longname();
267 var textdomain = engine.get_textdomain();
268 var transname = GLib.dgettext(textdomain, longname);
265 button.set_relief(Gtk.ReliefStyle.NONE); 269 button.set_relief(Gtk.ReliefStyle.NONE);
266 button.show(); 270 button.show();
267 271
268 button.enter_notify_event.connect((e) => { 272 button.enter_notify_event.connect((e) => {
269 button.grab_focus(); 273 button.grab_focus();
270 m_selected_engine = index; 274 m_selected_engine = index;
271 return true; 275 return true;
272 }); 276 });
273 277
274 button.button_press_event.connect((e) => { 278 button.button_press_event.connect((e) => {
275 m_selected_engine = index; 279 m_selected_engine = index;
276 m_result = (int)m_selected_engine; 280 m_result = (int)m_selected_engine;
277 m_loop.quit(); 281 m_loop.quit();
278 return true; 282 return true;
279 }); 283 });
280 284
281 button.longname = longname; 285 button.transname = transname;
282 m_label.set_label(longname); 286 m_label.set_label(transname);
283 287
284 int width; 288 int width;
285 m_label.get_preferred_width(null, out width); 289 m_label.get_preferred_width(null, out width);
286 max_label_width = int.max(max_label_width, width); 290 max_label_width = int.max(max_label_width, width);
287 291
288 m_box.pack_start(button, true, true); 292 m_box.pack_start(button, true, true);
289 m_buttons += button; 293 m_buttons += button;
290 } 294 }
291 295
292 m_label.set_text(m_buttons[0].longname); 296 m_label.set_text(m_buttons[0].transname);
293 m_label.set_ellipsize(Pango.EllipsizeMode.END); 297 m_label.set_ellipsize(Pango.EllipsizeMode.END);
294 298
295 Gdk.Display display = Gdk.Display.get_default(); 299 Gdk.Display display = Gdk.Display.get_default();
296 Gdk.Screen screen = (display != null) ? 300 Gdk.Screen screen = (display != null) ?
297 display.get_default_screen() : null; 301 display.get_default_screen() : null;
298 int screen_width = 0; 302 int screen_width = 0;
299 303
300 if (screen != null) { 304 if (screen != null) {
301 screen_width = screen.get_width(); 305 screen_width = screen.get_width();
302 } 306 }
303 307
304 if (screen_width > 0 && max_label_width > (screen_width / 4)) { 308 if (screen_width > 0 && max_label_width > (screen_width / 4)) {
305 max_label_width = screen_width / 4; 309 max_label_width = screen_width / 4;
306 } 310 }
307 311
308 /* add random padding */ 312 /* add random padding */
309 max_label_width += 20; 313 max_label_width += 20;
310 set_default_size(max_label_width, -1); 314 set_default_size(max_label_width, -1);
311 } 315 }
312 316
313 private void next_engine() { 317 private void next_engine() {
314 if (m_selected_engine == m_engines.length - 1) 318 if (m_selected_engine == m_engines.length - 1)
315 m_selected_engine = 0; 319 m_selected_engine = 0;
316 else 320 else
317 m_selected_engine ++; 321 m_selected_engine ++;
318 m_label.set_text(m_buttons[m_selected_engine].longname); 322 m_label.set_text(m_buttons[m_selected_engine].transname);
319 set_focus(m_buttons[m_selected_engine]); 323 set_focus(m_buttons[m_selected_engine]);
320 } 324 }
321 325
322 private void previous_engine() { 326 private void previous_engine() {
323 if (m_selected_engine == 0) 327 if (m_selected_engine == 0)
324 m_selected_engine = m_engines.length - 1; 328 m_selected_engine = m_engines.length - 1;
325 else 329 else
326 m_selected_engine --; 330 m_selected_engine --;
327 m_label.set_text(m_buttons[m_selected_engine].longname); 331 m_label.set_text(m_buttons[m_selected_engine].transname);
328 set_focus(m_buttons[m_selected_engine]); 332 set_focus(m_buttons[m_selected_engine]);
329 } 333 }
330 334
331 private void restore_window_position(string debug_str) { 335 private void restore_window_position(string debug_str) {
332 debug("restore_window_position %s: (%ld, %ld)\n", 336 debug("restore_window_position %s: (%ld, %ld)\n",
333 debug_str, m_root_x, m_root_y); 337 debug_str, m_root_x, m_root_y);
334 338
335 if (m_popup_delay_time_id == 0) { 339 if (m_popup_delay_time_id == 0) {
336 return; 340 return;
337 } 341 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 public IBus.EngineDesc? get_selected_engine() { 485 public IBus.EngineDesc? get_selected_engine() {
482 return m_result_engine; 486 return m_result_engine;
483 } 487 }
484 488
485 public void reset() { 489 public void reset() {
486 m_input_context_path = ""; 490 m_input_context_path = "";
487 m_result = -1; 491 m_result = -1;
488 m_result_engine = null; 492 m_result_engine = null;
489 } 493 }
490 } 494 }
OLDNEW
« no previous file with comments | « ui/gtk3/panel.vala ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b