Search in sources :

Example 11 with MdiEntry

use of com.biglybt.ui.mdi.MdiEntry in project BiglyBT by BiglySoftware.

the class SideBar method fillDropDownMenu.

/**
 * @param menuDropDown
 *
 * @since 3.1.1.1
 */
protected void fillDropDownMenu(Menu menuDropDown, TreeItem[] items, int indent) {
    String s = "";
    for (int i = 0; i < indent; i++) {
        s += "   ";
    }
    for (int i = 0; i < items.length; i++) {
        TreeItem treeItem = items[i];
        SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
        if (entry == null) {
            continue;
        }
        org.eclipse.swt.widgets.MenuItem menuItem = new org.eclipse.swt.widgets.MenuItem(menuDropDown, entry.isSelectable() ? SWT.RADIO : SWT.CASCADE);
        String id = entry.getViewID();
        menuItem.setData("Plugin.viewID", id);
        ViewTitleInfo titleInfo = entry.getViewTitleInfo();
        String ind = "";
        if (titleInfo != null) {
            String o = (String) titleInfo.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
            if (o != null) {
                ind = "  (" + o + ")";
            // ind = "\t" + o;
            }
        }
        menuItem.setText(s + entry.getTitle() + ind);
        menuItem.addSelectionListener(dropDownSelectionListener);
        MdiEntry currentEntry = getCurrentEntry();
        if (currentEntry != null && currentEntry.getViewID().equals(id)) {
            menuItem.setSelection(true);
        }
        TreeItem[] subItems = treeItem.getItems();
        if (subItems.length > 0) {
            Menu parent = menuDropDown;
            if (!entry.isSelectable()) {
                parent = new Menu(menuDropDown.getParent().getShell(), SWT.DROP_DOWN);
                menuItem.setMenu(parent);
            }
            fillDropDownMenu(parent, subItems, indent + 1);
        }
    }
}
Also used : MenuItem(com.biglybt.pif.ui.menus.MenuItem) org.eclipse.swt.widgets(org.eclipse.swt.widgets) MdiEntry(com.biglybt.ui.mdi.MdiEntry) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 12 with MdiEntry

use of com.biglybt.ui.mdi.MdiEntry in project BiglyBT by BiglySoftware.

the class SideBar method createSideBar.

private void createSideBar() {
    SWTSkinObject soSideBarList = skin.getSkinObject("sidebar-list");
    if (soSideBarList == null) {
        return;
    }
    Composite sidebarList = (Composite) soSideBarList.getControl();
    pluginSash = Utils.createSashWrapper(sidebarList, "Sidebar.Plugin.SplitAt", 75);
    pluginSash.setBottomVisible(false);
    Composite[] kids = pluginSash.getChildren();
    cPluginsArea = new Composite(kids[1], SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = layout.marginWidth = 0;
    layout.verticalSpacing = layout.horizontalSpacing = 0;
    cPluginsArea.setLayout(layout);
    cPluginsArea.setLayoutData(Utils.getFilledFormData());
    tree = new Tree(kids[0], SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.DOUBLE_BUFFERED | SWT.NO_SCROLL);
    tree.setHeaderVisible(false);
    new SideBarToolTips(this, tree);
    tree.setLayoutData(Utils.getFilledFormData());
    SWTSkinProperties skinProperties = skin.getSkinProperties();
    bg = skinProperties.getColor("color.sidebar.bg");
    fg = skinProperties.getColor("color.sidebar.fg");
    configBGColorListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            Utils.execSWTThread(new Runnable() {

                @Override
                public void run() {
                    swt_updateSideBarColors();
                }
            });
        }
    };
    COConfigurationManager.addParameterListener("config.skin.color.sidebar.bg", configBGColorListener);
    COConfigurationManager.addParameterListener("Side Bar Close Position", configBGColorListener);
    tree.setBackground(bg);
    tree.setForeground(fg);
    fontHeader = FontUtils.getFontWithStyle(tree.getFont(), SWT.BOLD, 1.0f);
    // after a scroll we need to recalculate the hit areas as they will have moved!
    ScrollBar vBar = tree.getVerticalBar();
    vBar.setData("ScrollOnMouseOver", (Runnable) () -> {
        int pos = vBar.getSelection();
        TreeItem item = getTreeItemAt(pos);
        if (item != null) {
            tree.setTopItem(item);
        }
    });
    // repaint problems on mousewheel scroll on OSX
    if (Constants.isOSX) {
        vBar.setData("ScrollOnMouseOver2", (Runnable) () -> {
            tree.redraw();
        });
    }
    vBar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail == SWT.None) {
                SideBarEntrySWT[] sideBarEntries = getEntries(new SideBarEntrySWT[0]);
                swt_updateSideBarHitAreasY(sideBarEntries);
            }
            // repaint problems on mousewheel scroll on OSX
            if (Constants.isOSX) {
                tree.redraw();
            }
        }
    });
    Listener treeListener = new Listener() {

        TreeItem lastTopItem = null;

        boolean mouseDowned = false;

        Rectangle lastCloseAreaClicked = null;

        private boolean wasExpanded;

        @Override
        public void handleEvent(final Event event) {
            if (Utils.isDisplayDisposed()) {
                if (event.type == SWT.Dispose) {
                    saveCloseables();
                }
                return;
            }
            TreeItem treeItem = (TreeItem) event.item;
            Tree tree = getTree();
            try {
                switch(event.type) {
                    case SWT.MeasureItem:
                        {
                            int clientWidth = tree.getClientArea().width;
                            String text = treeItem.getText(event.index);
                            Point size = event.gc.textExtent(text);
                            if (event.x + event.width < clientWidth) {
                                // tree.getClientArea().width;
                                event.width = size.x + event.x;
                                event.x = 0;
                            }
                            if (Constants.isWindows) {
                                event.width = clientWidth - event.x;
                            }
                            event.height = 20;
                            break;
                        }
                    case SWT.PaintItem:
                        {
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            // System.out.println("PaintItem: " + event.item + ";" + event.index + ";" + event.detail + ";" + event.getBounds() + ";" + event.gc.getClipping());
                            if (entry != null) {
                                boolean selected = getCurrentEntry() == entry;
                                if (!selected) {
                                    event.detail &= ~SWT.SELECTED;
                                } else {
                                    event.detail |= SWT.SELECTED;
                                }
                                entry.swt_paintSideBar(event);
                            }
                            break;
                        }
                    case SWT.Paint:
                        {
                            // System.out.println("Paint: " + event.getBounds() + ";" + event.detail + ";" + event.index + ";" + event.gc.getClipping());// + "  " + Debug.getCompressedStackTrace());
                            if (!USE_PAINT) {
                                return;
                            }
                            Rectangle bounds = event.getBounds();
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            int y = event.y + 1;
                            treeItem = tree.getItem(new Point(indent, y));
                            while (treeItem != null) {
                                SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                                Rectangle itemBounds = entry == null ? null : entry.swt_getBounds();
                                // happened once, so let's check..
                                if (itemBounds != null && entry != null) {
                                    event.item = treeItem;
                                    boolean selected = getCurrentEntry() == entry && entry.isSelectable();
                                    event.detail = selected ? SWT.SELECTED : SWT.NONE;
                                    Rectangle newClip = bounds.intersection(itemBounds);
                                    // System.out.println("Paint " + id + " @ " + newClip);
                                    event.setBounds(newClip);
                                    Utils.setClipping(event.gc, newClip);
                                    entry.swt_paintSideBar(event);
                                    y = itemBounds.y + itemBounds.height + 1;
                                } else {
                                    y += tree.getItemHeight();
                                }
                                if (y > bounds.y + bounds.height) {
                                    break;
                                }
                                TreeItem oldTreeItem = treeItem;
                                treeItem = tree.getItem(new Point(indent, y));
                                if (oldTreeItem == treeItem) {
                                    break;
                                }
                            }
                            if (tree.getTopItem() != lastTopItem) {
                                lastTopItem = tree.getTopItem();
                                SideBarEntrySWT[] sideBarEntries = getEntries(new SideBarEntrySWT[0]);
                                swt_updateSideBarHitAreasY(sideBarEntries);
                            }
                            break;
                        }
                    case SWT.EraseItem:
                        {
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            if (entry == null) {
                                event.detail = 0;
                            }
                            // event.detail &= ~SWT.FOREGROUND;
                            // event.detail &= ~(SWT.FOREGROUND | SWT.BACKGROUND);
                            event.doit = true;
                            break;
                        }
                    case SWT.Resize:
                        {
                            tree.redraw();
                            break;
                        }
                    case SWT.Selection:
                        {
                            if (treeItem == null) {
                                return;
                            }
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            if (entry != null) {
                                Point cursorLocation = tree.toControl(event.display.getCursorLocation());
                                if (lastCloseAreaClicked != null && lastCloseAreaClicked.contains(cursorLocation.x, cursorLocation.y)) {
                                    return;
                                }
                                showEntry(entry);
                            } else if (getCurrentEntry() != null) {
                                TreeItem topItem = tree.getTopItem();
                                // prevent "jumping" in the case where selection is off screen
                                // setSelection would jump the item on screen, and then
                                // showItem would jump back to where the user was.
                                tree.setRedraw(false);
                                TreeItem ti = getCurrentEntry().getTreeItem();
                                if (ti != null) {
                                    tree.setSelection(ti);
                                }
                                if (topItem != null) {
                                    // Seen on OSX
                                    tree.setTopItem(topItem);
                                }
                                tree.setRedraw(true);
                                event.doit = false;
                            }
                            break;
                        }
                    case SWT.MouseMove:
                        {
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            treeItem = tree.getItem(new Point(indent, event.y));
                            SideBarEntrySWT entry = (SideBarEntrySWT) ((treeItem == null || treeItem.isDisposed()) ? null : treeItem.getData("MdiEntry"));
                            int cursorNo = SWT.CURSOR_ARROW;
                            if (treeItem != null) {
                                Rectangle closeArea = (Rectangle) treeItem.getData("closeArea");
                                if (closeArea != null && closeArea.contains(event.x, event.y)) {
                                    cursorNo = SWT.CURSOR_HAND;
                                } else if (entry != null && treeItem.getItemCount() > 0) {
                                    cursorNo = SWT.CURSOR_HAND;
                                } else if (entry != null) {
                                    List<MdiEntryVitalityImageSWT> vitalityImages = entry.getVitalityImages();
                                    for (MdiEntryVitalityImageSWT vitalityImage : vitalityImages) {
                                        if (vitalityImage == null || !vitalityImage.isVisible()) {
                                            continue;
                                        }
                                        Rectangle hitArea = vitalityImage.getHitArea();
                                        if (hitArea == null) {
                                            continue;
                                        }
                                        // setHitArea needs it relative to entry
                                        Rectangle itemBounds = entry.swt_getBounds();
                                        int relY = event.y - (itemBounds == null ? 0 : itemBounds.y);
                                        if (hitArea.contains(event.x, relY)) {
                                            if (vitalityImage.hasListeners()) {
                                                cursorNo = SWT.CURSOR_HAND;
                                            }
                                        }
                                    }
                                }
                            }
                            Cursor cursor = event.display.getSystemCursor(cursorNo);
                            if (tree.getCursor() != cursor) {
                                tree.setCursor(cursor);
                            }
                            if (treeItem != null) {
                                wasExpanded = entry != null && entry.isExpanded();
                            } else {
                                wasExpanded = false;
                            }
                            break;
                        }
                    case SWT.MouseDown:
                        {
                            mouseDowned = true;
                            lastCloseAreaClicked = null;
                            if (tree.getItemCount() == 0 || event.button != 1) {
                                return;
                            }
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            treeItem = tree.getItem(new Point(indent, event.y));
                            if (treeItem == null) {
                                return;
                            }
                            Rectangle closeArea = (Rectangle) treeItem.getData("closeArea");
                            if (closeArea != null && closeArea.contains(event.x, event.y)) {
                                lastCloseAreaClicked = closeArea;
                                SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                                if (entry != null) {
                                    closeEntry(entry, true);
                                } else {
                                    treeItem.dispose();
                                }
                                // pretend we don't have a mouse down, so we don't process a showEntry
                                mouseDowned = false;
                            }
                            break;
                        }
                    case SWT.MouseUp:
                        {
                            if (!mouseDowned) {
                                return;
                            }
                            mouseDowned = false;
                            if (tree.getItemCount() == 0 || event.button != 1) {
                                return;
                            }
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            treeItem = tree.getItem(new Point(indent, event.y));
                            if (treeItem == null) {
                                return;
                            }
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            Rectangle closeArea = (Rectangle) treeItem.getData("closeArea");
                            if (closeArea != null && closeArea.contains(event.x, event.y)) {
                                // treeItem.dispose();
                                return;
                            } else if (getCurrentEntry() != entry && Constants.isOSX) {
                            // showEntry(entry);  removed as we'll get a selection event if needed
                            }
                            if (entry != null) {
                                List<MdiEntryVitalityImageSWT> vitalityImages = entry.getVitalityImages();
                                for (MdiEntryVitalityImageSWT vitalityImage : vitalityImages) {
                                    if (vitalityImage == null || !vitalityImage.isVisible()) {
                                        continue;
                                    }
                                    Rectangle hitArea = vitalityImage.getHitArea();
                                    if (hitArea == null) {
                                        continue;
                                    }
                                    // setHitArea needs it relative to entry
                                    Rectangle itemBounds = entry.swt_getBounds();
                                    int relY = event.y - (itemBounds == null ? 0 : itemBounds.y);
                                    if (hitArea.contains(event.x, relY)) {
                                        vitalityImage.triggerClickedListeners(event.x, relY);
                                        return;
                                    }
                                }
                                if (treeItem.getItemCount() > 0) {
                                    Integer rhs = (Integer) treeItem.getData("expandoRHS");
                                    int limit = rhs == null ? 20 : rhs;
                                    if (event.x < limit) {
                                        // Note: On Windows, user can expand row by clicking the invisible area where the OS twisty would be
                                        MdiEntry currentEntry = getCurrentEntry();
                                        String collapsedID = entry.getViewID();
                                        while (currentEntry != null) {
                                            String parentID = currentEntry.getParentID();
                                            if (collapsedID.equals(parentID)) {
                                                showEntryByID(collapsedID);
                                                break;
                                            }
                                            currentEntry = getEntry(parentID);
                                        }
                                        entry.setExpanded(!wasExpanded);
                                        wasExpanded = !wasExpanded;
                                    }
                                }
                            }
                            break;
                        }
                    case SWT.MouseDoubleClick:
                        {
                            int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                            treeItem = tree.getItem(new Point(indent, event.y));
                            SideBarEntrySWT entry = (SideBarEntrySWT) ((treeItem == null || treeItem.isDisposed()) ? null : treeItem.getData("MdiEntry"));
                            if (entry != null) {
                                // don't trigger popout if double click is in close area or
                                // item has child and user is clicking in the expandy area
                                boolean done = false;
                                Point cursorLocation = tree.toControl(event.display.getCursorLocation());
                                if (lastCloseAreaClicked == null || !lastCloseAreaClicked.contains(cursorLocation.x, cursorLocation.y)) {
                                    Integer offset = (Integer) treeItem.getData("contentStartOffset");
                                    if (treeItem.getItemCount() == 0 || (offset != null && event.x >= offset)) {
                                        if (canPopoutEntry(entry)) {
                                            done = popoutEntry(entry, true);
                                        }
                                    }
                                }
                                if (!done) {
                                    if (treeItem.getItemCount() > 0) {
                                        entry.setExpanded(!entry.isExpanded());
                                    }
                                }
                            }
                            break;
                        }
                    case SWT.Dispose:
                        {
                            fontHeader.dispose();
                            if (dropTarget != null && !dropTarget.isDisposed()) {
                                dropTarget.dispose();
                            }
                            saveCloseables();
                            break;
                        }
                    case SWT.Collapse:
                        {
                            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                            MdiEntry currentEntry = getCurrentEntry();
                            String collapsedID = entry.getViewID();
                            while (currentEntry != null) {
                                String parentID = currentEntry.getParentID();
                                if (collapsedID.equals(parentID)) {
                                    showEntryByID(collapsedID);
                                    break;
                                }
                                currentEntry = getEntry(parentID);
                            }
                            break;
                        }
                    case SWT.KeyDown:
                        {
                            MdiEntry currentEntry = getCurrentEntry();
                            if (currentEntry != null) {
                                if (currentEntry.processAccelerator(event.character, event.stateMask)) {
                                    event.doit = false;
                                }
                            }
                            break;
                        }
                }
            } catch (Exception e) {
                Debug.out(e);
            }
        }
    };
    tree.addListener(SWT.Resize, treeListener);
    if (USE_PAINT) {
        tree.addListener(SWT.Paint, treeListener);
    }
    tree.addListener(SWT.MeasureItem, treeListener);
    tree.addListener(SWT.PaintItem, treeListener);
    tree.addListener(SWT.EraseItem, treeListener);
    tree.addListener(SWT.Selection, treeListener);
    tree.addListener(SWT.Dispose, treeListener);
    tree.addListener(SWT.MouseDoubleClick, treeListener);
    // For icons
    tree.addListener(SWT.MouseUp, treeListener);
    tree.addListener(SWT.MouseDown, treeListener);
    // For cursor
    tree.addListener(SWT.MouseMove, treeListener);
    // to disable collapsing
    tree.addListener(SWT.Collapse, treeListener);
    // for accelerators
    tree.addListener(SWT.KeyDown, treeListener);
    dropTarget = new DropTarget(tree, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
    dropTarget.setTransfer(new Transfer[] { FixedHTMLTransfer.getInstance(), FixedURLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance() });
    dropTarget.addDropListener(new DropTargetAdapter() {

        @Override
        public void dropAccept(DropTargetEvent event) {
            event.currentDataType = FixedURLTransfer.pickBestType(event.dataTypes, event.currentDataType);
        }

        @Override
        public void dragEnter(DropTargetEvent event) {
        }

        @Override
        public void dragOperationChanged(DropTargetEvent event) {
        }

        // @see org.eclipse.swt.dnd.DropTargetAdapter#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
        @Override
        public void dragOver(DropTargetEvent event) {
            TreeItem treeItem = (event.item instanceof TreeItem) ? (TreeItem) event.item : null;
            if (treeItem != null) {
                SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                draggingOver = entry;
            } else {
                draggingOver = null;
            }
            if (draggingOver == null || !draggingOver.hasDropListeners()) {
                boolean isTorrent = TorrentOpener.doesDropHaveTorrents(event);
                if (isTorrent) {
                    event.detail = DND.DROP_COPY;
                } else {
                    event.detail = DND.DROP_NONE;
                }
                draggingOver = null;
            } else if ((event.operations & DND.DROP_LINK) > 0)
                event.detail = DND.DROP_LINK;
            else if ((event.operations & DND.DROP_COPY) > 0)
                event.detail = DND.DROP_COPY;
            else if ((event.operations & DND.DROP_DEFAULT) > 0)
                event.detail = DND.DROP_COPY;
            if (Constants.isOSX) {
                tree.redraw();
            }
            event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL | DND.FEEDBACK_EXPAND;
        }

        // @see org.eclipse.swt.dnd.DropTargetAdapter#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
        @Override
        public void dragLeave(DropTargetEvent event) {
            draggingOver = null;
            tree.redraw();
        }

        @Override
        public void drop(DropTargetEvent event) {
            draggingOver = null;
            tree.redraw();
            if (!(event.item instanceof TreeItem)) {
                defaultDrop(event);
                return;
            }
            TreeItem treeItem = (TreeItem) event.item;
            SideBarEntrySWT entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
            boolean handled = entry != null && entry.triggerDropListeners(event.data);
            if (!handled) {
                defaultDrop(event);
            }
        }
    });
    final Menu menuTree = new Menu(tree);
    tree.setMenu(menuTree);
    tree.addMenuDetectListener(e -> {
        menuTree.setData("MenuSource", e.detail);
    });
    menuTree.addMenuListener(new MenuListener() {

        boolean bShown = false;

        @Override
        public void menuHidden(MenuEvent e) {
            bShown = false;
            if (Constants.isOSX) {
                return;
            }
            // Must dispose in an asyncExec, otherwise SWT.Selection doesn't
            // get fired (async workaround provided by Eclipse Bug #87678)
            Utils.execSWTThreadLater(0, new AERunnable() {

                @Override
                public void runSupport() {
                    if (bShown || menuTree.isDisposed()) {
                        return;
                    }
                    Utils.disposeSWTObjects(menuTree.getItems());
                }
            });
        }

        @Override
        public void menuShown(MenuEvent e) {
            Utils.disposeSWTObjects(menuTree.getItems());
            bShown = true;
            Object oMenuSource = menuTree.getData("MenuSource");
            int menuSource = (oMenuSource instanceof Number) ? ((Number) oMenuSource).intValue() : SWT.MENU_MOUSE;
            SideBarEntrySWT entry;
            if (menuSource != SWT.MENU_KEYBOARD) {
                Point ptMouse = tree.toControl(e.display.getCursorLocation());
                int indent = END_INDENT ? tree.getClientArea().width - 1 : 0;
                TreeItem treeItem = tree.getItem(new Point(indent, ptMouse.y));
                if (treeItem != null) {
                    entry = (SideBarEntrySWT) treeItem.getData("MdiEntry");
                } else {
                    entry = null;
                }
            } else {
                entry = getCurrentEntry();
            }
            if (entry != null) {
                fillMenu(menuTree, entry, "sidebar");
            }
            if (entry == null || entry.getParentID() == null) {
                MenuBuildUtils.addSeparator(menuTree);
                org.eclipse.swt.widgets.MenuItem mi = new org.eclipse.swt.widgets.MenuItem(menuTree, SWT.PUSH);
                mi.setText(MessageText.getString("menu.sidebar.options"));
                mi.addListener(SWT.Selection, (ev) -> {
                    UIFunctions uif = UIFunctionsManager.getUIFunctions();
                    if (uif != null) {
                        JSONObject args = new JSONObject();
                        args.put("select", ConfigSectionInterfaceDisplaySWT.REFID_SECTION_SIDEBAR);
                        String args_str = JSONUtils.encodeToJSON(args);
                        uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, ConfigSectionInterfaceDisplaySWT.SECTION_ID + args_str);
                    }
                });
            }
            if (menuTree.getItemCount() == 0) {
                Utils.execSWTThreadLater(0, new AERunnable() {

                    @Override
                    public void runSupport() {
                        menuTree.setVisible(false);
                    }
                });
            }
        }
    });
    if (soSideBarPopout != null) {
        SWTSkinObject soDropDown = skin.getSkinObject("sidebar-dropdown");
        if (soDropDown != null) {
            final Menu menuDropDown = new Menu(soDropDown.getControl());
            menuDropDown.addMenuListener(new MenuListener() {

                boolean bShown = false;

                @Override
                public void menuHidden(MenuEvent e) {
                    bShown = false;
                    if (Constants.isOSX) {
                        return;
                    }
                    // Must dispose in an asyncExec, otherwise SWT.Selection doesn't
                    // get fired (async workaround provided by Eclipse Bug #87678)
                    Utils.execSWTThreadLater(0, new AERunnable() {

                        @Override
                        public void runSupport() {
                            if (bShown || menuDropDown.isDisposed()) {
                                return;
                            }
                            Utils.disposeSWTObjects(menuDropDown.getItems());
                        }
                    });
                }

                @Override
                public void menuShown(MenuEvent e) {
                    Utils.disposeSWTObjects(menuDropDown.getItems());
                    bShown = true;
                    fillDropDownMenu(menuDropDown, tree.getItems(), 0);
                }
            });
            dropDownSelectionListener = new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String id = (String) e.widget.getData("Plugin.viewID");
                    showEntryByID(id);
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            };
            SWTSkinButtonUtility btnDropDown = new SWTSkinButtonUtility(soDropDown);
            btnDropDown.addSelectionListener(new SWTSkinButtonUtility.ButtonListenerAdapter() {

                @Override
                public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                    Control c = buttonUtility.getSkinObject().getControl();
                    menuDropDown.setLocation(c.getDisplay().getCursorLocation());
                    menuDropDown.setVisible(!menuDropDown.getVisible());
                }
            });
        }
        SWTSkinObject soExpand = skin.getSkinObject("sidebar-expand");
        if (soExpand != null) {
            SWTSkinButtonUtility btnExpand = new SWTSkinButtonUtility(soExpand);
            btnExpand.addSelectionListener(new SWTSkinButtonUtility.ButtonListenerAdapter() {

                @Override
                public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                    flipSideBarVisibility();
                }
            });
        }
        SWTSkinObject soCloseItem = skin.getSkinObject("sidebar-closeitem");
        if (soCloseItem != null) {
            btnCloseItem = new SWTSkinButtonUtility(soCloseItem);
            btnCloseItem.addSelectionListener(new SWTSkinButtonUtility.ButtonListenerAdapter() {

                @Override
                public void pressed(SWTSkinButtonUtility buttonUtility, SWTSkinObject skinObject, int stateMask) {
                    closeEntry(getCurrentEntry(), true);
                }
            });
        }
    }
}
Also used : COConfigurationManager(com.biglybt.core.config.COConfigurationManager) PluginManager(com.biglybt.pif.PluginManager) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) UIFunctionsManagerSWT(com.biglybt.ui.swt.UIFunctionsManagerSWT) UIFunctionsManager(com.biglybt.ui.UIFunctionsManager) ConfigSectionInterfaceDisplaySWT(com.biglybt.ui.swt.views.configsections.ConfigSectionInterfaceDisplaySWT) Utils(com.biglybt.ui.swt.Utils) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo) IViewAlwaysInitialize(com.biglybt.ui.swt.views.IViewAlwaysInitialize) TorrentOpener(com.biglybt.ui.swt.mainwindow.TorrentOpener) com.biglybt.ui.swt.pifimpl(com.biglybt.ui.swt.pifimpl) ViewManagerSWT(com.biglybt.ui.swt.views.ViewManagerSWT) FontUtils(com.biglybt.ui.swt.utils.FontUtils) org.eclipse.swt.layout(org.eclipse.swt.layout) org.eclipse.swt.graphics(org.eclipse.swt.graphics) ParameterListener(com.biglybt.core.config.ParameterListener) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) MessageText(com.biglybt.core.internat.MessageText) List(java.util.List) JSONObject(org.json.simple.JSONObject) MdiEntry(com.biglybt.ui.mdi.MdiEntry) UIManager(com.biglybt.pif.ui.UIManager) SWT(org.eclipse.swt.SWT) UIFunctions(com.biglybt.ui.UIFunctions) FixedHTMLTransfer(com.biglybt.ui.swt.FixedHTMLTransfer) com.biglybt.ui.swt.mdi(com.biglybt.ui.swt.mdi) java.util(java.util) com.biglybt.pif.ui.menus(com.biglybt.pif.ui.menus) Download(com.biglybt.pif.download.Download) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils) PluginInterface(com.biglybt.pif.PluginInterface) SWTViewListener(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl.SWTViewListener) UIUpdaterSWT(com.biglybt.ui.swt.uiupdater.UIUpdaterSWT) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UIUpdater(com.biglybt.ui.common.updater.UIUpdater) UIInstance(com.biglybt.pif.ui.UIInstance) org.eclipse.swt.dnd(org.eclipse.swt.dnd) CoreFactory(com.biglybt.core.CoreFactory) QuickLinksView(com.biglybt.ui.swt.views.QuickLinksView) org.eclipse.swt.events(org.eclipse.swt.events) org.eclipse.swt.widgets(org.eclipse.swt.widgets) ObfuscateImage(com.biglybt.ui.swt.debug.ObfuscateImage) JSONUtils(com.biglybt.util.JSONUtils) com.biglybt.core.util(com.biglybt.core.util) MainMDISetup(com.biglybt.ui.swt.shells.main.MainMDISetup) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) FixedURLTransfer(com.biglybt.ui.swt.FixedURLTransfer) com.biglybt.ui.swt.skin(com.biglybt.ui.swt.skin) UIFunctions(com.biglybt.ui.UIFunctions) List(java.util.List) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) ParameterListener(com.biglybt.core.config.ParameterListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) SWTViewListener(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl.SWTViewListener) org.eclipse.swt.widgets(org.eclipse.swt.widgets) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MenuItem(com.biglybt.pif.ui.menus.MenuItem) ParameterListener(com.biglybt.core.config.ParameterListener) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent)

