refactor(main): 重构目录选择逻辑和界面布局
This commit is contained in:
		
							parent
							
								
									78d70b9c7a
								
							
						
					
					
						commit
						69263ee966
					
				
							
								
								
									
										8
									
								
								.idea/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | # 默认忽略的文件 | ||||||
|  | /shelf/ | ||||||
|  | /workspace.xml | ||||||
|  | # 基于编辑器的 HTTP 客户端请求 | ||||||
|  | /httpRequests/ | ||||||
|  | # Datasource local storage ignored files | ||||||
|  | /dataSources/ | ||||||
|  | /dataSources.local.xml | ||||||
							
								
								
									
										9
									
								
								.idea/CoverCrawler.iml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								.idea/CoverCrawler.iml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <module type="WEB_MODULE" version="4"> | ||||||
|  |   <component name="Go" enabled="true" /> | ||||||
|  |   <component name="NewModuleRootManager"> | ||||||
|  |     <content url="file://$MODULE_DIR$" /> | ||||||
|  |     <orderEntry type="inheritedJdk" /> | ||||||
|  |     <orderEntry type="sourceFolder" forTests="false" /> | ||||||
|  |   </component> | ||||||
|  | </module> | ||||||
							
								
								
									
										6
									
								
								.idea/MarsCodeWorkspaceAppSettings.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/MarsCodeWorkspaceAppSettings.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="com.codeverse.userSettings.MarscodeWorkspaceAppSettingsState"> | ||||||
|  |     <option name="ckgOperationStatus" value="SUCCESS" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										6
									
								
								.idea/elasticsearchSettings.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/elasticsearchSettings.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="ElasticsearchConfiguration"> | ||||||
|  |     <option name="version" value="2" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										8
									
								
								.idea/modules.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/modules.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="ProjectModuleManager"> | ||||||
|  |     <modules> | ||||||
|  |       <module fileurl="file://$PROJECT_DIR$/.idea/CoverCrawler.iml" filepath="$PROJECT_DIR$/.idea/CoverCrawler.iml" /> | ||||||
|  |     </modules> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										6
									
								
								.idea/vcs.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/vcs.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project version="4"> | ||||||
|  |   <component name="VcsDirectoryMappings"> | ||||||
|  |     <mapping directory="$PROJECT_DIR$" vcs="Git" /> | ||||||
|  |   </component> | ||||||
|  | </project> | ||||||
							
								
								
									
										
											BIN
										
									
								
								__debug_bin3905452747
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								__debug_bin3905452747
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								fyne-cross/.DS_Store
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								fyne-cross/.DS_Store
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								fyne-cross/bin/.DS_Store
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								fyne-cross/bin/.DS_Store
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								fyne-cross/bin/windows-amd64/CoverCrawler.exe
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								fyne-cross/bin/windows-amd64/CoverCrawler.exe
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								fyne-cross/dist/windows-amd64/CoverCrawler.exe.zip
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								fyne-cross/dist/windows-amd64/CoverCrawler.exe.zip
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								fyne-cross/tmp/windows-amd64/Icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								fyne-cross/tmp/windows-amd64/Icon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 18 KiB | 
							
								
								
									
										98
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										98
									
								
								main.go
									
									
									
									
									
								
							| @ -17,78 +17,58 @@ func main() { | |||||||
| 	myWindow.Resize(fyne.NewSize(640, 480)) | 	myWindow.Resize(fyne.NewSize(640, 480)) | ||||||
| 
 | 
 | ||||||
| 	// 创建显示框
 | 	// 创建显示框
 | ||||||
| 	displayBox1 := widget.NewLabel("未选择") | 	sourceDirLabel := widget.NewLabel("未选择") | ||||||
| 	displayBox2 := widget.NewLabel("未选择") | 	targetDirLabel := widget.NewLabel("未选择") | ||||||
| 	displayBoxInfo := canvas.NewText("", colornames.Blue) | 	displayBoxInfo := canvas.NewText("", colornames.Blue) | ||||||
| 
 | 
 | ||||||
| 	// 创建目录选择框
 | 	// 创建目录选择框
 | ||||||
| 	dirSelect1 := widget.NewButton("选择作品存放目录", func() { | 	selectSourceDir := widget.NewButton("选择作品存放目录", func() { | ||||||
| 		dirDialog := dialog.NewFolderOpen(func(d fyne.ListableURI, err error) { | 		dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) { | ||||||
| 			if err == nil && d != nil { | 			if err != nil { | ||||||
| 				displayBox1.SetText(d.Path()) | 				sourceDirLabel.SetText("选择目录失败: " + err.Error()) | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 			if uri != nil { | ||||||
|  | 				sourceDirLabel.SetText(uri.Path()) | ||||||
| 			} | 			} | ||||||
| 		}, myWindow) | 		}, myWindow) | ||||||
| 		dirDialog.Show() |  | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	dirSelect2 := widget.NewButton("选择输出目录", func() { | 	selectTargetDir := widget.NewButton("选择输出目录", func() { | ||||||
| 		dirDialog := dialog.NewFolderOpen(func(d fyne.ListableURI, err error) { | 		dialog.ShowFolderOpen(func(uri fyne.ListableURI, err error) { | ||||||
| 			if err == nil && d != nil { | 			if err != nil { | ||||||
| 				displayBox2.SetText(d.Path()) | 				targetDirLabel.SetText("选择目录失败: " + err.Error()) | ||||||
|  | 				return | ||||||
|  | 			} | ||||||
|  | 			if uri != nil { | ||||||
|  | 				targetDirLabel.SetText(uri.Path()) | ||||||
| 			} | 			} | ||||||
| 		}, myWindow) | 		}, myWindow) | ||||||
| 		dirDialog.Show() |  | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	// 创建确定按钮
 | 	// 创建主布局
 | ||||||
| 	okButton := widget.NewButton("确  定", func() { |  | ||||||
| 		dir1 := displayBox1.Text |  | ||||||
| 		dir2 := displayBox2.Text |  | ||||||
| 
 |  | ||||||
| 		displayBoxInfo.Color = colornames.Blue |  | ||||||
| 		displayBoxInfo.Text = "处理中ing..." |  | ||||||
| 
 |  | ||||||
| 		crawler := NewCrawler(dir1, dir2) |  | ||||||
| 		if err := crawler.Handle(); err != nil { |  | ||||||
| 			displayBoxInfo.Color = colornames.Red |  | ||||||
| 			displayBoxInfo.Text = err.Error() |  | ||||||
| 		} else { |  | ||||||
| 			displayBoxInfo.Color = colornames.Green |  | ||||||
| 			displayBoxInfo.Text = "处理完成" |  | ||||||
| 		} |  | ||||||
| 	}) |  | ||||||
| 
 |  | ||||||
| 	// 创建水平布局,将目录选择框和显示框并排排列
 |  | ||||||
| 	dirSelect1WithDisplay := container.NewHBox( |  | ||||||
| 		dirSelect1, |  | ||||||
| 		displayBox1, |  | ||||||
| 	) |  | ||||||
| 
 |  | ||||||
| 	dirSelect2WithDisplay := container.NewHBox( |  | ||||||
| 		dirSelect2, |  | ||||||
| 		displayBox2, |  | ||||||
| 	) |  | ||||||
| 
 |  | ||||||
| 	dirSelect3WithDisplay := container.NewHBox( |  | ||||||
| 		layout.NewSpacer(), |  | ||||||
| 		displayBoxInfo, |  | ||||||
| 		layout.NewSpacer(), |  | ||||||
| 	) |  | ||||||
| 
 |  | ||||||
| 	// 创建水平布局,将确定按钮居中
 |  | ||||||
| 	okButtonContainer := container.NewHBox( |  | ||||||
| 		layout.NewSpacer(), |  | ||||||
| 		okButton, |  | ||||||
| 		layout.NewSpacer(), |  | ||||||
| 	) |  | ||||||
| 
 |  | ||||||
| 	// 创建垂直布局,将上述水平布局和确定按钮垂直排列
 |  | ||||||
| 	content := container.NewVBox( | 	content := container.NewVBox( | ||||||
| 		dirSelect1WithDisplay, | 		container.NewHBox(selectSourceDir, sourceDirLabel), | ||||||
| 		dirSelect2WithDisplay, | 		container.NewHBox(selectTargetDir, targetDirLabel), | ||||||
| 		dirSelect3WithDisplay, | 		container.NewCenter(displayBoxInfo), | ||||||
| 		layout.NewSpacer(), | 		layout.NewSpacer(), | ||||||
| 		okButtonContainer, | 		container.NewCenter( | ||||||
|  | 			widget.NewButton("开始处理", func() { | ||||||
|  | 				displayBoxInfo.Text = "处理中..." | ||||||
|  | 				displayBoxInfo.Color = colornames.Blue | ||||||
|  | 				displayBoxInfo.Refresh() | ||||||
|  | 
 | ||||||
|  | 				crawler := NewCrawler(sourceDirLabel.Text, targetDirLabel.Text) | ||||||
|  | 				if err := crawler.Handle(); err != nil { | ||||||
|  | 					displayBoxInfo.Text = "处理失败: " + err.Error() | ||||||
|  | 					displayBoxInfo.Color = colornames.Red | ||||||
|  | 				} else { | ||||||
|  | 					displayBoxInfo.Text = "处理完成" | ||||||
|  | 					displayBoxInfo.Color = colornames.Green | ||||||
|  | 				} | ||||||
|  | 				displayBoxInfo.Refresh() | ||||||
|  | 			}), | ||||||
|  | 		), | ||||||
| 	) | 	) | ||||||
| 
 | 
 | ||||||
| 	myWindow.SetContent(content) | 	myWindow.SetContent(content) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user