|
1 | 1 | // The module 'vscode' contains the VS Code extensibility API |
2 | 2 | // Import the module and reference it with the alias vscode in your code below |
3 | 3 | import axios from 'axios'; |
4 | | -import * as apiClient from '@hackmd/api'; |
5 | | -import { MdTextDocumentContentProvider } from './mdTextDocument'; |
6 | 4 | import * as vscode from 'vscode'; |
7 | 5 | import * as markdownitContainer from 'markdown-it-container'; |
8 | 6 | import * as S from 'string'; |
9 | 7 | import { store } from './store' |
10 | 8 | import { initializeStorage } from './store/storage' |
11 | 9 | import * as Prism from 'prismjs'; |
12 | | -import { checkLogin, login, refreshHistoryList } from './tree/index'; |
13 | | -import { HackMDTreeViewProvider } from './tree/index' |
| 10 | +import { registerCommand } from './commands' |
14 | 11 |
|
15 | 12 | require('prismjs/components/prism-wiki'); |
16 | 13 | require('prismjs/components/prism-haskell'); |
@@ -228,83 +225,11 @@ function highlightRender(code, lang) { |
228 | 225 | let highlight; |
229 | 226 | // this method is called when your extension is activated |
230 | 227 | // your extension is activated the very first time the command is executed |
231 | | -const API = new apiClient.default(); |
232 | 228 | axios.defaults.withCredentials = true; |
233 | 229 |
|
234 | 230 | export async function activate(context: vscode.ExtensionContext) { |
235 | 231 | initializeStorage(context); |
236 | | - context.subscriptions.push(vscode.commands.registerCommand('HackMD.login', async () => { |
237 | | - if (await checkLogin()) { |
238 | | - vscode.window.showInformationMessage('Already logged in, please log out first.'); |
239 | | - return; |
240 | | - } |
241 | | - |
242 | | - const email = await vscode.window.showInputBox({ |
243 | | - ignoreFocusOut: true, |
244 | | - password: false, |
245 | | - placeHolder: 'email', |
246 | | - prompt: 'Please enter your email account', |
247 | | - validateInput: (text) => { |
248 | | - if (text && text !== "") { |
249 | | - return undefined; |
250 | | - } else { |
251 | | - return 'Email cannot be empty'; |
252 | | - } |
253 | | - } |
254 | | - }); |
255 | | - const password = await vscode.window.showInputBox({ |
256 | | - ignoreFocusOut: true, |
257 | | - password: true, |
258 | | - placeHolder: 'password', |
259 | | - prompt: 'Please enter your password', |
260 | | - validateInput: (text) => { |
261 | | - if (text && text !== "") { |
262 | | - return undefined; |
263 | | - } else { |
264 | | - return 'password cannot be empty'; |
265 | | - } |
266 | | - } |
267 | | - }); |
268 | | - |
269 | | - context.globalState.update('email', email); |
270 | | - context.globalState.update('password', password); |
271 | | - |
272 | | - await login(context); |
273 | | - await refreshHistoryList(context); |
274 | | - })); |
275 | | - |
276 | | - context.subscriptions.push(vscode.commands.registerCommand('HackMD.logout', async () => { |
277 | | - if (!(await checkLogin())) { |
278 | | - vscode.window.showInformationMessage('Currently not logged in.'); |
279 | | - return; |
280 | | - } |
281 | | - await API.logout(); |
282 | | - store.isLogin = false; |
283 | | - context.globalState.update('isLogin', false); |
284 | | - vscode.window.showInformationMessage('Successfully logged out.'); |
285 | | - await refreshHistoryList(context); |
286 | | - })); |
287 | | - |
288 | | - const hackMDTreeViewProvider = new HackMDTreeViewProvider(store); |
289 | | - context.subscriptions.push( |
290 | | - vscode.window.registerTreeDataProvider('mdTreeItems', hackMDTreeViewProvider) |
291 | | - ); |
292 | | - context.subscriptions.push( |
293 | | - vscode.commands.registerCommand('treeView.refreshList', () => hackMDTreeViewProvider.refresh()) |
294 | | - ); |
295 | | - |
296 | | - context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('hackmd', new MdTextDocumentContentProvider())); |
297 | | - |
298 | | - context.subscriptions.push(vscode.commands.registerCommand('clickTreeItem', async (label, noteId) => { |
299 | | - if (label && noteId) { |
300 | | - const content = await API.exportString(noteId, apiClient.ExportType.MD); |
301 | | - if (content) { |
302 | | - const uri = vscode.Uri.parse(`hackmd:${label}.md#${noteId}`); |
303 | | - const doc = await vscode.workspace.openTextDocument(uri); |
304 | | - await vscode.window.showTextDocument(doc, { preview: false }); |
305 | | - } |
306 | | - } |
307 | | - })); |
| 232 | + registerCommand(context, store); |
308 | 233 |
|
309 | 234 | return { |
310 | 235 | extendMarkdownIt(md: any) { |
|
0 commit comments