Skip to content

Commit 0febe16

Browse files
authored
Merge pull request #59 from davesp/add-tab-width-pref
Allow tab width to be set via "Edit -> Preferences -> Advanced".
2 parents fb2b727 + 0e285f3 commit 0febe16

File tree

5 files changed

+58
-3
lines changed

5 files changed

+58
-3
lines changed

data/lxterminal-preferences.glade

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
<property name="step_increment">10</property>
2121
<property name="page_increment">10</property>
2222
</object>
23+
<object class="GtkAdjustment" id="tab_width_adjustment">
24+
<property name="upper">1000</property>
25+
<property name="value">100</property>
26+
<property name="step_increment">1</property>
27+
<property name="page_increment">10</property>
28+
</object>
2329
<object class="GtkListStore" id="values_color_presets">
2430
<columns>
2531
<!-- column-name gchararray1 -->
@@ -953,7 +959,7 @@
953959
<object class="GtkTable" id="table_advanced">
954960
<property name="visible">True</property>
955961
<property name="can_focus">False</property>
956-
<property name="n_rows">3</property>
962+
<property name="n_rows">5</property>
957963
<property name="n_columns">2</property>
958964
<property name="column_spacing">5</property>
959965
<property name="row_spacing">3</property>
@@ -1052,6 +1058,19 @@
10521058
<property name="y_options">GTK_FILL</property>
10531059
</packing>
10541060
</child>
1061+
<child>
1062+
<object class="GtkLabel" id="label_tab_width">
1063+
<property name="visible">True</property>
1064+
<property name="can_focus">False</property>
1065+
<property name="xalign">1</property>
1066+
<property name="label" translatable="yes">Tab width</property>
1067+
</object>
1068+
<packing>
1069+
<property name="top_attach">4</property>
1070+
<property name="bottom_attach">5</property>
1071+
<property name="y_options">GTK_FILL</property>
1072+
</packing>
1073+
</child>
10551074
<child>
10561075
<object class="GtkEntry" id="select_by_word">
10571076
<property name="visible">True</property>
@@ -1068,6 +1087,26 @@
10681087
<property name="y_options">GTK_FILL</property>
10691088
</packing>
10701089
</child>
1090+
<child>
1091+
<object class="GtkSpinButton" id="tab_width">
1092+
<property name="visible">True</property>
1093+
<property name="can_focus">True</property>
1094+
<property name="invisible_char">•</property>
1095+
<property name="width_chars">4</property>
1096+
<property name="primary_icon_activatable">False</property>
1097+
<property name="secondary_icon_activatable">False</property>
1098+
<property name="primary_icon_sensitive">True</property>
1099+
<property name="secondary_icon_sensitive">True</property>
1100+
<property name="adjustment">tab_width_adjustment</property>
1101+
</object>
1102+
<packing>
1103+
<property name="left_attach">1</property>
1104+
<property name="right_attach">2</property>
1105+
<property name="top_attach">4</property>
1106+
<property name="bottom_attach">5</property>
1107+
<property name="y_options">GTK_FILL</property>
1108+
</packing>
1109+
</child>
10711110
</object>
10721111
<packing>
10731112
<property name="position">2</property>

