Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.

Commit ecbd4af

Browse files
authored
Feature/add git commit functionality (#2441)
As part of fleshing out the VCS this pr adds the ability to commit a file using the git sidebar. Additions: * Menu command toggle vcs visibility * Recent Commits Section: commits made whilst in oni (later might be preferable to get a git log rather than commits from oni) * Commiting: see below ![vcs_commit](https://user-images.githubusercontent.com/22454918/43024011-bd3e27ac-8c64-11e8-8d2e-944047d7ed8d.gif)
1 parent 4ce7b50 commit ecbd4af

35 files changed

+1495
-435
lines changed

browser/src/Input/KeyBindings.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ export const applyDefaultKeyBindings = (oni: Oni.Plugin.Api, config: Configurati
2828
editors.activeEditor.mode === "insert" || editors.activeEditor.mode === "cmdline_normal"
2929

3030
const oniWithSidebar = oni as Oni.Plugin.Api & ISidebar
31-
const isExplorerActive = () =>
32-
oniWithSidebar.sidebar.activeEntryId === "oni.sidebar.explorer" &&
31+
const isSidebarPaneOpen = (paneId: string) =>
32+
oniWithSidebar.sidebar.activeEntryId === paneId &&
3333
oniWithSidebar.sidebar.isFocused &&
3434
!isInsertOrCommandMode() &&
3535
!isMenuOpen()
3636

37+
const isExplorerActive = () => isSidebarPaneOpen("oni.sidebar.explorer")
38+
const isVCSActive = () => isSidebarPaneOpen("oni.sidebar.vcs")
39+
3740
const isMenuOpen = () => menu.isMenuOpen()
3841

3942
if (Platform.isMac()) {
@@ -159,4 +162,9 @@ export const applyDefaultKeyBindings = (oni: Oni.Plugin.Api, config: Configurati
159162
input.bind("j", "browser.scrollDown")
160163
input.bind("h", "browser.scrollLeft")
161164
input.bind("l", "browser.scrollRight")
165+
166+
// VCS
167+
input.bind("e", "vcs.openFile", isVCSActive)
168+
input.bind("<c-r>", "vcs.refresh", isVCSActive)
169+
input.bind("?", "vcs.showHelp", isVCSActive)
162170
}

browser/src/Services/Sidebar/SidebarStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export class SidebarManager {
6262
return this._contentSplit.isFocused
6363
}
6464

65+
get isVisible(): boolean {
66+
return this._contentSplit.isVisible
67+
}
68+
6569
public get store(): Store<ISidebarState> {
6670
return this._store
6771
}

browser/src/Services/VersionControl/VersionControlManager.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as React from "react"
66

77
import { store, SupportedProviders, VersionControlPane, VersionControlProvider } from "./"
88
import { Notifications } from "./../../Services/Notifications"
9-
import { Branch } from "./../../UI/components/VersionControl"
9+
import { Branch } from "./../../UI/components/VersionControl/Branch"
1010
import { MenuManager } from "./../Menu"
1111
import { SidebarManager } from "./../Sidebar"
1212
import { IWorkspace } from "./../Workspace"
@@ -15,6 +15,7 @@ interface ISendNotificationsArgs {
1515
detail: string
1616
level: "info" | "warn"
1717
title: string
18+
expiration?: number
1819
}
1920

2021
export type ISendVCSNotification = (args: ISendNotificationsArgs) => void
@@ -62,11 +63,11 @@ export class VersionControlManager {
6263
}
6364

6465
// Use arrow function to maintain this binding of sendNotification
65-
public sendNotification: ISendVCSNotification = ({ detail, level, title }) => {
66+
public sendNotification: ISendVCSNotification = ({ expiration = 3_000, ...args }) => {
6667
const notification = this._notifications.createItem()
67-
notification.setContents(title, detail)
68-
notification.setExpiration(3_000)
69-
notification.setLevel(level)
68+
notification.setContents(args.title, args.detail)
69+
notification.setExpiration(expiration)
70+
notification.setLevel(args.level)
7071
notification.show()
7172
}
7273

@@ -140,6 +141,8 @@ export class VersionControlManager {
140141
this._workspace,
141142
this._vcsProvider,
142143
this.sendNotification,
144+
this._commands,
145+
this._sidebar,
143146
store,
144147
)
145148
this._sidebar.add("code-fork", vcsPane)
@@ -170,15 +173,27 @@ export class VersionControlManager {
170173
}
171174

172175
private _registerCommands = () => {
176+
const toggleVCS = () => {
177+
this._sidebar.toggleVisibilityById("oni.sidebar.vcs")
178+
}
179+
180+
this._commands.registerCommand({
181+
command: "vcs.sidebar.toggle",
182+
name: "Version Control: Toggle Visibility",
183+
detail: "Toggles the vcs pane in the sidebar",
184+
execute: toggleVCS,
185+
enabled: () => this._configuration.getValue("experimental.vcs.sidebar"),
186+
})
187+
173188
this._commands.registerCommand({
174-
command: `oni.${this._vcs}.fetch`,
189+
command: `vcs.fetch`,
175190
name: "Fetch the selected branch",
176191
detail: "",
177192
execute: this._fetchBranch,
178193
})
179194

180195
this._commands.registerCommand({
181-
command: `oni.${this._vcs}.branches`,
196+
command: `vcs.branches`,
182197
name: `Local ${capitalize(this._vcs)} Branches`,
183198
detail: "Open a menu with a list of all local branches",
184199
execute: this._createBranchList,
@@ -194,6 +209,7 @@ export class VersionControlManager {
194209
}
195210

196211
try {
212+
// FIXME: there is race condition on deactivation of the provider
197213
const branch = await this._vcsProvider.getBranch()
198214
const diff = await this._vcsProvider.getDiff()
199215

0 commit comments

Comments
 (0)