Skip to content

Commit

Permalink
Merge pull request #87 from ccordoba12/ui-fixes
Browse files Browse the repository at this point in the history
PR: Simplify new terminal actions
  • Loading branch information
ccordoba12 committed Jul 7, 2017
2 parents 1359922 + 0cf6de9 commit ef23f32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 42 deletions.
18 changes: 0 additions & 18 deletions CHANGELOG.temp

This file was deleted.

62 changes: 38 additions & 24 deletions spyder_terminal/terminalplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
from spyder.config.base import _
from spyder.utils import icon_manager as ima
from spyder.utils.programs import find_program
from spyder.utils.qthelpers import (create_action, create_toolbutton,
add_actions)
from spyder.utils.qthelpers import (add_actions, create_action,
create_toolbutton,
MENU_SEPARATOR)
from spyder.widgets.tabs import Tabs
# from spyder.config.gui import set_shortcut, config_shortcut
# from spyder.plugins import SpyderPluginWidget
Expand Down Expand Up @@ -110,7 +111,8 @@ def __init__(self, parent):
# self.shortcuts = self.create_shortcuts()
corner_widgets = {Qt.TopRightCorner: [new_term_btn, menu_btn]}
self.tabwidget = Tabs(self, menu=self.menu, actions=self.menu_actions,
corner_widgets=corner_widgets)
corner_widgets=corner_widgets, rename_tabs=True)

if hasattr(self.tabwidget, 'setDocumentMode') \
and not sys.platform == 'darwin':
# Don't set document mode to true on OSX because it generates
Expand Down Expand Up @@ -174,10 +176,10 @@ def check_compatibility(self):
message = ''
valid = True
if PYQT4 or PYSIDE:
message = 'This plugin does not work with Qt 4'
message = _('This plugin does not work with Qt 4')
valid = False
elif WINDOWS and PY2:
message = 'This plugin does not work with Python 2 on Windows'
message = _('This plugin does not work with Python 2 on Windows')
valid = False
return valid, message

Expand All @@ -193,44 +195,50 @@ def get_plugin_icon(self):

def get_plugin_actions(self):
"""Get plugin actions."""
new_terminal_menu = QMenu(_("Create new terminal"), self)
new_terminal_menu.setIcon(ima.icon('project_expanded'))
new_terminal_cwd = create_action(self,
_("Current workspace path"),
icon=ima.icon('cmdprompt'),
_("New terminal in current "
"working directory"),
tip=_("Sets the pwd at "
"the current workspace "
"folder"),
"the current working "
"directory"),
triggered=self.create_new_term)

self.new_terminal_project = create_action(self,
_("Current project folder"),
icon=ima.icon('cmdprompt'),
_("New terminal in current "
"project"),
tip=_("Sets the pwd at "
"the current project "
"folder"),
"directory"),
triggered=lambda:
self.create_new_term(
path=self.project_path))

if self.project_path is None:
self.new_terminal_project.setEnabled(False)

new_terminal_file = create_action(self,
_("Current opened file folder"),
icon=ima.icon('cmdprompt'),
_("New terminal in current Editor "
"file"),
tip=_("Sets the pwd at "
"the folder that contains "
"the directory that contains "
"the current opened file"),
triggered=lambda:
self.create_new_term(
path=self.current_file_path))
add_actions(new_terminal_menu, (new_terminal_cwd,
self.new_terminal_project,
new_terminal_file))
self.menu_actions = [None, new_terminal_menu, None]

rename_tab_action = create_action(self,
_("Rename terminal"),
triggered=self.tab_name_editor)

self.menu_actions = [new_terminal_cwd, self.new_terminal_project,
new_terminal_file, MENU_SEPARATOR,
rename_tab_action]
self.setup_menu_actions()

return self.menu_actions

def setup_menu_actions(self):
"""Setup and update the Options menu actions."""
if self.project_path is None:
self.new_terminal_project.setEnabled(False)

def get_focus_widget(self):
"""
Set focus on current selected terminal.
Expand Down Expand Up @@ -270,6 +278,7 @@ def register_plugin(self):
self.main.projects.sig_project_loaded.connect(self.set_project_path)
self.main.projects.sig_project_closed.connect(self.unset_project_path)
self.main.editor.open_file_update.connect(self.set_current_opened_file)
self.menu.aboutToShow.connect(self.setup_menu_actions)

# ------ Public API (for terminals) -------------------------
def get_terms(self):
Expand Down Expand Up @@ -360,3 +369,8 @@ def move_tab(self, index_from, index_to):
"""
term = self.terms.pop(index_from)
self.terms.insert(index_to, term)

def tab_name_editor(self):
"""Trigger the tab name editor."""
index = self.tabwidget.currentIndex()
self.tabwidget.tabBar().tab_name_editor.edit_tab(index)

0 comments on commit ef23f32

Please sign in to comment.