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

PR: Add function/class search shortcut, menu and toolbar entries #3878

Merged
merged 11 commits into from
Jan 10, 2017
4 changes: 2 additions & 2 deletions spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
'_/quit': "Ctrl+Q",
# -- In plugins/editor
'_/file switcher': 'Ctrl+P',
'_/symbol finder': 'Ctrl+Alt+P',
'_/debug': "Ctrl+F5",
'_/debug step over': "Ctrl+F10",
'_/debug continue': "Ctrl+F12",
Expand Down Expand Up @@ -425,7 +426,6 @@
'editor/run cell and advance': RUN_CELL_AND_ADVANCE_SHORTCUT,
# -- In plugins/editor.py
'editor/show/hide outline': "Ctrl+Alt+O",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shortcut is no more needed because

  1. If Spyder has no project active, the Project explorer is empty.
  2. If the project is active, I think users would expect the Project explorer to be visible all the time.

@goanpeca, what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then @andfoy please remove this shortcut as part of this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the project is active, I think users would expect the Project explorer to be visible all the time.

I don't mind that much about the shortcut, but I don't expect the Project explorer to be visible all the time. I actually close the Project explorer when working on my laptop because the screen is not big enough, and I find it pretty annoying that it always comes back when I launch Spyder. Even on my desktop screen, which is big enough, I don't find the Project explorer particularly useful - I only use it when opening files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the Project Explorer can be closed at any time, so it's not enforced on users. It's just a visual clue that you're working on a project.

I find it pretty annoying that it always comes back when I launch Spyder

Please submit a PR to fix that. I don't have a problem with it :-)

'editor/show/hide project explorer': "Ctrl+Alt+P",
# -- In Breakpoints
'_/switch to breakpoints': "Ctrl+Shift+B",
# ---- Consoles (in widgets/shell) ----
Expand Down Expand Up @@ -656,7 +656,7 @@
# or if you want to *rename* options, then you need to do a MAJOR update in
# version, e.g. from 3.0.0 to 4.0.0
# 3. You don't need to touch this value if you're just adding a new option
CONF_VERSION = '31.0.0'
CONF_VERSION = '32.0.0'

# Main configuration instance
try:
Expand Down
40 changes: 27 additions & 13 deletions spyder/plugins/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,25 +614,24 @@ def get_plugin_actions(self):
context=Qt.WidgetWithChildrenShortcut)
self.register_shortcut(self.toggle_outline_action, context="Editor",
name="Show/hide outline")
self.toggle_project_action = create_action(self,
_("Show/hide project explorer"),
triggered=self.show_hide_projects,
context=Qt.WidgetWithChildrenShortcut)
self.register_shortcut(self.toggle_project_action, context="Editor",
name="Show/hide project explorer")
self.addActions([self.toggle_outline_action, self.toggle_project_action])

self.addActions([self.toggle_outline_action])
# ---- File menu and toolbar ----
self.new_action = create_action(self, _("&New file..."),
self.new_action = create_action(
self,
_("&New file..."),
icon=ima.icon('filenew'), tip=_("New file"),
triggered=self.new,
context=Qt.WidgetShortcut)
context=Qt.WidgetShortcut
)
self.register_shortcut(self.new_action, context="Editor",
name="New file", add_sc_to_tip=True)

self.open_last_closed_action = create_action(self, _("O&pen last closed"),
self.open_last_closed_action = create_action(
self,
_("O&pen last closed"),
tip=_("Open last closed"),
triggered=self.open_last_closed)
triggered=self.open_last_closed
)
self.register_shortcut(self.open_last_closed_action, context="Editor",
name="Open last closed")

Expand All @@ -651,6 +650,14 @@ def get_plugin_actions(self):
self.register_shortcut(self.file_switcher_action, context="_",
name="File switcher", add_sc_to_tip=True)

self.symbol_finder_action = create_action(self, _('Symbol finder...'),
icon=ima.icon('symbol_find'),
tip=_('Fast symbol search in file'),
triggered=self.call_symbol_finder,
context=Qt.ApplicationShortcut)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not saying you should change this, just a comment for reference.