Example 13 with MdiEntry

use of com.biglybt.ui.mdi.MdiEntry in project BiglyBT by BiglySoftware.

the class SideBar method showPrevious.

private void showPrevious() {
    MdiEntry current = getCurrentEntry();
    String next = null;
    synchronized (entryViewHistory) {
        boolean future_added = false;
        if (current != null && entryExists(current.getViewID()) && current.isSelectable()) {
            String cid = current.getViewID();
            if (entryViewFuture.isEmpty() || !entryViewFuture.peek().equals(cid)) {
                entryViewFuture.push(cid);
            }
            future_added = true;
        }
        while (!entryViewHistory.isEmpty()) {
            String maybe_next = entryViewHistory.pop();
            if (current != null && current.getViewID().equals(maybe_next)) {
                continue;
            }
            if (entryExists(maybe_next)) {
                next = maybe_next;
                if (!future_added) {
                    if (entryViewFuture.isEmpty() || !entryViewFuture.peek().equals(next)) {
                        entryViewFuture.push(next);
                    }
                }
                // prepare for show-next so we keep future history
                entryViewHistory.push(next);
                break;
            }
        }
    }
    if (next == null) {
        next = SideBar.SIDEBAR_SECTION_LIBRARY;
    }
    showEntryByID(next);
}
Also used : MdiEntry(com.biglybt.ui.mdi.MdiEntry)

Example 14 with MdiEntry

use of com.biglybt.ui.mdi.MdiEntry in project BiglyBT by BiglySoftware.

the class SideBarEntrySWT method setTreeItem.

public void setTreeItem(TreeItem treeItem) {
    if (swtItem != null && treeItem != null) {
        Debug.out("Warning: Sidebar " + id + " already has a treeitem");
        return;
    }
    this.swtItem = treeItem;
    if (treeItem != null) {
        ImageLoader imageLoader = ImageLoader.getInstance();
        imgClose = imageLoader.getImage("image.sidebar.closeitem");
        imgCloseSelected = imageLoader.getImage("image.sidebar.closeitem-selected");
        treeItem.addDisposeListener(e -> closeView());
        treeItem.getParent().addTreeListener(new TreeListener() {

            @Override
            public void treeExpanded(TreeEvent e) {
                if (e.item == swtItem) {
                    SideBarEntrySWT.super.setExpanded(true);
                }
            }

            @Override
            public void treeCollapsed(TreeEvent e) {
                if (e.item == swtItem) {
                    SideBarEntrySWT.super.setExpanded(false);
                }
            }
        });
        // Some/All OSes will auto-set treeitem's expanded flag to false if there
        // is no children.  To workaround, we store expanded state internally and
        // set parent to expanded when a child is added
        TreeItem parentItem = treeItem.getParentItem();
        if (parentItem != null) {
            MdiEntry parentEntry = (MdiEntry) parentItem.getData("MdiEntry");
            if (parentEntry.isExpanded()) {
                parentItem.setExpanded(true);
            }
        }
        setExpanded(isExpanded());
    }
    if (buildonSWTItemSet) {
        build();
    }
    if (showonSWTItemSet) {
        show();
    }
}
Also used : BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 15 with MdiEntry