src/lxterminal.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,8 @@ static void terminal_settings_apply_to_term(LXTerminal * terminal, Term * term)
11771177
/* Create a new terminal. */
11781178
static Term * terminal_new(LXTerminal * terminal, const gchar * label, const gchar * pwd, gchar * * env, gchar * * exec)
11791179
{
1180+
Setting * setting = get_setting();
1181+
11801182
/* Create and initialize Term structure for new terminal. */
11811183
Term * term = g_slice_new0(Term);
11821184
term->parent = terminal;
@@ -1302,7 +1304,7 @@ static Term * terminal_new(LXTerminal * terminal, const gchar * label, const gch
13021304
term->user_specified_label = FALSE;
13031305
}
13041306
term->label = gtk_label_new((label != NULL) ? label : vte_terminal_get_window_title(VTE_TERMINAL(term->vte)));
1305-
gtk_widget_set_size_request(GTK_WIDGET(term->label), 100, -1);
1307+
gtk_widget_set_size_request(GTK_WIDGET(term->label), setting->tab_width, -1);
13061308
gtk_label_set_ellipsize(GTK_LABEL(term->label), PANGO_ELLIPSIZE_END);
13071309
#if GTK_CHECK_VERSION(3, 0, 0)
13081310
gtk_widget_set_valign(term->label, GTK_ALIGN_CENTER);

src/preferences.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ void terminal_preferences_dialog(GtkAction * action, LXTerminal * terminal)
455455
g_signal_connect(G_OBJECT(w), "toggled",
456456
G_CALLBACK(preferences_dialog_generic_toggled_event), &setting->disable_confirm);
457457

458+
w = GTK_WIDGET(gtk_builder_get_object(builder, "tab_width"));
459+
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), setting->tab_width);
460+
g_signal_connect(G_OBJECT(w), "value-changed",
461+
G_CALLBACK(preferences_dialog_int_value_changed_event), &setting->tab_width);
462+
458463
/* Shortcuts */
459464
#define PREF_SETUP_SHORTCUT(OBJ, VAR) \
460465
w = GTK_WIDGET(gtk_builder_get_object(builder, OBJ)); \

src/setting.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void print_setting()
135135
printf("Disable F10: %i\n", setting->disable_f10);
136136
printf("Disable Alt: %i\n", setting->disable_alt);
137137
printf("Disable Confirm: %i\n", setting->disable_confirm);
138+
printf("Tab width: %i\n", setting->tab_width);
138139
printf("Geometry change: %i\n", setting->geometry_change);
139140

140141
/* Shortcut group settings. */
@@ -150,7 +151,7 @@ void print_setting()
150151
printf("MOVE_TAB_LEFT_ACCEL: %s\n", setting->move_tab_left_accel);
151152
printf("MOVE_TAB_RIGHT_ACCEL: %s\n", setting->move_tab_right_accel);
152153
}
153-
#endif
154+
#endif /* 0 */
154155

155156
Setting * get_setting()
156157
{
@@ -226,6 +227,7 @@ void save_setting()
226227
g_key_file_set_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_F10, setting->disable_f10);
227228
g_key_file_set_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_ALT, setting->disable_alt);
228229
g_key_file_set_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_CONFIRM, setting->disable_confirm);
230+
g_key_file_set_integer(setting->keyfile, GENERAL_GROUP, TAB_WIDTH, setting->tab_width);
229231

230232
/* Shortcut group settings. */
231233
g_key_file_set_string(setting->keyfile, SHORTCUT_GROUP, NEW_WINDOW_ACCEL, setting->new_window_accel);
@@ -449,6 +451,11 @@ Setting * load_setting()
449451
setting->disable_f10 = g_key_file_get_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_F10, NULL);
450452
setting->disable_alt = g_key_file_get_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_ALT, NULL);
451453
setting->disable_confirm = g_key_file_get_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_CONFIRM, NULL);
454+
g_clear_error(&error);
455+
setting->tab_width = g_key_file_get_integer(setting->keyfile, GENERAL_GROUP, TAB_WIDTH, &error);
456+
if (error && (error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
457+
setting->tab_width = 100;
458+
}
452459

453460
/* Shortcut group settings. */
454461
setting->new_window_accel = g_key_file_get_string(setting->keyfile, SHORTCUT_GROUP, NEW_WINDOW_ACCEL, NULL);

src/setting.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define DISABLE_F10 "disablef10"
4848
#define DISABLE_ALT "disablealt"
4949
#define DISABLE_CONFIRM "disableconfirm"
50+
#define TAB_WIDTH "tabwidth"
5051
#define PALETTE_COLOR_PREFIX "palette_color_"
5152
#define COLOR_PRESET "color_preset"
5253

@@ -117,6 +118,7 @@ typedef struct _setting {
117118
gboolean disable_f10; /* True if F10 will be passed to program; false if it brings up File menu */
118119
gboolean disable_alt; /* True if Alt-n is passed to shell; false if it is used to switch between tabs */
119120
gboolean disable_confirm; /* True if confirmation exit dialog shows before terminal window close*/
121+
gint tab_width; /* Tab width */
120122

121123
gboolean geometry_change; /* True if there is a geometry change, until it has been acted on */
122124

0 commit comments

Comments
 (0)