Skip to content

Commit

Permalink
Restore the action and shortcut to set a static title from the menus
Browse files Browse the repository at this point in the history
This reverts 9bbe19e with a minor
adjustment to the accelerator handling to keep up with later changes.

https://bugzilla.redhat.com/show_bug.cgi?id=1296110
  • Loading branch information
debarshiray committed Mar 28, 2018
1 parent b3d93a9 commit 62a2460
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ migrate_accels (GSettings *global_settings,
{ "zoom_in", "zoom-in" },
{ "zoom_out", "zoom-out" },
{ "zoom_normal", "zoom-normal" },
{ "set_window_title", "set-terminal-title" },
{ "reset", "reset" },
{ "reset_and_clear", "reset-and-clear" },
{ "prev_tab", "prev-tab" },
Expand Down
4 changes: 4 additions & 0 deletions src/org.gnome.Terminal.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@
<default>'disabled'</default>
<summary>Keyboard shortcut to toggle the read-only state</summary>
</key>
<key name="set-terminal-title" type="s">
<default>'disabled'</default>
<summary>Keyboard shortcut to set the terminal title</summary>
</key>
<key name="reset" type="s">
<default>'disabled'</default>
<summary>Keyboard shortcut to reset the terminal</summary>
Expand Down
3 changes: 3 additions & 0 deletions src/terminal-accels.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#define KEY_RESET "reset"
#define KEY_SAVE_CONTENTS "save-contents"
#define KEY_SELECT_ALL "select-all"
#define KEY_SET_TERMINAL_TITLE "set-terminal-title"
#define KEY_TOGGLE_MENUBAR "toggle-menubar"
#define KEY_ZOOM_IN "zoom-in"
#define KEY_ZOOM_NORMAL "zoom-normal"
Expand Down Expand Up @@ -107,6 +108,7 @@
#define ACCEL_PATH_KEY_RESET_AND_CLEAR ACCEL_PATH_ROOT "TerminalResetClear"
#define ACCEL_PATH_KEY_SAVE_CONTENTS ACCEL_PATH_ROOT "FileSaveContents"
#define ACCEL_PATH_KEY_SELECT_ALL ACCEL_PATH_ROOT "EditSelectAll"
#define ACCEL_PATH_KEY_SET_TERMINAL_TITLE ACCEL_PATH_ROOT "TerminalSetTitle"
#define ACCEL_PATH_KEY_TOGGLE_MENUBAR ACCEL_PATH_ROOT "ViewMenubar"
#define ACCEL_PATH_KEY_ZOOM_IN ACCEL_PATH_ROOT "ViewZoomIn"
#define ACCEL_PATH_KEY_ZOOM_NORMAL ACCEL_PATH_ROOT "ViewZoom100"
Expand Down Expand Up @@ -190,6 +192,7 @@ static KeyEntry terminal_entries[] = {
ENTRY (N_("Read-Only"), KEY_READ_ONLY, "read-only", NULL, NULL ),
ENTRY (N_("Reset"), KEY_RESET, "reset", "b", "false"),
ENTRY (N_("Reset and Clear"), KEY_RESET_AND_CLEAR, "reset", "b", "true" ),
ENTRY (N_("Set Title"), KEY_SET_TERMINAL_TITLE, "set-title", NULL, NULL ),
};

static KeyEntry tabs_entries[] = {
Expand Down
88 changes: 88 additions & 0 deletions src/terminal-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ static void view_zoom_out_callback (GtkAction *action,
TerminalWindow *window);
static void view_zoom_normal_callback (GtkAction *action,
TerminalWindow *window);
static void terminal_set_title_callback (GtkAction *action,
TerminalWindow *window);
static void terminal_add_encoding_callback (GtkAction *action,
TerminalWindow *window);
static void terminal_reset_callback (GtkAction *action,
Expand Down Expand Up @@ -733,6 +735,88 @@ action_move_tab_cb (GSimpleAction *action,
value);
}

static void
terminal_set_title_dialog_response_cb (GtkWidget *dialog,
int response,
TerminalScreen *screen)
{
if (response == GTK_RESPONSE_OK)
{
GtkEntry *entry;
const char *text;

entry = GTK_ENTRY (g_object_get_data (G_OBJECT (dialog), "title-entry"));
text = gtk_entry_get_text (entry);
terminal_screen_set_user_title (screen, text);
}

gtk_widget_destroy (dialog);
}

static void
action_set_title_cb (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
TerminalWindow *window = user_data;
TerminalWindowPrivate *priv = window->priv;
GtkWidget *dialog, *message_area, *hbox, *label, *entry;

if (priv->active_screen == NULL)
return;

/* FIXME: hook the screen up so this dialogue closes if the terminal screen closes */

dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_OTHER,
GTK_BUTTONS_OK_CANCEL,
"%s", "");

gtk_window_set_title (GTK_WINDOW (dialog), _("Set Title"));
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
gtk_window_set_role (GTK_WINDOW (dialog), "gnome-terminal-change-title");
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
/* Alternative button order was set automatically by GtkMessageDialog */

g_signal_connect (dialog, "response",
G_CALLBACK (terminal_set_title_dialog_response_cb), priv->active_screen);
g_signal_connect (dialog, "delete-event",
G_CALLBACK (terminal_util_dialog_response_on_delete), NULL);

message_area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog));
gtk_container_foreach (GTK_CONTAINER (message_area), (GtkCallback) gtk_widget_hide, NULL);

hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_box_pack_start (GTK_BOX (message_area), hbox, FALSE, FALSE, 0);

label = gtk_label_new_with_mnemonic (_("_Title:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);

entry = gtk_entry_new ();
gtk_entry_set_width_chars (GTK_ENTRY (entry), 32);
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
gtk_widget_show_all (hbox);

gtk_widget_grab_focus (entry);
gtk_entry_set_text (GTK_ENTRY (entry), terminal_screen_get_user_title (priv->active_screen));
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
g_object_set_data (G_OBJECT (dialog), "title-entry", entry);

gtk_window_present (GTK_WINDOW (dialog));
}

static void
terminal_set_title_callback (GtkAction *action,
TerminalWindow *window)
{
g_action_activate (g_action_map_lookup_action (G_ACTION_MAP (window), "set-title"),
NULL);
}

static void
action_zoom_cb (GSimpleAction *action,
GVariant *parameter,
Expand Down Expand Up @@ -2441,6 +2525,7 @@ terminal_window_init (TerminalWindow *window)
{ "reset", action_reset_cb, "b", NULL, NULL },
{ "switch-tab", action_switch_tab_cb, "i", NULL, NULL },
{ "move-tab", action_move_tab_cb, "i", NULL, NULL },
{ "set-title", action_set_title_cb, NULL, NULL, NULL },
{ "zoom", action_zoom_cb, "i", NULL, NULL },
{ "detach-tab", action_detach_tab_cb, NULL, NULL, NULL },
{ "find", action_find_cb, "s", NULL, NULL },
Expand Down Expand Up @@ -2544,6 +2629,9 @@ terminal_window_init (TerminalWindow *window)

/* Terminal menu */
{ "TerminalProfiles", NULL, N_("Change _Profile") },
{ "TerminalSetTitle", NULL, N_("_Set Title…"), NULL,
NULL,
G_CALLBACK (terminal_set_title_callback) },
{ "TerminalSetEncoding", NULL, N_("Set _Character Encoding") },
{ "TerminalReset", NULL, N_("_Reset"), NULL,
NULL,
Expand Down
2 changes: 2 additions & 0 deletions src/terminal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
</menu>
<menu action="Terminal">
<menu action="TerminalProfiles" />
<menuitem action="TerminalSetTitle" />
<menu action="TerminalSetEncoding" >
<placeholder name="EncodingsPH" />
<separator />
Expand Down Expand Up @@ -111,6 +112,7 @@
<menuitem action="TabsMoveRight"/>
<separator />
<menuitem action="TabsDetach"/>
<menuitem action="TerminalSetTitle" />
<separator />
<menuitem action="FileCloseTab"/>
</popup>
Expand Down

0 comments on commit 62a2460

Please sign in to comment.