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

Add new hotkey to open new tab in same directory #2136

Merged
merged 1 commit into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion guake/data/org.guake.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,17 @@
<default>'&lt;Control&gt;&lt;Shift&gt;t'</default>
<summary>Add a new tab.</summary>
<description>Calls the function to add a new tab in guake window.</description>
</key>
</key>
<key name="new-tab-home" type="s">
<default>'&lt;Control&gt;&lt;Shift&gt;h'</default>
<summary>Add a new tab in home directory.</summary>
<description>Calls the function to add a new home directory tab in guake window.</description>
</key>
<key name="new-tab-cwd" type="s">
<default>'&lt;Super&gt;t'</default>
<summary>Add a new tab in current directory.</summary>
<description>Calls the function to add a new tab in guake window, in the same directory as the current tab.</description>
</key>
<key name="close-tab" type="s">
<default>'&lt;Control&gt;&lt;Shift&gt;w'</default>
<summary>Closes the current tab.</summary>
Expand Down
11 changes: 9 additions & 2 deletions guake/guake_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,11 @@ def accel_add_home(self, *args):
self.add_tab(os.environ["HOME"])
return True

def accel_add_cwd(self, *args):
"""Callback to add a new tab in current directory. Called by the accel key."""
self.add_tab(open_tab_cwd=True)
return True

def accel_prev(self, *args):
"""Callback to go to the previous tab. Called by the accel key."""
if self.get_notebook().get_current_page() == 0:
Expand Down Expand Up @@ -1231,12 +1236,14 @@ def terminal_spawned(self, notebook, terminal, pid):
terminal.directory = terminal.get_current_directory()

@save_tabs_when_changed
def add_tab(self, directory=None):
def add_tab(self, directory=None, open_tab_cwd=False):
"""Adds a new tab to the terminal notebook."""
position = None
if self.settings.general.get_boolean("new-tab-after"):
position = 1 + self.get_notebook().get_current_page()
self.get_notebook().new_page_with_focus(directory, position=position)
self.get_notebook().new_page_with_focus(
directory, position=position, open_tab_cwd=open_tab_cwd
)

def find_tab(self, directory=None):
log.debug("find")
Expand Down
1 change: 1 addition & 0 deletions guake/keybindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def x(*args):
("toggle-fullscreen", self.guake.accel_toggle_fullscreen),
("new-tab", self.guake.accel_add),
("new-tab-home", self.guake.accel_add_home),
("new-tab-cwd", self.guake.accel_add_cwd),
("close-tab", x),
("rename-current-tab", self.guake.accel_rename_current_tab),
("previous-tab", self.guake.accel_prev),
Expand Down
20 changes: 14 additions & 6 deletions guake/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ def delete_page_by_label(self, label, kill=True, prompt=0):
def delete_page_current(self, kill=True, prompt=0):
self.delete_page(self.get_current_page(), kill, prompt)

def new_page(self, directory=None, position=None, empty=False):
def new_page(self, directory=None, position=None, empty=False, open_tab_cwd=False):
terminal_box = TerminalBox()
if empty:
terminal = None
else:
terminal = self.terminal_spawn(directory)
terminal = self.terminal_spawn(directory, open_tab_cwd)
terminal_box.set_terminal(terminal)
root_terminal_box = RootTerminalBox(self.guake, self)
root_terminal_box.set_child(terminal_box)
Expand Down Expand Up @@ -379,7 +379,7 @@ def hide_tabbar_if_one_tab(self):
else:
self.set_property("show-tabs", True)

def terminal_spawn(self, directory=None):
def terminal_spawn(self, directory=None, open_tab_cwd=False):
terminal = GuakeTerminal(self.guake)
terminal.grab_focus()
terminal.connect(
Expand All @@ -389,7 +389,7 @@ def terminal_spawn(self, directory=None):
if not isinstance(directory, str):
directory = os.environ["HOME"]
try:
if self.guake.settings.general.get_boolean("open-tab-cwd"):
if self.guake.settings.general.get_boolean("open-tab-cwd") or open_tab_cwd:
# Do last focused terminal still alive?
active_terminal = self.get_current_terminal()
if not active_terminal:
Expand All @@ -410,9 +410,17 @@ def terminal_attached(self, terminal):
self.emit("terminal-spawned", terminal, terminal.pid)

def new_page_with_focus(
self, directory=None, label=None, user_set=False, position=None, empty=False
self,
directory=None,
label=None,
user_set=False,
position=None,
empty=False,
open_tab_cwd=False,
):
box, page_num, terminal = self.new_page(directory, position=position, empty=empty)
box, page_num, terminal = self.new_page(
directory, position=position, empty=empty, open_tab_cwd=open_tab_cwd
)
self.set_current_page(page_num)
if not label:
self.rename_page(page_num, self.guake.compute_tab_title(terminal), False)
Expand Down
1 change: 1 addition & 0 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"keys": [
{"key": "new-tab", "label": _("New tab")},
{"key": "new-tab-home", "label": _("New tab in home directory")},
{"key": "new-tab-cwd", "label": _("New tab in current directory")},
{"key": "close-tab", "label": _("Close tab")},
{"key": "rename-current-tab", "label": _("Rename current tab")},
],
Expand Down
3 changes: 3 additions & 0 deletions releasenotes/notes/new-tab-cwd-hotkey-0e9db9f37b994000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
features:
- |
- Add a new hotkey to open a new tab in the same directory as the current tab.