package name.abuchen.portfolio.ui.util;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;

import name.abuchen.portfolio.model.Bookmark;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.editor.PortfolioPart;
import name.abuchen.portfolio.ui.views.settings.SettingsView;

public class BookmarkMenu extends MenuManager
{
    private final Security security;
    private final Client client;
    private final PortfolioPart editor;

    public BookmarkMenu(PortfolioPart editor, Security security)
    {
        super(Messages.MenuOpenSecurityOnSite);

        this.security = security;
        this.editor = editor;
        this.client = editor.getClient();

        addDefaultPages();
    }

    private void addDefaultPages()
    {
        for (Bookmark bookmark : client.getSettings().getBookmarks())
        {
            if (bookmark.isSeparator())
            {
                add(new Separator());
            }
            else
            {
                add(new SimpleAction(bookmark.getLabel(),
                                a -> DesktopAPI.browse(bookmark.constructURL(client, security))));
            }
        }

        add(new Separator());
        add(new SimpleAction(Messages.BookmarkMenu_EditBookmarks,
                        a -> editor.activateView(SettingsView.class, Integer.valueOf(0))));
    }
}

@@ -34,16 +34,132 @@
 .util;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A
 import o
@@ -1399,195 +1399,1254 @@
   %7D%0A
-%0A        add(new Separator());%0A        add(new SimpleAction(Messages.BookmarkMenu_EditBookmarks,%0A                        a -%3E editor.activateView(SettingsView.class, Integer.valueOf(0))))
+        // check for urls in notes of security%0A        List%3CString%3E urls = getUrlsFromNotes(security);%0A        if (!urls.isEmpty())%0A        %7B%0A            add(new Separator());%0A            for (String url : urls)%0A            %7B%0A                add(new SimpleAction(url, a -%3E DesktopAPI.browse(url)));%0A            %7D%0A        %7D%0A%0A        add(new Separator());%0A        add(new SimpleAction(Messages.BookmarkMenu_EditBookmarks,%0A                        a -%3E editor.activateView(SettingsView.class, Integer.valueOf(0))));%0A    %7D%0A    %0A    /**%0A     * Gets all URLs contained in the notes of the given %7B@link Security%7D.%0A     * %0A     * @param security%0A     *            %7B@link Security%7D%0A     * @return list of notes%0A     */%0A    private static List%3CString%3E getUrlsFromNotes(Security security)%0A    %7B%0A        ArrayList%3CString%3E urls = new ArrayList%3CString%3E();%0A        String notes = security.getNote();%0A        if ((notes != null) && (notes.length() %3E 0))%0A        %7B%0A            Pattern urlPattern = Pattern.compile(%22(https?%5C%5C:%5C%5C/%5C%5C/%5B%5E %5C%5Ct%5C%5Cr%5C%5Cn%5D+)%22, Pattern.CASE_INSENSITIVE); //$NON-NLS-1$%0A            Matcher m = urlPattern.matcher(notes);%0A            while (m.find())%0A            %7B%0A                urls.add(m.group());%0A            %7D%0A        %7D%0A        return urls
 ;%0A  

add URLs found in notes of security to URLs context menu.