-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Enables users to toggle between suggestions * Disables suggestion toggling when user has typed ahead * Removes println for incrementing and decrementing * Fixes formatting * Makes adjustment for various checkstyle items
- Loading branch information
Showing
7 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...src/software/aws/toolkits/eclipse/amazonq/handlers/AbstractQToggleSuggestionsHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.handlers; | ||
|
||
import org.eclipse.core.commands.AbstractHandler; | ||
import org.eclipse.core.commands.ExecutionEvent; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.util.QInvocationSession; | ||
|
||
public abstract class AbstractQToggleSuggestionsHandler extends AbstractHandler { | ||
public enum Direction { | ||
FORWARD, BACKWARD | ||
} | ||
|
||
private Direction direction = Direction.FORWARD; | ||
|
||
@Override | ||
public final boolean isEnabled() { | ||
QInvocationSession qInvocationSessionInstance = QInvocationSession.getInstance(); | ||
return qInvocationSessionInstance != null && !qInvocationSessionInstance.hasBeenTypedahead() | ||
&& qInvocationSessionInstance.isPreviewingSuggestions(); | ||
} | ||
|
||
/** | ||
* Executes the command when the user triggers the handler. | ||
* <p> | ||
* Subclasses overriding this method should ensure that the following conditions are met: | ||
* </p> | ||
* <ul> | ||
* <li>The method should make sure to set a direction of toggle</li> | ||
* <li>The method should make sure to call the super's counter part of this method</li> | ||
* </ul> | ||
* | ||
* @param event The execution event that triggered the handler. | ||
* @return The result of the execution, or <code>null</code> if there is no result. | ||
* | ||
* @implSpec | ||
* Implementations should call {@code super.execute(event)} at the end to delegate the actual movement. | ||
*/ | ||
@Override | ||
public Object execute(final ExecutionEvent event) { | ||
QInvocationSession qInvocationSessionInstance = QInvocationSession.getInstance(); | ||
|
||
switch (direction) { | ||
case FORWARD: | ||
qInvocationSessionInstance.incrementCurentSuggestionIndex(); | ||
break; | ||
case BACKWARD: | ||
qInvocationSessionInstance.decrementCurrentSuggestionIndex(); | ||
break; | ||
default: | ||
qInvocationSessionInstance.incrementCurentSuggestionIndex(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected final void setCommandDirection(final Direction direction) { | ||
this.direction = direction; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/software/aws/toolkits/eclipse/amazonq/handlers/QToggleSuggestionsBackwardHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.handlers; | ||
|
||
import org.eclipse.core.commands.ExecutionEvent; | ||
|
||
public class QToggleSuggestionsBackwardHandler extends AbstractQToggleSuggestionsHandler { | ||
// Actual command handler logic consolidated in parent class | ||
@Override | ||
public final Object execute(final ExecutionEvent event) { | ||
super.setCommandDirection(Direction.BACKWARD); | ||
|
||
return super.execute(event); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/software/aws/toolkits/eclipse/amazonq/handlers/QToggleSuggestionsForwardHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.handlers; | ||
|
||
import org.eclipse.core.commands.ExecutionEvent; | ||
|
||
public class QToggleSuggestionsForwardHandler extends AbstractQToggleSuggestionsHandler { | ||
// Actual command handler logic consolidated in parent class | ||
@Override | ||
public final Object execute(final ExecutionEvent event) { | ||
super.setCommandDirection(Direction.FORWARD); | ||
|
||
return super.execute(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters