Skip to content

Commit

Permalink
Add Hg package
Browse files Browse the repository at this point in the history
  • Loading branch information
westbury committed Oct 22, 2019
1 parent 0782a4f commit 5d5735c
Show file tree
Hide file tree
Showing 69 changed files with 8,808 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@theia/filesystem": "^0.9.0",
"@theia/getting-started": "^0.9.0",
"@theia/git": "^0.9.0",
"@theia/hg": "^0.9.0",
"@theia/java": "^0.9.0",
"@theia/java-debug": "^0.9.0",
"@theia/json": "^0.9.0",
Expand Down
1 change: 1 addition & 0 deletions examples/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@theia/filesystem": "^0.9.0",
"@theia/getting-started": "^0.9.0",
"@theia/git": "^0.9.0",
"@theia/hg": "^0.9.0",
"@theia/java": "^0.9.0",
"@theia/java-debug": "^0.9.0",
"@theia/json": "^0.9.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/hg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Theia - Git Integration

A visual git client for the Theia IDE.
Providing a user interface for authoring commits (staging, etc.) and the basic git commands like `pull`, `merge`, `push` and `fetch`.

## License
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
10 changes: 10 additions & 0 deletions packages/hg/compile.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../configs/base.tsconfig",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
]
}
75 changes: 75 additions & 0 deletions packages/hg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "@theia/hg",
"version": "0.9.0",
"description": "Theia - Mercurial Integration",
"dependencies": {
"@theia/core": "^0.9.0",
"@theia/editor": "^0.9.0",
"@theia/filesystem": "^0.9.0",
"@theia/languages": "^0.9.0",
"@theia/navigator": "^0.9.0",
"@theia/scm": "^0.9.0",
"@theia/workspace": "^0.9.0",
"@types/diff": "^3.2.2",
"@types/fs-extra": "^4.0.2",
"@types/p-queue": "^2.3.1",
"upath": "^1.0.2",
"diff": "^3.4.0",
"dugite-extra": "0.1.11",
"find-git-exec": "^0.0.1-alpha.2",
"find-git-repositories": "^0.1.0",
"fs-extra": "^4.0.2",
"lodash.debounce": "^4.0.8",
"moment": "^2.21.0",
"octicons": "^7.1.0",
"p-queue": "^2.4.2",
"ts-md5": "^1.2.2"
},
"publishConfig": {
"access": "public"
},
"theiaExtensions": [
{
"frontend": "lib/browser/hg-frontend-module",
"backend": "lib/node/hg-backend-module"
},
{
"backend": "lib/node/env/hg-env-module",
"backendElectron": "lib/electron-node/env/electron-hg-env-module"
},
{
"frontend": "lib/browser/prompt/hg-prompt-module",
"frontendElectron": "lib/electron-browser/prompt/electron-hg-prompt-module"
}
],
"keywords": [
"theia-extension"
],
"license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0",
"repository": {
"type": "git",
"url": "https://github.com/theia-ide/theia.git"
},
"bugs": {
"url": "https://github.com/theia-ide/theia/issues"
},
"homepage": "https://github.com/theia-ide/theia",
"files": [
"lib",
"src"
],
"scripts": {
"prepare": "yarn run clean && yarn run build",
"clean": "theiaext clean",
"build": "theiaext build",
"watch": "theiaext watch",
"test": "theiaext test --no-cluster",
"test:watch": "theiaext test:watch"
},
"devDependencies": {
"@theia/ext-scripts": "^0.9.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
}
}
117 changes: 117 additions & 0 deletions packages/hg/src/browser/diff/hg-diff-contribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { CommandRegistry, Command, MenuModelRegistry, SelectionService, MessageService } from '@theia/core/lib/common';
import { FrontendApplication, AbstractViewContribution } from '@theia/core/lib/browser';
import { WidgetManager } from '@theia/core/lib/browser/widget-manager';
import { injectable, inject } from 'inversify';
import { HgDiffWidget, HG_DIFF } from './hg-diff-widget';
import { open, OpenerService } from '@theia/core/lib/browser';
import { NavigatorContextMenu } from '@theia/navigator/lib/browser/navigator-contribution';
import { UriCommandHandler, UriAwareCommandHandler } from '@theia/core/lib/common/uri-command-handler';
import { HgQuickOpenService } from '../hg-quick-open-service';
import { FileSystem } from '@theia/filesystem/lib/common';
import { DiffUris } from '@theia/core/lib/browser/diff-uris';
import URI from '@theia/core/lib/common/uri';
import { HG_RESOURCE_SCHEME } from '../hg-resource';
import { Hg } from '../../common';
import { HgRepositoryProvider } from '../hg-repository-provider';

export namespace HgDiffCommands {
export const OPEN_FILE_DIFF: Command = {
id: 'hg-diff:open-file-diff',
category: 'Hg Diff',
label: 'Compare With...'
};
}

@injectable()
export class HgDiffContribution extends AbstractViewContribution<HgDiffWidget> {

constructor(
@inject(SelectionService) protected readonly selectionService: SelectionService,
@inject(WidgetManager) protected readonly widgetManager: WidgetManager,
@inject(FrontendApplication) protected readonly app: FrontendApplication,
@inject(HgQuickOpenService) protected readonly quickOpenService: HgQuickOpenService,
@inject(FileSystem) protected readonly fileSystem: FileSystem,
@inject(OpenerService) protected openerService: OpenerService,
@inject(MessageService) protected readonly notifications: MessageService,
@inject(HgRepositoryProvider) protected readonly repositoryProvider: HgRepositoryProvider
) {
super({
widgetId: HG_DIFF,
widgetName: 'Hg diff',
defaultWidgetOptions: {
area: 'left',
rank: 500
}
});
}

registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction(NavigatorContextMenu.COMPARE, {
commandId: HgDiffCommands.OPEN_FILE_DIFF.id
});
}

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(HgDiffCommands.OPEN_FILE_DIFF, this.newUriAwareCommandHandler({
isVisible: uri => !!this.repositoryProvider.findRepository(uri),
isEnabled: uri => !!this.repositoryProvider.findRepository(uri),
execute: async fileUri => {
await this.quickOpenService.chooseTagsAndBranches(
async (fromRevision, toRevision) => {
const uri = fileUri.toString();
const fileStat = await this.fileSystem.getFileStat(uri);
const options: Hg.Options.Status = {
uri,
range: {
fromRevision,
toRevision
}
};
if (fileStat) {
if (fileStat.isDirectory) {
this.showWidget(options);
} else {
const fromURI = fileUri.withScheme(HG_RESOURCE_SCHEME).withQuery(fromRevision);
const toURI = fileUri;
const diffUri = DiffUris.encode(fromURI, toURI);
if (diffUri) {
open(this.openerService, diffUri).catch(e => {
this.notifications.error(e.message);
});
}
}
}
}, this.repositoryProvider.findRepository(fileUri));
}
}));
}

async showWidget(options: Hg.Options.Status): Promise<HgDiffWidget> {
const widget = await this.widget;
await widget.setContent(options);
return this.openView({
activate: true
});
}

protected newUriAwareCommandHandler(handler: UriCommandHandler<URI>): UriAwareCommandHandler<URI> {
return new UriAwareCommandHandler(this.selectionService, handler);
}

}
34 changes: 34 additions & 0 deletions packages/hg/src/browser/diff/hg-diff-frontend-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { interfaces } from 'inversify';
import { HgDiffContribution } from './hg-diff-contribution';
import { WidgetFactory, bindViewContribution } from '@theia/core/lib/browser';
import { HgDiffWidget, HG_DIFF } from './hg-diff-widget';

import '../../../src/browser/style/diff.css';

export function bindHgDiffModule(bind: interfaces.Bind): void {

bind(HgDiffWidget).toSelf();
bind(WidgetFactory).toDynamicValue(ctx => ({
id: HG_DIFF,
createWidget: () => ctx.container.get<HgDiffWidget>(HgDiffWidget)
}));

bindViewContribution(bind, HgDiffContribution);

}
Loading

0 comments on commit 5d5735c

Please sign in to comment.