Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 6 additions & 37 deletions lib/items/changed-file-item.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Emitter} from 'event-kit';
import ItemComponent from './item-component';

import {WorkdirContextPoolPropType} from '../prop-types';
import {autobind} from '../helpers';
import ChangedFileContainer from '../containers/changed-file-container';
import RefHolder from '../models/ref-holder';

export default class ChangedFileItem extends React.Component {
export default class ChangedFileItem extends ItemComponent {
static propTypes = {
workdirContextPool: WorkdirContextPoolPropType.isRequired,

Expand Down Expand Up @@ -36,15 +34,9 @@ export default class ChangedFileItem extends React.Component {
}

constructor(props) {
super(props);
autobind(this, 'destroy');
super(props, {});

this.emitter = new Emitter();
this.isDestroyed = false;
this.hasTerminatedPendingState = false;

this.refEditor = new RefHolder();
this.refEditor.observe(editor => {
this.refHolder.observe(editor => {
this.emitter.emit('did-change-embedded-text-editor', editor);
});
}
Expand All @@ -56,29 +48,6 @@ export default class ChangedFileItem extends React.Component {
return title;
}

terminatePendingState() {
if (!this.hasTerminatedPendingState) {
this.emitter.emit('did-terminate-pending-state');
this.hasTerminatedPendingState = true;
}
}

onDidTerminatePendingState(callback) {
return this.emitter.on('did-terminate-pending-state', callback);
}

destroy() {
/* istanbul ignore else */
if (!this.isDestroyed) {
this.emitter.emit('did-destroy');
this.isDestroyed = true;
}
}

onDidDestroy(callback) {
return this.emitter.on('did-destroy', callback);
}

render() {
const repository = this.props.workdirContextPool.getContext(this.props.workingDirectory).getRepository();

Expand All @@ -87,14 +56,14 @@ export default class ChangedFileItem extends React.Component {
itemType={this.constructor}
repository={repository}
destroy={this.destroy}
refEditor={this.refEditor}
refEditor={this.refHolder}
{...this.props}
/>
);
}

observeEmbeddedTextEditor(cb) {
this.refEditor.map(editor => cb(editor));
this.refHolder.map(editor => cb(editor));
return this.emitter.on('did-change-embedded-text-editor', cb);
}

Expand Down
43 changes: 6 additions & 37 deletions lib/items/commit-detail-item.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Emitter} from 'event-kit';

import ItemComponent from './item-component';
import {WorkdirContextPoolPropType} from '../prop-types';
import CommitDetailContainer from '../containers/commit-detail-container';
import RefHolder from '../models/ref-holder';

export default class CommitDetailItem extends React.Component {
export default class CommitDetailItem extends ItemComponent {
static propTypes = {
workdirContextPool: WorkdirContextPoolPropType.isRequired,
workingDirectory: PropTypes.string.isRequired,
Expand All @@ -20,43 +20,16 @@ export default class CommitDetailItem extends React.Component {
}

constructor(props) {
super(props);
super(props, {title: 'Commit', icon: 'git-commit'});

this.emitter = new Emitter();
this.isDestroyed = false;
this.hasTerminatedPendingState = false;
this.shouldFocus = true;
this.refInitialFocus = new RefHolder();

this.refEditor = new RefHolder();
this.refEditor.observe(editor => {
this.refHolder.observe(editor => {
this.emitter.emit('did-change-embedded-text-editor', editor);
});
}

terminatePendingState() {
if (!this.hasTerminatedPendingState) {
this.emitter.emit('did-terminate-pending-state');
this.hasTerminatedPendingState = true;
}
}

onDidTerminatePendingState(callback) {
return this.emitter.on('did-terminate-pending-state', callback);
}

destroy = () => {
/* istanbul ignore else */
if (!this.isDestroyed) {
this.emitter.emit('did-destroy');
this.isDestroyed = true;
}
}

onDidDestroy(callback) {
return this.emitter.on('did-destroy', callback);
}

render() {
const repository = this.props.workdirContextPool.getContext(this.props.workingDirectory).getRepository();

Expand All @@ -66,7 +39,7 @@ export default class CommitDetailItem extends React.Component {
repository={repository}
{...this.props}
destroy={this.destroy}
refEditor={this.refEditor}
refEditor={this.refHolder}
refInitialFocus={this.refInitialFocus}
/>
);
Expand All @@ -76,12 +49,8 @@ export default class CommitDetailItem extends React.Component {
return `Commit: ${this.props.sha}`;
}

getIconName() {
return 'git-commit';
}

observeEmbeddedTextEditor(cb) {
this.refEditor.map(editor => cb(editor));
this.refHolder.map(editor => cb(editor));
return this.emitter.on('did-change-embedded-text-editor', cb);
}

Expand Down
47 changes: 6 additions & 41 deletions lib/items/commit-preview-item.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import PropTypes from 'prop-types';
import {Emitter} from 'event-kit';
import ItemComponent from './item-component';

import {WorkdirContextPoolPropType} from '../prop-types';
import CommitPreviewContainer from '../containers/commit-preview-container';
import RefHolder from '../models/ref-holder';

export default class CommitPreviewItem extends React.Component {
export default class CommitPreviewItem extends ItemComponent {
static propTypes = {
workdirContextPool: WorkdirContextPoolPropType.isRequired,
workingDirectory: PropTypes.string.isRequired,
Expand All @@ -23,42 +23,15 @@ export default class CommitPreviewItem extends React.Component {
}

constructor(props) {
super(props);
super(props, {title: 'Staged Changes', icon: 'tasklist'});

this.emitter = new Emitter();
this.isDestroyed = false;
this.hasTerminatedPendingState = false;
this.refInitialFocus = new RefHolder();

this.refEditor = new RefHolder();
this.refEditor.observe(editor => {
this.refHolder.observe(editor => {
this.emitter.emit('did-change-embedded-text-editor', editor);
});
}

terminatePendingState() {
if (!this.hasTerminatedPendingState) {
this.emitter.emit('did-terminate-pending-state');
this.hasTerminatedPendingState = true;
}
}

onDidTerminatePendingState(callback) {
return this.emitter.on('did-terminate-pending-state', callback);
}

destroy = () => {
/* istanbul ignore else */
if (!this.isDestroyed) {
this.emitter.emit('did-destroy');
this.isDestroyed = true;
}
}

onDidDestroy(callback) {
return this.emitter.on('did-destroy', callback);
}

render() {
const repository = this.props.workdirContextPool.getContext(this.props.workingDirectory).getRepository();

Expand All @@ -68,22 +41,14 @@ export default class CommitPreviewItem extends React.Component {
repository={repository}
{...this.props}
destroy={this.destroy}
refEditor={this.refEditor}
refEditor={this.refHolder}
refInitialFocus={this.refInitialFocus}
/>
);
}

getTitle() {
return 'Staged Changes';
}

getIconName() {
return 'tasklist';
}

observeEmbeddedTextEditor(cb) {
this.refEditor.map(editor => cb(editor));
this.refHolder.map(editor => cb(editor));
return this.emitter.on('did-change-embedded-text-editor', cb);
}

Expand Down
44 changes: 22 additions & 22 deletions lib/items/git-tab-item.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';

import RefHolder from '../models/ref-holder';
import ItemComponent from './item-component';
import GitTabContainer from '../containers/git-tab-container';

export default class GitTabItem extends React.Component {
export default class GitTabItem extends ItemComponent {
static propTypes = {
repository: PropTypes.object.isRequired,
}
Expand All @@ -16,15 +16,13 @@ export default class GitTabItem extends React.Component {
}

constructor(props) {
super(props);

this.refController = new RefHolder();
super(props, {title: 'Git', icon: 'git-commit'});
}

render() {
return (
<GitTabContainer
controllerRef={this.refController}
controllerRef={this.refHolder}
{...this.props}
/>
);
Expand All @@ -37,14 +35,6 @@ export default class GitTabItem extends React.Component {
};
}

getTitle() {
return 'Git';
}

getIconName() {
return 'git-commit';
}

getDefaultLocation() {
return 'right';
}
Expand All @@ -61,37 +51,47 @@ export default class GitTabItem extends React.Component {
return this.props.repository.getWorkingDirectoryPath();
}

// no-op
destroy() {
return false;
}

// no-op
terminatePendingState() {
return false;
}

// Forwarded to the controller instance when one is present

rememberLastFocus(...args) {
return this.refController.map(c => c.rememberLastFocus(...args));
return this.refHolder.map(c => c.rememberLastFocus(...args));
}

restoreFocus(...args) {
return this.refController.map(c => c.restoreFocus(...args));
return this.refHolder.map(c => c.restoreFocus(...args));
}

hasFocus(...args) {
return this.refController.map(c => c.hasFocus(...args));
return this.refHolder.map(c => c.hasFocus(...args));
}

focus() {
return this.refController.map(c => c.restoreFocus());
return this.refHolder.map(c => c.restoreFocus());
}

focusAndSelectStagingItem(...args) {
return this.refController.map(c => c.focusAndSelectStagingItem(...args));
return this.refHolder.map(c => c.focusAndSelectStagingItem(...args));
}

focusAndSelectCommitPreviewButton() {
return this.refController.map(c => c.focusAndSelectCommitPreviewButton());
return this.refHolder.map(c => c.focusAndSelectCommitPreviewButton());
}

quietlySelectItem(...args) {
return this.refController.map(c => c.quietlySelectItem(...args));
return this.refHolder.map(c => c.quietlySelectItem(...args));
}

focusAndSelectRecentCommit() {
return this.refController.map(c => c.focusAndSelectRecentCommit());
return this.refHolder.map(c => c.focusAndSelectRecentCommit());
}
}
Loading