mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
refactor
This commit is contained in:
parent
a5141247cf
commit
6e5cdd4458
34
package.json
34
package.json
@ -30,7 +30,7 @@
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-key-b",
|
||||
"command": "extension.magit-branching",
|
||||
"title": "Magit Branching",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
@ -39,6 +39,16 @@
|
||||
"title": "Magit Pushing",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-stage",
|
||||
"title": "Magit Stage",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-stage-all",
|
||||
"title": "Magit Stage All",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-help",
|
||||
"title": "Magit Help",
|
||||
@ -53,13 +63,21 @@
|
||||
"menus": {
|
||||
"commandPalette": [
|
||||
{
|
||||
"command": "extension.magit-key-b",
|
||||
"command": "extension.magit-branching",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-choose",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-stage",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-stage-all",
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-commit",
|
||||
"when": "editorLangId == magit-status"
|
||||
@ -106,7 +124,7 @@
|
||||
"when": "editorTextFocus && editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-key-b",
|
||||
"command": "extension.magit-branching",
|
||||
"key": "b",
|
||||
"when": "editorTextFocus && editorLangId == magit-status"
|
||||
},
|
||||
@ -120,6 +138,16 @@
|
||||
"key": "?",
|
||||
"when": "editorTextFocus && editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-stage",
|
||||
"key": "s",
|
||||
"when": "editorTextFocus && editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-stage-all",
|
||||
"key": "shift+s",
|
||||
"when": "editorTextFocus && editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-save-and-close-commit-msg",
|
||||
"key": "ctrl+c ctrl+c",
|
||||
|
@ -1,5 +1,10 @@
|
||||
import { window } from "vscode";
|
||||
|
||||
// TODO:
|
||||
// to be dynamic
|
||||
// Just show the keymap for vscode magit
|
||||
// that way its updated with users changes
|
||||
|
||||
export function magitHelp() {
|
||||
window.showInformationMessage(`Popup and dwim commands
|
||||
A Cherry-picking b Branching B Bisecting c Committing
|
||||
|
24
src/commands/stagingCommands.ts
Normal file
24
src/commands/stagingCommands.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { getCurrentMagitRepo } from "../utils/magitUtils";
|
||||
|
||||
// repository.apply( hunk.diff ) FOR Å STAGE HUNKS!
|
||||
|
||||
// NB! Trenger kanskje headeren til hele diffen for å utføre disse.
|
||||
// Den kan hektes på i et eget felt i Hunk-modellen, null stress joggedress!
|
||||
|
||||
export function magitStage() {
|
||||
let currentRepository = getCurrentMagitRepo();
|
||||
|
||||
if (currentRepository) {
|
||||
|
||||
currentRepository.apply("my cool diff");
|
||||
}
|
||||
}
|
||||
|
||||
export function magitStageAll() {
|
||||
let currentRepository = getCurrentMagitRepo();
|
||||
|
||||
if (currentRepository) {
|
||||
|
||||
currentRepository.apply("all my cool diffs");
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ import { MagitChange } from "../models/magitChange";
|
||||
import { encodeLocation } from "../contentProvider";
|
||||
import { workspace, window, ViewColumn } from "vscode";
|
||||
import { gitApi, magitRepositories } from "../extension";
|
||||
import { Repository, Status } from "../typings/git";
|
||||
import { Repository, Status, Change } from "../typings/git";
|
||||
import { FilePathUtils } from "../utils/filePathUtils";
|
||||
import { GitTextUtils } from "../utils/gitTextUtils";
|
||||
import { MagitRepository } from "../models/magitRepository";
|
||||
|
@ -8,6 +8,7 @@ import { magitStatus } from './commands/statusCommands';
|
||||
import { magitChoose } from './commands/chooseCommands';
|
||||
import { MagitRepository } from './models/magitRepository';
|
||||
import { magitCommit } from './commands/commitCommands';
|
||||
import { magitStage, magitStageAll } from './commands/stagingCommands';
|
||||
import { saveClose } from './commands/macros';
|
||||
|
||||
export const magitRepositories: { [id: string]: MagitRepository } = {};
|
||||
@ -42,12 +43,14 @@ export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-commit', magitCommit));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-choose', magitChoose));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-help', magitHelp));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-key-F', async () => {
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-pulling', async () => {
|
||||
// TODO: Options should be dynamically decided based on whether or not they can be done
|
||||
// e.g Pull in magit with no remotes results in: e elsewhere
|
||||
}));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-pushing', pushing));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-key-b', branching));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-branching', branching));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-stage', magitStage));
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-stage-all', magitStageAll));
|
||||
|
||||
context.subscriptions.push(commands.registerCommand('extension.magit-save-and-close-commit-msg', saveClose));
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ export class GitTextUtils {
|
||||
public static diffToHunks(diff: string): MagitChangeHunk[] {
|
||||
return diff
|
||||
.substring(diff.indexOf("@@"))
|
||||
.split(/^(?=@@.*@@.*$)/gm)
|
||||
.split(/\n(?=^@@.*@@.*$)/gm)
|
||||
.map(hunkText => ({ diff: hunkText }));
|
||||
}
|
||||
}
|
14
src/views/abstract/textView.ts
Normal file
14
src/views/abstract/textView.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { View } from "./view";
|
||||
import { Range } from "vscode";
|
||||
import * as Constants from '../../common/constants';
|
||||
|
||||
export abstract class TextView extends View {
|
||||
|
||||
textContent: string = "";
|
||||
|
||||
render(startLineNumber: number): string[] {
|
||||
let lines = this.textContent.split(Constants.LineSplitterRegex);
|
||||
this.range = new Range(startLineNumber, 0, lines.length, lines[lines.length-1].length);
|
||||
return [this.textContent];
|
||||
}
|
||||
}
|
@ -4,16 +4,16 @@ export abstract class View {
|
||||
|
||||
subViews: View[] = [];
|
||||
range: Range = new Range(0, 0, 0, 0);
|
||||
abstract onClicked(): any;
|
||||
|
||||
render(startLineNumber: number): string[] {
|
||||
|
||||
let currentLineNumber = startLineNumber;
|
||||
let render: string[] = [];
|
||||
|
||||
this.subViews.forEach(
|
||||
v => {
|
||||
let subViewRender = v.render(currentLineNumber);
|
||||
currentLineNumber += subViewRender.length;
|
||||
currentLineNumber += v.range.end.line - v.range.start.line;
|
||||
render.push(...subViewRender);
|
||||
}
|
||||
);
|
||||
@ -22,9 +22,14 @@ export abstract class View {
|
||||
return render;
|
||||
}
|
||||
|
||||
onClickedPosition(position: Position): void {
|
||||
click(position: Position): any {
|
||||
if (this.range.contains(position)) {
|
||||
this.subViews.forEach( subView => subView.onClickedPosition(position));
|
||||
let result = this.onClicked();
|
||||
let subResults = this.subViews
|
||||
.map( subView => subView.click(position))
|
||||
.filter(r => r);
|
||||
|
||||
return subResults.length > 0 ? subResults[0] : result;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
import { View } from "./view";
|
||||
import { Range } from "vscode";
|
||||
import { MagitChange } from "../models/magitChange";
|
||||
import { HunkView } from "./HunkView";
|
||||
import { Status } from "../typings/git";
|
||||
|
||||
export class ChangeView extends View {
|
||||
|
||||
constructor(private change: MagitChange) {
|
||||
super();
|
||||
if (this.change.hunks) {
|
||||
this.subViews = this.change.hunks.map(hunk => new HunkView(hunk));
|
||||
}
|
||||
}
|
||||
|
||||
render(startLineNumber: number): string[] {
|
||||
let render = [
|
||||
`${mapFileStatusToLabel(this.change.status)} ${this.change.uri.path}`,
|
||||
...super.render(startLineNumber + 1)];
|
||||
|
||||
// TODO: broken abstraction. Pass in extra content array as optional to render?
|
||||
this.range = new Range(startLineNumber, 0, this.range.end.line, this.range.end.character);
|
||||
|
||||
return render;
|
||||
}
|
||||
}
|
||||
|
||||
function mapFileStatusToLabel(status: Status): string {
|
||||
switch (status) {
|
||||
case Status.INDEX_MODIFIED:
|
||||
case Status.MODIFIED:
|
||||
return "modified";
|
||||
case Status.INDEX_ADDED:
|
||||
return "added";
|
||||
case Status.INDEX_DELETED:
|
||||
case Status.DELETED:
|
||||
return "deleted";
|
||||
case Status.INDEX_RENAMED:
|
||||
return "renamed";
|
||||
case Status.INDEX_COPIED:
|
||||
return "copied";
|
||||
case Status.UNTRACKED:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
36
src/views/changes/changeHeaderView.ts
Normal file
36
src/views/changes/changeHeaderView.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { TextView } from "../abstract/textView";
|
||||
import { MagitChange } from "../../models/magitChange";
|
||||
import { Status } from "../../typings/git";
|
||||
|
||||
export class ChangeHeaderView extends TextView {
|
||||
|
||||
constructor(private change: MagitChange) {
|
||||
super();
|
||||
this.textContent = `${mapFileStatusToLabel(this.change.status)} ${this.change.uri.path}`;
|
||||
}
|
||||
|
||||
onClicked(): any {
|
||||
return this.change;
|
||||
}
|
||||
}
|
||||
|
||||
function mapFileStatusToLabel(status: Status): string {
|
||||
switch (status) {
|
||||
case Status.INDEX_MODIFIED:
|
||||
case Status.MODIFIED:
|
||||
return "modified";
|
||||
case Status.INDEX_ADDED:
|
||||
return "added";
|
||||
case Status.INDEX_DELETED:
|
||||
case Status.DELETED:
|
||||
return "deleted";
|
||||
case Status.INDEX_RENAMED:
|
||||
return "renamed";
|
||||
case Status.INDEX_COPIED:
|
||||
return "copied";
|
||||
case Status.UNTRACKED:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
19
src/views/changes/changeView.ts
Normal file
19
src/views/changes/changeView.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { View } from "../abstract/view";
|
||||
import { Range } from "vscode";
|
||||
import { MagitChange } from "../../models/magitChange";
|
||||
import { HunkView } from "./HunkView";
|
||||
import { Status } from "../../typings/git";
|
||||
import { ChangeHeaderView } from "./changeHeaderView";
|
||||
|
||||
export class ChangeView extends View {
|
||||
|
||||
constructor(private change: MagitChange) {
|
||||
super();
|
||||
this.subViews = [new ChangeHeaderView(change)];
|
||||
if (this.change.hunks) {
|
||||
this.subViews.push(...this.change.hunks.map(hunk => new HunkView(hunk)));
|
||||
}
|
||||
}
|
||||
|
||||
onClicked(): any { }
|
||||
}
|
14
src/views/changes/hunkView.ts
Normal file
14
src/views/changes/hunkView.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { MagitChangeHunk } from "../../models/magitChangeHunk";
|
||||
import { TextView } from "../abstract/textView";
|
||||
|
||||
export class HunkView extends TextView {
|
||||
|
||||
constructor(private changeHunk: MagitChangeHunk) {
|
||||
super();
|
||||
this.textContent = changeHunk.diff;
|
||||
}
|
||||
|
||||
onClicked(): any {
|
||||
return this.changeHunk;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
import { Position } from "vscode";
|
||||
import { MagitChangeHunk } from "../models/magitChangeHunk";
|
||||
import { TextView } from "./textView";
|
||||
|
||||
export class HunkView extends TextView {
|
||||
|
||||
constructor(private changeHunk: MagitChangeHunk) {
|
||||
super();
|
||||
this.content = changeHunk.diff;
|
||||
}
|
||||
|
||||
onClickedPosition(position: Position) : any {
|
||||
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ import * as vscode from 'vscode';
|
||||
import { MagitState } from '../models/magitStatus';
|
||||
import { MagitChange } from "../models/magitChange";
|
||||
import { Status } from '../typings/git';
|
||||
import { ChangeView } from './changeView';
|
||||
import { ChangeView } from './changes/changeView';
|
||||
|
||||
export default class StatusDocument {
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
import { View } from "./view";
|
||||
|
||||
export class TextView extends View {
|
||||
|
||||
content: string = "";
|
||||
|
||||
render(startLineNumber: number): string[] {
|
||||
return [this.content];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user