Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tab width to be set via "Edit -> Preferences -> Advanced". #59

Merged
merged 8 commits into from
Dec 3, 2021
41 changes: 40 additions & 1 deletion data/lxterminal-preferences.glade
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
<property name="step_increment">10</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="tab_width_adjustment">
<property name="upper">1000</property>
<property name="value">100</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkListStore" id="values_color_presets">
<columns>
<!-- column-name gchararray1 -->
Expand Down Expand Up @@ -953,7 +959,7 @@
<object class="GtkTable" id="table_advanced">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">3</property>
<property name="n_rows">5</property>
<property name="n_columns">2</property>
<property name="column_spacing">5</property>
<property name="row_spacing">3</property>
Expand Down Expand Up @@ -1052,6 +1058,19 @@
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label_tab_width">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Tab width</property>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="select_by_word">
<property name="visible">True</property>
Expand All @@ -1068,6 +1087,26 @@
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="tab_width">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
<property name="width_chars">4</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<property name="adjustment">tab_width_adjustment</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
Expand Down
4 changes: 3 additions & 1 deletion src/lxterminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,8 @@ static void terminal_settings_apply_to_term(LXTerminal * terminal, Term * term)
/* Create a new terminal. */
static Term * terminal_new(LXTerminal * terminal, const gchar * label, const gchar * pwd, gchar * * env, gchar * * exec)
{
Setting * setting = get_setting();

/* Create and initialize Term structure for new terminal. */
Term * term = g_slice_new0(Term);
term->parent = terminal;
Expand Down Expand Up @@ -1302,7 +1304,7 @@ static Term * terminal_new(LXTerminal * terminal, const gchar * label, const gch
term->user_specified_label = FALSE;
}
term->label = gtk_label_new((label != NULL) ? label : vte_terminal_get_window_title(VTE_TERMINAL(term->vte)));
gtk_widget_set_size_request(GTK_WIDGET(term->label), 100, -1);
gtk_widget_set_size_request(GTK_WIDGET(term->label), setting->tab_width, -1);
gtk_label_set_ellipsize(GTK_LABEL(term->label), PANGO_ELLIPSIZE_END);
#if GTK_CHECK_VERSION(3, 0, 0)
gtk_widget_set_valign(term->label, GTK_ALIGN_CENTER);
Expand Down
5 changes: 5 additions & 0 deletions src/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ void terminal_preferences_dialog(GtkAction * action, LXTerminal * terminal)
g_signal_connect(G_OBJECT(w), "toggled",
G_CALLBACK(preferences_dialog_generic_toggled_event), &setting->disable_confirm);

w = GTK_WIDGET(gtk_builder_get_object(builder, "tab_width"));
gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), setting->tab_width);
g_signal_connect(G_OBJECT(w), "value-changed",
G_CALLBACK(preferences_dialog_int_value_changed_event), &setting->tab_width);

/* Shortcuts */
#define PREF_SETUP_SHORTCUT(OBJ, VAR) \
w = GTK_WIDGET(gtk_builder_get_object(builder, OBJ)); \
Expand Down
9 changes: 8 additions & 1 deletion src/setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ void print_setting()
printf("Disable F10: %i\n", setting->disable_f10);
printf("Disable Alt: %i\n", setting->disable_alt);
printf("Disable Confirm: %i\n", setting->disable_confirm);
printf("Tab width: %i\n", setting->tab_width);
printf("Geometry change: %i\n", setting->geometry_change);

/* Shortcut group settings. */
Expand All @@ -150,7 +151,7 @@ void print_setting()
printf("MOVE_TAB_LEFT_ACCEL: %s\n", setting->move_tab_left_accel);
printf("MOVE_TAB_RIGHT_ACCEL: %s\n", setting->move_tab_right_accel);
}
#endif
#endif /* 0 */

Setting * get_setting()
{
Expand Down Expand Up @@ -226,6 +227,7 @@ void save_setting()
g_key_file_set_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_F10, setting->disable_f10);
g_key_file_set_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_ALT, setting->disable_alt);
g_key_file_set_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_CONFIRM, setting->disable_confirm);
g_key_file_set_integer(setting->keyfile, GENERAL_GROUP, TAB_WIDTH, setting->tab_width);

/* Shortcut group settings. */
g_key_file_set_string(setting->keyfile, SHORTCUT_GROUP, NEW_WINDOW_ACCEL, setting->new_window_accel);
Expand Down Expand Up @@ -449,6 +451,11 @@ Setting * load_setting()
setting->disable_f10 = g_key_file_get_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_F10, NULL);
setting->disable_alt = g_key_file_get_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_ALT, NULL);
setting->disable_confirm = g_key_file_get_boolean(setting->keyfile, GENERAL_GROUP, DISABLE_CONFIRM, NULL);
g_clear_error(&error);
setting->tab_width = g_key_file_get_integer(setting->keyfile, GENERAL_GROUP, TAB_WIDTH, &error);
if (error && (error->code == G_KEY_FILE_ERROR_KEY_NOT_FOUND)) {
setting->tab_width = 100;
}

/* Shortcut group settings. */
setting->new_window_accel = g_key_file_get_string(setting->keyfile, SHORTCUT_GROUP, NEW_WINDOW_ACCEL, NULL);
Expand Down
2 changes: 2 additions & 0 deletions src/setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define DISABLE_F10 "disablef10"
#define DISABLE_ALT "disablealt"
#define DISABLE_CONFIRM "disableconfirm"
#define TAB_WIDTH "tabwidth"
#define PALETTE_COLOR_PREFIX "palette_color_"
#define COLOR_PRESET "color_preset"

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

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

Expand Down