11package io .zxnnet .controller ;
22
33import com .jfoenix .controls .*;
4- import io .zxnnet .model .CloneProject ;
5- import io .zxnnet .model .InitGitResposity ;
6- import io .zxnnet .model .openlocalRepositorie ;
4+ import io .zxnnet .model .*;
75import io .zxnnet .view .GitRepoMetaData ;
86import io .zxnnet .view .RepoInfo ;
97import javafx .application .Platform ;
1715import javafx .scene .input .MouseEvent ;
1816import javafx .scene .layout .BorderPane ;
1917import javafx .scene .layout .StackPane ;
18+ import javafx .scene .text .Font ;
2019import javafx .scene .text .Text ;
21- import javafx .stage .DirectoryChooser ;
2220import javafx .stage .Stage ;
2321import org .eclipse .jgit .api .errors .GitAPIException ;
2422
@@ -40,133 +38,151 @@ public class MainController implements Initializable {
4038 @ FXML public Label branchId ;
4139 @ FXML public Label branchName ;
4240 @ FXML public JFXListView <Label > listview ;
43- @ FXML public JFXListView <Label > commitview ;
41+ @ FXML public JFXListView <String > commitview ;
42+ @ FXML public JFXListView <String > historyfiles ;
4443 @ FXML public Button Delete ;
4544 @ FXML public Button exitButton ;
4645 @ FXML public Button minButton ;
4746 @ FXML public Button maxButton ;
4847 @ FXML public BorderPane BasePane ;
4948 @ FXML public StackPane stackPane ;
5049
50+
51+ private ArrayList <File > allRepoLocation = new ArrayList <>();
52+ private ArrayList <String > shortMessage ;
53+ private ArrayList <ArrayList <String >> commitHistory ;
54+ private ArrayList <String > currfiles ;
55+
5156 private Tooltip tooltip = new Tooltip ();
52- private openlocalRepositorie localRes = new openlocalRepositorie ();
53- private InitGitResposity initRes = new InitGitResposity ();
5457
5558 @ Override
5659 public void initialize (URL url , ResourceBundle rb ){
5760 try {
5861// JFXPopup jfxPopup = new JFXPopup();
62+ Font .loadFont (Objects .requireNonNull (getClass ().getClassLoader ().
63+ getResource ("Data/DejaVuSansMono-Bold.ttf" )).toExternalForm (), 12 );
64+
5965 listview .setExpanded (true );
6066 listview .depthProperty ().set (2 );
6167 commitview .setExpanded (true );
6268 commitview .depthProperty ().set (2 );
63- //TODO add a way to storage the location
64- //System.out.println(Objects.requireNonNull(MainController.class.getClassLoader().getResource("Style/light.css")).getPath());
69+ // currentfiles.setExpanded(true);
70+ // currentfiles.depthProperty().set(2);
71+ historyfiles .setExpanded (true );
72+ historyfiles .depthProperty ().set (2 );
73+
74+ File chechfile = new File (System .getProperty ("user.home" ) +
75+ File .separator + "temp" + File .separator + "RepoData.ssr" );
76+
77+ if (chechfile .exists ()){
78+ System .out .println ("Rebuild" );
79+
80+ StorgeData storgeData = new StorgeData ("RepoData" );
81+
82+ allRepoLocation = storgeData .rebuild ();
83+
84+ for (File x : allRepoLocation ){
85+ RepoInfo data = openlocalRepositorie .openres (x );
86+ assert data != null ;
87+ setScreen (data );
88+ }
89+ }
6590
6691 }catch (Exception ex ){
6792 Logger .getLogger (MainController .class .getName ()).log (Level .SEVERE ,null ,ex );
6893 }
6994 }
7095
71- //设置底边栏的快速浏览
72- private void setInfoBar (String branchname ,String id ){
73- branchName .setText (branchname );
74- branchId .setText (id );
96+ //TODO 这个函数用来刷新界面来显示文件和底边栏信息,刷新当前库信息
97+ private void setScreen (RepoInfo data ){
98+
99+ Label label = new Label (data .reponame + "\n " + data .branchname );
100+ ImageView imag = new ImageView (new Image (Objects .requireNonNull (
101+ getClass ().getClassLoader ().getResource (
102+ "Icon/git2.png" )).toExternalForm ()));
103+
104+ imag .setFitHeight (30 );
105+ imag .setFitWidth (30 );
106+ label .setGraphic (imag );
107+
108+ listview .getItems ().add (label );
75109 }
76110
111+
112+
77113 //TODO 这里新建完一个库之后要导入listview中
78114 @ FXML
79- public void initProject () throws GitAPIException {
80- DirectoryChooser directoryChooser = new DirectoryChooser ();
81- directoryChooser .setTitle ("init Local Git Repository" );
82- directoryChooser .setInitialDirectory (new File (System .getProperty ("user.home" )));
83- File file = directoryChooser .showDialog (new Stage ());
115+ public void initProject () throws GitAPIException , IOException {
116+
117+ File file = DirOpener .open ();
118+
84119 if (file != null ){
85- System .out .println (file .getAbsolutePath ());
86- initRes .init (file .getAbsolutePath ());
87120
121+ RepoInfo data = InitGitResposity .init (file );
122+ setScreen (data );
88123 JFXSnackbar snackbar = new JFXSnackbar (stackPane );
89124 snackbar .show ("Successful!\n Successfully init a Repository!" ,"Close" ,5000 ,
90125 event -> snackbar .unregisterSnackbarContainer (stackPane ));
91126 }
92- }
93127
128+ allRepoLocation .add (file );
129+ }
94130
95- //TODO listview 应该修改出去,不要再这里直接调用
96131 @ FXML
97132 public void openProject () throws IOException {
98- DirectoryChooser directoryChooser = new DirectoryChooser ();
99- directoryChooser .setTitle ("Open Local Git Repository" );
100- // use user.name to cross platform
101- directoryChooser .setInitialDirectory (new File (System .getProperty ("user.home" )));
102- File file = directoryChooser .showDialog (new Stage ());
103-
104- if (file != null ){
105133
106- File tempjument = new File (file .getAbsolutePath () + File .separator + ".git" );
134+ File file = DirOpener .open ();
135+ RepoInfo data = openlocalRepositorie .openres (file );
107136
108- if (tempjument .exists () && tempjument .isDirectory ()){
109- RepoInfo data = localRes .openres (file .getAbsolutePath ());
110- setInfoBar (data .name ,data .id );
111-
112- Label templabel = new Label (file .getName () + "\n " + branchName .getText ());
113-
114- ImageView tempimag = new ImageView (new Image (Objects .requireNonNull (
115- getClass ().getClassLoader ().getResource (
116- "Icon/git2.png" )).toExternalForm ()));
117-
118- tempimag .setFitHeight (30 );
119- tempimag .setFitWidth (30 );
120- templabel .setGraphic (tempimag );
121-
122- listview .getItems ().add (templabel );
123-
124- if (data .exinfo != null ){
125- JFXSnackbar snackbar = new JFXSnackbar (stackPane );
126- snackbar .show ("Note!\n " + data .exinfo ,"Close" ,5000 ,
127- event -> snackbar .unregisterSnackbarContainer (stackPane ));
128- }
129- }
130- else {
137+ if (data != null ) {
138+ setScreen (data );
131139
140+ if (data .exinfo != null ) {
132141 JFXSnackbar snackbar = new JFXSnackbar (stackPane );
133- snackbar .show ("Wrong!\n This Folder does not init with git\n " +
134- "Please init with Git and try again!" ,"Close" ,5000 ,
142+ snackbar .show ("Note!\n " + data .exinfo , "Close" , 5000 ,
135143 event -> snackbar .unregisterSnackbarContainer (stackPane ));
136144 }
145+ } else {
146+ JFXSnackbar snackbar = new JFXSnackbar (stackPane );
147+ snackbar .show ("Wrong!\n This Folder does not init with git\n " +
148+ "Please init with Git and try again!" , "Close" , 5000 ,
149+ event -> snackbar .unregisterSnackbarContainer (stackPane ));
137150 }
151+ allRepoLocation .add (file );
138152 }
139153
140- @ FXML
141154 //TODO 这里克隆完之后要调用open来导入
155+ @ FXML
142156 public void cloneProject () throws Exception {
143157
144- CloneProject cloneProject = new CloneProject ();
145-
146158 JFXDialogLayout content = new JFXDialogLayout ();
147159 content .setHeading (new Text ("Working..." ));
148160 content .setBody (new Text ("Cloning, Please Don't Close The window!" ));
149161 JFXDialog jfxDialog = new JFXDialog (stackPane , content , JFXDialog .DialogTransition .CENTER );
150162 jfxDialog .show ();
151163
152- boolean finised = cloneProject .Clone ();
164+ File file = DirOpener .open ();
165+ RepoInfo data = CloneProject .Clone (file );
153166
154- if (finised ){
167+ if (data != null ){
155168 jfxDialog .close ();
169+ setScreen (data );
156170 JFXSnackbar snackbar = new JFXSnackbar (stackPane );
157171 snackbar .show ("Successful!\n Successfully Clone a Repository!" ,"Close" ,5000 ,
158172 event -> snackbar .unregisterSnackbarContainer (stackPane ));
173+ setScreen (data );
159174 }
160175 else {
161176 jfxDialog .close ();
162177 JFXSnackbar snackbar = new JFXSnackbar (stackPane );
163178 snackbar .show ("Fail!\n Check your information and Try again!" ,"Close" ,5000 ,
164179 event -> snackbar .unregisterSnackbarContainer (stackPane ));
165180 }
166- }
167181
182+ allRepoLocation .add (file );
183+ }
168184
169- //删除选中的条目
185+ //TODO 删除选中的条目
170186 @ FXML
171187 public void deleteProject () {
172188 final int seleteIdx = listview .getSelectionModel ().getSelectedIndex ();
@@ -181,23 +197,77 @@ public void deleteProject() {
181197 listview .getSelectionModel ().select (newSelectedIdx );
182198 System .out .println ("selectIdx: " + seleteIdx );
183199 System .out .println ("item: " + itemToRemove .getText ());
200+
201+ allRepoLocation .remove (seleteIdx );
202+ commitview .getItems ().clear ();
203+ historyfiles .getItems ().clear ();
204+ // currentfiles.getItems().clear();
205+ shortMessage .clear ();
206+ commitHistory .clear ();
207+ currfiles .clear ();
208+ }
209+ }
210+
211+ @ FXML
212+ public void ChangeRepo () throws IOException , GitAPIException {
213+
214+ int seleteIdx = listview .getSelectionModel ().getSelectedIndex ();
215+
216+ if (seleteIdx != -1 ){
217+ File file = allRepoLocation .get (seleteIdx );
218+ RepoInfo data = openlocalRepositorie .openres (file );
219+ assert data != null ;
220+ GitRepoMetaData metaData = new GitRepoMetaData ();
221+ metaData .setRepository (data .repository );
222+ metaData .setRevCommit (data .commit );
223+ metaData .setRevWalk (data .walk );
224+
225+ shortMessage = metaData .getShortMessage ();
226+ commitHistory = metaData .getCommitFiles ();
227+ currfiles = metaData .getUncommit ();
228+
229+ branchName .setText (data .branchname );
230+ branchId .setText (data .id );
231+
232+ // setCurrentfiles(currfiles);
233+ setCommitview (shortMessage );
234+ historyfiles .getItems ().clear ();
184235 }
185236 }
186237
238+ private void setCommitview (ArrayList <String > Message ){
187239
188- private void ShowAlertDialog (JFXDialogLayout content ) {
189- JFXDialog dialog = new JFXDialog (stackPane ,content ,JFXDialog .DialogTransition .CENTER );
190- JFXButton button = new JFXButton ("Close" );
191- button .setOnMouseClicked (event -> dialog .close ());
192- content .setActions (button );
193- dialog .show ();
240+ commitview .getItems ().clear ();
241+ for (String x : Message ) {
242+ commitview .getItems ().add (x );
243+ }
194244 }
195245
246+ // private void setCurrentfiles(ArrayList<String> curr){
247+ // historyfiles.getItems().clear();
248+ // for (String x: curr){
249+ // historyfiles.getItems().add(x);
250+ // }
251+ // }
196252
253+ private void setFileview (int idx ) {
197254
255+ historyfiles .getItems ().clear ();
256+ for (String x :commitHistory .get (idx )) {
257+ historyfiles .getItems ().add (x );
258+ }
259+ }
260+
261+ @ FXML
262+ public void showFile () {
263+ int seleteIdx = commitview .getSelectionModel ().getSelectedIndex ();
264+ if (seleteIdx != -1 ){
265+ setFileview (seleteIdx );
266+ }
267+ }
198268
199- //下面的代码是用来解决Windows的问题
200269
270+ //下面的代码是用来解决Windows的问题
201271 class Delta {
202272 double x ,y ;
203273 }
@@ -238,6 +308,9 @@ public void maxalert(){
238308
239309 @ FXML
240310 public void exitapp (){
311+ StorgeData storgeData = new StorgeData ("RepoData" );
312+ System .out .println ("Storing!" );
313+ storgeData .store (allRepoLocation );
241314 Platform .exit ();
242315 }
243316
0 commit comments