diff --git a/plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF b/plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF index cbca83ec..54f34f47 100644 --- a/plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF +++ b/plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Editors Bundle-SymbolicName: raven.sqdev.editors;singleton:=true -Bundle-Version: 0.3.0 +Bundle-Version: 0.3.1 Bundle-Activator: raven.sqdev.editors.activator.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, diff --git a/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/BasicCodeEditor.class b/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/BasicCodeEditor.class index 4f2660f5..a03be8b7 100644 Binary files a/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/BasicCodeEditor.class and b/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/BasicCodeEditor.class differ diff --git a/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler$1.class b/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler$1.class index e6397de4..ff34f79b 100644 Binary files a/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler$1.class and b/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler$1.class differ diff --git a/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler.class b/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler.class index 9a8c5bd0..1462d78d 100644 Binary files a/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler.class and b/plugin/Raven.SQDev.Editors/bin/raven/sqdev/editors/CharacterPairHandler.class differ diff --git a/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicCodeEditor.java b/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicCodeEditor.java index 25901356..ec7043d3 100644 --- a/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicCodeEditor.java +++ b/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/BasicCodeEditor.java @@ -145,7 +145,7 @@ public void setEditorKeyEventQueue(EditorKeyEventQueue editorKeyEventQueue) { * @see CharacterPair */ public void addCharacterPairHandler() { - CharacterPairHandler pairHandler = new CharacterPairHandler(); + CharacterPairHandler pairHandler = new CharacterPairHandler(this); // TODO: make all completions optional via preference pairHandler.addPair(CharacterPair.DOUBLE_QUOTATION_MARKS); diff --git a/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/CharacterPairHandler.java b/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/CharacterPairHandler.java index 1b3d42c0..b32d0fe7 100644 --- a/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/CharacterPairHandler.java +++ b/plugin/Raven.SQDev.Editors/src/raven/sqdev/editors/CharacterPairHandler.java @@ -4,6 +4,7 @@ import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.graphics.Point; import raven.sqdev.interfaces.IEditorKeyHandler; import raven.sqdev.misc.CharacterPair; @@ -17,28 +18,40 @@ * registered to this handler * * @author Raven - * + * */ public class CharacterPairHandler implements IEditorKeyHandler { - + /** + * The list of pairs to match + */ private ArrayList pairs; + /** + * The last matched opening character (used for caret skipping in + * handleMatchedClosingCharacter()) + */ private char lastMatchedOpeningCharacter; + /** + * The editor this Handler works on + */ + private BasicCodeEditor editor; - public CharacterPairHandler(ArrayList list) { + public CharacterPairHandler(ArrayList list, BasicCodeEditor editor) { this.setPairs(list); + + this.editor = editor; } - public CharacterPairHandler() { - this(new ArrayList()); + public CharacterPairHandler(BasicCodeEditor editor) { + this(new ArrayList(), editor); } @SuppressWarnings("serial") - public CharacterPairHandler(CharacterPair pair) { + public CharacterPairHandler(CharacterPair pair, BasicCodeEditor editor) { this(new ArrayList() { { add(pair); } - }); + }, editor); } @Override @@ -48,6 +61,18 @@ public boolean willHandle(VerifyEvent event) { return false; } + Point selection = ((StyledText) event.getSource()).getSelection(); + if (selection.x != selection.y) { + // don't do anything when an area is modified + return false; + } + + if (editor.getBasicProvider().getPartitioner().getContentType(selection.x).toLowerCase() + .contains("string")) { + // disable in strings + return false; + } + if (IEditorKeyHandler.isDeletion(event.character)) { // handle deletions return true; @@ -68,6 +93,15 @@ public void handleAddition(VerifyEvent event) { boolean isOpener = isRegisteredOpeningCharacter(event.character); boolean isCloser = isRegisteredClosingCharacter(event.character); + // is always StyledText (checked in willHandle()) + StyledText textWidget = (StyledText) event.getSource(); + Point selection = textWidget.getSelection(); + + if (selection.x != selection.y) { + // don't do anything when an area is modified + return; + } + if (isOpener && isCloser) { // if it's part of a CharacterPair whichs start and end are equal @@ -88,7 +122,7 @@ public void handleAddition(VerifyEvent event) { String.valueOf(event.character)); int occuranceAfter = TextUtils.countMatches(followingText, String.valueOf(event.character)); - + // TODO: handle escaped character or only consider characters // outside of strings/comments @@ -139,9 +173,23 @@ public void handleAddition(VerifyEvent event) { public void handleMatchedOpeningCharacter(VerifyEvent event) { char pairingCharacter = this.getPairingCharacter(event.character); - StyledText text = (StyledText) event.getSource(); + StyledText textWidget = (StyledText) event.getSource(); + int offset = textWidget.getCaretOffset(); - text.insert(String.valueOf(pairingCharacter)); + if (textWidget.getText().length() <= offset + 1) { + // always complete on EOF + textWidget.insert(String.valueOf(pairingCharacter)); + } else { + // check what comes after the addition + char nextChar = textWidget.getText().charAt(offset); + + if (!TextUtils.isWordPart(nextChar)) { + // complete only if not directly in front of a word + textWidget.insert(String.valueOf(pairingCharacter)); + } else { + resetLastMatchedOpeningCharacter(); + } + } } /** diff --git a/plugin/Raven.SQDev.Util/META-INF/MANIFEST.MF b/plugin/Raven.SQDev.Util/META-INF/MANIFEST.MF index 2361a934..2e6a67e2 100644 --- a/plugin/Raven.SQDev.Util/META-INF/MANIFEST.MF +++ b/plugin/Raven.SQDev.Util/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Util Bundle-SymbolicName: raven.sqdev.util;singleton:=true -Bundle-Version: 0.5.2 +Bundle-Version: 0.5.3 Bundle-Activator: raven.sqdev.activator.Activator Bundle-Vendor: Raven Require-Bundle: org.eclipse.core.runtime, diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$1.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$1.class index 6f7e20ea..64ac1949 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$1.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$1.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$2.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$2.class index 0f8d0a95..21e39d23 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$2.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$2.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$3.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$3.class index 0642ff55..3101a44d 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$3.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$3.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$4.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$4.class index 38604400..7390105e 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$4.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$4.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$5.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$5.class index a6d3b4fa..ff564606 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$5.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$5.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$6.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$6.class index cb40a3ed..469bcd94 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$6.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$6.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7$1.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7$1.class index a9068024..31100bb9 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7$1.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7$1.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7.class index 0f73080f..4e32574c 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$8.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$8.class index 71a2ec23..0a8b5deb 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$8.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$8.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType.class index 7a8cec34..ccfc1925 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/FileSystemUtil.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/FileSystemUtil.class index d3880faa..507cb692 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/FileSystemUtil.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/FileSystemUtil.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/ProjectUtil.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/ProjectUtil.class index 60b78008..10bdf529 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/ProjectUtil.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/ProjectUtil.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/SQDevInformation.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/SQDevInformation.class index 0ff1a936..a09c9b7e 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/SQDevInformation.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/SQDevInformation.class differ diff --git a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/TextUtils.class b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/TextUtils.class index 9c32c56a..0f4a6585 100644 Binary files a/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/TextUtils.class and b/plugin/Raven.SQDev.Util/bin/raven/sqdev/util/TextUtils.class differ diff --git a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/EFileType.java b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/EFileType.java index c9987e78..40815db5 100644 --- a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/EFileType.java +++ b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/EFileType.java @@ -37,7 +37,7 @@ * selected in the package explorer or at a given Path within the workspace. * * @author Raven - * + * */ public enum EFileType { /** @@ -51,8 +51,23 @@ public String getExtension() { @Override public String getInitialContent() { - return ("scopeName " + getFileName().substring(0, getFileName().length() - 4) - + ";\n\n"); + String author = "", projectName = ""; + + if (isInformationSet()) { + author = getInformation().getProfile(); + projectName = getInformation().getName(); + } + + String content = "/**\n * " + projectName + " - " + + getFileName().substring(0, getFileName().length() - getExtension().length()) + + "\n * "; + content += "\n * Author: " + author + "\n * "; + content += "\n * Description:\n * Not given\n * "; + content += "\n * Parameter(s):"; + content += "\n * 0: None \n * "; + content += "\n * Return Value:\n * None \n * \n */"; + + return content; } }, @@ -295,7 +310,7 @@ public IStatus run(IProgressMonitor monitor) { SQDevInfobox info = new SQDevInfobox( "Failed at creating file \"" + getFileName() + "\"!", e1); - + info.open(); } } @@ -305,7 +320,7 @@ public IStatus run(IProgressMonitor monitor) { SQDevInfobox info = new SQDevInfobox("Can't create file \"" + getFileName() + "\" because it already exists!", SWT.ICON_ERROR); - + info.open(); } @@ -320,7 +335,7 @@ public IStatus run(IProgressMonitor monitor) { SQDevInfobox info = new SQDevInfobox( "Failed at creating file \"" + getFileName() + "\"!", e); - + info.open(); } } @@ -335,7 +350,7 @@ public void run() { // open the editor on the created file IWorkbenchPage page = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); - + IEditorPart part = IDE.openEditor(page, file, true); if (part instanceof ITextEditor) { @@ -431,12 +446,12 @@ public void run() { ISelectionService service = window.getSelectionService(); IStructuredSelection structured = (IStructuredSelection) service .getSelection("org.eclipse.jdt.ui.PackageExplorer"); - + if (structured == null) { // The ective explorer might be the project explorer structured = (IStructuredSelection) service .getSelection("org.eclipse.ui.navigator.ProjectExplorer"); - + if (structured == null) { SQDevInfobox info = new SQDevInfobox("Selection is null!", SWT.ERROR); info.open(); diff --git a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/FileSystemUtil.java b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/FileSystemUtil.java index 9a78fc24..d5533dd2 100644 --- a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/FileSystemUtil.java +++ b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/FileSystemUtil.java @@ -15,7 +15,7 @@ * directories * * @author Raven - * + * */ public class FileSystemUtil { @@ -194,7 +194,7 @@ public static boolean deleteFiles(File file) { */ public static void copyFilesWithExceptions(File directory, IPath destination, ArrayList filesToIgnore) { - + if (directory.isFile() && !filesToIgnore.contains(directory.getName())) { // copy the file if it shouldn't be ignored try { @@ -206,7 +206,7 @@ public static void copyFilesWithExceptions(File directory, IPath destination, String message = "Failed at copying file \"" + directory.getName() + "\"!\nReason: " + ((e.getMessage() == null || e.getMessage().isEmpty()) ? "Unknown" : e.getMessage()); - + SQDevInfobox info = new SQDevInfobox(message, SWT.ERROR); info.open(); @@ -233,7 +233,7 @@ public static void copyFilesWithExceptions(File directory, IPath destination, + "\"!\nReason: " + ((e.getMessage() == null || e.getMessage().isEmpty()) ? "Unknown" : e.getMessage()); - + SQDevInfobox info = new SQDevInfobox(message, SWT.ERROR); info.open(); @@ -272,9 +272,12 @@ public static void copyFile(File file, IPath destination) throws IOException { content += currentLine + "\n"; } - // remove the last newLine so that the copied file does not differ - // from the original - content.substring(0, content.length() - 1); + if (!content.isEmpty()) { + // remove the last newLine so that the copied file does not + // differ + // from the original + content.substring(0, content.length() - 1); + } // write the content into the new file out.write(content); @@ -287,7 +290,7 @@ public static void copyFile(File file, IPath destination) throws IOException { // directory if (!destination.toFile().isDirectory()) { destination.append(file.getName()); - }else { + } else { return; } } diff --git a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/ProjectUtil.java b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/ProjectUtil.java index 8dd0e154..da911c1e 100644 --- a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/ProjectUtil.java +++ b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/ProjectUtil.java @@ -82,7 +82,7 @@ public static String export(IProject project, IPath destination, "The export process would require an unusual high amount (" + diff + ") of new folders being created.\n\nDo you want to proceed?", SWT.ICON_QUESTION | SWT.YES | SWT.NO); - + if (info.open() != SWT.YES) { // abort the export process return CANCELED; @@ -104,7 +104,7 @@ public static String export(IProject project, IPath destination, + "\".\nAny files that are not part of the project in the eclipse " + "workspace will be deleted.\n\nDo you want to proceed?", SWT.ICON_QUESTION | SWT.YES | SWT.NO); - + if (info.open() != SWT.YES) { return CANCELED; } @@ -120,7 +120,7 @@ public static String export(IProject project, IPath destination, + "\"\nMake sure the files are not opened somewhere and try again" + "\n\nCanceled the export process.", SWT.ICON_INFORMATION); - + info.open(); // abort export when cleaning can't be performed @@ -152,7 +152,7 @@ public static String export(IProject project, IPath destination, String message = "Failed at exporting \"" + project.getName() + "\"\nReason: " + ((e.getMessage() == null || e.getMessage().isEmpty()) ? "Unknown" : e.getMessage()); - + SQDevInfobox info = new SQDevInfobox(message, SWT.ICON_ERROR); info.open(); @@ -175,7 +175,7 @@ public static String export(IProject project, IPath destination, public static boolean isSQDevProject(IProject project) { IFile testFile = project .getFile(ESQDevFileType.LINK.toString() + EFileType.SQDEV.getExtension()); - + return testFile.exists(); } @@ -193,14 +193,14 @@ public static String getMissionProfile(IProject project) { try { String profile = linkFile.parseAttribute(ESQDevFileAttribute.PROFILE).getValue() .toString(); - + return profile; } catch (SQDevFileIsInvalidException e) { // inform the user SQDevInfobox info = new SQDevInfobox( "The linkFile in the project \"" + project.getName() + "\" is invalid!", SWT.ICON_ERROR); - + info.open(); // rethrow @@ -221,7 +221,7 @@ public static SQDevFile getLinkFile(IProject project) { IResource linkMember = project .findMember(ESQDevFileType.LINK + EFileType.SQDEV.getExtension()); - + if (linkMember.getType() == IResource.FILE) { try { SQDevFile linkFile = new SQDevFile((IFile) linkMember); @@ -236,6 +236,23 @@ public static SQDevFile getLinkFile(IProject project) { } } + /** + * Gets the SQDevInformation corresponding to the given + * SQDevProject + * + * @param project + * The SQDevProject + * @return The respective SQDevInformation or null + * if the given project is no SQDevProject + */ + public static SQDevInformation getInformation(IProject project) { + if (!isSQDevProject(project)) { + return null; + } + + return new SQDevInformation(getLinkFile(project)); + } + /** * Checks whether a project with the given name already exists in the * workspace @@ -264,7 +281,7 @@ public static boolean exists(String name) { public static String importAsProject(Path path) { Assert.isTrue(path.isAbsolute() && path.toFile().exists() && Util.isMissionFolder(new File(path.toOSString()))); - + String projectName = path.lastSegment().substring(0, path.lastSegment().indexOf(".")); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); @@ -273,7 +290,7 @@ public static String importAsProject(Path path) { String message = "Failed at importing \"" + path.toOSString() + "\" because there is already a project with the name \"" + projectName + "\"!"; - + SQDevInfobox info = new SQDevInfobox(message, SWT.ICON_ERROR); info.open(); @@ -309,7 +326,7 @@ public static String importAsProject(Path path) { } } - //refresh project + // refresh project project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); } catch (CoreException e) { diff --git a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/SQDevInformation.java b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/SQDevInformation.java index d05ef473..981a7113 100644 --- a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/SQDevInformation.java +++ b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/SQDevInformation.java @@ -1,12 +1,18 @@ package raven.sqdev.util; +import java.io.IOException; + +import raven.sqdev.exceptions.SQDevFileIsInvalidException; +import raven.sqdev.sqdevFile.ESQDevFileAttribute; +import raven.sqdev.sqdevFile.SQDevFile; + /** * The class for transferring information between several SQDev classes.
* It contains various fields that can be set and does the handling with defualt * values for fields that are not set * * @author Raven - * + * */ public class SQDevInformation { @@ -41,6 +47,41 @@ public class SQDevInformation { */ protected String name; + /** + * Creates a new instance of this SQDevInformation with default + * values + */ + public SQDevInformation() { + // default constructor + } + + /** + * Creates a new instance of this SQDevInformation and applies + * the values stated int eh given SQDevFile + */ + public SQDevInformation(SQDevFile file) { + try { + // gather information from the given file + if (file.contains(ESQDevFileAttribute.PROFILE)) { + this.profile = file.parseAttribute(ESQDevFileAttribute.PROFILE).getValue(); + } + + if (file.contains(ESQDevFileAttribute.TERRAIN)) { + this.terrain = file.parseAttribute(ESQDevFileAttribute.TERRAIN).getValue(); + } + + if (file.contains(ESQDevFileAttribute.AUTOEXPORT)) { + setAutoExport(file.parseAttribute(ESQDevFileAttribute.AUTOEXPORT).getValue()); + } + } catch (IOException | SQDevFileIsInvalidException e) { + // report + SQDevInfobox info = new SQDevInfobox("Couldn't get information from the SQDevFile...", + e); + info.open(); + e.printStackTrace(); + } + } + /** * Checks if the profile has been set diff --git a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/TextUtils.java b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/TextUtils.java index 14b7f75e..c34c38b0 100644 --- a/plugin/Raven.SQDev.Util/src/raven/sqdev/util/TextUtils.java +++ b/plugin/Raven.SQDev.Util/src/raven/sqdev/util/TextUtils.java @@ -8,14 +8,13 @@ * A class containing various static text functions * * @author Raven - * + * */ public class TextUtils { /** - * An array containing all special characters that are allowed in project - * names + * An array containing all special characters that are allowed in file names */ - public static final char[] ALLOWED_SPECIAL_CHARACTER_PROJECTNAME = { '.', ' ', '_' }; + public static final char[] ALLOWED_SPECIAL_CHARACTER_FILENAME = { '.', '_' }; /** * Counts the occurence of a String in another String @@ -53,33 +52,7 @@ public static int countMatches(String str, String match) { * name. May be null */ public static boolean isValidName(String name, ArrayList allowedChars) { - if (name.isEmpty() || name == null) { - // an empty name can't be valid - return false; - } - - if (allowedChars == null) { - // initialize empty list - allowedChars = new ArrayList(); - } - - char[] chars = name.toCharArray(); - - if (!Character.isLetter(chars[0])) { - // name has to start with a letter - return false; - } - - for (char currentChar : chars) { - if (!Character.isLetterOrDigit(currentChar)) { - // check if special character is allowed - if (!allowedChars.contains((Character) currentChar)) { - return false; - } - } - } - - return true; + return whyIsInvalidName(name, allowedChars) == null; } /** @@ -92,12 +65,7 @@ public static boolean isValidName(String name, ArrayList allowedChars * name. May be null * @return The error message explaining why the given name isn't valid. */ - public static String whyIsInvalidName(String name, ArrayList allowedChars) { - if (isValidName(name, allowedChars) || name == null) { - // if it is a valid name no error message can be found - return null; - } - + public static String whyIsInvalidName(String name, ArrayList allowedChars) { if (name.isEmpty()) { return "A name must not be empty!"; } @@ -118,12 +86,16 @@ public static String whyIsInvalidName(String name, ArrayList allowedC if (!Character.isLetterOrDigit(currentChar)) { // check if special character is allowed if (!allowedChars.contains((Character) currentChar)) { + if(currentChar == ' ') { + return "Blanks are not allowed in this name!"; + } + return "Invalid character '" + currentChar + "' in \"" + name + "\"!"; } } } - // one of the above has to have matched + // all good with the given name return null; } @@ -134,10 +106,10 @@ public static String whyIsInvalidName(String name, ArrayList allowedC * The name to check * @see #isValidName */ - public static boolean isValidProjectName(String name) { + public static boolean isValidFileName(String name) { ArrayList allowedChars = new ArrayList(); - for (char currentChar : ALLOWED_SPECIAL_CHARACTER_PROJECTNAME) { + for (char currentChar : ALLOWED_SPECIAL_CHARACTER_FILENAME) { allowedChars.add((Character) currentChar); } @@ -151,10 +123,10 @@ public static boolean isValidProjectName(String name) { * The name to check (mustn't be valid) * @see #whyIsInvalidName */ - public static String whyIsInvalidProjectName(String name) { + public static String whyIsInvalidFileName(String name) { ArrayList allowedChars = new ArrayList(); - for (char currentChar : ALLOWED_SPECIAL_CHARACTER_PROJECTNAME) { + for (char currentChar : ALLOWED_SPECIAL_CHARACTER_FILENAME) { allowedChars.add((Character) currentChar); } diff --git a/plugin/Raven.SQDev.Wizards/META-INF/MANIFEST.MF b/plugin/Raven.SQDev.Wizards/META-INF/MANIFEST.MF index 080bea57..a9bf7d98 100644 --- a/plugin/Raven.SQDev.Wizards/META-INF/MANIFEST.MF +++ b/plugin/Raven.SQDev.Wizards/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Wizards Bundle-SymbolicName: raven.sqdev.wizards;singleton:=true -Bundle-Version: 0.2.0 +Bundle-Version: 0.2.1 Bundle-Activator: raven.sqdev.wizards.activator.Activator Bundle-Vendor: Raven Require-Bundle: org.eclipse.core.runtime, diff --git a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.class b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.class index de42ec8a..f3f9900b 100644 Binary files a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.class and b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.class differ diff --git a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.class b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.class index a6d22a8b..50856b05 100644 Binary files a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.class and b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.class differ diff --git a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage$1.class b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage$1.class index c33f5d01..2a677b8c 100644 Binary files a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage$1.class and b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage$1.class differ diff --git a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.class b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.class index cd551479..bb56b082 100644 Binary files a/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.class and b/plugin/Raven.SQDev.Wizards/bin/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.class differ diff --git a/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.java b/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.java index 92f1335f..175ed43b 100644 --- a/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.java +++ b/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqdevProject/SQDevProjectWizardPage.java @@ -215,8 +215,8 @@ private void validate() { } // check if the entered project name is valid - if (!TextUtils.isValidProjectName(getProjectName())) { - updateStatus(TextUtils.whyIsInvalidProjectName(getProjectName())); + if (!TextUtils.isValidFileName(getProjectName())) { + updateStatus(TextUtils.whyIsInvalidFileName(getProjectName())); return; } diff --git a/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.java b/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.java index 34e76d56..9cc16b14 100644 --- a/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.java +++ b/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizard.java @@ -4,10 +4,16 @@ import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.*; import raven.sqdev.util.EFileType; +import raven.sqdev.util.ProjectUtil; +import raven.sqdev.util.SQDevInformation; /** * This is a little wizard for the creation of a new SQF-file that will have the @@ -42,7 +48,53 @@ public void addPages() { public boolean performFinish() { final String fileName = page.getFileName(); - EFileType.SQF.create(fileName); + EFileType file = EFileType.SQF; + SQDevInformation info = null; + + if (selection instanceof IStructuredSelection) { + Object obj = ((IStructuredSelection) selection).getFirstElement(); + + if (obj instanceof IResource && obj != null) { + IContainer container; + + if (obj instanceof IContainer) { + container = (IContainer) obj; + } else { + container = ((IResource) obj).getParent(); + } + + IPath containerLocation = container.getRawLocation(); + + if (containerLocation == null) { + // in case rawLocation does not work + containerLocation = container.getLocation(); + } + + // set path for the file to be created + file.setPath(containerLocation.toOSString()); + + while (!(container instanceof IProject) && container != null) { + container = container.getParent(); + } + + if(container != null) { + IProject project = (IProject) container; + + if (ProjectUtil.isSQDevProject(project)) { + // retrieve additional information + info = ProjectUtil.getInformation(project); + + info.setName(project.getName()); + } + } + } + } + + if(info != null) { + file.setInformation(info); + } + + file.create(fileName); return true; } diff --git a/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.java b/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.java index 5329ea6a..8b77d461 100644 --- a/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.java +++ b/plugin/Raven.SQDev.Wizards/src/raven/sqdev/wizards/sqfNewFileWizard/SqfNewFileWizardPage.java @@ -18,6 +18,8 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; +import raven.sqdev.util.TextUtils; + /** * The "New" wizard page allows setting the container for the new file as well * as the file name. The page will only accept file name without the extension @@ -125,6 +127,11 @@ private void dialogChanged() { return; } + if (!TextUtils.isValidFileName(fileName)) { + updateStatus(TextUtils.whyIsInvalidFileName(fileName)); + return; + } + if (fileName.replace('\\', '/').indexOf('/', 1) > 0) { updateStatus("File name must be valid"); return; diff --git a/plugin/Raven.SQDev/feature.xml b/plugin/Raven.SQDev/feature.xml index b02e15c2..f2fb00f1 100644 --- a/plugin/Raven.SQDev/feature.xml +++ b/plugin/Raven.SQDev/feature.xml @@ -2,7 +2,7 @@ @@ -43,7 +43,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRES id="raven.sqdev.editors" download-size="0" install-size="0" - version="0.3.0" + version="0.3.1" unpack="false"/> - +