Merge lp:~jeremywootten/pantheon-terminal/fix-1621637-same-tab-name-in-terminal into lp:~elementary-apps/pantheon-terminal/trunk

Proposed by Jeremy Wootten
Status: Needs review
Proposed branch: lp:~jeremywootten/pantheon-terminal/fix-1621637-same-tab-name-in-terminal
Merge into: lp:~elementary-apps/pantheon-terminal/trunk
Diff against target: 116 lines (+73/-8)
2 files modified
src/PantheonTerminalWindow.vala (+73/-1)
src/TerminalWidget.vala (+0/-7)
To merge this branch: bzr merge lp:~jeremywootten/pantheon-terminal/fix-1621637-same-tab-name-in-terminal
Reviewer Review Type Date Requested Status
Zisu Andrei Pending
Review via email: mp+316391@code.launchpad.net

This proposal supersedes a proposal from 2016-09-09.

Description of the change

Where two tabs are opened at different folders that have the same name, label the tabs in a way that distinguishes them.

In this branch, enough of the parent path needed to distinguish them is prepended to the tab-name.

However, because of the limited and fixed size of the tabs it is quite likely that the distinguishing parts of the name will not be visible on the tab and can only be seen in the tooltip displayed when the tab is hovered. It would be necessary to patch Granite.Widgets.DynamicNotebook to allow variable tab sizes to address this.

To post a comment you must log in.
Revision history for this message
Zisu Andrei (matzipan) wrote : Posted in a previous version of this proposal

Some comments inline.

Can you confirm this behavior isn't already present in trunk?

review: Needs Fixing
Revision history for this message
Rico Tzschichholz (ricotz) wrote : Posted in a previous version of this proposal

Assigning a string an owned variable already results in an implicit copy.
So "string name = t.window_title.dup ();" results in two copies are made.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Terminal has moved to GitHub, please resubmit at https://github.com/elementary/terminal

Unmerged revisions

896. By Jeremy Wootten

Merge trunk to r936

895. By Jeremy Wootten

Fix code style

894. By Jeremy Wootten

Deal with duplicate tab names with different paths

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/PantheonTerminalWindow.vala'
2--- src/PantheonTerminalWindow.vala 2017-01-23 18:01:21 +0000
3+++ src/PantheonTerminalWindow.vala 2017-02-04 18:40:59 +0000
4@@ -501,7 +501,7 @@
5 private void on_switch_page (Granite.Widgets.Tab? old,
6 Granite.Widgets.Tab new_tab) {
7 current_terminal = get_term_widget (new_tab);
8- title = current_terminal.window_title ?? "";
9+ title = current_terminal.tab.label ?? "";
10 new_tab.icon = null;
11 new_tab.page.grab_focus ();
12 }
13@@ -575,6 +575,14 @@
14 }
15 });
16
17+ t.window_title_changed.connect (() => {
18+ t.tab.label = check_for_tab_with_same_name (t);
19+
20+ if (t == this.current_terminal) {
21+ this.title = t.tab.label;
22+ }
23+ });
24+
25 t.set_font (term_font);
26
27 int minimum_width = t.calculate_width (80) / 2;
28@@ -782,6 +790,70 @@
29 return (TerminalWidget)((Gtk.Bin)tab.page).get_child ();
30 }
31
32+ private string check_for_tab_with_same_name (TerminalWidget t) {
33+ string name = t.window_title;
34+ string new_name = name;
35+ string? path = t.get_shell_location ();
36+
37+ foreach (Granite.Widgets.Tab tab in notebook.tabs) {
38+ var scrolled_window = (Gtk.ScrolledWindow)(tab.page);
39+ var content = (TerminalWidget)(scrolled_window.get_child ());
40+ if (content != t) {
41+ string? content_path = content.get_shell_location ();
42+ if (content.window_title == name && content_path != path) {
43+ if (content.window_title == content.tab.label) {
44+ Idle.add_full (GLib.Priority.LOW, () => {
45+ content.window_title_changed ();
46+ return false;
47+ }); /* Trigger relabelling of conflicting tab (but not before this function finishes) */
48+ }
49+ new_name = append_parent (name, path, content_path); /*Also relabel this tab */
50+ }
51+ }
52+ }
53+
54+ return new_name;
55+ }
56+
57+ private string append_parent (string name, string path, string conflict_path) {
58+ string sfx = "";
59+ string sfx2 = "";
60+ string p = path;
61+ string p2 = conflict_path;
62+
63+ /* Add parent directories until path and conflict path differ */
64+ while (sfx == sfx2) {
65+ var pp = get_parent_path_from_path (p);
66+ var pp2 = get_parent_path_from_path (p2);
67+ sfx = Path.get_basename (pp) + Path.DIR_SEPARATOR_S + sfx;
68+ sfx2 = Path.get_basename (pp2) + Path.DIR_SEPARATOR_S + sfx2;
69+ p = pp;
70+ p2 = pp2;
71+ }
72+
73+ return sfx + name;
74+ }
75+
76+ /*** Simplified version of PF.FileUtils function, with fewer checks ***/
77+ private string get_parent_path_from_path (string path) {
78+ if (path.length < 2) {
79+ return Path.DIR_SEPARATOR_S;
80+ }
81+
82+ StringBuilder sb = new StringBuilder (path);
83+ if (path.has_suffix (Path.DIR_SEPARATOR_S)) {
84+ sb.erase (sb.str.length - 1,-1);
85+ }
86+
87+ int last_separator = sb.str.last_index_of (Path.DIR_SEPARATOR_S);
88+ if (last_separator < 0) {
89+ last_separator = 0;
90+ }
91+
92+ sb.erase (last_separator, -1);
93+ return sb.str + Path.DIR_SEPARATOR_S;
94+ }
95+
96 static const Gtk.ActionEntry[] main_entries = {
97 { "CloseTab", "gtk-close", N_("Close"),
98 "<Control><Shift>w", N_("Close"),
99
100=== modified file 'src/TerminalWidget.vala'
101--- src/TerminalWidget.vala 2016-07-10 16:08:53 +0000
102+++ src/TerminalWidget.vala 2017-02-04 18:40:59 +0000
103@@ -139,13 +139,6 @@
104 window.main_actions.get_action ("Copy").set_sensitive (get_has_selection ());
105 });
106
107- window_title_changed.connect ((event) => {
108- if (this == window.current_terminal)
109- window.title = window_title;
110-
111- tab.label = window_title;
112- });
113-
114 child_exited.connect (on_child_exited);
115
116 /* target entries specify what kind of data the terminal widget accepts */

Subscribers

People subscribed via source and target branches