Skip to content

Commit

Permalink
#328 - Extracts addition of resources to a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
iapazmino committed Sep 5, 2017
1 parent 97b31c7 commit 311c51a
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions gui/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,9 @@ func toArray(groupList gtki.ListStore) []string {
func (r *roster) createAccountPeerPopup(jid string, account *account, bt gdki.EventButton) {
builder := newBuilder("ContactPopupMenu")
mn := builder.getObj("contactMenu").(gtki.Menu)
menuItem := builder.getObj("resourcesoMenuItem").(gtki.MenuItem)
innerMenu, _ := g.gtk.MenuNew()

peer, _ := r.ui.getPeer(account, jid)
for _, resource := range peer.Resources() {
fullJid := jid + "/" + resource
item, _ := g.gtk.CheckMenuItemNewWithMnemonic(resource)
item.Connect("activate",
func() {
doInUIThread(func() {
r.openConversationView(account, fullJid, true)
})
})
innerMenu.Append(item)
}
menuItem.SetSubmenu(innerMenu)
menuItem := builder.getObj("resourcesoMenuItem").(gtki.MenuItem)
r.appendResourcesAsMenuItems(jid, account, menuItem)

builder.ConnectSignals(map[string]interface{}{
"on_remove_contact": func() {
Expand Down Expand Up @@ -256,6 +243,32 @@ func (r *roster) createAccountPeerPopup(jid string, account *account, bt gdki.Ev
mn.PopupAtPointer(bt)
}

func (r *roster) appendResourcesAsMenuItems(jid string, account *account, menuItem gtki.MenuItem) {
peer, ok := r.ui.getPeer(account, jid)
innerMenu, _ := g.gtk.MenuNew()

if !ok {
innerMenu.SetVisible(false)
menuItem.SetSubmenu(innerMenu)
return
}

for _, resource := range peer.Resources() {
fullJid := jid + "/" + resource
item, _ := g.gtk.CheckMenuItemNewWithMnemonic(resource)
item.Connect("activate",
func() {
doInUIThread(func() {
r.openConversationView(account, fullJid, true)
})
})
innerMenu.Append(item)
}

innerMenu.SetVisible(peer.HasResources())
menuItem.SetSubmenu(innerMenu)
}

func (r *roster) createAccountPopup(jid string, account *account, bt gdki.EventButton) {
mn := account.createSubmenu()
if *config.DebugFlag {
Expand Down

0 comments on commit 311c51a

Please sign in to comment.