-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from GustavoASC/copy-url
Developed command to copy URL to clipboard
- Loading branch information
Showing
13 changed files
with
205 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DriveModel } from "../model/driveModel"; | ||
import { IDriveView } from "../view/driveView"; | ||
import { IControllerSupport } from "./controllerSupport"; | ||
import { DriveUrlBuilder } from "../model/driveUrlBuilder"; | ||
import { IClipboardProvider } from "./clipboardProvider"; | ||
|
||
export class CopyToClipboardSupport implements IControllerSupport { | ||
|
||
private builder = new DriveUrlBuilder(); | ||
|
||
constructor(private provider: IClipboardProvider) {}; | ||
|
||
fireCommand(model: DriveModel, view: IDriveView, fileId: string): void { | ||
const url = this.builder.buildUrlFromId(model, fileId); | ||
if (url) { | ||
this.provider.writeToClipboard(url); | ||
view.showInformationMessage('Remote URL copied to clipboard.') | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export interface IClipboardProvider { | ||
|
||
writeToClipboard(text: string): void; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { DriveModel } from "./driveModel"; | ||
import { DriveFile, FileType } from "./driveTypes"; | ||
|
||
const DRIVE_WEBSITE = 'https://drive.google.com'; | ||
|
||
export class DriveUrlBuilder { | ||
|
||
buildUrlFromId(model: DriveModel, fileId: string): string | undefined { | ||
const file = model.getDriveFile(fileId); | ||
if (file) { | ||
return this.buildUrlFromFile(file); | ||
} | ||
return undefined; | ||
} | ||
|
||
private buildUrlFromFile(file: DriveFile): string { | ||
const location = this.getFileTypeLocation(file.type); | ||
const finalUrl = DRIVE_WEBSITE + location + file.id; | ||
return finalUrl; | ||
} | ||
|
||
private getFileTypeLocation(type: FileType): string { | ||
return type == FileType.DIRECTORY | ||
? '/drive/folders/' | ||
: '/file/d/'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { expect } from 'chai'; | ||
import 'mocha'; | ||
import { DriveModel } from '../../../drive/model/driveModel'; | ||
import { DriveFile, FileType } from '../../../drive/model/driveTypes'; | ||
import { AbstractMockFileProvider } from './abstractFileProvider.test'; | ||
import { DriveUrlBuilder } from '../../../drive/model/driveUrlBuilder'; | ||
|
||
describe('Remote URL manipulation', () => { | ||
|
||
it('Checks remote URL building', async () => { | ||
const model = new DriveModel(new MockFileProvider()); | ||
await model.listFiles('root'); | ||
const urlBuilder = new DriveUrlBuilder(); | ||
expect('https://drive.google.com/file/d/1Cdffsdfsdfsdfdfocz').to.equal(urlBuilder.buildUrlFromId(model, '1Cdffsdfsdfsdfdfocz')); | ||
expect('https://drive.google.com/drive/folders/1C7udIKXCkxsvXO37gCBpfaasqn9wocz').to.equal(urlBuilder.buildUrlFromId(model, '1C7udIKXCkxsvXO37gCBpfaasqn9wocz')); | ||
expect(undefined).to.equal(urlBuilder.buildUrlFromId(model, 'xxxxxx')); | ||
}); | ||
|
||
}); | ||
|
||
class MockFileProvider extends AbstractMockFileProvider { | ||
|
||
provideFiles(parentFolderId: string): Promise<DriveFile[]> { | ||
return new Promise((resolve) => { | ||
const firstFolder: DriveFile = { iconLink: 'http://www.mylink.com/folder', id: '1C7udIKXadsdssdsadsadsddsocz', name: 'VSCode', type: FileType.DIRECTORY, size: 0, createdTime: 1341393000000, modifiedTime: 1341393000000 }; | ||
const secondFolder: DriveFile = { iconLink: 'http://www.mylink.com/folder', id: '1C7udIKXCkxsvXO37gvfbfbdfbHihn9wocz', name: 'subFolder', type: FileType.DIRECTORY, parent: firstFolder, size: 0, createdTime: 1341393000000, modifiedTime: 1341393000000 }; | ||
const thirdFolder: DriveFile = { iconLink: 'http://www.mylink.com/folder', id: '1C7udIKXCkxsvXO37gCBpfaasqn9wocz', name: 'thirdFolder', type: FileType.DIRECTORY, parent: secondFolder, size: 0, createdTime: 1341393000000, modifiedTime: 1341393000000 }; | ||
const finalFile: DriveFile = { iconLink: 'http://www.mylink.com/file', id: '1Cdffsdfsdfsdfdfocz', name: 'myFile.txt', type: FileType.FILE, parent: secondFolder, size: 1325, createdTime: 1341393000000, modifiedTime: 1341393000000 }; | ||
resolve([thirdFolder, finalFile]); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IClipboardProvider } from "./drive/controller/clipboardProvider"; | ||
import * as vscode from 'vscode'; | ||
|
||
export class VscodeClipboardProvider implements IClipboardProvider { | ||
|
||
writeToClipboard(text: string): void { | ||
vscode.env.clipboard.writeText(text) | ||
} | ||
|
||
} |