Skip to content

Commit

Permalink
few bug fixes and improvements; fixes #53
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed May 14, 2016
1 parent f389e09 commit 5236854
Show file tree
Hide file tree
Showing 45 changed files with 248 additions and 93 deletions.
2 changes: 1 addition & 1 deletion plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,28 +18,40 @@
* registered to this handler
*
* @author Raven
*
*
*/
public class CharacterPairHandler implements IEditorKeyHandler {

/**
* The list of pairs to match
*/
private ArrayList<CharacterPair> 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<CharacterPair> list) {
public CharacterPairHandler(ArrayList<CharacterPair> list, BasicCodeEditor editor) {
this.setPairs(list);

this.editor = editor;
}

public CharacterPairHandler() {
this(new ArrayList<CharacterPair>());
public CharacterPairHandler(BasicCodeEditor editor) {
this(new ArrayList<CharacterPair>(), editor);
}

@SuppressWarnings("serial")
public CharacterPairHandler(CharacterPair pair) {
public CharacterPairHandler(CharacterPair pair, BasicCodeEditor editor) {
this(new ArrayList<CharacterPair>() {
{
add(pair);
}
});
}, editor);
}

@Override
Expand All @@ -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;
Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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();
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugin/Raven.SQDev.Util/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$1.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$2.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$3.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$4.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$5.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$6.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7$1.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$7.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType$8.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/EFileType.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/FileSystemUtil.class
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/ProjectUtil.class
Binary file not shown.
Binary file not shown.
Binary file modified plugin/Raven.SQDev.Util/bin/raven/sqdev/util/TextUtils.class
Binary file not shown.
33 changes: 24 additions & 9 deletions plugin/Raven.SQDev.Util/src/raven/sqdev/util/EFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* selected in the package explorer or at a given Path within the workspace.
*
* @author Raven
*
*
*/
public enum EFileType {
/**
Expand All @@ -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 <Any>\n * ";
content += "\n * Return Value:\n * None <Any>\n * \n */";

return content;
}
},

Expand Down Expand Up @@ -295,7 +310,7 @@ public IStatus run(IProgressMonitor monitor) {
SQDevInfobox info = new SQDevInfobox(
"Failed at creating file \"" + getFileName() + "\"!",
e1);

info.open();
}
}
Expand All @@ -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();
}

Expand All @@ -320,7 +335,7 @@ public IStatus run(IProgressMonitor monitor) {

SQDevInfobox info = new SQDevInfobox(
"Failed at creating file \"" + getFileName() + "\"!", e);

info.open();
}
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
19 changes: 11 additions & 8 deletions plugin/Raven.SQDev.Util/src/raven/sqdev/util/FileSystemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* directories
*
* @author Raven
*
*
*/
public class FileSystemUtil {

Expand Down Expand Up @@ -194,7 +194,7 @@ public static boolean deleteFiles(File file) {
*/
public static void copyFilesWithExceptions(File directory, IPath destination,
ArrayList<String> filesToIgnore) {

if (directory.isFile() && !filesToIgnore.contains(directory.getName())) {
// copy the file if it shouldn't be ignored
try {
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down
Loading

0 comments on commit 5236854

Please sign in to comment.