Commit 4fe44113 authored by Tim Steenvoorden's avatar Tim Steenvoorden
Browse files

add first setup for ace editlet

- move Main to new directory structure
parent 2d3746af
old/
main-data/
Examples/
definition module Extensions.Ace
/// This module is to be used qualified!!!
///
/// import Extensions.Ace as Ace
/// Ace.editlet ...
import iTasks.API.Core.Client.Editlet
:: AceEditor = AceEditor //TODO
:: AceClient =
{ editor :: !JSObj AceEditor
}
:: AceServer =
{ configuration :: [AceOption]
, position :: Position //FIXME multiple cursors?
, selection :: Maybe Region
, highlights :: [Region]
, source :: String //FIXME
}
:: AceDiff = AceDiff //TODO
:: AceOption = AceOption //TODO
derive class iTask AceEditor, AceClient, AceServer, AceDiff, AceOption
:: Position :== (Line, Column)
:: Region :== (Position, Position)
:: Line :== Int
:: Column :== Int
aceEditlet :: AceServer -> Editlet AceServer AceDiff AceClient
implementation module Extensions.Ace
??? = ???
($) infixr 9 // :: (a -> b) a -> b
($) f a :== f a
import iTasks
import iTasks.API.Core.Client.Editlet
import _SystemArray
derive class iTask AceEditor, AceClient, AceServer, AceDiff, AceOption
:: AceHandler :==
ComponentId {JSObj JSEvent} AceClient !*JSWorld
-> *(!AceClient, !ComponentDiff AceDiff AceClient, !*JSWorld)
:: AceHandleMaker :== AceHandler ComponentId -> JSFun ()
// instance Editlet AceServer AceDiff AceClient where
// onInit
// onDiffClient
// onDiffServer
// generateDiff
// generateUI
aceEditlet :: AceServer -> Editlet AceServer AceDiff AceClient
aceEditlet editor =
{ Editlet
| currVal = editor
, defValSrv = gDefault{|*|} // or `neutral`
, genUI = editorUI
, initClient = onInit
, appDiffClt = onDiffClient
, appDiffSrv = onDiffServer
, genDiffSrv = generateAceDiff
}
where
editorUI id world = (
{ ComponentHTML
| html = DivTag [IdAttr ("editor-" +++ toString id), StyleAttr "width:100%; height:100%"] []
, width = ExactSize 600
, height = ExactSize 600
}, world)
initClient ::
AceHandleMaker ComponentId {JSObj JSEvent} AceClient !*JSWorld
-> *(AceClient, ComponentDiff AceDiff AceClient, !*JSWorld)
initClient handleMaker id eventHandlers aceClient world
// # (aceEditor, world) = getObject (getElementById $ "editor-" +++ toString id) world
/* var ace = this.ace; */
# (ace, world) = findObject "ace" world
/* var editor = ace.edit("editor"); */
# (aceEditor, world) = (ace .# "edit" .$ ("editor-") +++ toString id) world
/* editor.setTheme("ace/theme/twilight"); */
# (_, world) = (aceEditor .# "setTheme" .$ ("ace/theme/solarized_dark")) world
/* editor.session.setMode("ace/mode/javascript"); */
# (_, world) = (aceEditor .# "session" .# "setMode" .$ ("ace/mode/haskell")) world
= (aceClient, NoDiff, world)
// // We get an AceHanldeMaker, which is a backdoor to create JavaScript event
// // handlers tailored to this Ace instance.
// onInit :: AceHandleMaker ComponentId -> JSIO AceClient
// onInit handleMaker id world =
// let clientState = gDefault{|*|} in
// findObject "ace" >>= \aceObject ->
// if (jsIsUndefined aceObject) (
// // The script is loaded asynchroniously, thus we have to wrap our
// // initialization function in a handler which JavaScript calls on a
// // successfull load.
// addJSFromUrl "src-min-noconflict/ace.js"
// (Just $ handleMaker (initClient handleMaker) id) >>>
// pure clientState
// ) (
// initClient handleMaker id clientState >>= \(clientState, _) >>>
// pure clientState
// )
// We get an AceHandleMaker, which is a backdoor to create JavaScript event
// handlers tailored to this Ace instance.
onInit :: AceHandleMaker ComponentId !*JSWorld -> *(AceClient, !*JSWorld)
onInit handleMaker id world
# clientState = gDefault{|*|}
# (ace, world) = findObject "ace" world
| jsIsUndefined ace
// The script is loaded asynchroniously, thus we have to wrap our
// initialization function in a handler which JavaScript calls on a
// successfull load.
# world = addJSFromUrl "ace/src-min-noconflict/ace.js"
(Just $ handleMaker (initClient handleMaker) id) world
= (clientState, world)
# (clientState, _, world) = initClient handleMaker id {} clientState world
= (clientState, world)
onDiffClient :: ((EditletEventHandlerFunc AceDiff AceClient) ComponentId -> JSFun ()) ComponentId AceDiff AceClient *JSWorld -> *(AceClient, *JSWorld)
onDiffClient handler id diff client world = (client, world)
onDiffServer :: AceDiff AceServer -> AceServer
onDiffServer diff server = server
generateAceDiff :: AceServer AceServer -> Maybe AceDiff
generateAceDiff old new = Nothing
module Main
import iTasks
import iTasks.API.Extensions.CodeMirror
import Extensions.Ace
Start world =
startEngine aceEditor world
codeMirrorHandlers = []
codeMirrorState =
{ configuration = [CMMode "haskell", CMLineNumbers True]
, position = (0,1)
, selection = Nothing
, highlighted = [((0,1),(0,3))]
, source =
[ "definition module iTasks"
, ""
, "/**"
, "* Main iTask module exporting all end user iTask modules"
, "*/"
, "import iTasks.Framework.Engine // iTasks engine"
, " // iTasks API"
, " , iTasks.API"
, ""
, " // Miscellaneous machinery"
, " , Text.JSON // JSON is used for serializing/deserializing strings"
, " , iTasks.Framework.Generic // Generic foundation modules"
, " "
, " // API extensions for user & workflow management"
, " , iTasks.API.Extensions.Admin.UserAdmin"
, " , iTasks.API.Extensions.Admin.WorkflowAdmin"
, ""
, " //StdEnv modules"
, " , StdInt"
, " , StdBool"
, " , StdString"
, " , StdList"
, " , StdOrdList"
, " , StdTuple"
, " , StdEnum"
, " , StdOverloaded"
, ""
, "from StdFunc import id, const, o"
, "from Data.List import instance Functor []"
]
}
// codeMirrorEditor :: Task CodeMirror
// codeMirrorEditor =
// withShared codeMirrorState (\cm ->
// updateSharedInformation "The code:" [UpdateWith (\cm -> codeMirrorEditlet cm []) (\_ editlet -> editlet.currVal)] cm
// -||
// updateSharedInformation "The data:" [] cm)
// codeMirrorEditor :: Task CodeMirror
// codeMirrorEditor =
// updateInformation "The code:" [UpdateWith (\cm -> codeMirrorEditlet cm []) (\_ editlet -> editlet.currVal)] codeMirrorState
codeMirrorEditor :: Task (Editlet CodeMirror [CodeMirrorDiff] CodeMirrorClient)
codeMirrorEditor =
updateInformation "The code:" [] (codeMirrorEditlet codeMirrorState codeMirrorHandlers)
aceEditor :: Task (Editlet AceServer AceDiff AceClient)
aceEditor =
updateInformation "The code:" [] (aceEditlet gDefault{|*|})
......@@ -7,7 +7,7 @@ Global
CheckStacks: False
CheckIndexes: True
Application
HeapSize: 2097152
HeapSize: 20971520
StackSize: 512000
ExtraMemory: 8192
IntialHeapSize: 204800
......@@ -38,12 +38,12 @@ Global
GenerateDLL: False
ExportedNames:
Paths
Path: {Project}/src
Path: {Project}/Sources
Precompile:
Postlink:
MainModule
Name: Main
Dir: {Project}/src
Dir: {Project}/Sources
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
......@@ -56,6 +56,20 @@ MainModule
ReuseUniqueNodes: True
Fusion: False
OtherModules
Module
Name: Extensions.Ace
Dir: {Project}/Sources
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: StdDynamic
Dir: {Application}/lib/Dynamics
......@@ -1918,7 +1932,7 @@ OtherModules
ReuseUniqueNodes: True
Fusion: False
Module
Name: iTasks.API.Extensions.Clock
Name: iTasks.API.Extensions.CodeMirror
Dir: {Application}/lib/iTasks-SDK/Server
Compiler
NeverMemoryProfile: False
......
module Main
import iTasks
import iTasks.API.Extensions.Clock
Start world =
startEngine
[ publish "/" (WebApp []) (\_ -> viewTime)
] world
viewTime :: Task Time
viewTime = viewSharedInformation "The current time is:" [ViewWith AnalogClock] currentTime
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment