implementation module ExperimentalDomain import iTasks, Text, Functor from Util import instance toString Maybe derive gUpdate FormattedText, FormattedTextControls, SourceCode, SourceCodeLanguage, Color derive gDefaultMask FormattedText, FormattedTextControls, SourceCode, SourceCodeLanguage, Color derive gVerify FormattedText, FormattedTextControls, SourceCode, SourceCodeLanguage, Color derive JSONEncode FormattedText, FormattedTextControls, SourceCode, SourceCodeLanguage, Color derive JSONDecode FormattedText, FormattedTextControls, SourceCode, SourceCodeLanguage, Color derive gEq FormattedText, SourceCode, Color, FormattedTextControls, SourceCodeLanguage derive bimap Maybe, (,) mkEmptyFormattedText :: !FormattedTextControls -> FormattedText mkEmptyFormattedText controls = mkFormattedText "" controls mkFormattedText :: !String !FormattedTextControls -> FormattedText mkFormattedText src controls = FormattedText src controls setFormattedTextSrc :: !String !FormattedText -> FormattedText setFormattedTextSrc cont (FormattedText _ controls) = FormattedText cont controls getFormattedTextSrc :: !FormattedText -> String getFormattedTextSrc (FormattedText src _) = removeMarkerTags src where removeMarkerTags s # s = case indexOf "" s + 14) (textSize s) s # s = case indexOf "" s + 12) (textSize s) s = s allControls :: FormattedTextControls allControls = { alignmentControls = True , colorControls = True , fontControl = True , fontSizeControls = True , formatControls = True , linkControl = True , listControls = True , sourceEditControl = True } noControls :: FormattedTextControls noControls = { alignmentControls = False , colorControls = False , fontControl = False , fontSizeControls = False , formatControls = False , linkControl = False , listControls = False , sourceEditControl = False } gVisualizeText{|FormattedText|} _ val = [toString val] gVisualizeHtml{|FormattedText|} _ val = [html val] gVisualizeEditor{|FormattedText|} val vst = visualizeControlSimple (TUICustomControl "itasks.tui.FormattedText") val vst where replaceMarkers v //# v = replaceSubString SelectionStartMarker ("") v //# v = replaceSubString SelectionEndMarker ("") v = v toUnformattedString :: !FormattedText !Bool -> String toUnformattedString (FormattedText s _) includeCursorMarkers # s = if includeCursorMarkers (insertMarkers s) s # s = replaceSubString "
" "\n" s # s = replaceSubString "
" "\n" s # s = replaceSubString "
" "\n" s # s = replaceSubString "
" "\n" s # s = replaceSubString "" "\n" s # s = stripHtmlTags s # s = replaceSubString " " " " s # s = replaceSubString "<" "<" s # s = replaceSubString ">" ">" s # s = replaceSubString "&" "&" s = s where stripHtmlTags s # fstOpen = indexOf "<" s # fstClose = indexOf ">" s | fstOpen <> -1 && fstClose <> -1 && fstOpen < fstClose = stripHtmlTags (subString 0 fstOpen s +++ subString (fstClose + 1) (textSize s - fstClose) s) | otherwise = s insertMarkers s # s = case indexOf "" s + 14) (textSize s) s # s = case indexOf "" s + 12) (textSize s) s = s removeMarkers :: !String -> String removeMarkers s # s = replaceSubString SelectionStartMarker "" s # s = replaceSubString SelectionEndMarker "" s = s instance html FormattedText where html (FormattedText src _) = RawText (removeMarkers src) instance toString FormattedText where toString (FormattedText s _) = s mkSourceCode :: !String !SourceCodeLanguage -> SourceCode mkSourceCode src lang = SourceCode src lang setSource :: !String !SourceCode -> SourceCode setSource src (SourceCode _ lang) = SourceCode src lang getSource :: !SourceCode -> String getSource (SourceCode src _) = src gVisualizeText{|SourceCode|} _ val = [toString val] gVisualizeHtml{|SourceCode|} _ val = [html val] gVisualizeEditor{|SourceCode|} val vst = visualizeControlSimple (TUICustomControl "itasks.tui.SourceCode") val vst instance html SourceCode where html (SourceCode src _) = Text src instance toString SourceCode where toString (SourceCode src _) = src gVisualizeText{|Color|} _ val = [toString val] gVisualizeHtml{|Color|} _ val = [html val] gVisualizeEditor{|Color|} val vst = visualizeControlSimple (TUICustomControl "itasks.tui.ColorChooser") val vst instance html Color where html (Color c) = DivTag [StyleAttr ("background-color: #" +++ c +++ "; border: 1px solid; border-color: #ACA899; height: 10px; width: 10px;")] [] instance toString Color where toString (Color c) = "#" +++ c