Merge lp:~jcheun93/pantheon-terminal/fix-1169006 into lp:~elementary-apps/pantheon-terminal/trunk

Proposed by Jesse Cheun
Status: Rejected
Rejected by: Danielle Foré
Proposed branch: lp:~jcheun93/pantheon-terminal/fix-1169006
Merge into: lp:~elementary-apps/pantheon-terminal/trunk
Diff against target: 412 lines (+333/-5)
4 files modified
CMakeLists.txt (+2/-1)
src/PantheonTerminal.vala (+2/-2)
src/PantheonTerminalWindow.vala (+11/-2)
src/PreferencesDialog.vala (+318/-0)
To merge this branch: bzr merge lp:~jcheun93/pantheon-terminal/fix-1169006
Reviewer Review Type Date Requested Status
Danielle Foré Disapprove
Review via email: mp+225108@code.launchpad.net

Description of the change

Add Preferences Dialog to Terminal. Change basic settings like tab behaviors, font, theme etc. Right click terminal widget and select preference to access.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Sorry Jesse. We don't want to add a prefs UI to Terminal

review: Disapprove

Unmerged revisions

581. By Jesse Cheun

Add Preferences Dialog to Terminal. Right Click terminal widget to access.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-05-29 10:10:46 +0000
3+++ CMakeLists.txt 2014-07-01 03:53:45 +0000
4@@ -63,6 +63,7 @@
5 src/TerminalWidget.vala
6 src/ForegroundProcessDialog.vala
7 src/Constants.vala
8+ src/PreferencesDialog.vala
9 PACKAGES
10 vte-2.90
11 granite
12@@ -89,4 +90,4 @@
13
14 install (TARGETS pantheon-terminal RUNTIME DESTINATION bin)
15 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/pantheon-terminal.desktop DESTINATION share/applications)
16-install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/open-pantheon-terminal-here.desktop DESTINATION share/applications)
17+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/open-pantheon-terminal-here.desktop DESTINATION share/applications)
18\ No newline at end of file
19
20=== modified file 'src/PantheonTerminal.vala'
21--- src/PantheonTerminal.vala 2014-05-29 10:10:46 +0000
22+++ src/PantheonTerminal.vala 2014-07-01 03:53:45 +0000
23@@ -22,7 +22,7 @@
24
25 public class PantheonTerminalApp : Granite.Application {
26
27- private GLib.List <PantheonTerminalWindow> windows;
28+ public GLib.List <PantheonTerminalWindow> windows;
29
30 private static string app_cmd_name;
31 public static string? working_directory = null;
32@@ -194,4 +194,4 @@
33 return app.run (args_primary_instance);
34 }
35 }
36-} // Namespace
37+} // Namespace
38\ No newline at end of file
39
40=== modified file 'src/PantheonTerminalWindow.vala'
41--- src/PantheonTerminalWindow.vala 2014-04-22 19:32:46 +0000
42+++ src/PantheonTerminalWindow.vala 2014-07-01 03:53:45 +0000
43@@ -32,7 +32,7 @@
44 Pango.FontDescription term_font;
45 private Gtk.Clipboard clipboard;
46
47- private GLib.List <TerminalWidget> terminals = new GLib.List <TerminalWidget> ();
48+ public GLib.List <TerminalWidget> terminals = new GLib.List <TerminalWidget> ();
49 private HashTable<string, TerminalWidget> restorable_terminals;
50 private int restorable_counter = 0;
51
52@@ -65,6 +65,7 @@
53 <menuitem name="Paste" action="Paste"/>
54 <menuitem name="Select All" action="Select All"/>
55 <separator />
56+ <menuitem name="Preference" action="Preference"/>
57 <menuitem name="About" action="About"/>
58 </popup>
59 </ui>
60@@ -589,6 +590,11 @@
61 new_tab ();
62 }
63
64+ void action_preferences () {
65+ var dialog = new PantheonTerminal.Dialogs.Preferences (this);
66+ dialog.show_all ();
67+ }
68+
69 void action_about () {
70 app.show_about (this);
71 }
72@@ -647,6 +653,9 @@
73 { "Select All", "gtk-select-all",
74 N_("Select All"), "<Control><Shift>a",
75 N_("Select all the text in the terminal"), action_select_all },
76+
77+ { "Preference", Gtk.Stock.PREFERENCES, N_("Preference"),
78+ null, N_("Show about window"), action_preferences },
79
80 { "About", "gtk-about", N_("About"),
81 null, N_("Show about window"), action_about },
82@@ -672,4 +681,4 @@
83 action_fullscreen }
84 };
85 }
86-}
87+}
88\ No newline at end of file
89
90=== added file 'src/PreferencesDialog.vala'
91--- src/PreferencesDialog.vala 1970-01-01 00:00:00 +0000
92+++ src/PreferencesDialog.vala 2014-07-01 03:53:45 +0000
93@@ -0,0 +1,318 @@
94+// Based off of Versable elementary-tweaks terminal tweaks
95+// https://launchpad.net/elementary-community/elementary-tweaks
96+
97+using Gtk;
98+using Granite.Widgets;
99+
100+struct TerminalTheme
101+{
102+ public TerminalTheme (string _name, string _cursor, string fg, string bg, string _palette) {
103+ name = _name;
104+ cursor = _cursor;
105+ foreground = fg;
106+ background = bg;
107+ palette = _palette;
108+ }
109+ string name;
110+ string cursor;
111+ string foreground;
112+ string background;
113+ string palette;
114+}
115+
116+const TerminalTheme[] DEFAULT_THEMES = {
117+ {
118+ "Default",
119+ "#839496",
120+ "#94a3a5",
121+ "#252e32",
122+ "#073642:#dc322f:#859900:#b58900:#268bd2:#ec0048:#2aa198:#94a3a5:#586e75:#cb4b16:#859900:#b58900:#268bd2:#d33682:#2aa198:#6c71c4"
123+ },
124+ {
125+ "Solarized Dark",
126+ "#0f0f49499999",
127+ "#838394949696",
128+ "#00002B2B3636",
129+ "#070736364242:#DCDC32322F2F:#858599990000:#B5B589890000:#26268B8BD2D2:#D3D336368282:#2A2AA1A19898:#EEEEE8E8D5D5:#00002B2B3636:#CBCB4B4B1616:#58586E6E7575:#65657B7B8383:#838394949696:#6C6C7171C4C4:#9393A1A1A1A1:#FDFDF6F6E3E3"
130+ },
131+ {
132+ "Solarized Light",
133+ "#9393a1a1a1a1",
134+ "#00002B2B3636",
135+ "#fdfdf6f6e3e3",
136+ "#070736364242:#dcdc32322f2f:#858599990000:#b5b589890000:#26268ae0d2d2:#d3d336368282:#2a2aa1a19898:#eeeee8e8d5d5:#00002b2b3636:#cbcb4b4b1616:#65657bfb8383:#58586e6e7575:#9393a1a1a1a1:#6c6c7171c4c4:#838394949696:#fdfdf6f6e3e3"
137+ },
138+ { "Jelly Bean",
139+ "#d7d7d7",
140+ "#d7d7d7",
141+ "#121212",
142+ "#393939:#ca674a:#96a967:#d3a94a:#5778c1:#9c35ac:#6eb5f3:#a9a9a9:#535551:#ea2828:#87dd32:#f7e44d:#6f9bca:#a97ca4:#32dddd:#e9e9e7"
143+ },
144+};
145+
146+
147+namespace PantheonTerminal.Dialogs {
148+ public class Preferences : Gtk.Dialog {
149+ public Preferences (PantheonTerminalWindow window) {
150+ // Set window properties
151+ set_title (_("Preferences"));
152+ //set_transient_for (window);
153+ set_position (WindowPosition.CENTER);
154+ set_type_hint (Gdk.WindowTypeHint.DIALOG);
155+ set_size_request (630, 330);
156+ set_resizable (false);
157+
158+ response.connect ((response_id) => {
159+ if (response_id == Gtk.ResponseType.CLOSE)
160+ destroy();
161+ });
162+ add_button ("_Close", Gtk.ResponseType.CLOSE);
163+
164+ var content_area = get_content_area ();
165+
166+ var content = new Grid ();
167+ content.column_spacing = 5;
168+ content.row_spacing = 5;
169+ content.margin_left = 15;
170+ content.margin_right = 15;
171+ content.margin_top = 15;
172+ content.margin_bottom = 10;
173+ content.row_homogeneous = true;
174+ int row = 0;
175+
176+ add_section (content, new Label (_("General:")), ref row);
177+
178+ /* Set tab bar behavior */
179+ var behavior_label = new Label(_("Tab behavior:"));
180+ var behavior_cbox = new ComboBoxText ();
181+ behavior_cbox.width_request = 250;
182+ behavior_cbox.append ("Always Show Tabs", _("Always Show Tabs"));
183+ behavior_cbox.append ("Hide When Single Tab", _("Hide When Single Tab"));
184+ behavior_cbox.append ("Never Show Tabs", _("Never Show Tabs"));
185+ behavior_cbox.active = settings.tab_bar_behavior;
186+ behavior_cbox.changed.connect(() => {
187+ settings.tab_bar_behavior = (DynamicNotebook.TabBarBehavior)behavior_cbox.get_active();
188+ window.app.windows.foreach ((app) => {
189+ app.notebook.tab_bar_behavior = settings.tab_bar_behavior;
190+ });
191+ });
192+ add_option (content, behavior_label, behavior_cbox, ref row);
193+
194+ /* Set allow bold */
195+ var bold_label = new Label(_("Allow bold fonts:"));
196+ var bold_switch = new Switch();
197+ settings.schema.bind ("allow-bold", bold_switch, "active", SettingsBindFlags.DEFAULT);
198+ add_option (content, bold_label, bold_switch, ref row);
199+
200+ /* Set audible bell */
201+ var bell_label = new Label(_("Enable terminal bell:"));
202+ var bell_switch = new Switch();
203+ settings.schema.bind ("audible-bell", bell_switch, "active", SettingsBindFlags.DEFAULT);
204+ add_option (content, bell_label, bell_switch, ref row);
205+
206+ /* Set follow last tab */
207+ var follow_label = new Label(_("Open last active tab path on new tab:"));
208+ var follow_switch = new Switch();
209+ settings.schema.bind ("follow-last-tab", follow_switch, "active", SettingsBindFlags.DEFAULT);
210+ add_option (content, follow_label, follow_switch, ref row);
211+
212+ /* Set remember tabs */
213+ var remember_label = new Label(_("Save open tabs:"));
214+ var remember_switch = new Switch();
215+ settings.schema.bind ("remember-tabs", remember_switch, "active", SettingsBindFlags.DEFAULT);
216+ add_option (content, remember_label, remember_switch, ref row);
217+
218+ /* Create theme ui */
219+ add_section (content, new Label (_("Appearence:")), ref row);
220+ theme_ui (content, window, ref row);
221+
222+ content_area.add (content);
223+ }
224+
225+ void theme_ui (Grid grid, PantheonTerminalWindow window, ref int row) {
226+ var theme_cbox = new ComboBoxText ();
227+ var palette_btns = create_palette (theme_cbox);
228+
229+ /* Select cursor type and color */
230+ var cursor_label = new Label(_("Cursor shape:"));
231+ var cursor_cbox = new ComboBoxText ();
232+ cursor_cbox.width_request = 250;
233+ cursor_cbox.append ("Block", _("Block"));
234+ cursor_cbox.append ("I-Beam", _("I-Beam"));
235+ cursor_cbox.append ("Underline", _("Underline"));
236+ cursor_cbox.active = settings.cursor_shape;
237+ cursor_cbox.changed.connect(() => {
238+ settings.cursor_shape = (Vte.TerminalCursorShape)cursor_cbox.get_active();
239+ });
240+ var cursor_color = new ColorButton ();
241+ cursor_color.color_set.connect(() => {
242+ if (settings.cursor_color != rgba_to_hex (cursor_color.rgba)) {
243+ settings.cursor_color = rgba_to_hex (cursor_color.rgba);
244+ theme_cbox.active = DEFAULT_THEMES.length;
245+ }
246+ });
247+ var cursor_box = new Box (Orientation.HORIZONTAL, 5);
248+ cursor_box.pack_start(cursor_cbox, false);
249+ cursor_box.pack_start(cursor_color, false);
250+ add_option (grid, cursor_label, cursor_box, ref row);
251+
252+ /* Select Font and color */
253+ var font_label = new Label (_("Custom Font:"));
254+
255+ var font_select = new FontButton ();
256+ font_select.font = settings.font;
257+ font_select.width_request = 250;
258+ font_select.font_set.connect(() => {
259+ settings.font = font_select.font_desc.to_string ();
260+ window.app.windows.foreach ((app) => {
261+ app.terminals.foreach((entry) => {
262+ entry.set_font (font_select.font_desc);
263+ });
264+ });
265+ });
266+ var fgcolor_btn = new ColorButton ();
267+ fgcolor_btn.color_set.connect(() => {
268+ if (settings.foreground != rgba_to_hex (fgcolor_btn.rgba)) {
269+ settings.foreground = rgba_to_hex (fgcolor_btn.rgba);
270+ theme_cbox.active = DEFAULT_THEMES.length;
271+ }
272+ });
273+
274+ var font_box = new Box (Orientation.HORIZONTAL, 5);
275+ font_box.pack_start(font_select, false);
276+ font_box.pack_start(fgcolor_btn, false);
277+
278+ add_option (grid, font_label, font_box, ref row);
279+
280+ /* Set opacity */
281+ var opacity_label = new Label(_("Opacity:"));
282+ var opacity_spin = new SpinButton.with_range ( 0, 100, 1);;
283+ settings.schema.bind ("opacity", opacity_spin, "value", SettingsBindFlags.DEFAULT);
284+ add_option (grid, opacity_label, opacity_spin, ref row);
285+
286+ /* Background color */
287+ var bgcolor_label = new Label(_("Background color:"));
288+ var bgcolor_btn = new ColorButton ();
289+ bgcolor_btn.color_set.connect(() => {
290+ if (settings.background != rgba_to_hex (bgcolor_btn.rgba)) {
291+ settings.background = rgba_to_hex (bgcolor_btn.rgba);
292+ theme_cbox.active = DEFAULT_THEMES.length;
293+ }
294+ });
295+ add_option (grid, bgcolor_label, bgcolor_btn, ref row);
296+
297+ /* Select theme */
298+ var theme_label = new Label(_("Theme:"));
299+ theme_cbox.width_request = 250;
300+ theme_cbox.active = DEFAULT_THEMES.length;
301+ for (int i = 0; i < DEFAULT_THEMES.length; ++ i) {
302+ theme_cbox.append (DEFAULT_THEMES[i].name, DEFAULT_THEMES[i].name);
303+ if (DEFAULT_THEMES[i].palette == settings.palette &&
304+ DEFAULT_THEMES[i].cursor == settings.cursor_color &&
305+ DEFAULT_THEMES[i].foreground == settings.foreground &&
306+ DEFAULT_THEMES[i].background == settings.background)
307+ theme_cbox.active = i;
308+ }
309+ theme_cbox.append ("Custom", "Custom");
310+ if (theme_cbox.active == -1)
311+ theme_cbox.active = DEFAULT_THEMES.length;
312+
313+ theme_cbox.changed.connect(() => {
314+ if (theme_cbox.active != DEFAULT_THEMES.length) {
315+ var i = theme_cbox.active;
316+ settings.palette = DEFAULT_THEMES[i].palette;
317+ settings.cursor_color = DEFAULT_THEMES[i].cursor;
318+ settings.foreground = DEFAULT_THEMES[i].foreground;
319+ settings.background = DEFAULT_THEMES[i].background;
320+ update_btn_color (bgcolor_btn, fgcolor_btn, cursor_color, palette_btns);
321+ }
322+ });
323+ add_option (grid, theme_label, theme_cbox, ref row);
324+
325+ /* Color palette */
326+ var palette = new Grid ();
327+ palette.column_spacing = 5;
328+ palette.row_spacing = 5;
329+ palette.row_homogeneous = true;
330+ for (int i = 0; i < 16; ++ i) {
331+ palette.attach (palette_btns[i], i - ((int)(i / 8) * 8), (i < 8) ? 0 : 1, 1, 1);
332+ }
333+ add_option (grid, new Label (_("")), palette, ref row, 2);
334+
335+ update_btn_color (bgcolor_btn, fgcolor_btn, cursor_color, palette_btns);
336+ }
337+
338+ /* Update all color button on theme change */
339+ void update_btn_color (ColorButton bg, ColorButton fg, ColorButton cursor, ColorButton[] palette){
340+ Gdk.RGBA color = {0};
341+ color.parse (settings.background);
342+ bg.rgba = color;
343+ color.parse (settings.foreground);
344+ fg.rgba = color;
345+ color.parse (settings.cursor_color);
346+ cursor.rgba = color;
347+ var sys_color = settings.palette.split(":");
348+ for (int index = 0; index < 16; ++ index) {
349+ color.parse (sys_color[index]);
350+ palette[index].rgba = color;
351+ }
352+ }
353+
354+
355+ /* Create an array of color button */
356+ ColorButton[] create_palette (ComboBoxText theme_cbox) {
357+ ColorButton[] color_btn = new ColorButton[16];
358+ for (int index = 0; index < 16; ++ index) {
359+ color_btn[index] = new ColorButton ();
360+ color_btn[index].color_set.connect(() => {
361+ if (settings.palette != palette_s (color_btn)) {
362+ settings.palette = palette_s (color_btn);
363+ theme_cbox.active = DEFAULT_THEMES.length;
364+ }
365+ });
366+ }
367+ return color_btn;
368+ }
369+
370+ /* Convert colorbuttons' color to a palette string */
371+ string palette_s (ColorButton[] palette) {
372+ var palette_s = new string[palette.length];
373+ for (int index = 0; index < palette.length; ++ index) {
374+ palette_s[index] = rgba_to_hex (palette[index].rgba);
375+ }
376+ return string.joinv (":", palette_s);
377+ }
378+
379+ /* Convert rgba color to hex string */
380+ string rgba_to_hex (Gdk.RGBA color) {
381+ return "#%02X%02X%02X".printf((int)(color.red * 255),
382+ (int)(color.green * 255),
383+ (int)(color.blue * 255));
384+ }
385+
386+ /* Helper functions for adding elements to grid */
387+ void add_section (Grid grid, Label label, ref int row) {
388+ label.set_markup ("<b>%s</b>".printf (label.get_text ()));
389+ label.halign = Align.START;
390+ grid.attach (label, 0, row, 1, 1);
391+ ++ row;
392+ }
393+
394+ void add_option (Grid grid, Label label, Widget widget, ref int row, int col = 1) {
395+ label.halign = Align.END;
396+ label.margin_left = 20;
397+ label.margin_bottom = (col > 1) ? 5 : 0;
398+ widget.halign = Align.FILL;
399+
400+ /* don't want it to be expanded */
401+ if (widget is Switch || widget is Entry ||
402+ widget is ColorButton || widget is ComboBoxText) {
403+ widget.halign = Align.START;
404+ }
405+
406+ grid.attach (label, 0, row, 1, 1);
407+ grid.attach_next_to (widget, label, PositionType.RIGHT, 3, col);
408+ ++ row;
409+ }
410+ }
411+}
412\ No newline at end of file

Subscribers

People subscribed via source and target branches