miqt: use index tab comparisons instead of pointer comparisons, fix context menu offset

This commit is contained in:
mappu 2025-01-06 19:06:44 +13:00
parent 8705777203
commit c23090739a

26
main.go
View File

@ -361,7 +361,7 @@ func (self *DockerGUI) create_menu_bar() {
func (self *DockerGUI) show_context_menu(position *qt.QPoint) { func (self *DockerGUI) show_context_menu(position *qt.QPoint) {
context_menu := qt.NewQMenu2() context_menu := qt.NewQMenu2()
current_tab := self.tab_widget.CurrentWidget() current_tab := self.tab_widget.CurrentIndex()
// Add refresh action to context menu // Add refresh action to context menu
refresh_action := qt.NewQAction5("&Refresh", self.QObject) refresh_action := qt.NewQAction5("&Refresh", self.QObject)
@ -370,7 +370,7 @@ func (self *DockerGUI) show_context_menu(position *qt.QPoint) {
context_menu.AddSeparator() context_menu.AddSeparator()
if current_tab == self.containers_tab { if current_tab == ContainersTab {
terminal_action := qt.NewQAction5("&Terminal", self.QObject) terminal_action := qt.NewQAction5("&Terminal", self.QObject)
terminal_action.OnTriggered(func() { self.handle_action("Terminal") }) terminal_action.OnTriggered(func() { self.handle_action("Terminal") })
context_menu.AddAction(terminal_action) context_menu.AddAction(terminal_action)
@ -393,7 +393,9 @@ func (self *DockerGUI) show_context_menu(position *qt.QPoint) {
remove_action.OnTriggered(func() { self.handle_action("Remove") }) remove_action.OnTriggered(func() { self.handle_action("Remove") })
context_menu.AddAction(remove_action) context_menu.AddAction(remove_action)
} else if current_tab == self.images_tab { context_menu.ExecWithPos(self.containers_tree.Viewport().MapToGlobalWithQPoint(position))
} else if current_tab == ImagesTab {
pull_action := qt.NewQAction5("&Pull", self.QObject) pull_action := qt.NewQAction5("&Pull", self.QObject)
pull_action.OnTriggered(self.pull_image) pull_action.OnTriggered(self.pull_image)
context_menu.AddAction(pull_action) context_menu.AddAction(pull_action)
@ -404,19 +406,23 @@ func (self *DockerGUI) show_context_menu(position *qt.QPoint) {
remove_action.OnTriggered(self.remove_image) remove_action.OnTriggered(self.remove_image)
context_menu.AddAction(remove_action) context_menu.AddAction(remove_action)
} else if current_tab == self.networks_tab { context_menu.ExecWithPos(self.images_tree.Viewport().MapToGlobalWithQPoint(position))
} else if current_tab == NetworksTab {
remove_action := qt.NewQAction5("Remo&ve", self.QObject) remove_action := qt.NewQAction5("Remo&ve", self.QObject)
remove_action.OnTriggered(func() { self.handle_action("Remove") }) remove_action.OnTriggered(func() { self.handle_action("Remove") })
context_menu.AddAction(remove_action) context_menu.AddAction(remove_action)
} else if current_tab == self.volumes_tab { context_menu.ExecWithPos(self.networks_tree.Viewport().MapToGlobalWithQPoint(position))
} else if current_tab == VolumesTab {
remove_action := qt.NewQAction5("Remo&ve", self.QObject) remove_action := qt.NewQAction5("Remo&ve", self.QObject)
remove_action.OnTriggered(func() { self.handle_action("Remove") }) remove_action.OnTriggered(func() { self.handle_action("Remove") })
context_menu.AddAction(remove_action) context_menu.AddAction(remove_action)
context_menu.ExecWithPos(self.volumes_tree.Viewport().MapToGlobalWithQPoint(position))
} }
context_menu.ExecWithPos(current_tab.MapToGlobalWithQPoint(position))
} }
func (self *DockerGUI) setup_auto_refresh() { func (self *DockerGUI) setup_auto_refresh() {
@ -441,9 +447,9 @@ func (self *DockerGUI) setup_auto_refresh() {
} }
func (self *DockerGUI) handle_action(action string) { func (self *DockerGUI) handle_action(action string) {
current_tab := self.tab_widget.CurrentWidget() current_tab := self.tab_widget.CurrentIndex()
if current_tab == self.containers_tab { if current_tab == ContainersTab {
selected_items := self.containers_tree.SelectedItems() selected_items := self.containers_tree.SelectedItems()
if len(selected_items) == 0 { if len(selected_items) == 0 {
return return
@ -460,7 +466,7 @@ func (self *DockerGUI) handle_action(action string) {
exec.Command("docker", "rm", "-f", container_id).Run() exec.Command("docker", "rm", "-f", container_id).Run()
} }
} else if current_tab == self.networks_tab { } else if current_tab == NetworksTab {
selected_items := self.networks_tree.SelectedItems() selected_items := self.networks_tree.SelectedItems()
if len(selected_items) == 0 { if len(selected_items) == 0 {
return return
@ -471,7 +477,7 @@ func (self *DockerGUI) handle_action(action string) {
exec.Command("docker", "network", "rm", network_id).Run() exec.Command("docker", "network", "rm", network_id).Run()
} }
} else if current_tab == self.volumes_tab { } else if current_tab == VolumesTab {
selected_items := self.volumes_tree.SelectedItems() selected_items := self.volumes_tree.SelectedItems()
if len(selected_items) == 0 { if len(selected_items) == 0 {
return return