Skip to content

Commit

Permalink
feat: add discard to trash settings in preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 29, 2023
1 parent d2600bb commit bdd16a6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/src/lib/app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ export interface IAppState {
/** Whether or not the app should use Windows' OpenSSH client */
readonly useWindowsOpenSSH: boolean

/** Whether or not to discard the changes to Trash */
readonly discardToTrash: boolean

/** Whether or not the app should show the commit length warning */
readonly showCommitLengthWarning: boolean

Expand Down
14 changes: 14 additions & 0 deletions app/src/lib/stores/app-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ const pullRequestFileListConfigKey: string = 'pull-request-files-width'

const askToMoveToApplicationsFolderDefault: boolean = true
const confirmRepoRemovalDefault: boolean = true
const discardToTrashDefault: boolean = true
const showCommitLengthWarningDefault: boolean = false
const confirmDiscardChangesDefault: boolean = true
const confirmDiscardChangesPermanentlyDefault: boolean = true
Expand All @@ -360,6 +361,7 @@ const askForConfirmationOnForcePushDefault = true
const confirmUndoCommitDefault: boolean = true
const askToMoveToApplicationsFolderKey: string = 'askToMoveToApplicationsFolder'
const confirmRepoRemovalKey: string = 'confirmRepoRemoval'
const discardToTrashKey: string = 'discardToTrash'
const showCommitLengthWarningKey: string = 'showCommitLengthWarning'
const confirmDiscardChangesKey: string = 'confirmDiscardChanges'
const confirmDiscardStashKey: string = 'confirmDiscardStash'
Expand Down Expand Up @@ -516,6 +518,8 @@ export class AppStore extends TypedBaseStore<IAppState> {

private useWindowsOpenSSH: boolean = false

private discardToTrash: boolean = discardToTrashDefault

private showCommitLengthWarning: boolean = showCommitLengthWarningDefault

private hasUserViewedStash = false
Expand Down Expand Up @@ -998,6 +1002,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
currentTheme: this.currentTheme,
apiRepositories: this.apiRepositoriesStore.getState(),
useWindowsOpenSSH: this.useWindowsOpenSSH,
discardToTrash: this.discardToTrash,
showCommitLengthWarning: this.showCommitLengthWarning,
optOutOfUsageTracking: this.statsStore.getOptOut(),
currentOnboardingTutorialStep: this.currentOnboardingTutorialStep,
Expand Down Expand Up @@ -2105,6 +2110,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
setBoolean(showCommitLengthWarningKey, true)
}

this.discardToTrash = getBoolean(discardToTrashKey, discardToTrashDefault)

this.showCommitLengthWarning = getBoolean(
showCommitLengthWarningKey,
showCommitLengthWarningDefault
Expand Down Expand Up @@ -3559,6 +3566,13 @@ export class AppStore extends TypedBaseStore<IAppState> {
this.emitUpdate()
}

public _setDiscardToTrash(discardToTrash: boolean) {
setBoolean(discardToTrashKey, discardToTrash)
this.discardToTrash = discardToTrash

this.emitUpdate()
}

public _setShowCommitLengthWarning(showCommitLengthWarning: boolean) {
setBoolean(showCommitLengthWarningKey, showCommitLengthWarning)
this.showCommitLengthWarning = showCommitLengthWarning
Expand Down
1 change: 1 addition & 0 deletions app/src/ui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ export class App extends React.Component<IAppProps, IAppState> {
}
showDiscardChangesSetting={showSetting}
discardingAllChanges={discardingAllChanges}
discardToTrash={this.state.discardToTrash}
onDismissed={onPopupDismissedFn}
onConfirmDiscardChangesChanged={this.onConfirmDiscardChangesChanged}
/>
Expand Down
3 changes: 2 additions & 1 deletion app/src/ui/discard-changes/discard-changes-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IDiscardChangesProps {
*/
readonly discardingAllChanges: boolean
readonly showDiscardChangesSetting: boolean
readonly discardToTrash: boolean
readonly onDismissed: () => void
readonly onConfirmDiscardChangesChanged: (optOut: boolean) => void
}
Expand Down Expand Up @@ -57,7 +58,7 @@ export class DiscardChanges extends React.Component<
this.state = {
isDiscardingChanges: false,
confirmDiscardChanges: this.props.confirmDiscardChanges,
moveToTrash: true,
moveToTrash: this.props.discardToTrash,
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/ui/dispatcher/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,10 @@ export class Dispatcher {
this.appStore._setUseWindowsOpenSSH(useWindowsOpenSSH)
}

public setDiscardToTrash(discardToTrash: boolean) {
this.appStore._setDiscardToTrash(discardToTrash)
}

public setShowCommitLengthWarning(showCommitLengthWarning: boolean) {
this.appStore._setShowCommitLengthWarning(showCommitLengthWarning)
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/ui/preferences/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ interface IPreferencesState {
readonly confirmForcePush: boolean
readonly confirmUndoCommit: boolean
readonly uncommittedChangesStrategy: UncommittedChangesStrategy
readonly discardToTrash: boolean
readonly availableEditors: ReadonlyArray<string>
readonly selectedExternalEditor: string | null
readonly availableShells: ReadonlyArray<Shell>
Expand Down Expand Up @@ -137,6 +138,7 @@ export class Preferences extends React.Component<
confirmForcePush: false,
confirmUndoCommit: false,
uncommittedChangesStrategy: defaultUncommittedChangesStrategy,
discardToTrash: true,
selectedExternalEditor: this.props.selectedExternalEditor,
availableShells: [],
selectedShell: this.props.selectedShell,
Expand Down Expand Up @@ -375,6 +377,7 @@ export class Preferences extends React.Component<
confirmCheckoutCommit={this.state.confirmCheckoutCommit}
confirmForcePush={this.state.confirmForcePush}
confirmUndoCommit={this.state.confirmUndoCommit}
discardToTrash={this.state.discardToTrash}
onConfirmRepositoryRemovalChanged={
this.onConfirmRepositoryRemovalChanged
}
Expand All @@ -394,6 +397,7 @@ export class Preferences extends React.Component<
onShowCommitLengthWarningChanged={
this.onShowCommitLengthWarningChanged
}
onDiscardToTrashChanged={this.onDiscardToTrashChanged}
/>
)
break
Expand Down Expand Up @@ -486,6 +490,10 @@ export class Preferences extends React.Component<
this.setState({ uncommittedChangesStrategy })
}

private onDiscardToTrashChanged = (discardToTrash: boolean) => {
this.setState({ discardToTrash })
}

private onCommitterNameChanged = (committerName: string) => {
this.setState({
committerName,
Expand Down Expand Up @@ -587,6 +595,7 @@ export class Preferences extends React.Component<
}

this.props.dispatcher.setUseWindowsOpenSSH(this.state.useWindowsOpenSSH)
this.props.dispatcher.setDiscardToTrash(this.state.discardToTrash)
this.props.dispatcher.setShowCommitLengthWarning(
this.state.showCommitLengthWarning
)
Expand Down
23 changes: 23 additions & 0 deletions app/src/ui/preferences/prompts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IPromptsPreferencesProps {
readonly confirmUndoCommit: boolean
readonly showCommitLengthWarning: boolean
readonly uncommittedChangesStrategy: UncommittedChangesStrategy
readonly discardToTrash: boolean
readonly onConfirmDiscardChangesChanged: (checked: boolean) => void
readonly onConfirmDiscardChangesPermanentlyChanged: (checked: boolean) => void
readonly onConfirmDiscardStashChanged: (checked: boolean) => void
Expand All @@ -25,6 +26,7 @@ interface IPromptsPreferencesProps {
readonly onUncommittedChangesStrategyChanged: (
value: UncommittedChangesStrategy
) => void
readonly onDiscardToTrashChanged: (checked: boolean) => void
}

interface IPromptsPreferencesState {
Expand All @@ -36,6 +38,7 @@ interface IPromptsPreferencesState {
readonly confirmForcePush: boolean
readonly confirmUndoCommit: boolean
readonly uncommittedChangesStrategy: UncommittedChangesStrategy
readonly discardToTrash: boolean
}

export class Prompts extends React.Component<
Expand All @@ -55,6 +58,7 @@ export class Prompts extends React.Component<
confirmForcePush: this.props.confirmForcePush,
confirmUndoCommit: this.props.confirmUndoCommit,
uncommittedChangesStrategy: this.props.uncommittedChangesStrategy,
discardToTrash: this.props.discardToTrash,
}
}

Expand Down Expand Up @@ -128,6 +132,15 @@ export class Prompts extends React.Component<
this.props.onUncommittedChangesStrategyChanged(value)
}

private onDiscardToTrashChanged = (
event: React.FormEvent<HTMLInputElement>
) => {
const value = event.currentTarget.checked

this.setState({ discardToTrash: value })
this.props.onDiscardToTrashChanged(event.currentTarget.checked)
}

private onShowCommitLengthWarningChanged = (
event: React.FormEvent<HTMLInputElement>
) => {
Expand Down Expand Up @@ -234,6 +247,16 @@ export class Prompts extends React.Component<
onSelected={this.onUncommittedChangesStrategyChanged}
/>
</div>
<div className="advanced-section">
<h2>Discarding Changes</h2>
<Checkbox
label="Discard the changes to the Trash"
value={
this.state.discardToTrash ? CheckboxValue.On : CheckboxValue.Off
}
onChange={this.onDiscardToTrashChanged}
/>
</div>
<div className="advanced-section">
<h2>Commit Length</h2>
<Checkbox
Expand Down

0 comments on commit bdd16a6

Please sign in to comment.