mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
dispatch, file popup, and theming
This commit is contained in:
parent
c2a01678c1
commit
de982a094f
@ -1,7 +1,10 @@
|
||||
|
||||
## MINOR: NB! Thenables dont work with regular try/catch !
|
||||
|
||||
## MINOR: break out / refactor commands vs internal commands a bit?
|
||||
|
||||
## TODO: try making switches for a command
|
||||
## TODO: try making options for a command (e.g logging)
|
||||
|
||||
## Feature requests
|
||||
Feature#1
|
||||
|
10
package.json
10
package.json
@ -190,6 +190,16 @@
|
||||
"key": "ctrl+x g",
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-dispatch",
|
||||
"key": "ctrl+x alt+g",
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-file-popup",
|
||||
"key": "ctrl+c alt+g",
|
||||
"when": "editorTextFocus"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-toggle-fold",
|
||||
"key": "tab",
|
||||
|
@ -8,7 +8,7 @@ export class Command {
|
||||
|
||||
// MINOR: this class could maybe use some refactoring?
|
||||
|
||||
static primeRepo(command: (repository: MagitRepository) => Promise<void>, triggersUpdate: boolean = true): (editor: TextEditor) => Promise<void> {
|
||||
static primeRepo(command: (repository: MagitRepository) => Promise<any>, triggersUpdate: boolean = true): (editor: TextEditor) => Promise<any> {
|
||||
|
||||
return async (editor: TextEditor) => {
|
||||
const repository = MagitUtils.getCurrentMagitRepo(editor.document);
|
||||
@ -28,7 +28,7 @@ export class Command {
|
||||
};
|
||||
}
|
||||
|
||||
static primeRepoAndView(command: (repository: MagitRepository, view: DocumentView) => Promise<void>, triggersUpdate: boolean = true): (editor: TextEditor) => Promise<void> {
|
||||
static primeRepoAndView(command: (repository: MagitRepository, view: DocumentView) => Promise<any>, triggersUpdate: boolean = true): (editor: TextEditor) => Promise<any> {
|
||||
|
||||
return async (editor: TextEditor) => {
|
||||
const [repository, currentView] = MagitUtils.getCurrentMagitRepoAndView(editor);
|
||||
@ -48,8 +48,7 @@ export class Command {
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: prime file command with repo and file
|
||||
static primeFileCommand(command: (repository: MagitRepository, fileUri: Uri) => Promise<void>, triggersUpdate: boolean = true): (editor: TextEditor) => Promise<void> {
|
||||
static primeFileCommand(command: (repository: MagitRepository, fileUri: Uri) => Promise<any>, triggersUpdate: boolean = true): (editor: TextEditor) => Promise<any> {
|
||||
return async (editor: TextEditor) => {
|
||||
|
||||
const fileUri = editor.document.uri;
|
||||
|
@ -2,11 +2,12 @@ import { Uri } from 'vscode';
|
||||
import { MenuUtil, MenuState } from '../menu/menu';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
import { magitCommit } from './commitCommands';
|
||||
import { stageFile } from './stagingCommands';
|
||||
|
||||
const branchingMenu = {
|
||||
title: 'File Actions',
|
||||
commands: [
|
||||
{ label: 's', description: 'Stage', action: () => { } },
|
||||
{ label: 's', description: 'Stage', action: ({ repository, data }: MenuState) => stageFile(repository, data as Uri) },
|
||||
{ label: 'u', description: 'Unstage', action: () => { } },
|
||||
{ label: 'c', description: 'Commit', action: ({ repository }: MenuState) => magitCommit(repository) },
|
||||
// { label: 'D', description: 'Diff...', action: () => { } },
|
||||
|
@ -5,24 +5,24 @@ export function magitHelp() {
|
||||
|
||||
return workspace.openTextDocument({
|
||||
content: `Popup and dwim commands
|
||||
A Cherry-picking b Branching B Bisecting c Committing
|
||||
d Diffing D Change diffs e Ediff dwimming E Ediffing
|
||||
f Fetching F Pulling l Logging L Change logs
|
||||
m Merging M Remoting o Submodules O Subtrees
|
||||
P Pushing r Rebasing t Tagging T Notes
|
||||
V Reverting w Apply patches W Format patches X Resetting
|
||||
y Show Refs z Stashing ! Running % Worktree
|
||||
|
||||
Applying changes
|
||||
a Apply s Stage u Unstage
|
||||
v Reverse S Stage all U Unstage all
|
||||
k Discard
|
||||
|
||||
Essential commands
|
||||
g refresh current buffer
|
||||
TAB toggle section at point
|
||||
RET visit thing at point
|
||||
C-h m show all key bindings`,
|
||||
A Cherry-picking b Branching B Bisecting c Committing
|
||||
d Diffing D Change diffs e Ediff dwimming E Ediffing
|
||||
f Fetching F Pulling l Logging L Change logs
|
||||
m Merging M Remoting o Submodules O Subtrees
|
||||
P Pushing r Rebasing t Tagging T Notes
|
||||
V Reverting w Apply patches W Format patches X Resetting
|
||||
y Show Refs z Stashing ! Running % Worktree
|
||||
|
||||
Applying changes
|
||||
a Apply s Stage u Unstage
|
||||
v Reverse S Stage all U Unstage all
|
||||
k Discard
|
||||
|
||||
Essential commands
|
||||
g refresh current buffer
|
||||
TAB toggle section at point
|
||||
RET visit thing at point
|
||||
C-h m show all key bindings`,
|
||||
language: 'magit'
|
||||
}).then(doc => window.showTextDocument(doc, { viewColumn: MagitUtils.oppositeActiveViewColumn(), preserveFocus: true, preview: true }));
|
||||
|
||||
|
@ -31,9 +31,7 @@ export async function magitStage(repository: MagitRepository, currentView: Docum
|
||||
|
||||
const magitChange = (selectedView as ChangeView).change;
|
||||
|
||||
return repository
|
||||
._repository
|
||||
.add([magitChange.uri], { update: magitChange.section === Section.Unstaged });
|
||||
return stageFile(repository, magitChange.uri, magitChange.section === Section.Unstaged);
|
||||
|
||||
} else if (selectedView instanceof ChangeSectionView) {
|
||||
const section = (selectedView as ChangeSectionView).section;
|
||||
@ -59,7 +57,7 @@ export async function magitStage(repository: MagitRepository, currentView: Docum
|
||||
const chosenFile = await QuickMenuUtil.showMenu(files);
|
||||
|
||||
if (chosenFile) {
|
||||
return repository._repository.add([chosenFile], { update: false });
|
||||
return stageFile(repository, chosenFile);
|
||||
}
|
||||
|
||||
}
|
||||
@ -119,4 +117,10 @@ export async function magitUnstageAll(repository: MagitRepository, currentView:
|
||||
if (await MagitUtils.confirmAction('Unstage all changes?')) {
|
||||
return commands.executeCommand('git.unstageAll');
|
||||
}
|
||||
}
|
||||
|
||||
export async function stageFile(repository: MagitRepository, fileUri: Uri, update = false) {
|
||||
return repository
|
||||
._repository
|
||||
.add([fileUri], { update });
|
||||
}
|
@ -34,13 +34,11 @@ export async function magitStatus(editor: TextEditor, preserveFocus = false): Pr
|
||||
return workspace.openTextDocument(view.uri).then(doc => window.showTextDocument(doc, { viewColumn: MagitUtils.oppositeActiveViewColumn(), preserveFocus, preview: false }));
|
||||
}
|
||||
}
|
||||
const magitRepo: MagitRepository = repository;
|
||||
magitRepositories.set(repository.rootUri.path, repository);
|
||||
|
||||
await internalMagitStatus(magitRepo);
|
||||
await internalMagitStatus(repository);
|
||||
|
||||
const uri = MagitStatusView.encodeLocation(magitRepo.rootUri.path);
|
||||
views.set(uri.toString(), new MagitStatusView(uri, magitRepo.magitState!));
|
||||
const uri = MagitStatusView.encodeLocation(repository.rootUri.path);
|
||||
views.set(uri.toString(), new MagitStatusView(uri, repository.magitState!));
|
||||
|
||||
return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, { viewColumn: MagitUtils.oppositeActiveViewColumn(), preserveFocus, preview: false })
|
||||
|
||||
|
@ -22,6 +22,8 @@ import { magitDiscardAtPoint } from './commands/discardCommands';
|
||||
import { merging } from './commands/mergingCommands';
|
||||
import { rebasing } from './commands/rebasingCommands';
|
||||
import { filePopup } from './commands/filePopupCommands';
|
||||
import { DispatchView } from './views/dispatchView';
|
||||
import MagitUtils from './utils/magitUtils';
|
||||
|
||||
export const magitRepositories: Map<string, MagitRepository> = new Map<string, MagitRepository>();
|
||||
export const views: Map<string, DocumentView> = new Map<string, DocumentView>();
|
||||
@ -78,15 +80,11 @@ export function activate(context: ExtensionContext) {
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-file-popup', Command.primeFileCommand(filePopup)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-dispatch', async () => {
|
||||
|
||||
// TODO: IDEA dispatch
|
||||
// dispatch should open and FOCUS a dispatch DocumentView
|
||||
// that does almost nothing! just contain the popup command text, and be a magit type view
|
||||
|
||||
// Present giant menu of POPUP dwim commands
|
||||
// possible?
|
||||
}));
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-dispatch', Command.primeRepo(async (repository: MagitRepository) => {
|
||||
const uri = DispatchView.encodeLocation(repository);
|
||||
views.set(uri.toString(), new DispatchView(uri));
|
||||
return workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, { viewColumn: MagitUtils.oppositeActiveViewColumn(), preview: false }));
|
||||
}, false)));
|
||||
|
||||
context.subscriptions.push(commands.registerTextEditorCommand('extension.magit-toggle-fold', Command.primeRepoAndView(async (repo: MagitRepository, view: DocumentView) => {
|
||||
const selectedView = view.click(window.activeTextEditor!.selection.active);
|
||||
|
@ -30,10 +30,9 @@ export default class ContentProvider implements vscode.TextDocumentContentProvid
|
||||
}
|
||||
for (const visibleEditor of vscode.window.visibleTextEditors) {
|
||||
if (visibleEditor.document.uri.scheme === Constants.MagitUriScheme) {
|
||||
// MINOR: unecessary i think
|
||||
// if (FilePathUtils.isDescendant(visibleEditor.document.uri.query, doc.uri.fsPath)) {
|
||||
return magitStatus(visibleEditor, true);
|
||||
// }
|
||||
if (FilePathUtils.isDescendant(visibleEditor.document.uri.query, doc.uri.fsPath)) {
|
||||
return magitStatus(visibleEditor, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
@ -13,23 +13,16 @@ export default class MagitUtils {
|
||||
|
||||
if (!repository) {
|
||||
|
||||
const activeWorkspaceFolder = workspace.getWorkspaceFolder(document.uri);
|
||||
|
||||
if (activeWorkspaceFolder) {
|
||||
const workspaceRootPath = activeWorkspaceFolder.uri.path;
|
||||
|
||||
// MINOR: Any point in reusing repo from this map?
|
||||
for (const [key, repo] of magitRepositories.entries()) {
|
||||
if (FilePathUtils.isDescendant(key, workspaceRootPath)) {
|
||||
return repo;
|
||||
}
|
||||
// MINOR: Any point in reusing repo from this map?
|
||||
for (const [key, repo] of magitRepositories.entries()) {
|
||||
if (FilePathUtils.isDescendant(key, document.uri.path)) {
|
||||
return repo;
|
||||
}
|
||||
|
||||
repository = gitApi.repositories.filter(r => FilePathUtils.isDescendant(r.rootUri.path, workspaceRootPath))[0];
|
||||
} else {
|
||||
// MINOR: could be nice to rather show the list of repos to choose from?
|
||||
throw new Error('Current file not part of a workspace');
|
||||
}
|
||||
|
||||
// First time encountering this repo
|
||||
repository = gitApi.repositories.filter(r => FilePathUtils.isDescendant(r.rootUri.path, document.uri.path))[0];
|
||||
magitRepositories.set(repository.rootUri.path, repository);
|
||||
}
|
||||
|
||||
return repository;
|
||||
|
31
src/views/dispatchView.ts
Normal file
31
src/views/dispatchView.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { DocumentView } from './general/documentView';
|
||||
import { Uri } from 'vscode';
|
||||
import * as Constants from '../common/constants';
|
||||
import { TextView } from './general/textView';
|
||||
import { MagitRepository } from '../models/magitRepository';
|
||||
|
||||
export class DispatchView extends DocumentView {
|
||||
|
||||
static UriPath: string = 'dispatch.magit';
|
||||
needsUpdate = false;
|
||||
|
||||
constructor(public uri: Uri) {
|
||||
super(uri);
|
||||
|
||||
this.addSubview(new TextView(`Popup and dwim commands
|
||||
A Cherry-picking b Branching B Bisecting c Committing
|
||||
d Diffing D Change diffs e Ediff dwimming E Ediffing
|
||||
f Fetching F Pulling l Logging L Change logs
|
||||
m Merging M Remoting o Submodules O Subtrees
|
||||
P Pushing r Rebasing t Tagging T Notes
|
||||
V Reverting w Apply patches W Format patches X Resetting
|
||||
y Show Refs z Stashing ! Running % Worktree
|
||||
`));
|
||||
}
|
||||
|
||||
public update(repository: MagitRepository): void { }
|
||||
|
||||
static encodeLocation(repository: MagitRepository): Uri {
|
||||
return Uri.parse(`${Constants.MagitUriScheme}:${DispatchView.UriPath}?${repository.rootUri.path}`);
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
},
|
||||
"sectionHeader": {
|
||||
"match": "Untracked files|((Unstaged|Staged) changes)|Stashes|Recent commits|Unmerged into|Unpulled from|GitError!|(Merging .*(?= \\())|(Rebasing .* onto .*$)|Stash@{\\d+}",
|
||||
"name": "markup.bold keyword.section.header.magit"
|
||||
"name": "strong keyword.section.header.magit"
|
||||
},
|
||||
"highlights": {
|
||||
"match": "^(join)",
|
||||
@ -32,7 +32,7 @@
|
||||
},
|
||||
"modified": {
|
||||
"match": "^(modified|new file|deleted|renamed|copied|unmerged) .*$",
|
||||
"name": "markup.bold source.magit"
|
||||
"name": "strong"
|
||||
},
|
||||
"diff": {
|
||||
"begin": "(?=^@@)",
|
||||
|
Loading…
Reference in New Issue
Block a user