Search in sources :

Example 1 with MenuContext

use of com.biglybt.pif.ui.menus.MenuContext in project BiglyBT by BiglySoftware.

the class BuddyPluginView method buildMenu.

private void buildMenu(final Set<ChatInstance> current_instances) {
    if (menu_items.size() == 0 || !menu_latest_instances.equals(current_instances)) {
        for (MenuItem mi : menu_items) {
            mi.remove();
        }
        menu_items.clear();
        final MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
        MenuContext mc = beta_status.getMenuContext();
        for (final ChatInstance chat : sortChats(current_instances)) {
            String short_name = chat.getShortName();
            MenuItem mi = menu_manager.addMenuItem(mc, "!" + short_name + "!");
            mi.addListener(new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    try {
                        openChat(chat.getClone());
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
            menu_items.add(mi);
        }
        boolean need_sep = true;
        if (current_instances.size() > 1) {
            MenuItem mi = menu_manager.addMenuItem(mc, "sep1");
            need_sep = false;
            mi.setStyle(MenuItem.STYLE_SEPARATOR);
            menu_items.add(mi);
            mi = menu_manager.addMenuItem(mc, "label.open.all");
            mi.addListener(new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    for (ChatInstance chat : current_instances) {
                        try {
                            openChat(chat.getClone());
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            });
            menu_items.add(mi);
        }
        if (need_sep) {
            MenuItem mi = menu_manager.addMenuItem(mc, "sep2");
            mi.setStyle(MenuItem.STYLE_SEPARATOR);
            menu_items.add(mi);
        }
        // create channel
        MenuItem mi = menu_manager.addMenuItem(mc, "chat.view.create.chat");
        mi.setStyle(MenuItem.STYLE_MENU);
        menu_items.add(mi);
        mi.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.removeAllChildItems();
                MenuItem mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.public") + "...!");
                mi.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
                        entryWindow.prompt(new UIInputReceiverListener() {

                            @Override
                            public void UIInputReceiverClosed(UIInputReceiver receiver) {
                                if (!receiver.hasSubmittedInput()) {
                                    return;
                                }
                                String key = receiver.getSubmittedInput().trim();
                                BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, key, null);
                            }
                        });
                    }
                });
                mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.anon") + "...!");
                mi.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        if (plugin.getBeta().isI2PAvailable()) {
                            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
                            entryWindow.prompt(new UIInputReceiverListener() {

                                @Override
                                public void UIInputReceiverClosed(UIInputReceiver receiver) {
                                    if (!receiver.hasSubmittedInput()) {
                                        return;
                                    }
                                    String key = receiver.getSubmittedInput().trim();
                                    BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, key, null);
                                }
                            });
                        } else {
                            I2PHelpers.installI2PHelper(null, null, null);
                        }
                    }
                });
                if (I2PHelpers.isInstallingI2PHelper()) {
                    mi.setEnabled(false);
                    mi.setText(mi.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            }
        });
        // chat overview
        mi = menu_manager.addMenuItem(mc, "!" + MessageText.getString("chats.view.heading") + "...!");
        mi.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT);
                }
            }
        });
        menu_items.add(mi);
        mi = menu_manager.addMenuItem(mc, "sep3");
        mi.setStyle(MenuItem.STYLE_SEPARATOR);
        menu_items.add(mi);
        // options
        mi = menu_manager.addMenuItem(mc, "MainWindow.menu.view.configuration");
        mi.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                ui_instance.openView(UISWTInstance.VIEW_MAIN, VIEW_ID, null);
            }
        });
        menu_items.add(mi);
        menu_latest_instances = current_instances;
    }
}
Also used : ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuContext(com.biglybt.pif.ui.menus.MenuContext) UIFunctions(com.biglybt.ui.UIFunctions) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Aggregations

UIInputReceiver (com.biglybt.pif.ui.UIInputReceiver)1 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)1 MenuContext (com.biglybt.pif.ui.menus.MenuContext)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1 MenuManager (com.biglybt.pif.ui.menus.MenuManager)1 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)1 UIFunctions (com.biglybt.ui.UIFunctions)1 SimpleTextEntryWindow (com.biglybt.ui.swt.SimpleTextEntryWindow)1