1
0
mirror of https://github.com/desktop/desktop synced 2024-07-02 15:48:39 +00:00

Make toolbar branch dropdown button resizable

This commit is contained in:
Jorge Pedroso 2023-09-21 09:57:21 +03:00
parent c831ea7b63
commit 91d0fca84a
No known key found for this signature in database
8 changed files with 87 additions and 26 deletions

View File

@ -185,6 +185,9 @@ export interface IAppState {
/** The width of the files list in the pull request files changed view */
readonly pullRequestFilesListWidth: IConstrainedValue
/** The width of the resizable branch drop down button in the toolbar. */
readonly branchDropdownWidth: IConstrainedValue
/**
* Used to highlight access keys throughout the app when the
* Alt key is pressed. Only applicable on non-macOS platforms.

View File

@ -358,6 +358,9 @@ const stashedFilesWidthConfigKey: string = 'stashed-files-width'
const defaultPullRequestFileListWidth: number = 250
const pullRequestFileListConfigKey: string = 'pull-request-files-width'
const defaultBranchDropdownWidth: number = 230
const branchDropdownWidthConfigKey: string = 'branch-dropdown-width'
const askToMoveToApplicationsFolderDefault: boolean = true
const confirmRepoRemovalDefault: boolean = true
const showCommitLengthWarningDefault: boolean = false
@ -475,6 +478,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
private commitSummaryWidth = constrain(defaultCommitSummaryWidth)
private stashedFilesWidth = constrain(defaultStashedFilesWidth)
private pullRequestFileListWidth = constrain(defaultPullRequestFileListWidth)
private branchDropdownWidth = constrain(defaultBranchDropdownWidth)
private windowState: WindowState | null = null
private windowZoomFactor: number = 1
@ -994,6 +998,7 @@ export class AppStore extends TypedBaseStore<IAppState> {
focusCommitMessage: this.focusCommitMessage,
emoji: this.emoji,
sidebarWidth: this.sidebarWidth,
branchDropdownWidth: this.branchDropdownWidth,
commitSummaryWidth: this.commitSummaryWidth,
stashedFilesWidth: this.stashedFilesWidth,
pullRequestFilesListWidth: this.pullRequestFileListWidth,
@ -2112,6 +2117,9 @@ export class AppStore extends TypedBaseStore<IAppState> {
this.pullRequestFileListWidth = constrain(
getNumber(pullRequestFileListConfigKey, defaultPullRequestFileListWidth)
)
this.branchDropdownWidth = constrain(
getNumber(branchDropdownWidthConfigKey, defaultBranchDropdownWidth)
)
this.updateResizableConstraints()
// TODO: Initiliaze here for now... maybe move to dialog mounting
@ -5165,6 +5173,27 @@ export class AppStore extends TypedBaseStore<IAppState> {
return Promise.resolve()
}
public _setBranchDropdownWidth(width: number): Promise<void> {
this.branchDropdownWidth = { ...this.branchDropdownWidth, value: width }
setNumber(branchDropdownWidthConfigKey, width)
this.updateResizableConstraints()
this.emitUpdate()
return Promise.resolve()
}
public _resetBranchDropdownWidth(): Promise<void> {
this.branchDropdownWidth = {
...this.branchDropdownWidth,
value: defaultBranchDropdownWidth,
}
localStorage.removeItem(branchDropdownWidthConfigKey)
this.updateResizableConstraints()
this.emitUpdate()
return Promise.resolve()
}
public _setCommitSummaryWidth(width: number): Promise<void> {
this.commitSummaryWidth = { ...this.commitSummaryWidth, value: width }
setNumber(commitSummaryWidthConfigKey, width)

View File

@ -3211,6 +3211,7 @@ export class App extends React.Component<IAppProps, IAppState> {
<BranchDropdown
dispatcher={this.props.dispatcher}
isOpen={isOpen}
branchDropdownWidth={this.state.branchDropdownWidth}
onDropDownStateChanged={this.onBranchDropdownStateChanged}
repository={repository}
repositoryState={selection.state}

View File

@ -953,6 +953,14 @@ export class Dispatcher {
return this.appStore._setSidebarWidth(width)
}
public setBranchDropdownWidth(width: number): Promise<void> {
return this.appStore._setBranchDropdownWidth(width)
}
public resetBranchDropdownWidth(): Promise<void> {
return this.appStore._resetBranchDropdownWidth()
}
/**
* Set the update banner's visibility
*/

View File

@ -3,10 +3,12 @@ import { Dispatcher } from '../dispatcher'
import * as octicons from '../octicons/octicons.generated'
import { OcticonSymbol, syncClockwise } from '../octicons'
import { Repository } from '../../models/repository'
import { Resizable } from '../resizable'
import { TipState } from '../../models/tip'
import { ToolbarDropdown, DropdownState } from './dropdown'
import {
FoldoutType,
IConstrainedValue,
IRepositoryState,
isRebaseConflictState,
} from '../../lib/app-state'
@ -33,6 +35,9 @@ interface IBranchDropdownProps {
/** The current repository state as derived from AppState */
readonly repositoryState: IRepositoryState
/** The width of the resisable branch drop down button, as derived from AppState. */
readonly branchDropdownWidth: IConstrainedValue
/** Whether or not the branch dropdown is currently open */
readonly isOpen: boolean
@ -190,33 +195,48 @@ export class BranchDropdown extends React.Component<IBranchDropdownProps> {
return (
<>
<ToolbarDropdown
className="branch-button"
icon={icon}
iconClassName={iconClassName}
title={title}
description={description}
onContextMenu={this.onBranchToolbarButtonContextMenu}
tooltip={isOpen ? undefined : tooltip}
onDropdownStateChanged={this.onDropDownStateChanged}
dropdownContentRenderer={this.renderBranchFoldout}
dropdownState={currentState}
disabled={disabled}
showDisclosureArrow={canOpen}
progressValue={progressValue}
buttonClassName={buttonClassName}
onMouseEnter={this.onMouseEnter}
onlyShowTooltipWhenOverflowed={true}
isOverflowed={isDescriptionOverflowed}
enableFocusTrap={enableFocusTrap}
<Resizable
width={this.props.branchDropdownWidth.value}
onReset={this.onReset}
onResize={this.onResize}
maximumWidth={600}
>
{this.renderPullRequestInfo()}
</ToolbarDropdown>
{this.props.showCIStatusPopover && this.renderPopover()}
<ToolbarDropdown
className="branch-button"
icon={icon}
iconClassName={iconClassName}
title={title}
description={description}
onContextMenu={this.onBranchToolbarButtonContextMenu}
tooltip={isOpen ? undefined : tooltip}
onDropdownStateChanged={this.onDropDownStateChanged}
dropdownContentRenderer={this.renderBranchFoldout}
dropdownState={currentState}
disabled={disabled}
showDisclosureArrow={canOpen}
progressValue={progressValue}
buttonClassName={buttonClassName}
onMouseEnter={this.onMouseEnter}
onlyShowTooltipWhenOverflowed={true}
isOverflowed={isDescriptionOverflowed}
enableFocusTrap={enableFocusTrap}
>
{this.renderPullRequestInfo()}
</ToolbarDropdown>
{this.props.showCIStatusPopover && this.renderPopover()}
</Resizable>
</>
)
}
private onResize = (width: number) => {
this.props.dispatcher.setBranchDropdownWidth(width)
}
private onReset = () => {
this.props.dispatcher.resetBranchDropdownWidth()
}
/**
* Method to capture when the mouse is over the branch dropdown button.
*

View File

@ -352,7 +352,7 @@ export class ToolbarDropdown extends React.Component<
}
return {
position: 'absolute',
position: 'fixed',
top: rect.bottom,
left: 0,
width: '100%',

View File

@ -4,14 +4,14 @@
height: 100%;
display: flex;
flex-direction: column;
width: 365px;
width: 100%;
& > .tab-bar {
border-top: var(--base-border);
}
.branches-list {
width: 365px;
width: 100%;
min-height: 0;
}

View File

@ -39,7 +39,7 @@
.toolbar-button {
&.branch-toolbar-button {
width: 230px;
width: 100%;
}
&.revert-progress {
width: 230px;