Search in sources :

Example 1 with UIToolBarManager

use of com.biglybt.pif.ui.toolbar.UIToolBarManager in project BiglyBT by BiglySoftware.

the class MainMenuV3 method buildSimpleViewMenu.

/**
 * @param viewMenu
 *
 * @since 4.5.0.3
 */
private void buildSimpleViewMenu(final Menu viewMenu, int accelerator) {
    try {
        MenuFactory.addMenuItem(viewMenu, SWT.CHECK, PREFIX_V3 + ".view.sidebar", new Listener() {

            @Override
            public void handleEvent(Event event) {
                SideBar sidebar = (SideBar) SkinViewManager.getByClass(SideBar.class);
                if (sidebar != null) {
                    sidebar.flipSideBarVisibility();
                }
            }
        });
        if (COConfigurationManager.getIntParameter("User Mode") > 1) {
            SWTSkin skin = SWTSkinFactory.getInstance();
            SWTSkinObject plugin_bar = skin.getSkinObject(SkinConstants.VIEWID_PLUGINBAR);
            if (plugin_bar != null) {
                MenuItem mi = MainMenuV3.createViewMenuItem(skin, viewMenu, "v3.MainWindow.menu.view." + SkinConstants.VIEWID_PLUGINBAR, SkinConstants.VIEWID_PLUGINBAR + ".visible", SkinConstants.VIEWID_PLUGINBAR, true, -1);
                if (accelerator != -1 && mi.getAccelerator() == accelerator) {
                    Listener[] listeners = mi.getListeners(SWT.Selection);
                    for (Listener l : listeners) {
                        try {
                            l.handleEvent(null);
                        } catch (Throwable e) {
                        }
                    }
                }
            }
        }
        MenuFactory.addViewToolbarMenuItem(viewMenu);
        // ///////
        MenuItem itemStatusBar = MenuFactory.createTopLevelMenuItem(viewMenu, "v3.MainWindow.menu.view.statusbar");
        itemStatusBar.setText(itemStatusBar.getText());
        Menu menuStatusBar = itemStatusBar.getMenu();
        final String[] statusAreaLangs = { "ConfigView.section.style.status.show_sr", "ConfigView.section.style.status.show_nat", "ConfigView.section.style.status.show_ddb", "ConfigView.section.style.status.show_ipf" };
        final String[] statusAreaConfig = { "Status Area Show SR", "Status Area Show NAT", "Status Area Show DDB", "Status Area Show IPF" };
        for (int i = 0; i < statusAreaConfig.length; i++) {
            final String configID = statusAreaConfig[i];
            String langID = statusAreaLangs[i];
            final MenuItem item = new MenuItem(menuStatusBar, SWT.CHECK);
            Messages.setLanguageText(item, langID);
            item.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    COConfigurationManager.setParameter(configID, !COConfigurationManager.getBooleanParameter(configID));
                }
            });
            menuStatusBar.addListener(SWT.Show, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    item.setSelection(COConfigurationManager.getBooleanParameter(configID));
                }
            });
        }
        if (Constants.isWindows) {
            MenuFactory.addSeparatorMenuItem(viewMenu);
        }
        boolean needsSep = false;
        boolean enabled = COConfigurationManager.getBooleanParameter("Beta Programme Enabled");
        if (enabled) {
            MenuFactory.addMenuItem(viewMenu, SWT.CHECK, PREFIX_V2 + ".view.beta", new Listener() {

                @Override
                public void handleEvent(Event event) {
                    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                    if (mdi != null) {
                        mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_BETAPROGRAM);
                    }
                }
            });
            needsSep = true;
        }
        if (needsSep) {
            MenuFactory.addSeparatorMenuItem(viewMenu);
        }
        needsSep = PluginsMenuHelper.getInstance().buildViewMenu(viewMenu, viewMenu.getShell());
        if (COConfigurationManager.getBooleanParameter("Library.EnableSimpleView")) {
            if (needsSep) {
                MenuFactory.addSeparatorMenuItem(viewMenu);
            }
            // Ubuntu Unity (14.04) with SWT 4508 crashes when global View menu triggered as it appears
            // that radio menu items aren't supported
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=419729#c9
            int simple_advanced_menu_type = Constants.isLinux ? SWT.CHECK : SWT.RADIO;
            MenuFactory.addMenuItem(viewMenu, simple_advanced_menu_type, PREFIX_V3 + ".view.asSimpleList", new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                    if (tb != null) {
                        UIToolBarItem item = tb.getToolBarItem("modeBig");
                        if (item != null) {
                            item.triggerToolBarItem(UIToolBarActivationListener.ACTIVATIONTYPE_NORMAL, SelectedContentManager.convertSelectedContentToObject(null));
                        }
                    }
                }
            });
            MenuFactory.addMenuItem(viewMenu, simple_advanced_menu_type, PREFIX_V3 + ".view.asAdvancedList", new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                    if (tb != null) {
                        UIToolBarItem item = tb.getToolBarItem("modeSmall");
                        if (item != null) {
                            item.triggerToolBarItem(UIToolBarActivationListener.ACTIVATIONTYPE_NORMAL, SelectedContentManager.convertSelectedContentToObject(null));
                        }
                    }
                }
            });
        }
        viewMenu.addMenuListener(new MenuListener() {

            @Override
            public void menuShown(MenuEvent e) {
                MenuItem sidebarMenuItem = MenuFactory.findMenuItem(viewMenu, PREFIX_V3 + ".view.sidebar");
                if (sidebarMenuItem != null) {
                    MultipleDocumentInterface mdi = UIFunctionsManager.getUIFunctions().getMDI();
                    if (mdi != null) {
                        sidebarMenuItem.setSelection(mdi.isVisible());
                    }
                }
                if (COConfigurationManager.getBooleanParameter("Library.EnableSimpleView")) {
                    MenuItem itemShowAsSimple = MenuFactory.findMenuItem(viewMenu, PREFIX_V3 + ".view.asSimpleList");
                    if (itemShowAsSimple != null) {
                        UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                        if (tb != null) {
                            UIToolBarItem item = tb.getToolBarItem("modeBig");
                            long state = item == null ? 0 : item.getState();
                            itemShowAsSimple.setEnabled((state & UIToolBarItem.STATE_ENABLED) > 0);
                            itemShowAsSimple.setSelection((state & UIToolBarItem.STATE_DOWN) > 0);
                        }
                    }
                    MenuItem itemShowAsAdv = MenuFactory.findMenuItem(viewMenu, PREFIX_V3 + ".view.asAdvancedList");
                    if (itemShowAsAdv != null) {
                        UIToolBarManager tb = UIToolBarManagerImpl.getInstance();
                        if (tb != null) {
                            UIToolBarItem item = tb.getToolBarItem("modeSmall");
                            long state = item == null ? 0 : item.getState();
                            itemShowAsAdv.setEnabled((state & UIToolBarItem.STATE_ENABLED) > 0);
                            itemShowAsAdv.setSelection((state & UIToolBarItem.STATE_DOWN) > 0);
                        }
                    }
                }
            }

            @Override
            public void menuHidden(MenuEvent e) {
            }
        });
    } catch (Exception e) {
        Debug.out("Error creating View Menu", e);
    }
}
Also used : ParameterListener(com.biglybt.core.config.ParameterListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) SWTSkin(com.biglybt.ui.swt.skin.SWTSkin) UIException(com.biglybt.pif.ui.UIException) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UIToolBarManager(com.biglybt.pif.ui.toolbar.UIToolBarManager) IMainMenu(com.biglybt.ui.swt.mainwindow.IMainMenu) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) SideBar(com.biglybt.ui.swt.views.skin.sidebar.SideBar)

