# HG changeset patch # User Eugene Ostroukhov # Date 1265930861 28800 # Node ID f66df1e99ba54f8338e6cc684772d0e75b1c18a9 # Parent 22c6da0edf5d089b9357330a600b4f3e0a5b6183 Fixed Bug 1886 - Prompt to autorefresh preview after first refresh request diff -r 22c6da0edf5d -r f66df1e99ba5 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebappManager.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebappManager.java Thu Feb 11 15:00:37 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/http/WebappManager.java Thu Feb 11 15:27:41 2010 -0800 @@ -18,8 +18,6 @@ *******************************************************************************/ package org.symbian.tools.wrttools.previewer.http; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.util.Dictionary; import java.util.Hashtable; import java.util.logging.Level; @@ -124,11 +122,7 @@ public static String getHost() { if (host == null) { - try { - host = InetAddress.getLocalHost().getHostName().toLowerCase(); - } catch (Exception e) { - host = "127.0.0.1"; - } + host = "localhost"; } return host; } diff -r 22c6da0edf5d -r f66df1e99ba5 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java Thu Feb 11 15:00:37 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/AbstractPreviewPage.java Thu Feb 11 15:27:41 2010 -0800 @@ -85,19 +85,20 @@ if (!refreshScheduled && needsRefresh(files)) { asyncExec(new Runnable() { public void run() { - if (toggleState) { - refresh(); - } else { - needsRefresh = true; - refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.RED_SYNC)); - refreshAction.setToolTipText("Refresh the preview browser (there are updated files)"); - } + refreshBrowser(); } }); refreshScheduled = true; } } + protected void promptIfNeeded() { + if (toggleState) { + toggleState = previewView.promptUserToToggle(project, toggleState); + toggleRefresh.setChecked(toggleState); + } + } + private void asyncExec(Runnable runnable) { getControl().getDisplay().asyncExec(runnable); } @@ -174,4 +175,17 @@ public boolean isDisposed() { return browser != null && browser.isDisposed(); } + + private synchronized void refreshBrowser() { + if (toggleState) { + promptIfNeeded(); + } + if (toggleState) { + refresh(); + } else { + needsRefresh = true; + refreshAction.setImageDescriptor(PreviewerPlugin.getImageDescriptor(Images.RED_SYNC)); + refreshAction.setToolTipText("Refresh the preview browser (there are updated files)"); + } + } } diff -r 22c6da0edf5d -r f66df1e99ba5 org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java --- a/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Thu Feb 11 15:00:37 2010 -0800 +++ b/org.symbian.tools.wrttools.previewer/src/org/symbian/tools/wrttools/previewer/preview/PreviewView.java Thu Feb 11 15:27:41 2010 -0800 @@ -28,6 +28,7 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IWorkbenchPart; @@ -153,20 +154,12 @@ .getPreferenceStore(); String value = preferenceStore .getString(IWrtEditingPreferences.PREF_AUTO_REFRESH); - if (value == null || value.trim().length() == 0 - || MessageDialogWithToggle.PROMPT.equals(value)) { - return MessageDialogWithToggle - .openYesNoQuestion( - getSite().getShell(), - "WRT Preview", - "WRT IDE can refresh preview whenever any changes are made to project files. Refresh will always return the widget to initial page. Do you want to enable automatic refresh for your project?\nNote: you can toggle this setting for particular project on the preview toolbar.", - "Keep this setting for all new projects", false, - preferenceStore, - IWrtEditingPreferences.PREF_AUTO_REFRESH) - .getReturnCode() == IDialogConstants.YES_ID; - } else { - return MessageDialogWithToggle.ALWAYS.equals(value); + boolean toggle = !MessageDialogWithToggle.NEVER.equals(value); + if (MessageDialogWithToggle.NEVER.equals(value) + || MessageDialogWithToggle.ALWAYS.equals(value)) { + setProjectAutorefresh(project, toggle); } + return toggle; } private File getPreferencesFile() { @@ -181,7 +174,6 @@ return autorefresh.get(project); } else { boolean value = getDefaultAutorefresh(project); - setProjectAutorefresh(project, value); return value; } } @@ -271,4 +263,31 @@ } } + public boolean promptUserToToggle(IProject project, boolean toggle) { + IPreferenceStore preferenceStore = PreviewerPlugin.getDefault() + .getPreferenceStore(); + String value = preferenceStore + .getString(IWrtEditingPreferences.PREF_AUTO_REFRESH); + synchronized (autorefresh) { + if (!autorefresh.containsKey(project)) { + if (value == null || value.trim().length() == 0 + || MessageDialogWithToggle.PROMPT.equals(value)) { + boolean setting = MessageDialogWithToggle + .open( + MessageDialogWithToggle.QUESTION, + getSite().getShell(), + "WRT Preview", + "WRT IDE can refresh preview whenever any changes are made to project files. Refresh will always return the widget to initial page. Do you want to enable automatic refresh for your project?\nNote: you can toggle this setting for particular project on the preview toolbar.", + "Keep this setting for all new projects", + false, preferenceStore, + IWrtEditingPreferences.PREF_AUTO_REFRESH, + SWT.SHEET).getReturnCode() == IDialogConstants.YES_ID; + setProjectAutorefresh(project, setting); + return setting; + } + } + } + return toggle; + } + }