<NME> run-actions.cocoascript
<BEF> @import 'actions/action-inventory.cocoascript'

var currentCommandIdentifier = -1

var runReplicateLayersIdentifier = 0

var pluginPath = ""
var pluginVersion = ""
var currentDocument = nil
var currentSelection = nil


var userPresets = {
	myRetinaEnabled: 0,
var showTestLog = true
var testing = true



var onReplicateLayersRun = function(context) {
	if (showLog) { log("Running Replace Layers") }
	chooseAction(context, runReplicateLayersIdentifier, !testing)
}

var onGenerateStatesRun = function(context) {
	if (showLog) { log("Running Replicate States") }
	chooseAction(context, runGenerateStatesIdentifier, !testing)
}

var onSimulateKeynoteRun = function(context) {
	if (showLog) { log("Running Simulate Keynote") }
	chooseAction(context, runSimulateKeynoteIdentifier, !testing)
}

var onSettingRun = function(context) {
	if (showLog) { log("Running Settings") }
	chooseAction(context, runSettingsIdentifier, !testing)
}

var onRemoveExportPageRun = function(context) {
	if (showLog) { log("Running Remove Export Page...") }
	chooseAction(context, runRemoveExportPageIdentifier, !testing)
}

var onShowBarRun = function(context) {
	if (showLog) { log("Showing Bar") }
	chooseAction(context, runShowBarIdentifier, !testing)
}

var onSelectProjectFolderRun = function(context) {
	if (showLog) { log("Running Select Project Folder...") }
	chooseAction(context, runSelectProjectFolderIdentifier, !testing)
}

var onRemoveProjectFolderRun = function(context) {
	if (showLog) { log("Running Remove Project Folder...") }
	chooseAction(context, runRemoveProjectFolderIdentifier, !testing)
}

//


var showLog = true
var showTestLog = true
// var testing = true
//
var onTestingRun = function(context) {
	if (showLog) { log("Running Testing Environment") }
	chooseAction(context, runGenerateStatesIdentifier, testing)
}
		currentDocument = context.document
		currentSelection = context.document.selectedLayers().layers()

		methodStartTime = [NSDate date]
}

var onReplicateLayersRun = function(context) {
	if (showLog) { log("Running Replicate Layers") }
	decomposeContext(context)
	runReplicateLayers()
}

var onGenerateStatesRun = function(context) {
	if (showLog) { log("Running Generate States") }
	decomposeContext(context)
	runGenerateStates()
}

var onSimulateKeynoteRun = function(context) {
	if (showLog) { log("Running Simulate Keynote") }
	decomposeContext(context)
	runSimulateKeynote()
}

var onSettingRun = function(context) {
	if (showLog) { log("Running Settings") }
	decomposeContext(context)
	runSettings()
}

var onRemoveExportPageRun = function(context) {
	if (showLog) { log("Running Remove Export Page...") }
	decomposeContext(context)
	FramerInventory.showDoneMessage()
}

var onShowBarRun = function(context) {
	if (showLog) { log("Showing Bar") }
	decomposeContext(context)
	ToolbarInventory.createUIBar()
}


var onSelectOpenedProjectRun = function(context) {
	if (showLog) { log("Running Select Opened Project...") }
	decomposeContext(context)
	PathInventory.createPathModal()
}

var onSelectProjectFolderRun = function(context) {
	if (showLog) { log("Running Select Project Manually...") }
	decomposeContext(context)
	FramerInventory.runSelectProjectFolder()
}

var onRemoveProjectFolderRun = function(context) {
	if (showLog) { log("Running Remove Project Folder...") }
	decomposeContext(context)
	FramerInventory.runRemoveProjectFolder()
}

var onShowProjectFolderRun = function(context) {
	if (showLog) { log("Running Show Project Folder...") }
	decomposeContext(context)
	FramerInventory.runShowProjectFolder()
}

var onCheckUpdatesRun = function(context) {
	if (showLog) { log("Running Updates Checker") }
	decomposeContext(context)
	runCheckUpdates()
}

var onSaveSelectionRun = function(context) {
	if (showLog) { log("Running Save Selection") }
	decomposeContext(context)
	AbstractSelectionInventory.saveSelection(currentSelection)
}

var onAddToSelectionRun = function(context) {
	if (showLog) { log("Running Add to Selection") }
	decomposeContext(context)
	AbstractSelectionInventory.addToSelection(currentSelection)
}

var onClearSelectionRun = function(context) {
	if (showLog) { log("Running Clear Selection") }
	decomposeContext(context)
	AbstractSelectionInventory.clearSelection()
}

