Skip to content

Commit 51d18ac

Browse files
authored
Merge pull request #468 from Coding/git-push
git push 弹窗增加全选按钮
2 parents 3d6dc37 + 52689d0 commit 51d18ac

File tree

20 files changed

+175
-316
lines changed

20 files changed

+175
-316
lines changed

app/components/Editor/state.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ class Editor {
8080
// }
8181
// })
8282

83+
autorun(() => {
84+
const tab = this.tab;
85+
if (tab && tab.isActive && tab.editor && tab.editor.cm) {
86+
setTimeout(() => {
87+
tab.editor.cm.refresh();
88+
tab.editor.cm.focus();
89+
}, 0);
90+
}
91+
})
92+
8393
if (!this.file) {
8494
cm.setCursor(cm.posFromIndex(this.content.length))
8595
}

app/components/Git/GitCommitView.jsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ var GitCommitView = ({isWorkingDirClean, ...actionProps}) => {
1818
: (<div>
1919
<GitFileTree
2020
statusFiles={statusFiles}
21-
handleClick={(path) => {
22-
diffFile({
23-
path, newRef: 'HEAD', oldRef: '~~unstaged~~'
24-
})
25-
}}
21+
handleClick={path => diffFile({ path, newRef: 'HEAD', oldRef: '~~unstaged~~' })}
2622
/>
2723
<hr />
2824
<div className='git-commit-message-container'>

app/components/Git/GitFileTree.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class _GitFileTreeNode extends Component {
5959
return (
6060
<div className='filetree-node-container'>
6161
{ node.isRoot ?
62-
(<div className='filetree-node' ref={r => this.nodeDOM = r} >
62+
(<div className='filetree-node' ref={r => this.nodeDOM = r}>
6363
{ displayOnly ? null
6464
: <span className='filetree-node-checkbox'
6565
style={{marginRight: 0}}

app/components/Git/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ export const selectNode = createAction(GIT_STATUS_SELECT_NODE, node => node)
357357
export const GIT_STATUS_STAGE_NODE = 'GIT_STATUS_STAGE_NODE'
358358
export const toggleStaging = createAction(GIT_STATUS_STAGE_NODE, node => node)
359359

360+
export const GIT_STATUS_STAGE_ALL = 'GIT_STATUS_STAGE_ALL';
361+
export const toggleStagingAll = createAction(GIT_STATUS_STAGE_ALL);
362+
360363
export const GIT_MERGE = 'GIT_MERGE'
361364
export const gitMerge = createAction(GIT_MERGE)
362365
export function mergeFile (path) {

app/components/Git/reducer.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
GIT_STATUS_FOLD_NODE,
77
GIT_STATUS_SELECT_NODE,
88
GIT_STATUS_STAGE_NODE,
9+
GIT_STATUS_STAGE_ALL,
910
GIT_BRANCH,
1011
GIT_CHECKOUT,
1112
GIT_CHECKOUT_FAILED,
@@ -187,9 +188,10 @@ export default handleActions({
187188
const node = action.payload
188189
let statusFiles = state.statusFiles
189190
if (!node.isDir) {
190-
statusFiles = state.statusFiles.set(node.path,
191-
node.set('isStaged', !node.isStaged)
192-
)
191+
statusFiles = state.statusFiles.set(
192+
node.path,
193+
node.set('isStaged', !node.isStaged),
194+
);
193195
} else {
194196
const stagedLeafNodes = node.leafNodes.filter(leafNodePath =>
195197
state.statusFiles.get(leafNodePath).get('isStaged')
@@ -207,6 +209,17 @@ export default handleActions({
207209
return { ...state, statusFiles }
208210
},
209211

212+
[GIT_STATUS_STAGE_ALL]: (state, action) => {
213+
let statusFiles = state.statusFiles;
214+
const allStaged = statusFiles.toArray().filter(v => !v.isDir).every(node => node.isStaged);
215+
statusFiles = statusFiles.withMutations(statusFiles => {
216+
statusFiles.filter(v => !v.isDir).toArray().forEach(node => {
217+
statusFiles.set(node.path, node.set('isStaged', !allStaged));
218+
});
219+
return statusFiles;
220+
});
221+
return { ...state, statusFiles };
222+
},
210223

211224
[GIT_UPDATE_COMMIT_MESSAGE]: (state, action) => ({ ...state, commitMessage: action.payload }),
212225

app/components/Modal/GitCommitView/CommitFileList.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { PureComponent } from 'react'
22
import PropTypes from 'prop-types'
33
import cx from 'classnames'
44
import styled from 'styled-components'
5+
import i18n from 'utils/createI18n'
56

67
const Label = styled.span`
78
height: 100%;
@@ -13,19 +14,13 @@ const Label = styled.span`
1314
const SingleFileNode = ({ item, toggleStaging, handleClick, active }) => (
1415
<div className={cx('filetree-node filetree-node-container', { active: !!active })}>
1516
<span className='filetree-node-checkbox' onClick={e => toggleStaging(item)}>
16-
<i
17-
className={cx('fa', {
18-
'fa-check-square': !item.isDir && item.isStaged,
19-
'fa-square-o': !item.isDir && !item.isStaged
20-
})}
21-
/>
17+
<i className={`fa ${!item.isStaged ? 'fa-square-o' : 'fa-check-square'}`}></i>
2218
</span>
2319
<span className='filetree-node-icon'>
2420
<i
25-
className={cx('fa file-status-indicator', item.status.toLowerCase(), {
21+
className={cx('file-status-indicator fa', item.status.toLowerCase(), {
2622
'fa-folder-o': item.isDir,
27-
'fa-pencil-square':
28-
item.status === 'MODIFIED' || item.status === 'CHANGED' || item.status === 'MODIFY',
23+
'fa-pencil-square': item.status === 'MODIFIED' || item.status === 'CHANGED' || item.status === 'MODIFY',
2924
'fa-plus-square': item.status === 'UNTRACKED' || item.status === 'ADD',
3025
'fa-minus-square': item.status === 'MISSING',
3126
'fa-exclamation-circle': item.status === 'CONFLICTION'
@@ -46,17 +41,24 @@ SingleFileNode.propTypes = {
4641
class CommitFileList extends PureComponent {
4742
static propTypes = {
4843
statusFiles: PropTypes.object,
44+
toggleStagingAll: PropTypes.func,
4945
toggleStaging: PropTypes.func,
5046
handleClick: PropTypes.func,
5147
active: PropTypes.string
5248
}
5349

5450
render () {
55-
const { statusFiles, toggleStaging, handleClick, active } = this.props
56-
const unStagedFiles = statusFiles.filter(v => !v.isDir).toArray()
57-
51+
const { statusFiles, toggleStagingAll, toggleStaging, handleClick, active } = this.props
52+
const unStagedFiles = statusFiles.filter(v => !v.isDir).toArray();
53+
const allStaged = unStagedFiles.every(v => v.isStaged);
5854
return (
5955
<div className='git-commit-files git-filetree-container'>
56+
{unStagedFiles.length > 1 && (
57+
<div className="checkbox-all" onClick={toggleStagingAll}>
58+
<i className={`fa ${!allStaged ? 'fa-square-o' : 'fa-check-square'}`}></i>
59+
<span className="label">{i18n`git.commitView.all`}</span>
60+
</div>
61+
)}
6062
{unStagedFiles.map(item => (
6163
<SingleFileNode
6264
item={item}

app/components/Modal/GitCommitView/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ class GitCommitView extends PureComponent {
103103
updateCommitMessage,
104104
commit,
105105
statusFiles,
106-
toggleStaging
106+
toggleStagingAll,
107+
toggleStaging,
107108
} = this.props
108109
const { loading, original, modified, path, unknowFile } = this.state
109110
const initialCommitMessage = i18n.get('git.commitView.initMessage')
@@ -115,6 +116,7 @@ class GitCommitView extends PureComponent {
115116
<CommitFileList
116117
active={path}
117118
statusFiles={statusFiles}
119+
toggleStagingAll={toggleStagingAll}
118120
toggleStaging={toggleStaging}
119121
handleClick={this.handleClickFile}
120122
/>

app/components/MonacoEditor/Editors/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ const EditorWrapper = observer(({ tab, active }) => {
6868
// key is crutial here, it decides whether the component should re-construct
6969
// or keep using the existing instance.
7070
const key = `editor_${file.path}`;
71-
const editorElement = matchEditorByContentType(editor.editorType, editor.contentType, editor.filePath.split('.').pop());
71+
const editorElement = matchEditorByContentType(
72+
editor.editorType,
73+
editor.contentType,
74+
editor.filePath ? editor.filePath.split('.').pop() : '',
75+
);
7276
return React.createElement(editorElement, { editorInfo, key, tab, active, language: config.mainLanguage, path: file.path, size: file.size });
7377
})
7478

0 commit comments

Comments
 (0)