Skip to content

Commit

Permalink
🍿 修正多连接时,打开软件界面异常问题
Browse files Browse the repository at this point in the history
🍿 修正多连接组删除组时的界面空白问题
tab按索引获取位置
  • Loading branch information
airplayx committed Mar 19, 2020
1 parent bed0bb2 commit f667d94
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/app/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func Container(app fyne.App, win fyne.Window) *widget.TabContainer {
i = icon.Mssql
}
ipBox.Append(widget.NewTabItemWithIcon(v.Host+":"+v.Port, i, dbBox))
dbBox.SelectTabIndex(len(dbBox.Items) - 1)
}
if len(ipBox.Items) == 0 {
ipBox.Hide()
} else {
ipBox.SetTabLocation(widget.TabLocationLeading)
ipBox.SelectTabIndex(0)
}
toolBar := ToolBar(win, ipBox, options)
s2sBox := fyne.NewContainerWithLayout(
Expand Down
4 changes: 4 additions & 0 deletions internal/app/sql2struct/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func DataBase(window, currentWindow fyne.Window, ipBox *widget.TabContainer, opt
currentWindow.Close()
},
OnSubmit: func() {
if db.Text == "" {
dialog.ShowError(errors.New("数据库不能为空"), currentWindow)
return
}
newDB := widget.NewTabItemWithIcon(
db.Text, icon.Database,
Screen(currentWindow, &Sql2struct.SourceMap{
Expand Down
31 changes: 11 additions & 20 deletions internal/app/toolbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
var dbIndex []int
if ipBox.Items != nil && ipBox.Visible() {
sourceMap := options.SourceMap
for k, v := range sourceMap {
if v.Host+":"+v.Port == ipBox.CurrentTab().Text {
for k := range sourceMap {
if k == ipBox.CurrentTabIndex() {
dbIndex = []int{k}
break
}
Expand Down Expand Up @@ -92,16 +92,6 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
log.Fatalln(err)
}
}
//w := fyne.CurrentApp().NewWindow("命令行相关工具")
//w.SetContent(fyne.NewContainerWithLayout(
// layout.NewGridLayout(1),
// widget.NewScrollContainer(fyne.NewContainerWithLayout(
// layout.NewGridLayout(1),
// )),
//))
//w.Resize(fyne.Size{Width: 1000, Height: 500})
//w.CenterOnScreen()
//w.Show()
}),
widget.NewToolbarAction(icon.Edit, func() {
if ipBox.Items == nil {
Expand All @@ -113,7 +103,7 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
sourceMap := options.SourceMap
var dbIndex []int
for k, v := range sourceMap {
if v.Host+":"+v.Port == ipBox.CurrentTab().Text {
if k == ipBox.CurrentTabIndex() {
for key := range v.Db {
if key == dbBox.CurrentTabIndex() {
dbIndex = []int{k, key}
Expand All @@ -140,10 +130,11 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
content := widget.NewEntry()
content.SetPlaceHolder("请输入 " + ipBox.CurrentTab().Text + " 确认删除当前组记录")
content.OnChanged = func(text string) {
defer ipBox.SelectTabIndex(ipBox.CurrentTabIndex())
if text == ipBox.CurrentTab().Text {
sourceMap := options.SourceMap
for k, v := range sourceMap {
if v.Host+":"+v.Port == ipBox.CurrentTab().Text {
for k := range sourceMap {
if k == ipBox.CurrentTabIndex() {
options.SourceMap = append(sourceMap[:k], sourceMap[k+1:]...)
break
}
Expand Down Expand Up @@ -176,9 +167,9 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
if isDelete {
sourceMap := options.SourceMap
for k, v := range sourceMap {
if v.Host+":"+v.Port == ipBox.CurrentTab().Text {
for key, db := range v.Db {
if db == dbBox.CurrentTab().Text {
if k == ipBox.CurrentTabIndex() {
for key := range v.Db {
if key == dbBox.CurrentTabIndex() {
sourceMap[k].Db = append(v.Db[:key], v.Db[key+1:]...)
if len(sourceMap[k].Db) == 0 {
options.SourceMap = append(sourceMap[:k], sourceMap[k+1:]...)
Expand All @@ -197,20 +188,20 @@ func ToolBar(win fyne.Window, ipBox *widget.TabContainer, options *Sql2struct.SQ
if len(ipBox.Items) == 0 {
ipBox.Hide()
}
goto loop
}
ipBox.SelectTabIndex(ipBox.CurrentTabIndex() - 1)
goto loop
}

}
}
}
}
loop:
defer win.Canvas().Refresh(ipBox)
jsons, _ := json.Marshal(options)
if data, err := jsonparser.Set(configs.Json, jsons, "sql2struct"); err == nil {
configs.Json = data
//dialog.ShowInformation("操作", "保存成功", win)
} else {
dialog.ShowError(errors.New(err.Error()), win)
}
Expand Down

0 comments on commit f667d94

Please sign in to comment.