/*******************************************************************************
 * OulipoMachine licenses this file to you under the Apache License, Version 2.0
 * (the "License");  you may not use this file except in compliance with the License.  
 *
 * You may obtain a copy of the License at
 *   
 *       http://www.apache.org/licenses/LICENSE-2.0
 *    
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. See the NOTICE file distributed with this work for 
 * additional information regarding copyright ownership. 
 *******************************************************************************/
package org.oulipo.extensions;

import org.oulipo.browser.api.BrowserContext;
import org.oulipo.browser.api.Extension;
import org.oulipo.browser.api.bookmark.Bookmark;
import org.oulipo.browser.api.tabs.OulipoTab;
import org.oulipo.storage.StorageException;

import javafx.scene.control.MenuItem;

/**
 * Provides extension for creating bookmarks
 */
public class BookmarkExtensions implements Extension {

	@Override
	public void init(BrowserContext ctx) {
		MenuItem item = new MenuItem();
		item.setText("Bookmark This Page");
		item.setOnAction(e -> {
			OulipoTab tab = ctx.getTabManager().getSelectedTab();
			Bookmark bookmark = new Bookmark();
			bookmark.title = tab.getTitle();
			bookmark.id = tab.getTumblerAddress();
			bookmark.url = bookmark.id;
			try {
				ctx.getBookmarkManager().add(bookmark);
			} catch (StorageException e1) {
				e1.printStackTrace();
			}
		});
		ctx.getMenuContext().getBookmarkMenu().getItems().add(0, item);
	}

}

@@ -899,16 +899,44 @@
 sions;%0A%0A
+import java.util.Optional;%0A%0A
 import o
@@ -1131,546 +1131,1593 @@
 ipo.
-storage.StorageException;%0A%0Aimport javafx.scene.control.MenuItem;%0A%0A/**%0A * Provides extension for creating bookmarks%0A */%0Apublic class BookmarkExtensions implements Extension %7B%0A%0A%09@Override%0A%09public void init(BrowserContext ctx) %7B%0A%09%09MenuItem item = new MenuItem();%0A%09%09item.setText(%22Bookmark This Page%22);%0A%09%09item.setOnAction(e -%3E %7B%0A%09%09%09OulipoTab tab = ctx.getTabManager().getSelectedTab();%0A%09%09%09Bookmark bookmark = new Bookmark();%0A%09%09%09bookmark.title = tab.getTitle();%0A%09%09%09bookmark.id = tab.getTumblerAddress();%0A%09%09%09bookmark.url = bookmark.id;%0A%09%09%09try %7B%0A
+browser.controls.OulipoTable;%0Aimport org.oulipo.storage.StorageException;%0A%0Aimport javafx.geometry.Insets;%0Aimport javafx.scene.control.Alert;%0Aimport javafx.scene.control.Alert.AlertType;%0Aimport javafx.scene.control.ButtonBar.ButtonData;%0Aimport javafx.scene.control.ButtonType;%0Aimport javafx.scene.control.Dialog;%0Aimport javafx.scene.control.Label;%0Aimport javafx.scene.control.MenuItem;%0Aimport javafx.scene.control.TextField;%0Aimport javafx.scene.control.TextInputDialog;%0Aimport javafx.scene.layout.GridPane;%0Aimport javafx.scene.layout.VBox;%0A%0A/**%0A * Provides extension for creating bookmarks%0A */%0Apublic class BookmarkExtensions implements Extension %7B%0A%0A%09@Override%0A%09public void init(BrowserContext ctx) %7B%0A%09%09MenuItem item = new MenuItem();%0A%09%09item.setText(%22Bookmark This Page%22);%0A%09%09item.setOnAction(e -%3E %7B%0A%09%09%09OulipoTab tab = ctx.getTabManager().getSelectedTab();%0A%09%09%09Bookmark bookmark = new Bookmark();%0A%09%09%09bookmark.title = tab.getTitle();%0A%09%09%09bookmark.id = tab.getTumblerAddress();%0A%09%09%09bookmark.url = bookmark.id;%0A%0A%09%09%09OulipoTable table = new OulipoTable(50, 350);%0A%09%09%09table.title(%22Add bookmark%22);%0A%09%09%09table.addEditText(%22Name%22, bookmark.id);%0A%0A%09%09%09Dialog%3CButtonType%3E dialog = new Dialog%3C%3E();%0A%09%09%09dialog.getDialogPane().setContent(table);%0A%0A%09%09%09ButtonType doneButton = new ButtonType(%22OK%22, ButtonData.OK_DONE);%0A%09%09%09dialog.getDialogPane().getButtonTypes().addAll(doneButton, ButtonType.CANCEL);%0A%0A%09%09%09Optional%3CButtonType%3E result = dialog.showAndWait();%0A%0A%09%09%09if (result.isPresent() && result.get().getButtonData().equals(ButtonType.OK.getButtonData())) %7B%0A%09%09%09%09bookmark.title = table.getValue(%22Name%22);%0A%09%09%09%09try %7B%0A%09
 %09%09%09%09
@@ -2759,16 +2759,17 @@
 rk);%0A%09%09%09
+%09
 %7D catch 
@@ -2796,16 +2796,17 @@
 ) %7B%0A%09%09%09%09
+%09
 e1.print
@@ -2819,16 +2819,22 @@
 race();%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Add dialog box for adding bookmarks