1 """The "Actions" widget"""
2 from __future__
import division
, absolute_import
, unicode_literals
3 from functools
import partial
5 from qtpy
import QtCore
6 from qtpy
import QtWidgets
11 from ..widgets
import defs
12 from ..widgets
import remote
13 from ..widgets
import stash
14 from ..qtutils
import create_button
15 from ..qtutils
import connect_button
18 class QFlowLayoutWidget(QtWidgets
.QFrame
):
20 _horizontal
= QtWidgets
.QBoxLayout
.LeftToRight
21 _vertical
= QtWidgets
.QBoxLayout
.TopToBottom
23 def __init__(self
, parent
):
24 QtWidgets
.QFrame
.__init
__(self
, parent
)
25 self
._direction
= self
._vertical
26 self
._layout
= layout
= QtWidgets
.QBoxLayout(self
._direction
)
27 layout
.setSpacing(defs
.spacing
)
28 qtutils
.set_margin(layout
, defs
.margin
)
29 self
.setLayout(layout
)
30 policy
= QtWidgets
.QSizePolicy(
31 QtWidgets
.QSizePolicy
.Minimum
, QtWidgets
.QSizePolicy
.Minimum
33 self
.setSizePolicy(policy
)
34 self
.setMinimumSize(QtCore
.QSize(1, 1))
35 self
.aspect_ratio
= 0.8
37 def resizeEvent(self
, event
):
39 if size
.width() * self
.aspect_ratio
< size
.height():
42 dxn
= self
._horizontal
44 if dxn
!= self
._direction
:
46 self
.layout().setDirection(dxn
)
49 def tooltip_button(text
, layout
):
50 button
= create_button(text
, layout
=layout
)
51 button
.setToolTip(text
)
55 class ActionButtons(QFlowLayoutWidget
):
56 def __init__(self
, context
, parent
=None):
57 QFlowLayoutWidget
.__init
__(self
, parent
)
58 layout
= self
.layout()
59 self
.context
= context
60 self
.stage_button
= tooltip_button(N_('Stage'), layout
)
61 self
.unstage_button
= tooltip_button(N_('Unstage'), layout
)
62 self
.refresh_button
= tooltip_button(N_('Refresh'), layout
)
63 self
.fetch_button
= tooltip_button(N_('Fetch...'), layout
)
64 self
.push_button
= tooltip_button(N_('Push...'), layout
)
65 self
.pull_button
= tooltip_button(N_('Pull...'), layout
)
66 self
.stash_button
= tooltip_button(N_('Stash...'), layout
)
67 self
.aspect_ratio
= 0.4
69 self
.setMinimumHeight(30)
72 connect_button(self
.refresh_button
, cmds
.run(cmds
.Refresh
, context
))
73 connect_button(self
.fetch_button
, partial(remote
.fetch
, context
))
74 connect_button(self
.push_button
, partial(remote
.push
, context
))
75 connect_button(self
.pull_button
, partial(remote
.pull
, context
))
76 connect_button(self
.stash_button
, partial(stash
.view
, context
))
77 connect_button(self
.stage_button
, cmds
.run(cmds
.StageSelected
, context
))
78 connect_button(self
.unstage_button
, self
.unstage
)
81 """Unstage selected files, or all files if no selection exists."""
82 context
= self
.context
83 paths
= context
.selection
.staged
84 context
= self
.context
86 cmds
.do(cmds
.UnstageAll
, context
)
88 cmds
.do(cmds
.Unstage
, context
, paths
)