From 5ca8299714e4483e7b6a7ad6a7336016b33d4d81 Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Fri, 25 Nov 2016 03:12:05 +0500 Subject: [PATCH] Show selected server's information on active tab changing. URTrator will now show information about selected server on activated tab. E.g. when you switched from "Servers" to "Favorites", sidebar informational widget will be updated with server's data for selected server on "Favorites" tab. --- ui/mainwindow.go | 31 +++++++++++++++++++++++++++++++ ui/mainwindow_init.go | 7 +++++++ 2 files changed, 38 insertions(+) diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 4f1e6f7..d4c260c 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -132,8 +132,14 @@ type MainWindow struct { // Flags. + // Application is initialized? + initialized bool // Window is hidden? hidden bool + // Use other's tab information? + // Used when user changed active tab, to show information about + // server which is selected on activated tab. + use_other_servers_tab bool } func (m *MainWindow) addToFavorites() { @@ -502,6 +508,24 @@ func (m *MainWindow) loadProfiles(data map[string]string) { m.profiles.SetActive(0) } +func (m *MainWindow) tabChanged() { + if !m.initialized { + return + } + + fmt.Println("Active tab changed...") + current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage())) + fmt.Println(current_tab) + + m.use_other_servers_tab = true + if strings.Contains(current_tab, "Servers") { + m.fav_servers.Emit("cursor-changed") + } else if strings.Contains(current_tab, "Favorites") { + m.all_servers.Emit("cursor-changed") + } + m.use_other_servers_tab = false +} + func (m *MainWindow) serversUpdateCompleted(data map[string]string) { ctx.Eventer.LaunchEvent("setToolbarLabelText", map[string]string{"text": "Servers updated."}) // Trigger "selection-changed" events on currently active tab's @@ -548,6 +572,13 @@ func (m *MainWindow) showShortServerInformation() { fmt.Println("Server selection changed, updating server's information widget...") m.server_info_store.Clear() current_tab := m.tab_widget.GetTabLabelText(m.tab_widget.GetNthPage(m.tab_widget.GetCurrentPage())) + if m.use_other_servers_tab { + if strings.Contains(current_tab, "Servers") { + current_tab = "Favorites" + } else if strings.Contains(current_tab, "Favorites") { + current_tab = "Servers" + } + } srv_address := m.getIpFromServersList(current_tab) // Getting server information from cache. diff --git a/ui/mainwindow_init.go b/ui/mainwindow_init.go index f09eb04..4a7aa84 100644 --- a/ui/mainwindow_init.go +++ b/ui/mainwindow_init.go @@ -165,6 +165,9 @@ func (m *MainWindow) Initialize() { ctx.Eventer.LaunchEvent("loadFavoriteServers", map[string]string{}) ctx.Eventer.LaunchEvent("setToolbarLabelText", map[string]string{"text": "URTrator is ready."}) + // Set flag that shows to other parts that we're initialized. + m.initialized = true + gtk.Main() } @@ -291,6 +294,9 @@ func (m *MainWindow) initializeSidebar() { // Initializes internal storages. func (m *MainWindow) initializeStorages() { + // Application isn't initialized. + m.initialized = false + m.use_other_servers_tab = false // Gamemodes. m.gamemodes = make(map[string]string) m.gamemodes = map[string]string{ @@ -379,6 +385,7 @@ func (m *MainWindow) initializeStorages() { func (m *MainWindow) InitializeTabs() { // Create tabs widget. m.tab_widget = gtk.NewNotebook() + m.tab_widget.Connect("switch-page", m.tabChanged) tab_allsrv_hbox := gtk.NewHBox(false, 0) swin1 := gtk.NewScrolledWindow(nil, nil)