mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 333190: Moved refreshWorkspaceFiles() for general usage, in particular for the Import/Export Settings Wizard
This commit is contained in:
parent
7372454012
commit
b44f771423
5 changed files with 50 additions and 26 deletions
|
@ -0,0 +1,33 @@
|
|||
package org.eclipse.cdt.core.resources;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
public class ResourcesUtil {
|
||||
/**
|
||||
* Refresh file when it happens to belong to Workspace. There could
|
||||
* be multiple workspace {@link IFile} associated with one URI.
|
||||
* Hint: use {@link org.eclipse.core.filesystem.URIUtil#toURI(String)}
|
||||
* to convert filesystem path to URI.
|
||||
*
|
||||
* @param uri - URI of the file.
|
||||
*/
|
||||
public static void refreshWorkspaceFiles(URI uri) {
|
||||
if (uri!=null) {
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri);
|
||||
for (IFile file : files) {
|
||||
try {
|
||||
file.refreshLocal(IResource.DEPTH_ZERO, null);
|
||||
} catch (CoreException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -506,23 +506,4 @@ public class BuildConsoleManager implements IBuildConsoleManager, IResourceChang
|
|||
return defaultLogLocation.toOSString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh output file when it happens to belong to Workspace. There could
|
||||
* be multiple workspace {@link IFile} associated with one URI.
|
||||
*
|
||||
* @param uri - URI of the file.
|
||||
*/
|
||||
static void refreshWorkspaceFiles(URI uri) {
|
||||
if (uri!=null) {
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri);
|
||||
for (IFile file : files) {
|
||||
try {
|
||||
file.refreshLocal(IResource.DEPTH_ZERO, null);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.osgi.service.prefs.Preferences;
|
|||
import org.eclipse.cdt.core.ConsoleOutputStream;
|
||||
import org.eclipse.cdt.core.ProblemMarkerInfo;
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.core.resources.ResourcesUtil;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.preferences.BuildConsolePreferencePage;
|
||||
|
@ -320,7 +321,7 @@ public class BuildConsolePartitioner
|
|||
} catch (CoreException e) {
|
||||
CUIPlugin.log(e);
|
||||
} finally {
|
||||
BuildConsoleManager.refreshWorkspaceFiles(fLogURI);
|
||||
ResourcesUtil.refreshWorkspaceFiles(fLogURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +336,7 @@ public class BuildConsolePartitioner
|
|||
} catch (IOException e) {
|
||||
CUIPlugin.log(e);
|
||||
} finally {
|
||||
BuildConsoleManager.refreshWorkspaceFiles(fLogURI);
|
||||
ResourcesUtil.refreshWorkspaceFiles(fLogURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -347,7 +348,7 @@ public class BuildConsolePartitioner
|
|||
} catch (IOException e) {
|
||||
CUIPlugin.log(e);
|
||||
} finally {
|
||||
BuildConsoleManager.refreshWorkspaceFiles(fLogURI);
|
||||
ResourcesUtil.refreshWorkspaceFiles(fLogURI);
|
||||
}
|
||||
fLogStream = null;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.swt.widgets.FileDialog;
|
|||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.cdt.core.resources.IConsole;
|
||||
import org.eclipse.cdt.core.resources.ResourcesUtil;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IBuildConsoleManager;
|
||||
|
||||
|
@ -103,7 +104,7 @@ public class CopyBuildLogAction extends Action {
|
|||
MessageDialog.openError(shell, ConsoleMessages.CopyLog_ErrorCopyingFile,
|
||||
ConsoleMessages.CopyLog_ErrorWhileCopyingLog+e.getLocalizedMessage());
|
||||
} finally {
|
||||
BuildConsoleManager.refreshWorkspaceFiles(destURI);
|
||||
ResourcesUtil.refreshWorkspaceFiles(destURI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.wizards.settingswizards;
|
|||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.transform.OutputKeys;
|
||||
|
@ -23,12 +24,14 @@ import javax.xml.transform.sax.SAXTransformerFactory;
|
|||
import javax.xml.transform.sax.TransformerHandler;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.AttributesImpl;
|
||||
|
||||
import org.eclipse.cdt.core.resources.ResourcesUtil;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
@ -123,6 +126,7 @@ public class ProjectSettingsExportStrategy implements IProjectSettingsWizardPage
|
|||
ICConfigurationDescription config = page.getSelectedConfiguration();
|
||||
ICFolderDescription projectRoot = config.getRootFolderDescription();
|
||||
|
||||
boolean result = false;
|
||||
try {
|
||||
AttributesImpl attributes = new AttributesImpl();
|
||||
|
||||
|
@ -149,19 +153,23 @@ public class ProjectSettingsExportStrategy implements IProjectSettingsWizardPage
|
|||
handler.endDocument();
|
||||
newline(handler);
|
||||
|
||||
result = true;
|
||||
} catch (SAXException e) {
|
||||
CUIPlugin.log(e);
|
||||
page.showErrorDialog(Messages.ProjectSettingsExportStrategy_exportError,
|
||||
Messages.ProjectSettingsExportStrategy_xmlError);
|
||||
return false;
|
||||
result = false;
|
||||
} catch(SettingsImportExportException e) {
|
||||
CUIPlugin.log(e);
|
||||
page.showErrorDialog(Messages.ProjectSettingsExportStrategy_fileOpenError,
|
||||
Messages.ProjectSettingsExportStrategy_couldNotOpen);
|
||||
return false;
|
||||
result = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
URI uri = URIUtil.toURI(page.getDestinationFilePath());
|
||||
ResourcesUtil.refreshWorkspaceFiles(uri);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue