Skip to content

Commit 2ddd677

Browse files
committed
update settings dynamically
1 parent 37ad65a commit 2ddd677

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

commands/export/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const ExportDoc = ( doc, next ) => ({ error, data }) => {
2525
log( `${ JSON.stringify( error ) }\n` )
2626
return
2727
}
28+
2829
const { content, status } = data.result
2930

3031
// atelier: 'mypkg.subpkg.myclass.cls' => 'mypkg/subpkg/myclass.cls'
@@ -73,23 +74,30 @@ const doclist = ( { error, data } ) => {
7374
module.exports = env => {
7475

7576
//reassign module variables
76-
( { api, log, options } = env ); //env - environment
77-
( { root, folder, atelier } = options );
78-
if ( atelier ) doc2file = doc => asAtelier( doc )
77+
const init = () => {
78+
79+
( { api, log, options } = env ); //env - environment
80+
( { root, folder, atelier, category, generated, filter } = options() );
81+
doc2file = atelier ? doc => asAtelier( doc ) : doc => doc
82+
83+
}
84+
init()
7985

80-
// doclist options
81-
const { category, generated, filter } = options;
8286
const exportAll = () => {
8387

8488
if ( !root ){
8589
log( `COS.EXPORT: Open folder before export - Ctrl+K, Ctrl+O` )
8690
return
8791
}
8892

93+
init()
94+
8995
log( '\nLoad documents list ...' )
9096
api.getDocNames(
97+
9198
{ category, generated, filter }, //doclist options
9299
( error, data ) => doclist( { error, data } ) //callback wrapper
100+
93101
)
94102
}
95103

extension.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,50 @@ const CmdExport = require( './commands/export' )
1010
const { CurrentDoc }= require( './commands/currentdoc' )
1111
const IsApiError = require( './is-api-error' )
1212

13-
14-
1513
const activate = context => {
1614

1715
const log = LOG( window )
18-
const options = workspace.getConfiguration( 'cos' )
19-
const conn = options.get( 'conn' )
20-
conn.toString = function(){
21-
return JSON.stringify(
22-
Object.assign( {}, conn, {
23-
password: "***" //hide passw
24-
}),
25-
null, //replacer
26-
4 //space
27-
)
16+
17+
const Config = workspace => {
18+
19+
let options = null;
20+
const init = () =>{ options = workspace.getConfiguration( 'cos' ) }
21+
init()
22+
23+
return {
24+
25+
init,
26+
conn: () => {
27+
const _conn = options.get( 'conn' )
28+
_conn.toString = () => JSON.stringify( Object.assign( {}, _conn, { password: '***' } ), null, 4 )
29+
return _conn
30+
},
31+
export: () => {
32+
const root = workspace.rootPath
33+
return Object.assign( {}, options.get( 'export' ), { root } )
34+
}
35+
}
2836
}
2937

30-
const api = API( conn )
38+
const config = Config( workspace )
39+
let api = API( config.conn() )
40+
let { exportAll, ExportDoc } = CmdExport({ api, log, options: config.export })
3141

32-
api.headServer( err => {
42+
workspace.onDidChangeConfiguration( ()=>{
3343

34-
if ( err ) return log( 'Connection FAILED: ' + conn )
44+
config.init()
45+
api = API( config.conn() )
46+
( { exportAll, ExportDoc } = CmdExport({ api, log, options: config.export }) )
47+
48+
} , null, context.subscriptions ) //reload config on event
49+
50+
api.headServer( err => {
51+
const conn = config.conn()
52+
if ( err ) return log( 'Connection FAILED: ' + conn, err )
3553
log( 'Connected ' + conn )
3654
panel.set( conn )
37-
3855
})
3956

40-
const exportTo = options.get( 'export' )
41-
exportTo.root = workspace.rootPath
42-
43-
const { exportAll, ExportDoc } = CmdExport({ api, log, options: exportTo })
4457
const currentDoc = CurrentDoc({ window, languages, log })
4558

4659
const Save = ({ name, log }) => ( err, data ) => {
@@ -99,8 +112,8 @@ const activate = context => {
99112
}
100113

101114
context.subscriptions.push(
102-
vscode.commands.registerCommand( 'cos.compile', importCompileExport ),
103-
vscode.commands.registerCommand( 'cos.export', exportAll )
115+
vscode.commands.registerCommand( 'cos.compile', importCompileExport ),
116+
vscode.commands.registerCommand( 'cos.export', () => exportAll() )
104117
)
105118

106119
}

0 commit comments

Comments
 (0)