Skip to content

Commit

Permalink
Merge pull request #147 from ERSUCC/main
Browse files Browse the repository at this point in the history
Updated code to work with tabs redesign
  • Loading branch information
TheBizzle authored Jul 29, 2024
2 parents dcc7dab + 136d508 commit 155eb6b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ isSnapshot := true

netLogoExtName := "ls"
netLogoClassManager := "org.nlogo.ls.LevelSpace"
netLogoVersion := "6.3.0"
netLogoVersion := "6.4.0-c0582d3"
netLogoTestExtras += (baseDirectory.value / "test")

Compile / scalaSource := baseDirectory.value / "src" / "main"
Expand Down
4 changes: 2 additions & 2 deletions src/main/BackingModelManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait LSModelManager extends ModelManager {
}

class BackingModelManager extends LSModelManager {
override val guiComponent = new LevelSpaceMenu(App.app.tabs, this)
override val guiComponent = new LevelSpaceMenu(App.app.tabManager, this)
private val backingModels = ParHashMap.empty[String, (ChildModel, ModelCodeTab)]
private var openModels = Map.empty[String, ChildModel]

Expand All @@ -42,7 +42,7 @@ class BackingModelManager extends LSModelManager {

def existingTab(filePath: String): Option[CodeTab] =
if (filePath == App.app.workspace.getModelPath)
Some(App.app.tabs.mainCodeTab)
Some(App.app.tabManager.mainCodeTab)
else
backingModels.get(filePath).map(_._2)

Expand Down
16 changes: 7 additions & 9 deletions src/main/LevelSpaceMenu.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import javax.swing._
import org.nlogo.api.ModelSections.ModelSaveable
import org.nlogo.api.{ExtensionException, ModelSections, Version, Exceptions}
import org.nlogo.core.{CompilerException, Shape, ShapeParser}
import org.nlogo.app.{ModelSaver, App, Tabs}
import org.nlogo.app.{ModelSaver, App, TabManager}
import org.nlogo.app.codetab.CodeTab
import org.nlogo.awt.UserCancelException
import org.nlogo.fileformat
Expand All @@ -25,12 +25,11 @@ trait ModelManager {
(f: AbstractWorkspaceScala => ModelCodeTab): Option[ModelCodeTab]
}

class LevelSpaceMenu(tabs: Tabs, val backingModelManager: ModelManager)
class LevelSpaceMenu(tabManager: TabManager, val backingModelManager: ModelManager)
extends JMenu("LevelSpace") {

import LevelSpaceMenu._

val tabManager = tabs.getTabManager
val selectModel = new SelectModelAction("Open Model in Code Tab", backingModelManager)
val openModels = new JMenu("Edit Open Models...")
val newModel = new NewModelAction("Create new LevelSpace Model", backingModelManager)
Expand Down Expand Up @@ -59,7 +58,7 @@ class LevelSpaceMenu(tabs: Tabs, val backingModelManager: ModelManager)

private def newHeadlessBackedTab(filePath: String): Option[ModelCodeTab] =
backingModelManager.registerTab(filePath) { workspace =>
new ModelCodeTab(workspace, tabs, backingModelManager)
new ModelCodeTab(workspace, tabManager, backingModelManager)
}

private def replaceSwingTab(oldTab: ModelCodeTab, newTab: ModelCodeTab): Unit = {
Expand All @@ -69,8 +68,7 @@ class LevelSpaceMenu(tabs: Tabs, val backingModelManager: ModelManager)

object LevelSpaceMenu {
abstract class NewTabAction(name: String, modelManager: ModelManager) extends AbstractAction(name) {
val tabs = App.app.tabs
val tabManager = tabs.getTabManager
val tabManager = App.app.tabManager

def filePath: Option[String]

Expand All @@ -82,14 +80,14 @@ class LevelSpaceMenu(tabs: Tabs, val backingModelManager: ModelManager)

private def createNewTab(path: String): Option[CodeTab] = {
modelManager.registerTab(path) { workspace =>
val tab = new ModelCodeTab(workspace, tabs, modelManager)
tabManager.addNewTab(tab, tab.tabName)
val tab = new ModelCodeTab(workspace, tabManager, modelManager)
tabManager.addTab(tab, tab.tabName)
tab
}
}

override def actionPerformed(actionEvent: ActionEvent): Unit =
actingTab.foreach(tabManager.setPanelsSelectedComponent)
actingTab.foreach(tabManager.setSelectedTab)
}

class OpenModelAction(fileName: String, modelManager: ModelManager)
Expand Down
7 changes: 3 additions & 4 deletions src/main/ModelCodeTab.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.net.URI
import javax.swing.{ AbstractAction, JButton, JOptionPane }

import org.nlogo.api.{ ExtensionException, ModelReader, ModelSection, ModelType, Version }
import org.nlogo.app.{ Tabs, App }
import org.nlogo.app.{ App, TabManager }
import org.nlogo.app.codetab.{ ProceduresMenu, CodeTab }
import org.nlogo.awt.UserCancelException
import org.nlogo.core.{ I18N, Model }
Expand All @@ -18,8 +18,8 @@ import org.nlogo.workspace.{ AbstractWorkspaceScala, ModelTracker, OpenModel, Op

import java.nio.file.Paths

class ModelCodeTab(workspace: AbstractWorkspaceScala, tabs: Tabs, modelManager: ModelManager)
extends CodeTab(workspace, tabs)
class ModelCodeTab(workspace: AbstractWorkspaceScala, tabManager: TabManager, modelManager: ModelManager)
extends CodeTab(workspace, tabManager)
with ModelSavedEvent.Handler {
val tabName = workspace.getModelFileName
val filePath = workspace.getModelPath
Expand Down Expand Up @@ -65,7 +65,6 @@ with ModelSavedEvent.Handler {
}


val tabManager = tabs.getTabManager
protected var isDirty = false

override def getAdditionalToolBarComponents = Seq(new ToolBarActionButton(FileCloseAction))
Expand Down

0 comments on commit 155eb6b

Please sign in to comment.