use of com.biglybt.ui.mdi.MdiEntry in project BiglyBT by BiglySoftware.

the class FileInfoView method eventOccurred.

@Override
public boolean eventOccurred(UISWTViewEvent event) {
    switch(event.getType()) {
        case UISWTViewEvent.TYPE_CREATE:
            swtView = (UISWTView) event.getData();
            if (swtView instanceof MdiEntry) {
                MultipleDocumentInterface mdi = ((MdiEntry) swtView).getMDI();
                // We should always have an MDI, since this view goes under the "Files" tab
                if (mdi instanceof BaseMDI) {
                    // Is our Files tab also in an MDI (MyTorrents and Torrent Details View)?
                    UISWTView parentView = ((BaseMDI) mdi).getParentView();
                    if (!(parentView instanceof MdiEntry)) {
                        return false;
                    }
                }
            }
            swtView.setTitle(getFullTitle());
            break;
        case UISWTViewEvent.TYPE_DESTROY:
            delete();
            break;
        case UISWTViewEvent.TYPE_INITIALIZE:
            initialize((Composite) event.getData());
            break;
        case UISWTViewEvent.TYPE_LANGUAGEUPDATE:
            Messages.updateLanguageForControl(getComposite());
            swtView.setTitle(getFullTitle());
            break;
        case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
            dataSourceChanged(event.getData());
            break;
        case UISWTViewEvent.TYPE_FOCUSGAINED:
            refreshInfoCanvas();
            break;
        case UISWTViewEvent.TYPE_REFRESH:
            refresh();
            break;
    }
    return true;
}
Also used : UISWTView(com.biglybt.ui.swt.pif.UISWTView) BaseMDI(com.biglybt.ui.swt.mdi.BaseMDI) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface)

Aggregations

MdiEntry (com.biglybt.ui.mdi.MdiEntry)41 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)13 BaseMdiEntry (com.biglybt.ui.swt.mdi.BaseMdiEntry)11 MenuItem (com.biglybt.pif.ui.menus.MenuItem)4 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)4 MdiCloseListener (com.biglybt.ui.mdi.MdiCloseListener)4 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)4 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)4 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)4 ParameterListener (com.biglybt.core.config.ParameterListener)3 DownloadManager (com.biglybt.core.download.DownloadManager)3 PluginInterface (com.biglybt.pif.PluginInterface)3 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)3 UIFunctions (com.biglybt.ui.UIFunctions)3 DownloadManagerPeerListener (com.biglybt.core.download.DownloadManagerPeerListener)2 PEPeer (com.biglybt.core.peer.PEPeer)2 PEPeerStats (com.biglybt.core.peer.PEPeerStats)2 UIManager (com.biglybt.pif.ui.UIManager)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 MenuManager (com.biglybt.pif.ui.menus.MenuManager)2