Example 2 with UIToolBarManager

use of com.biglybt.pif.ui.toolbar.UIToolBarManager in project BiglyBT by BiglySoftware.

the class TorrentUtil method init.

public static synchronized void init() {
    if (initialised) {
        return;
    }
    initialised = true;
    for (String id : TU_ITEMS) {
        String key = "IconBar.visible." + id;
        if (!COConfigurationManager.hasParameter(key, false)) {
            COConfigurationManager.setParameter(key, false);
        }
    }
    UIManager ui_manager = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getUIManager();
    ui_manager.addUIListener(new UIManagerListener() {

        private List<UIToolBarItem> items = new ArrayList<>();

        @Override
        public void UIAttached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                UIToolBarManager tbm = instance.getToolBarManager();
                if (tbm != null) {
                    UIToolBarItem refresh_item = tbm.createToolBarItem(TU_ITEM_RECHECK);
                    refresh_item.setGroupID(TU_GROUP);
                    refresh_item.setImageID("recheck");
                    refresh_item.setToolTipID("MyTorrentsView.menu.recheck");
                    refresh_item.setDefaultActivationListener(new UIToolBarActivationListener() {

                        @Override
                        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                            List<DownloadManager> dms = getDMs(datasource);
                            for (DownloadManager dm : dms) {
                                if (dm.canForceRecheck()) {
                                    dm.forceRecheck();
                                }
                            }
                            return (true);
                        }
                    });
                    addItem(tbm, refresh_item);
                    // check files exist
                    UIToolBarItem cfe_item = tbm.createToolBarItem(TU_ITEM_CHECK_FILES);
                    cfe_item.setGroupID(TU_GROUP);
                    cfe_item.setImageID("filesexist");
                    cfe_item.setToolTipID("MyTorrentsView.menu.checkfilesexist");
                    cfe_item.setDefaultActivationListener(new UIToolBarActivationListener() {

                        @Override
                        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                            List<DownloadManager> dms = getDMs(datasource);
                            for (DownloadManager dm : dms) {
                                dm.filesExist(true);
                            }
                            return (true);
                        }
                    });
                    addItem(tbm, cfe_item);
                }
            }
        }

        private List<DownloadManager> getDMs(Object ds) {
            List<DownloadManager> result = new ArrayList<>();
            if (ds instanceof Download) {
                result.add(PluginCoreUtils.unwrap((Download) ds));
            } else if (ds instanceof Object[]) {
                Object[] objs = (Object[]) ds;
                for (Object obj : objs) {
                    if (obj instanceof Download) {
                        result.add(PluginCoreUtils.unwrap((Download) obj));
                    }
                }
            }
            return (result);
        }

        private void addItem(UIToolBarManager tbm, UIToolBarItem item) {
            items.add(item);
            tbm.addToolBarItem(item);
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                UIToolBarManager tbm = instance.getToolBarManager();
                if (tbm != null) {
                    for (UIToolBarItem item : items) {
                        tbm.removeToolBarItem(item.getID());
                    }
                }
                items.clear();
            }
        }
    });
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) ToolBarItem(com.biglybt.ui.common.ToolBarItem) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) UIToolBarManager(com.biglybt.pif.ui.toolbar.UIToolBarManager) List(java.util.List) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance)

Aggregations

UIToolBarActivationListener (com.biglybt.pif.ui.toolbar.UIToolBarActivationListener)2 UIToolBarItem (com.biglybt.pif.ui.toolbar.UIToolBarItem)2 UIToolBarManager (com.biglybt.pif.ui.toolbar.UIToolBarManager)2 ParameterListener (com.biglybt.core.config.ParameterListener)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 Download (com.biglybt.pif.download.Download)1 UIException (com.biglybt.pif.ui.UIException)1 UIInstance (com.biglybt.pif.ui.UIInstance)1 UIManager (com.biglybt.pif.ui.UIManager)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 ToolBarItem (com.biglybt.ui.common.ToolBarItem)1 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)1 IMainMenu (com.biglybt.ui.swt.mainwindow.IMainMenu)1 SWTSkin (com.biglybt.ui.swt.skin.SWTSkin)1 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)1 SideBar (com.biglybt.ui.swt.views.skin.sidebar.SideBar)1 List (java.util.List)1