# I tend to favor this one for several reasons. 
# It can be automatically performed and enforced by tools like yapf
# it results in more lines of code but ir more readable as each line corresponds 
# to a parameter
self.symbol_finder_action = create_action(
    self,
    _('Symbol finder...'),
    icon=ima.icon('symbol_find'),
    tip=_('Fast symbol search in file'),
    triggered=self.call_symbol_finder,
    context=Qt.ApplicationShortcut)

# or 

self.symbol_finder_action = create_action(self,
                                          _('Symbol finder...'),
                                          icon=ima.icon('symbol_find'),
                                          tip=_('Fast symbol search in file'),
                                          triggered=self.call_symbol_finder,
                                          context=Qt.ApplicationShortcut)

self.register_shortcut(self.symbol_finder_action, context="_",
name="symbol finder", add_sc_to_tip=True)

self.revert_action = create_action(self, _("&Revert"),
icon=ima.icon('revert'), tip=_("Revert file from disk"),
triggered=self.revert)
Expand Down Expand Up @@ -995,6 +1002,7 @@ def get_plugin_actions(self):
self.save_all_action,
save_as_action,
self.file_switcher_action,
self.symbol_finder_action,
self.revert_action,
MENU_SEPARATOR,
print_preview_action,
Expand All @@ -1007,7 +1015,8 @@ def get_plugin_actions(self):
self.main.file_menu_actions += file_menu_actions
file_toolbar_actions = [self.new_action, self.open_action,
self.save_action, self.save_all_action,
self.file_switcher_action]
self.file_switcher_action,
self.symbol_finder_action]
self.main.file_toolbar_actions += file_toolbar_actions

# ---- Find menu/toolbar construction ----
Expand Down Expand Up @@ -1725,6 +1734,11 @@ def call_file_switcher(self):
if self.editorstacks:
self.get_current_editorstack().open_fileswitcher_dlg()

@Slot()
def call_symbol_finder(self):
if self.editorstacks:
self.get_current_editorstack().open_symbolfinder_dlg()

def update_recent_file_menu(self):
"""Update recent file menu"""
recent_files = []
Expand Down
1 change: 1 addition & 0 deletions spyder/utils/icon_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
'spyder.autopep8': [('fa.eye',), {}],
'spyder.memory_profiler': [('fa.eye',), {}],
'spyder.line_profiler': [('fa.eye',), {}],
'symbol_find': [('fa.at',), {}]
}


Expand Down
10 changes: 10 additions & 0 deletions spyder/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ def __init__(self, parent, actions):
fileswitcher_action = create_action(self, _("File switcher..."),
icon=ima.icon('filelist'),
triggered=self.open_fileswitcher_dlg)
symbolfinder_action = create_action(self,
_("Find symbols in file..."),
icon=ima.icon('filelist'),
triggered=self.open_symbolfinder_dlg)
copy_to_cb_action = create_action(self, _("Copy path to clipboard"),
icon=ima.icon('editcopy'),
triggered=lambda:
Expand All @@ -356,6 +360,7 @@ def __init__(self, parent, actions):
triggered=self.close_all_but_this)

self.menu_actions = actions + [None, fileswitcher_action,
symbolfinder_action,
copy_to_cb_action, None, close_right,
close_all_but_this]
self.outlineexplorer = None
Expand Down Expand Up @@ -617,6 +622,11 @@ def open_fileswitcher_dlg(self):
self.fileswitcher_dlg.show()
self.fileswitcher_dlg.is_visible = True

@Slot()
def open_symbolfinder_dlg(self):
self.open_fileswitcher_dlg()
self.fileswitcher_dlg.set_search_text('@')

def update_fileswitcher_dlg(self):
"""Synchronize file list dialog box with editor widget tabs"""
if self.fileswitcher_dlg:
Expand Down
3 changes: 3 additions & 0 deletions spyder/widgets/fileswitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ def filter_text(self):
"""Get the normalized (lowecase) content of the filter text."""
return to_text_string(self.edit.text()).lower()

def set_search_text(self, _str):
self.edit.setText(_str)

def save_initial_state(self):
"""Saves initial cursors and initial active editor."""
paths = self.paths
Expand Down