var onRestoreSelectionRun = function(context) {
	if (showLog) { log("Running Save Selection") }
	decomposeContext(context)
	AbstractSelectionInventory.restoreSelection()
}




var onDisconnectSymbols = function(context) {
	if (showLog) { log("Disconnect Symbols") }
	decomposeContext(context)
	UtilsInventory.disconnectSymbols()
}

var onAddLayersAsArray = function(context) {
	if (showLog) { log("Add Layer as Array") }
	decomposeContext(context)
	UtilsInventory.addSelectionArray()
}

var onCleanAndCopyLayersAsArray = function(context) {
	if (showLog) { log("Clean and Copy Layers as Array") }
	decomposeContext(context)
	UtilsInventory.cleanAndCopySelection()
}

var onCreateShownHiddenStates = function(context) {
	if (showLog) { log("Create shown/hidden states") }
	decomposeContext(context)
	UtilsInventory.createShownHiddenStates()
}



var onSetRulers = function(context) {
	if (showLog) { log("Set Rulers") }
	decomposeContext(context)
	UtilsInventory.setRulers()
}

var onResetRulers = function(context) {
	if (showLog) { log("Reset Rulers") }
	decomposeContext(context)
	UtilsInventory.resetRulers()
}



var onTestingRun = function(context) {
	if (showLog) { log("Running Testing Environment") }
	// isTestingEnvironment = true
	// sendLog = false
	decomposeContext(context)
	runTestingEnvironment()
	// chooseAction(currentDocument, currentSelection, runTestingEnvironmentIdentifier)
}

<MSG> Context Refactoring

In case we need actual information any time we run action from UIBar,
I’ve changed the way we use context. Now we use currentDocument &
currentSelection. Now all run methods do not need context as an input
param.

p.s. runTesting is still using context (no time to handle this now)

<DFF> @@ -1,5 +1,11 @@
 @import 'actions/action-inventory.cocoascript'
 
+var methodStartTime = nil
+
+var pluginPath = ""
+var currentDocument = nil
+var currentSelection = nil
+
 var currentCommandIdentifier = -1
 
 var runReplicateLayersIdentifier = 0
@@ -15,46 +21,61 @@ var showLog = true
 var showTestLog = true
 var testing = true
 
-
+var decomposeContext = function(context) {
+		log(context)
+		if (showLog) { log("Current document is initialised") }
+		pluginPath = context.scriptPath.substring(0, context.scriptPath.lastIndexOf("/"))
+		if (showLog) { log(pluginPath) }
+		currentDocument = context.document
+		currentSelection = context.document.selectedLayers()
+}
 
 var onReplicateLayersRun = function(context) {
 	if (showLog) { log("Running Replace Layers") }
-	chooseAction(context, runReplicateLayersIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runReplicateLayersIdentifier, !testing)
 }
 
 var onGenerateStatesRun = function(context) {
 	if (showLog) { log("Running Replicate States") }
-	chooseAction(context, runGenerateStatesIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runGenerateStatesIdentifier, !testing)
 }
 
 var onSimulateKeynoteRun = function(context) {
 	if (showLog) { log("Running Simulate Keynote") }
-	chooseAction(context, runSimulateKeynoteIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runSimulateKeynoteIdentifier, !testing)
 }
 
 var onSettingRun = function(context) {
 	if (showLog) { log("Running Settings") }
-	chooseAction(context, runSettingsIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runSettingsIdentifier, !testing)
 }
 
 var onRemoveExportPageRun = function(context) {
 	if (showLog) { log("Running Remove Export Page...") }
-	chooseAction(context, runRemoveExportPageIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runRemoveExportPageIdentifier, !testing)
 }
 
 var onShowBarRun = function(context) {
 	if (showLog) { log("Showing Bar") }
-	chooseAction(context, runShowBarIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runShowBarIdentifier, !testing)
 }
 
 var onSelectProjectFolderRun = function(context) {
 	if (showLog) { log("Running Select Project Folder...") }
-	chooseAction(context, runSelectProjectFolderIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runSelectProjectFolderIdentifier, !testing)
 }
 
 var onRemoveProjectFolderRun = function(context) {
 	if (showLog) { log("Running Remove Project Folder...") }
-	chooseAction(context, runRemoveProjectFolderIdentifier, !testing)
+	decomposeContext(context)
+	chooseAction(currentDocument, currentSelection, runRemoveProjectFolderIdentifier, !testing)
 }
 
 //
@@ -65,6 +86,7 @@ var onRemoveProjectFolderRun = function(context) {
 // var testing = true
 //
 var onTestingRun = function(context) {
+	// ??????
 	if (showLog) { log("Running Testing Environment") }
 	chooseAction(context, runGenerateStatesIdentifier, testing)
 }

Context Refactoring