-
-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP : #258 #666
WIP : #258 #666
Changes from 5 commits
ceb955d
601c1e8
7fa4345
1413137
84c12f4
699e87d
945b03f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,6 +188,18 @@ export class Sync { | |
return matchedFolders.length > 0; | ||
}); | ||
} | ||
const customFileKeys: string[] = Object.keys( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. upload additional files |
||
customSettings.customFiles | ||
); | ||
if (customFileKeys.length > 0) { | ||
for (const key of customFileKeys) { | ||
const val = customSettings.customFiles[key]; | ||
const customFile: File = await FileService.GetCustomFile(val, key); | ||
if (customFile !== null) { | ||
allSettingFiles.push(customFile); | ||
} | ||
} | ||
} | ||
} else { | ||
Commons.LogException(null, common.ERROR_MESSAGE, true); | ||
return; | ||
|
@@ -437,7 +449,21 @@ export class Sync { | |
keys.forEach(gistName => { | ||
if (res.data.files[gistName]) { | ||
if (res.data.files[gistName].content) { | ||
if (gistName.indexOf(".") > -1) { | ||
const prefix = FileService.CUSTOMIZED_SYNC_PREFIX; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. download additional files |
||
if (gistName.indexOf(prefix) > -1) { | ||
const fileName = gistName.split(prefix).join(""); // |customized_sync|.htmlhintrc => .htmlhintrc | ||
if (!(fileName in customSettings.customFiles)) { | ||
// syncLocalSettings.json > customFiles doesn't have key | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. skip download if does not set download path. |
||
} | ||
const f: File = new File( | ||
fileName, | ||
res.data.files[gistName].content, | ||
customSettings.customFiles[fileName], | ||
gistName | ||
); | ||
updatedFiles.push(f); | ||
} else if (gistName.indexOf(".") > -1) { | ||
if ( | ||
env.OsType === OsType.Mac && | ||
gistName === env.FILE_KEYBINDING_DEFAULT | ||
|
@@ -559,10 +585,15 @@ export class Sync { | |
if (file.gistName === env.FILE_KEYBINDING_MAC) { | ||
file.fileName = env.FILE_KEYBINDING_DEFAULT; | ||
} | ||
const filePath: string = await FileService.CreateDirTree( | ||
env.USER_FOLDER, | ||
file.fileName | ||
); | ||
let filePath: string = ""; | ||
if (file.filePath !== null) { | ||
filePath = await FileService.CreateCustomDirTree(file.filePath); | ||
} else { | ||
filePath = await FileService.CreateDirTree( | ||
env.USER_FOLDER, | ||
file.fileName | ||
); | ||
} | ||
|
||
actionList.push( | ||
FileService.WriteFile(filePath, content) | ||
|
@@ -699,6 +730,8 @@ export class Sync { | |
"cmd.otherOptions.toggleAutoDownload", | ||
"cmd.otherOptions.toggleSummaryPage", | ||
"cmd.otherOptions.preserve", | ||
"cmd.otherOptions.customizedSync", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create new advanced option |
||
"cmd.otherOptions.downloadCustomFile", | ||
"cmd.otherOptions.joinCommunity", | ||
"cmd.otherOptions.openIssue", | ||
"cmd.otherOptions.releaseNotes" | ||
|
@@ -817,22 +850,89 @@ export class Sync { | |
} | ||
}, | ||
8: async () => { | ||
// add customized sync file | ||
const options: vscode.InputBoxOptions = { | ||
ignoreFocusOut: true, | ||
placeHolder: localize("cmd.otherOptions.customizedSync.placeholder"), | ||
prompt: localize("cmd.otherOptions.customizedSync.prompt") | ||
}; | ||
const input = await vscode.window.showInputBox(options); | ||
|
||
if (input) { | ||
const fileName: string = FileService.ExtractFileName(input); | ||
if (fileName === "") { | ||
return; | ||
} | ||
customSettings.customFiles[fileName] = input; | ||
const done: boolean = await common.SetCustomSettings(customSettings); | ||
if (done) { | ||
vscode.window.showInformationMessage( | ||
localize("cmd.otherOptions.customizedSync.done", fileName) | ||
); | ||
} | ||
} | ||
}, | ||
9: async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. download customized file from gist option |
||
// Import customized sync file to workspace | ||
const customFiles = await this.getCustomFilesFromGist( | ||
customSettings, | ||
setting | ||
); | ||
if (customFiles.length < 1) { | ||
return; | ||
} | ||
const options: vscode.QuickPickOptions = { | ||
ignoreFocusOut: true, | ||
placeHolder: localize( | ||
"cmd.otherOptions.downloadCustomFile.placeholder" | ||
) | ||
}; | ||
const fileName = await vscode.window.showQuickPick( | ||
customFiles.map(file => { | ||
return file.fileName; | ||
}), | ||
options | ||
); | ||
// if not pick anyone, do nothing | ||
if (!fileName) { | ||
return; | ||
} | ||
const selected = customFiles.find(f => { | ||
return f.fileName === fileName; | ||
}); | ||
if (selected && vscode.workspace.rootPath) { | ||
const downloadPath = FileService.ConcatPath( | ||
vscode.workspace.rootPath, | ||
selected.fileName | ||
); | ||
const done = await FileService.WriteFile( | ||
downloadPath, | ||
selected.content | ||
); | ||
if (done) { | ||
vscode.window.showInformationMessage( | ||
localize("cmd.otherOptions.downloadCustomFile.done", downloadPath) | ||
); | ||
} | ||
} | ||
}, | ||
10: async () => { | ||
vscode.commands.executeCommand( | ||
"vscode.open", | ||
vscode.Uri.parse( | ||
"https://join.slack.com/t/codesettingssync/shared_invite/enQtMzE3MjY5NTczNDMwLTYwMTIwNGExOGE2MTJkZWU0OTU5MmI3ZTc4N2JkZjhjMzY1OTk5OGExZjkwMDMzMDU4ZTBlYjk5MGQwZmMyNzk" | ||
) | ||
); | ||
}, | ||
9: async () => { | ||
11: async () => { | ||
vscode.commands.executeCommand( | ||
"vscode.open", | ||
vscode.Uri.parse( | ||
"https://github.com/shanalikhan/code-settings-sync/issues/new" | ||
) | ||
); | ||
}, | ||
10: async () => { | ||
12: async () => { | ||
vscode.commands.executeCommand( | ||
"vscode.open", | ||
vscode.Uri.parse( | ||
|
@@ -920,4 +1020,41 @@ export class Sync { | |
return; | ||
} | ||
} | ||
|
||
private async getCustomFilesFromGist( | ||
customSettings: CustomSettings, | ||
syncSetting: ExtensionConfig | ||
): Promise<File[]> { | ||
const github = new GitHubService( | ||
customSettings.token, | ||
customSettings.githubEnterpriseUrl | ||
); | ||
const res = await github.ReadGist(syncSetting.gist); | ||
if (!res) { | ||
Commons.LogException(res, "Sync : Unable to Read Gist.", true); | ||
return []; | ||
} | ||
const keys = Object.keys(res.data.files); | ||
const customFiles: File[] = []; | ||
keys.forEach(gistName => { | ||
if (res.data.files[gistName]) { | ||
if (res.data.files[gistName].content) { | ||
const prefix = FileService.CUSTOMIZED_SYNC_PREFIX; | ||
if (gistName.indexOf(prefix) > -1) { | ||
const fileName = gistName.split(prefix).join(""); // |customized_sync|.htmlhintrc => .htmlhintrc | ||
const f: File = new File( | ||
fileName, | ||
res.data.files[gistName].content, | ||
fileName in customSettings.customFiles | ||
? customSettings.customFiles[fileName] | ||
: null, | ||
gistName | ||
); | ||
customFiles.push(f); | ||
} | ||
} | ||
} | ||
}); | ||
return customFiles; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some util methods