Skip to content

Commit

Permalink
Add (currently non-functional) edit field at bottom of repl view. (ch…
Browse files Browse the repository at this point in the history
…erry-picking from commit f23db31)
  • Loading branch information
lindydonna committed Jun 20, 2011
1 parent 15e85e0 commit f76a3ff
Showing 1 changed file with 65 additions and 3 deletions.
Expand Up @@ -14,6 +14,9 @@ import org.eclipse.ui.IPropertyListener
import org.eclipse.ui.part.ViewPart
import org.eclipse.swt.graphics.Image
import org.eclipse.swt.custom.StyledText
import org.eclipse.swt.widgets.Text
import org.eclipse.swt.layout.GridData
import org.eclipse.swt.layout.GridLayout

// for the toolbar images
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants
Expand All @@ -30,7 +33,8 @@ class ReplConsoleView extends ViewPart {
var projectName: String = ""
private var scalaProject: ScalaProject = null
var isStopped = true

var inputField: Text = null

def setScalaProject(project: ScalaProject) {
scalaProject = project

Expand Down Expand Up @@ -80,6 +84,19 @@ class ReplConsoleView extends ViewPart {
}
}

object replayAction extends Action("Replay interpreter history") {
setToolTipText("Replay all commands")

import IInternalDebugUIConstants._
setImageDescriptor(DebugPluginImages.getImageDescriptor(IMG_ELCL_RESTART))
setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IMG_DLCL_RESTART))
setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IMG_ELCL_RESTART))

override def run() {
displayOutput("To do: replay all commands without restarting interpreter")
}
}

private def setStarted {
isStopped = false

Expand All @@ -105,19 +122,63 @@ class ReplConsoleView extends ViewPart {
codeBgColor = new Color(parent.getDisplay, 230, 230, 230) // light gray
codeFgColor = new Color(parent.getDisplay, 64, 0, 128) // eggplant

textWidget = new StyledText(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)
val panel = new Composite(parent, SWT.NONE)
panel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true))
panel.setLayout(new GridLayout)

textWidget = new StyledText(panel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)
textWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true))
textWidget.setEditable(false)
textWidget.setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)) // java editor font
val editorFont = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT)
textWidget.setFont(editorFont) // java editor font

inputField = new Text(panel, SWT.BORDER | SWT.SINGLE)
inputField.setFont(editorFont)
inputField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false))

val toolbarManager = getViewSite.getActionBars.getToolBarManager
toolbarManager.add(replayAction)
toolbarManager.add(new Separator)
toolbarManager.add(stopReplAction)
toolbarManager.add(relaunchAction)
toolbarManager.add(new Separator)
toolbarManager.add(clearConsoleAction)

createMenuActions

setPartName("Scala REPL (" + projectName + ")")
setStarted
}

private def createAction(name: String, payload: => Unit): Action = {
new Action(name) {
override def run() { payload }
}
}

def createMenuActions {
val showImportsAction = createAction("Import history", {
displayOutput("to do: add hook for :imports command. Note: will take a string argument\n")
})

val showImplicitsAction = createAction("Implicits in scope", {
displayOutput("to do: add hook for :implicits command. Note: has a verbose option\n")
})

val powerModeAction = createAction("Power user mode", {
displayOutput("to do: add hook for :power command. To do: add commands to dropdown: :dump, :phase, :wrap\n")
})

val typeAction = createAction("Show type", {
displayOutput("to do: add hook for :type command. Note: takes an argument. TBD: make this a right-click menu item?\n")
})

val menuManager = getViewSite.getActionBars.getMenuManager
menuManager.add(showImportsAction)
menuManager.add(showImplicitsAction)
menuManager.add(typeAction)
menuManager.add(powerModeAction)
}

def setFocus() { }

Expand Down Expand Up @@ -155,6 +216,7 @@ class ReplConsoleView extends ViewPart {
}

override def dispose() {
stopReplAction.run // FIXME: this should NOT WRITE anything to the widget because it will be disposed already
codeBgColor.dispose
codeFgColor.dispose
}
Expand Down

0 comments on commit f76a3ff

Please sign in to comment.