Editing favorites done.
This commit is contained in:
parent
26a3ead52a
commit
0f5dd8f236
@ -66,33 +66,29 @@ func (f *FavoriteDialog) fill() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
var idx_in_combobox int = 0
|
||||||
|
var idx_should_be_active int = 0
|
||||||
for p := range profiles {
|
for p := range profiles {
|
||||||
if profiles[p].Version == f.server.Version {
|
if profiles[p].Version == f.server.Version {
|
||||||
f.profile.AppendText(profiles[p].Name)
|
f.profile.AppendText(profiles[p].Name)
|
||||||
|
idx_should_be_active = idx_in_combobox
|
||||||
|
idx_in_combobox += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (f *FavoriteDialog) Initialize() {
|
|
||||||
if f.update {
|
|
||||||
fmt.Println("Updating favorite server...")
|
|
||||||
} else {
|
|
||||||
fmt.Println("New favorite server")
|
|
||||||
}
|
|
||||||
|
|
||||||
f.initializeWindow()
|
f.profile.SetActive(idx_should_be_active)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FavoriteDialog) InitializeNew() {
|
func (f *FavoriteDialog) InitializeNew() {
|
||||||
f.update = false
|
f.update = false
|
||||||
f.Initialize()
|
f.initializeWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FavoriteDialog) InitializeUpdate(server *datamodels.Server) {
|
func (f *FavoriteDialog) InitializeUpdate(server *datamodels.Server) {
|
||||||
fmt.Println("Favorites updating...")
|
fmt.Println("Favorites updating...")
|
||||||
f.update = true
|
f.update = true
|
||||||
f.server = server
|
f.server = server
|
||||||
f.Initialize()
|
f.initializeWindow()
|
||||||
f.fill()
|
f.fill()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +214,7 @@ func (f *FavoriteDialog) saveFavorite() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.Eventer.LaunchEvent("loadFavoriteServers")
|
ctx.Eventer.LaunchEvent("loadFavoriteServers")
|
||||||
|
f.window.Destroy()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -206,6 +206,33 @@ func (m *MainWindow) dropDatabasesData() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MainWindow) editFavorite() {
|
||||||
|
fmt.Println("Editing favorite server...")
|
||||||
|
|
||||||
|
sel := m.fav_servers.GetSelection()
|
||||||
|
model := m.fav_servers.GetModel()
|
||||||
|
iter := new(gtk.TreeIter)
|
||||||
|
_ = sel.GetSelected(iter)
|
||||||
|
|
||||||
|
// Getting server address.
|
||||||
|
var srv_addr string
|
||||||
|
srv_addr_gval := glib.ValueFromNative(srv_addr)
|
||||||
|
model.GetValue(iter, 7, srv_addr_gval)
|
||||||
|
server_address := srv_addr_gval.GetString()
|
||||||
|
|
||||||
|
if len(server_address) > 0 {
|
||||||
|
address := strings.Split(server_address, ":")[0]
|
||||||
|
port := strings.Split(server_address, ":")[1]
|
||||||
|
srv := []datamodels.Server{}
|
||||||
|
err := ctx.Database.Db.Select(&srv, ctx.Database.Db.Rebind("SELECT * FROM servers WHERE ip=? AND port=?"), address, port)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
m.favorite_dialog = &FavoriteDialog{}
|
||||||
|
m.favorite_dialog.InitializeUpdate(&srv[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (m *MainWindow) hideOfflineAllServers() {
|
func (m *MainWindow) hideOfflineAllServers() {
|
||||||
fmt.Println("(Un)Hiding offline servers in 'Servers' tab...")
|
fmt.Println("(Un)Hiding offline servers in 'Servers' tab...")
|
||||||
ctx.Eventer.LaunchEvent("loadAllServers")
|
ctx.Eventer.LaunchEvent("loadAllServers")
|
||||||
@ -564,12 +591,18 @@ func (m *MainWindow) InitializeToolbar() {
|
|||||||
fav_button.OnClicked(m.addToFavorites)
|
fav_button.OnClicked(m.addToFavorites)
|
||||||
m.toolbar.Insert(fav_button, 2)
|
m.toolbar.Insert(fav_button, 2)
|
||||||
|
|
||||||
|
fav_edit_button := gtk.NewToolButtonFromStock(gtk.STOCK_EDIT)
|
||||||
|
fav_edit_button.SetLabel("Edit favorite")
|
||||||
|
fav_edit_button.SetTooltipText("Edit selected favorite server")
|
||||||
|
fav_edit_button.OnClicked(m.editFavorite)
|
||||||
|
m.toolbar.Insert(fav_edit_button, 3)
|
||||||
|
|
||||||
// Remove server from favorites button.
|
// Remove server from favorites button.
|
||||||
fav_delete_button := gtk.NewToolButtonFromStock(gtk.STOCK_REMOVE)
|
fav_delete_button := gtk.NewToolButtonFromStock(gtk.STOCK_REMOVE)
|
||||||
fav_delete_button.SetLabel("Remove from favorites")
|
fav_delete_button.SetLabel("Remove from favorites")
|
||||||
fav_delete_button.SetTooltipText("Remove selected server from favorites")
|
fav_delete_button.SetTooltipText("Remove selected server from favorites")
|
||||||
fav_delete_button.OnClicked(m.deleteFromFavorites)
|
fav_delete_button.OnClicked(m.deleteFromFavorites)
|
||||||
m.toolbar.Insert(fav_delete_button, 3)
|
m.toolbar.Insert(fav_delete_button, 4)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MainWindow) launchGame() error {
|
func (m *MainWindow) launchGame() error {
|
||||||
|
Reference in New Issue
Block a user