@@ -2,27 +2,77 @@ const { commands, scm, window } = require("vscode");
22const { inputCommitMessage, changesCommitted } = require ( "./messages" ) ;
33const svn = require ( "./svn" ) ;
44
5- function SvnCommands ( ) {
6- commands . registerCommand ( "svn.fileOpen" , this . fileOpen ) ;
7- commands . registerCommand ( "svn.commitWithMessage" , this . commitWithMessage ) ;
8- commands . registerCommand ( "svn.add" , this . addFile ) ;
5+ function SvnCommands ( model ) {
6+ this . model = model ;
7+ this . commands = [
8+ {
9+ commandId : "svn.commitWithMessage" ,
10+ method : this . commitWithMessage ,
11+ options : { repository : true }
12+ }
13+ ] ;
14+
15+ this . commands . map ( ( { commandId, method, options } ) => {
16+ const command = this . createCommand ( method , options ) ;
17+ commands . registerCommand ( commandId , command ) ;
18+ } ) ;
19+ // commands.registerCommand("svn.fileOpen", this.fileOpen);
20+ // commands.registerCommand("svn.commitWithMessage", this.commitWithMessage);
21+ // commands.registerCommand("svn.add", this.addFile);
922}
1023
24+ SvnCommands . prototype . createCommand = function ( method , options ) {
25+ const result = ( ...args ) => {
26+ let result ;
27+
28+ if ( ! options . repository ) {
29+ result = Promise . resolve ( method . apply ( this , args ) ) ;
30+ } else {
31+ const repository = this . model . getRepository ( args [ 0 ] ) ;
32+ let repositoryPromise ;
33+
34+ if ( repository ) {
35+ repositoryPromise = Promise . resolve ( repository ) ;
36+ } else if ( this . model . openRepositories . length === 1 ) {
37+ repositoryPromise = Promise . resolve ( this . model . openRepositories [ 0 ] ) ;
38+ } else {
39+ repositoryPromise = this . model . pickRepository ( ) ;
40+ }
41+
42+ result = repositoryPromise . then ( repository => {
43+ if ( ! repository ) {
44+ return Promise . resolve ( ) ;
45+ }
46+
47+ return Promise . resolve ( method . apply ( this , [ repository , ...args ] ) ) ;
48+ } ) ;
49+ }
50+
51+ return result . catch ( async err => {
52+ console . error ( err ) ;
53+ } ) ;
54+ } ;
55+
56+ return result ;
57+ } ;
58+
1159SvnCommands . prototype . fileOpen = resourceUri => {
1260 commands . executeCommand ( "vscode.open" , resourceUri ) ;
1361} ;
1462
15- SvnCommands . prototype . commitWithMessage = async function ( ) {
16- this . svn = new svn ( ) ;
17- let message = await inputCommitMessage ( scm . inputBox . value ) ;
63+ SvnCommands . prototype . commitWithMessage = async function ( repository ) {
64+ // console.log("fsdsfsf");
65+ // this.svn = new svn();
66+ // let message = await inputCommitMessage(scm.inputBox.value);
1867
19- try {
20- await this . svn . commit ( message ) ;
21- scm . inputBox . value = "" ;
22- changesCommitted ( ) ;
23- } catch ( error ) {
24- console . log ( error ) ;
25- }
68+ console . log ( repository . inputBox . value ) ;
69+ // try {
70+ // await this.svn.commit(message);
71+ // scm.inputBox.value = "";
72+ // changesCommitted();
73+ // } catch (error) {
74+ // console.log(error);
75+ // }
2676} ;
2777
2878SvnCommands . prototype . addFile = async uri => {
0 commit comments