Skip to content

Commit

Permalink
Add stage_all and unstage_all buttons
Browse files Browse the repository at this point in the history
Minor backend API refractor.
  • Loading branch information
trollodel committed Sep 18, 2020
1 parent 4f7c3c8 commit 4e68d6e
Show file tree
Hide file tree
Showing 7 changed files with 744 additions and 339 deletions.
7 changes: 7 additions & 0 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,13 @@ def create_edit_action(text, tr_text, icon):
self.register_plugin(self.profiler)
self.thirdparty_plugins.append(self.profiler)

# VCS plugin
if CONF.get('vcs', 'enable'):
from spyder.plugins.vcs.plugin import VCS
self.vcs = VCS(self, configuration=CONF)
self.register_plugin(self.vcs)
self.thirdparty_plugins.append(self.vcs)

other_plugins = ['pylint']

for plugin_name in other_plugins:
Expand Down
5 changes: 2 additions & 3 deletions spyder/plugins/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

try:
from .plugin import VCS as PLUGIN_CLASS
except ImportError as ex:
import traceback
traceback.print_exc()
except ImportError:
pass
else:
PLUGIN_CLASSES = [PLUGIN_CLASS]
109 changes: 96 additions & 13 deletions spyder/plugins/vcs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# Third party imports
import qtawesome as qta
from qtpy.QtCore import Signal, Slot
from qtpy.QtWidgets import QAction

# Local imports
from spyder.api.plugins import Plugins, SpyderDockablePlugin
from spyder.api.translations import get_translation
from spyder.config.manager import CONF
from spyder.utils import icon_manager as ima
from spyder.utils.qthelpers import toggle_actions

Expand All @@ -31,14 +33,17 @@


class VCS(SpyderDockablePlugin): # pylint: disable=W0201
"""VCS plugin."""
"""
VCS plugin.
"""

NAME = 'VCS'
REQUIRES = [Plugins.Projects]
TABIFY = [Plugins.Help]
WIDGET_CLASS = VCSWidget
CONF_SECTION = NAME

# Signals definition
sig_repository_changed = Signal(str, str)
"""
This signal is emitted when the current managed repository change.
Expand All @@ -63,8 +68,75 @@ class VCS(SpyderDockablePlugin): # pylint: disable=W0201
:py:meth:`VCS.set_repository_root` instead.
"""

# Actions defintion
stage_all_action: QAction
"""
Action for stage all the unstaged changes.
When triggered,
the :py:meth:`~VCSBackendBase.stage_all` method is called.
"""

unstage_all_action: QAction
"""
Action for unstage all the staged changes.
When triggered,
the :py:meth:`~VCSBackendBase.unstage_all` method is called.
"""

commit_action: QAction
"""
Action for commit.
When triggered and there is a commit message,
the :py:meth:`~VCSBackendBase.commit` method is called.
"""

fetch_action: QAction
"""
Action for fetch.
When triggered, the :py:meth:`~VCSBackendBase.fetch` method is called.
"""

pull_action: QAction
"""
Action for pull.
When triggered, the :py:meth:`~VCSBackendBase.pull` method is called.
"""

push_action: QAction
"""
Action for push.
When triggered, the :py:meth:`~VCSBackendBase.push` method is called.
"""

# Other attributes definition

vcs_manager: VCSBackendManager
"""
The manager for the current VCS.
This can be used to get information about the repository.
.. warning::
Any call to the manager blocks the current thread and
may invoke subprocess or other long-running operation.
Is preferrable to run them in a separate thread and
wait the result asynchronously.
.. danger::
Do any operation that changes the repository state
will break the VCS pane UI.
Use actions where possible.
"""
def __init__(self, *args, **kwargs):
self.vcs_manager = VCSBackendManager(None)
# workaround when imported as 3rd party plugin
kwargs.setdefault("configuration", CONF)
super().__init__(
*args,
**kwargs,
Expand Down Expand Up @@ -139,17 +211,15 @@ def set_repository(self, repository_dir: str) -> str:
self.push_action, self.refresh_action), False)
self.sig_repository_changed.emit(None, None)
else:
for (action, feature) in (
for (action, featurename) in (
(self.commit_action, "commit"),
(self.fetch_action, "pull"),
(self.fetch_action, "fetch"),
(self.pull_action, "pull"),
(self.push_action, "push"),
):
action.setEnabled(
self.vcs_manager.check_features(
feature,
suppress_raise=True,
))
feature = getattr(self.vcs_manager, featurename, None)
if feature is not None:
action.setEnabled(feature.enabled)
self.refresh_action.setEnabled(True)
self.sig_repository_changed.emit(self.vcs_manager.repodir,
self.vcs_manager.VCSNAME)
Expand All @@ -164,14 +234,31 @@ def set_repository(self, repository_dir: str) -> str:
def _create_actions(self):
# TODO: Add tips
create_action = self.create_action
self.stage_all_action = create_action(
"vcs_stage_all_action",
_("stage all"),
icon=qta.icon("fa.long-arrow-down", color=ima.MAIN_FG_COLOR),
icon_text=_("stage all"),
# tip=_("ADD TIP HERE"),
shortcut_context=self.NAME,
triggered=lambda: None,
)
self.unstage_all_action = create_action(
"vcs_unstage_all_action",
_("unstage all"),
icon=qta.icon("fa.long-arrow-up", color=ima.MAIN_FG_COLOR),
icon_text=_("unstage all"),
# tip=_("ADD TIP HERE"),
shortcut_context=self.NAME,
triggered=lambda: None,
)
self.commit_action = create_action(
"vcs_commit_action",
_("commit"),
icon=qta.icon("mdi.source-commit", color=ima.MAIN_FG_COLOR),
icon_text=_("commit"),
# tip=_("ADD TIP HERE"),
shortcut_context=self.NAME,
# Workaround for prevent create_action to raise an error
triggered=lambda: None,
)

Expand All @@ -182,7 +269,6 @@ def _create_actions(self):
icon_text=_("fetch"),
# tip=_("ADD TIP HERE"),
shortcut_context=self.NAME,
# Workaround for prevent create_action to raise an error
triggered=lambda: None,
)

Expand All @@ -193,7 +279,6 @@ def _create_actions(self):
icon_text=_("pull"),
# tip=_("ADD TIP HERE"),
shortcut_context=self.NAME,
# Workaround for prevent create_action to raise an error
triggered=lambda: None,
)

Expand All @@ -204,7 +289,6 @@ def _create_actions(self):
icon_text=_("push"),
# tip=_("ADD TIP HERE"),
shortcut_context=self.NAME,
# Workaround for prevent create_action to raise an error
triggered=lambda: None,
)

Expand All @@ -215,6 +299,5 @@ def _create_actions(self):
icon_text=_("refresh"),
# tip=_("ADD TIP HERE"),
shortcut_context=self.NAME,
# Workaround for prevent create_action to raise an error
triggered=lambda: None,
)
Loading

0 comments on commit 4e68d6e

Please sign in to comment.