1- const vscode = require ( 'vscode' ) ;
2- const path = require ( 'path' ) ;
3- const Svn = require ( './svn' ) ;
4- const svnSCM = require ( './svnSCM' ) ;
5- const svnContentProvider = require ( './svnContentProvider' ) ;
6-
7- const checkAllFiles = ( svn ) => {
8- return new Promise ( ( resolve , reject ) => {
9- svn . getStatus ( )
10- . then ( ( data ) => resolve ( data ) )
11- . catch ( ( err ) => reject ( err ) ) ;
12- } ) ;
1+ const vscode = require ( "vscode" ) ;
2+ const path = require ( "path" ) ;
3+ const Svn = require ( "./svn" ) ;
4+ const svnSCM = require ( "./svnSCM" ) ;
5+ const svnContentProvider = require ( "./svnContentProvider" ) ;
6+ const SvnCommands = require ( "./commands" ) ;
7+
8+ const checkAllFiles = svn => {
9+ return new Promise ( ( resolve , reject ) => {
10+ svn
11+ . getStatus ( )
12+ . then ( data => resolve ( data ) )
13+ . catch ( err => reject ( err ) ) ;
14+ } ) ;
1315} ;
1416
1517function createResourceUri ( relativePath ) {
16- const absolutePath = path . join ( vscode . workspace . rootPath , relativePath ) ;
17- return vscode . Uri . file ( absolutePath ) ;
18- }
18+ const absolutePath = path . join ( vscode . workspace . rootPath , relativePath ) ;
19+ return vscode . Uri . file ( absolutePath ) ;
20+ }
1921
2022const updateResourceGroup = ( data , type ) => {
21- var matches = [ ] ;
22-
23- data . forEach ( item => {
24- if ( item [ 'wc-status' ] . $ . item == type ) {
25- matches . push ( { resourceUri : createResourceUri ( item . $ . path ) } ) ;
26- }
27- } ) ;
28-
29- return matches ;
30- }
23+ var matches = [ ] ;
3124
32- const updateChangesResourceGroup = ( data ) => {
33- const changes = [ 'added' , 'modified' , 'deleted' , 'missing' , 'conflicted' , 'replaced' ] ;
34- let matches = [ ] ;
35- const iconsRootPath = path . join ( __dirname , 'icons' ) ;
36-
37- data . forEach ( item => {
38- if ( changes . indexOf ( item [ 'wc-status' ] . $ . item ) != - 1 ) {
39- matches . push ( {
40- resourceUri : createResourceUri ( item . $ . path ) ,
41- decorations : {
42- iconPath : vscode . Uri . file ( path . join ( iconsRootPath , `${ item [ 'wc-status' ] . $ . item } .svg` ) ) ,
43- tooltip : item [ 'wc-status' ] . $ . item ,
44- } ,
45- command : {
46- command : 'svn.fileOpen' ,
47- title : 'Open' ,
48- arguments : [ createResourceUri ( item . $ . path ) ]
49- }
50- } ) ;
51- }
52- } ) ;
53-
54- return matches ;
55- }
25+ data . forEach ( item => {
26+ if ( item [ "wc-status" ] . $ . item == type ) {
27+ matches . push ( { resourceUri : createResourceUri ( item . $ . path ) } ) ;
28+ }
29+ } ) ;
5630
57- const updateNotTrackedResourceGroup = ( data ) => {
58- let matches = [ ] ;
59- const iconsRootPath = path . join ( __dirname , 'icons' ) ;
60-
61- data . forEach ( item => {
62- if ( item [ 'wc-status' ] . $ . item == 'unversioned' ) {
63- matches . push ( {
64- resourceUri : createResourceUri ( item . $ . path ) ,
65- decorations : {
66- iconPath : vscode . Uri . file ( path . join ( iconsRootPath , `unversioned.svg` ) ) ,
67- tooltip : item [ 'wc-status' ] . $ . item ,
68- } ,
69- command : {
70- command : 'svn.fileOpen' ,
71- title : 'Open' ,
72- arguments : [ createResourceUri ( item . $ . path ) ]
73- }
74- } ) ;
75- }
76- } ) ;
77-
78- return matches ;
79- }
31+ return matches ;
32+ } ;
8033
81- const registerFileOpenCommand = ( ) => {
82- vscode . commands . registerCommand ( 'svn.fileOpen' , ( resourceUri ) => {
83- vscode . commands . executeCommand ( 'vscode.open' , resourceUri ) ;
84- } ) ;
85- }
34+ const updateChangesResourceGroup = data => {
35+ const changes = [
36+ "added" ,
37+ "modified" ,
38+ "deleted" ,
39+ "missing" ,
40+ "conflicted" ,
41+ "replaced"
42+ ] ;
43+ let matches = [ ] ;
44+ const iconsRootPath = path . join ( __dirname , "icons" ) ;
45+
46+ data . forEach ( item => {
47+ if ( changes . indexOf ( item [ "wc-status" ] . $ . item ) != - 1 ) {
48+ matches . push ( {
49+ resourceUri : createResourceUri ( item . $ . path ) ,
50+ decorations : {
51+ iconPath : vscode . Uri . file (
52+ path . join ( iconsRootPath , `${ item [ "wc-status" ] . $ . item } .svg` )
53+ ) ,
54+ tooltip : item [ "wc-status" ] . $ . item
55+ } ,
56+ command : {
57+ command : "svn.fileOpen" ,
58+ title : "Open" ,
59+ arguments : [ createResourceUri ( item . $ . path ) ]
60+ }
61+ } ) ;
62+ }
63+ } ) ;
64+
65+ return matches ;
66+ } ;
67+
68+ const updateNotTrackedResourceGroup = data => {
69+ let matches = [ ] ;
70+ const iconsRootPath = path . join ( __dirname , "icons" ) ;
71+
72+ data . forEach ( item => {
73+ if ( item [ "wc-status" ] . $ . item == "unversioned" ) {
74+ matches . push ( {
75+ resourceUri : createResourceUri ( item . $ . path ) ,
76+ decorations : {
77+ iconPath : vscode . Uri . file (
78+ path . join ( iconsRootPath , `unversioned.svg` )
79+ ) ,
80+ tooltip : item [ "wc-status" ] . $ . item
81+ } ,
82+ command : {
83+ command : "svn.fileOpen" ,
84+ title : "Open" ,
85+ arguments : [ createResourceUri ( item . $ . path ) ]
86+ }
87+ } ) ;
88+ }
89+ } ) ;
90+
91+ return matches ;
92+ } ;
8693
8794function activate ( context ) {
88- console . log ( 'svn-scm is now active!' ) ;
89-
90- const disposable = [ ] ;
91- const rootPath = vscode . workspace . rootPath ;
92-
93- const watcher = vscode . workspace . createFileSystemWatcher ( `${ rootPath } /**/*` ) ;
94-
95- registerFileOpenCommand ( ) ;
96-
97- const sourceControl = new svnSCM ( ) ;
98- const contentProvider = new svnContentProvider ( ) ;
99- const svn = new Svn ( ) ;
100-
101- const changes = sourceControl . createResourceGroup ( 'changes' , 'Changes' ) ;
102- const notTracked = sourceControl . createResourceGroup ( 'unversioned' , 'Not Tracked' ) ;
103-
104- changes . hideWhenEmpty = true ;
105- notTracked . hideWhenEmpty = true ;
106-
107- const main = ( ) => {
108- return checkAllFiles ( svn )
109- . then ( ( data ) => {
110- changes . resourceStates = updateChangesResourceGroup ( data ) ;
111- notTracked . resourceStates = updateNotTrackedResourceGroup ( data ) ;
112- } )
113- . catch ( ( err ) => vscode . window . showErrorMessage ( err ) ) ;
114- } ;
115-
116- watcher . onDidChange ( main ) ;
117- watcher . onDidCreate ( main ) ;
118- watcher . onDidDelete ( main ) ;
119-
120- main ( ) ;
121-
122- context . subscriptions . push ( disposable ) ;
95+ console . log ( "svn-scm is now active!" ) ;
96+
97+ const disposable = [ ] ;
98+ const rootPath = vscode . workspace . rootPath ;
99+
100+ const watcher = vscode . workspace . createFileSystemWatcher ( `${ rootPath } /**/*` ) ;
101+
102+ const commands = new SvnCommands ( ) ;
103+ const sourceControl = new svnSCM ( ) ;
104+ const contentProvider = new svnContentProvider ( ) ;
105+ const svn = new Svn ( ) ;
106+
107+ const changes = sourceControl . createResourceGroup ( "changes" , "Changes" ) ;
108+ const notTracked = sourceControl . createResourceGroup (
109+ "unversioned" ,
110+ "Not Tracked"
111+ ) ;
112+
113+ changes . hideWhenEmpty = true ;
114+ notTracked . hideWhenEmpty = true ;
115+
116+ const main = ( ) => {
117+ return checkAllFiles ( svn )
118+ . then ( data => {
119+ changes . resourceStates = updateChangesResourceGroup ( data ) ;
120+ notTracked . resourceStates = updateNotTrackedResourceGroup ( data ) ;
121+ } )
122+ . catch ( err => vscode . window . showErrorMessage ( err ) ) ;
123+ } ;
124+
125+ watcher . onDidChange ( main ) ;
126+ watcher . onDidCreate ( main ) ;
127+ watcher . onDidDelete ( main ) ;
128+
129+ main ( ) ;
130+
131+ context . subscriptions . push ( disposable ) ;
123132}
124133exports . activate = activate ;
125134
126135// this method is called when your extension is deactivated
127- function deactivate ( ) {
128- }
129- exports . deactivate = deactivate ;
136+ function deactivate ( ) { }
137+ exports . deactivate = deactivate ;
0 commit comments