Thetruemank / SimpleEditor

0 stars 0 forks source link

Sweep: Make a new kotlin file named "UI2" #22

Open Thetruemank opened 5 months ago

Thetruemank commented 5 months ago

Add a menu bar, rich text field, like a IDE has.

Checklist - [X] Create `UI2.kt` ✓ https://github.com/Thetruemank/SimpleEditor/commit/7b5157fba5b332a254e60f63e4d3814eba9ef45a [Edit](https://github.com/Thetruemank/SimpleEditor/edit/sweep/make_a_new_kotlin_file_named_ui2/UI2.kt)
sweep-ai[bot] commented 5 months ago
Install Sweep Configs: Pull Request

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


❌ Unable to Complete PR

I'm sorry, but it looks like an error has occurred due to a planning failure. The error message is 'progress_url'. Feel free to add more details to the issue description so Sweep can better address it. Alternatively, reach out to Kevin or William for help at https://community.sweep.dev/.

For bonus GPT-4 tickets, please report this bug on Discourse (tracking ID: 165e6716e7).


Please look at the generated plan. If something looks wrong, please add more details to your issue.

File Path Proposed Changes
UI2.kt Create UI2.kt with contents:

Create a new file named "UI2.kt" in the same directory as "UI.kt".


import javax.swing.
import javax.swing.event.CaretListener
import javax.swing.event.CaretEvent
import javax.swing.undo.UndoManager
import java.awt.

import java.io.File
import javax.swing.filechooser.FileNameExtensionFilter
import javax.swing.text.*
import java.awt.GraphicsEnvironment
import javax.swing.border.EmptyBorder

class UI2 : JFrame("Rich Text Editor") {
private val textPane: JTextPane = JTextPane()
private val fileNameLabel: JLabel = JLabel("Untitled")
private val lineCounter: JLabel = JLabel("Line: 1")
private val caretPositionCounter: JLabel = JLabel("Column: 0")

init {
defaultCloseOperation = JFrame.EXIT_ON_CLOSE
setSize(800, 600)

textPane.document = createStyledDocument()

val scrollPane = JScrollPane(textPane)
add(scrollPane)

val counterPanel = JPanel()
val counterPanelLayout = BoxLayout(counterPanel, BoxLayout.X_AXIS)
counterPanel.layout = counterPanelLayout
counterPanel.add(lineCounter)
counterPanel.add(Box.createRigidArea(Dimension(10, 0)))
counterPanel.add(caretPositionCounter)
counterPanel.add(Box.createHorizontalGlue())
counterPanel.add(Box.createRigidArea(Dimension(10, 0)))
counterPanel.add(fileNameLabel)

val panel = JPanel(BorderLayout())
panel.add(counterPanel, BorderLayout.WEST)
panel.border = EmptyBorder(5, 5, 5, 5)
add(panel, BorderLayout.SOUTH)

textPane.addCaretListener(LineAndCaretPositionCaretListener(textPane, lineCounter, caretPositionCounter))

val menuBar = createMenuBar(textPane)
jMenuBar = menuBar

isVisible = true
}

private fun createStyledDocument(): StyledDocument {
val doc = DefaultStyledDocument()
val style = doc.addStyle("DefaultStyle", null)
StyleConstants.setFontFamily(style, "Arial")
StyleConstants.setFontSize(style, 12)

return doc
}

private fun createMenuBar(textPane: JTextPane): JMenuBar {
val menuBar = JMenuBar()

val fileMenu = JMenu("File")
val editMenu = JMenu("Edit")
val styleMenu = JMenu("Style")

val openMenuItem = JMenuItem("Open")
val saveMenuItem = JMenuItem("Save")
val newMenuItem = JMenuItem("New")
val exitMenuItem = JMenuItem("Exit")

val undoMenuItem = JMenuItem("Undo")
val redoMenuItem = JMenuItem("Redo")
val copyMenuItem = JMenuItem("Copy")
val pasteMenuItem = JMenuItem("Paste")
val cutMenuItem = JMenuItem("Cut")
val findMenuItem = JMenuItem("Find")
val replaceMenuItem = JMenuItem("Replace")

val fontMenuItem = JMenuItem("Font")
val textColorMenuItem = JMenuItem("Text Color")

val editorMenu = JMenu("Editor")
val spacingMenuItem = JMenuItem("Spacing")

// Implement menu item actions similar to UI.kt

fileMenu.add(newMenuItem)
fileMenu.add(openMenuItem)
fileMenu.add(saveMenuItem)
fileMenu.add(exitMenuItem)

editMenu.add(undoMenuItem)
editMenu.add(redoMenuItem)
editMenu.add(copyMenuItem)
editMenu.add(pasteMenuItem)
editMenu.add(cutMenuItem)
editMenu.add(findMenuItem)
editMenu.add(replaceMenuItem)
editMenu.add(editorMenu)

styleMenu.add(fontMenuItem)
styleMenu.add(textColorMenuItem)

editorMenu.add(spacingMenuItem)

menuBar.add(fileMenu)
menuBar.add(editMenu)
menuBar.add(styleMenu)

return menuBar
}

// Implement openFile, saveFile, and other utility functions similar to UI.kt
}

fun main() {
UI2()
}

🎉 Latest improvements to Sweep:
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description.

This is an automated message generated by Sweep AI.