Skip to content

Commit

Permalink
First steps of Guake#71 implemented
Browse files Browse the repository at this point in the history
Split terminal functionality implemented
  • Loading branch information
bwrsandman committed Mar 22, 2014
1 parent 308d0a1 commit 67fb092
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 4 deletions.
36 changes: 36 additions & 0 deletions data/guake.glade
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,42 @@
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="context_hsplit_terminal">
<property name="label" translatable="yes">Split Horizontally</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">False</property>
<signal name="activate" handler="hsplit_terminal" swapped="no"/>
<child internal-child="image">
<widget class="GtkImage" id="hsplit_terminal_icon">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-hsplit</property>
<property name="icon-size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="context_vsplit_terminal">
<property name="label" translatable="yes">Split Vertically</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">False</property>
<signal name="activate" handler="vsplit_terminal" swapped="no"/>
<child internal-child="image">
<widget class="GtkImage" id="vsplit_terminal_icon">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-vsplit</property>
<property name="icon-size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="context_close_tab">
<property name="label" translatable="yes">Close Tab</property>
Expand Down
24 changes: 24 additions & 0 deletions data/guake.schemas
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,30 @@
</locale>
</schema>

<schema>
<key>/schemas/apps/guake/keybindings/local/hsplit_terminal</key>
<applyto>/apps/guake/keybindings/local/hsplit_terminal</applyto>
<owner>guake</owner>
<type>string</type>
<default>&lt;Control&gt;&lt;Shift&gt;o</default>
<locale name="C">
<short>Split terminal horizontally.</short>
<long>Calls the function to split a terminal horizontally in guake tab.</long>
</locale>
</schema>

<schema>
<key>/schemas/apps/guake/keybindings/local/vsplit_terminal</key>
<applyto>/apps/guake/keybindings/local/vsplit_terminal</applyto>
<owner>guake</owner>
<type>string</type>
<default>&lt;Control&gt;&lt;Shift&gt;e</default>
<locale name="C">
<short>Split terminal vertically.</short>
<long>Calls the function to split a terminal vertically in guake tab.</long>
</locale>
</schema>

<schema>
<key>/schemas/apps/guake/keybindings/local/close_tab</key>
<applyto>/apps/guake/keybindings/local/close_tab</applyto>
Expand Down
67 changes: 63 additions & 4 deletions src/guake
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ class GConfKeyHandler(object):
notify_add = self.client.notify_add
notify_add(GKEY('show_hide'), self.reload_globals)

keys = ['toggle_fullscreen', 'new_tab', 'close_tab', 'rename_current_tab',
keys = ['toggle_fullscreen', 'new_tab', 'hsplit_terminal', 'vsplit_terminal',
'close_tab', 'rename_current_tab',
'previous_tab', 'next_tab', 'clipboard_copy', 'clipboard_paste',
'quit', 'zoom_in', 'zoom_out', "search_on_web",
'switch_tab1', 'switch_tab2', 'switch_tab3', 'switch_tab4', 'switch_tab5',
Expand Down Expand Up @@ -439,6 +440,16 @@ class GConfKeyHandler(object):
self.accel_group.connect_group(key, mask, gtk.ACCEL_VISIBLE,
self.guake.accel_add)

key, mask = gtk.accelerator_parse(gets('hsplit_terminal'))
if key > 0:
self.accel_group.connect_group(key, mask, gtk.ACCEL_VISIBLE,
self.guake.accel_hsplit)

key, mask = gtk.accelerator_parse(gets('vsplit_terminal'))
if key > 0:
self.accel_group.connect_group(key, mask, gtk.ACCEL_VISIBLE,
self.guake.accel_vsplit)

key, mask = gtk.accelerator_parse(gets('close_tab'))
if key > 0:
self.accel_group.connect_group(
Expand Down Expand Up @@ -1205,6 +1216,18 @@ class Guake(SimpleGladeApp):
self.add_tab()
return True

def accel_hsplit(self, *args):
"""Callback to split a terminal horizontally. Called by the accel key.
"""
self.hsplit_terminal()
return True

def accel_vsplit(self, *args):
"""Callback to split a terminal horizontally. Called by the accel key.
"""
self.vsplit_terminal()
return True

def accel_prev(self, *args):
"""Callback to go to the previous tab. Called by the accel key.
"""
Expand Down Expand Up @@ -1521,9 +1544,7 @@ class Guake(SimpleGladeApp):
os.environ['https_proxy'] = 'http://%s:%d' % (
ssl_host, ssl_port)

def add_tab(self, directory=None):
"""Adds a new tab to the terminal notebook.
"""
def add_terminal(self, directory=None):
box = GuakeTerminalBox()
box.terminal.grab_focus()
box.terminal.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
Expand Down Expand Up @@ -1561,7 +1582,12 @@ class Guake(SimpleGladeApp):
pid = box.terminal.fork_command(**final_params)
box.terminal.pid = pid
self.pid_list.append(pid)
return box

def add_tab(self, directory=None):
"""Adds a new tab to the terminal notebook.
"""
box = self.add_terminal(directory)
# Adding a new radio button to the tabbar
label = box.terminal.get_window_title() or _("Terminal")
tabs = self.tabs.get_children()
Expand Down Expand Up @@ -1595,6 +1621,39 @@ class Guake(SimpleGladeApp):
if self.is_fullscreen :
self.fullscreen()

def split_terminal(self, horizontal=True, directory=None):
terminal = self.window.focus_widget

terminal_box = terminal.parent
parent_widget = terminal_box.parent
frame = gtk.HPaned() if horizontal else gtk.VPaned()
frame.show()
height = parent_widget.allocation.height
width = parent_widget.allocation.width
parent_widget.remove(terminal_box)

new_terminal_box = self.add_terminal(directory)
self.load_config()

if horizontal:
width //= 2
else:
height //= 2
terminal_box.set_size_request(width, height)
new_terminal_box.set_size_request(width, height)

frame.add(terminal_box)
frame.add(new_terminal_box)

parent_widget.add(frame)
new_terminal_box.terminal.grab_focus()

def hsplit_terminal(self, directory=None):
self.split_terminal(True, directory)

def vsplit_terminal(self, directory=None):
self.split_terminal(False, directory)

def on_drag_tab(self, widget, context, selection, targetType, eventTime):
tab_pos = self.tabs.get_children().index(widget)
selection.set(selection.target, 32, str(tab_pos))
Expand Down
4 changes: 4 additions & 0 deletions src/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
{'label': 'Tab management',
'keys': [{'key': LKEY('new_tab'),
'label': 'New tab'},
{'key': LKEY('hsplit_terminal'),
'label': 'Split terminal horizontally'},
{'key': LKEY('vsplit_terminal'),
'label': 'Split terminal vertically'},
{'key': LKEY('close_tab'),
'label': 'Close tab'},
{'key': LKEY('rename_current_tab'),
Expand Down

0 comments on commit 67fb092

Please sign in to comment.