Merging code from trunk that fixes #774, this work was done by incastrix
[phpeclipse.git] / net.sourceforge.phpeclipse.webbrowser / src / net / sourceforge / phpeclipse / webbrowser / internal / InternalWebBrowser.java
1 package net.sourceforge.phpeclipse.webbrowser.internal;
2
3 import java.net.URL;
4
5 import net.sourceforge.phpeclipse.webbrowser.IInternalWebBrowser;
6 import net.sourceforge.phpeclipse.webbrowser.IInternalWebBrowserWorkingCopy;
7 import net.sourceforge.phpeclipse.webbrowser.WebBrowserEditorInput;
8
9 import org.eclipse.ui.IMemento;
10
11 /**
12  * 
13  */
14 public class InternalWebBrowser implements IInternalWebBrowser {
15         private static final String MEMENTO_NEW_PAGE = "new_page";
16
17         private static final String MEMENTO_CLEAR_HISTORY_ON_EXIT = "clear_history";
18
19         protected boolean useNewPage;
20
21         protected boolean clearHistory;
22
23         /*
24          * (non-Javadoc)
25          * 
26          * @see net.sourceforge.phpeclipse.webbrowser.IWebBrowser#getName()
27          */
28         public String getName() {
29                 return WebBrowserUIPlugin.getResource("%internalWebBrowserName");
30         }
31
32         public boolean getUseNewPage() {
33                 return useNewPage;
34         }
35
36         public boolean getClearHistoryOnExit() {
37                 return clearHistory;
38         }
39
40         public boolean isWorkingCopy() {
41                 return false;
42         }
43
44         public IInternalWebBrowserWorkingCopy getWorkingCopy() {
45                 return new InternalWebBrowserWorkingCopy(this);
46         }
47
48         protected void setInternal(IInternalWebBrowser browser) {
49                 useNewPage = browser.getUseNewPage();
50                 clearHistory = browser.getClearHistoryOnExit();
51         }
52
53         /*
54          * (non-Javadoc)
55          * 
56          * @see net.sourceforge.phpeclipse.webbrowser.IWebBrowser#openURL(java.net.URL)
57          */
58         public void openURL(URL url) {
59                 WebBrowserEditor.open(new WebBrowserEditorInput(url));
60         }
61
62         protected void save(IMemento memento) {
63                 memento.putString(MEMENTO_NEW_PAGE, useNewPage ? "true" : "false");
64                 memento.putString(MEMENTO_CLEAR_HISTORY_ON_EXIT, clearHistory ? "true"
65                                 : "false");
66         }
67
68         protected void load(IMemento memento) {
69                 String s = memento.getString(MEMENTO_NEW_PAGE);
70                 if ("true".equals(s))
71                         useNewPage = true;
72                 else
73                         useNewPage = false;
74
75                 s = memento.getString(MEMENTO_CLEAR_HISTORY_ON_EXIT);
76                 if ("true".equals(s))
77                         clearHistory = true;
78                 else
79                         clearHistory = false;
80         }
81
82         public String toString() {
83                 return "Internal Web browser";
84         }
85 }