Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Continued with Text editor (not yet working)

  • Loading branch information...
commit 076086c41244ff763398ef66e61d6bffd70bc6e3 1 parent 3c74433
@jutaro jutaro authored
View
2  leksah-dummy/src/Leksah/Dummy.hs
@@ -130,7 +130,7 @@ data DummyPane = DummyPane {
data DummyPaneState = DPState
deriving(Eq,Ord,Read,Show)
-instance PaneInterface DummyPane where
+instance PaneInterface DummyPane where
data PaneState DummyPane = DummyPaneState
deriving(Eq,Ord,Read,Show)
type PaneArgs DummyPane = ()
View
4 leksah-sourceview/src/Text/TextEditor.hs
@@ -168,6 +168,8 @@ instance TextEditorBackend GtkSourceView where
onKeyRelease = onKeyRelease'
onLookupInfo = onLookupInfo'
onPopulatePopup = onPopulatePopup'
+-- Conversion
+ fromGtkColor = fromGtkColor'
-- Buffer
newBuffer' :: Maybe FilePath -> String -> FilePath -> IDEM (EditorBuffer GtkSourceView)
@@ -736,3 +738,5 @@ onPopulatePopup' (GtkEditorView sv) f = do
#endif
return [castCID id1]
+fromGtkColor' :: Gtk.Color -> EditorColor GtkSourceView
+fromGtkColor' c = GtkEditorColor c
View
16 leksah-textedit-interface/leksah-textedit-interface.cabal
@@ -15,19 +15,19 @@ category: IDE
author: Juergen "jutaro" Nicklisch-Franken
tested-with: GHC ==7.0
data-dir: ""
-
+
library
build-depends: base >=4.0.0.0 && <4.4,
billeksah-forms >=1.0.0 && <1.1, billeksah-pane >=1.0.0 && <1.1,
billeksah-services >=1.0.0 && <1.1, containers >=0.2 && <0.5,
directory >=1.1.0.0 && <1.2, filepath >=1.2.0.0 && <1.3,
- glib >=0.12.0 && <0.13, gtk >=0.12.0 && <0.13,
- leksah-main >=1.0.0 && <1.1, mtl >=1.1.0.2 && <2.1,
- old-time >=1.0.0 && <1.0.1, parsec >=3.1.1 && <4,
- pretty >=1.0.1.0 && <1.1, transformers >=0.2.2.0 && <0.3
- exposed-modules: Plugin.LeksahTexteditInterface Text.BufferModeInterface
- Text.TextEditorInterface
+ glib >=0.12.0 && <0.13, gtk -any, leksah-main >=1.0.0 && <1.1,
+ mtl >=1.1.0.2 && <2.1, old-time >=1.0.0 && <1.0.1,
+ parsec >=3.1.1 && <4, pretty >=1.0.1.0 && <1.1,
+ transformers >=0.2.2.0 && <0.3
+ exposed-modules: Plugin.LeksahTexteditInterface
+ Text.BufferModeInterface Text.TextEditorInterface
exposed: True
buildable: True
hs-source-dirs: src
-
+
View
35 leksah-textedit-interface/src/Text/BufferModeInterface.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE ExistentialQuantification #-}
+{-# LANGUAGE ExistentialQuantification, MultiParamTypeClasses #-}
-----------------------------------------------------------------------------
--
-- Module : IDE.BufferMode
@@ -18,20 +18,29 @@ module Text.BufferModeInterface where
import Text.TextEditorInterface
import Leksah (IDEM, IDEAction)
-class BufferMode alpha where
- modeName :: alpha -> String
- modeEditComment :: alpha -> IDEAction
- modeEditUncomment :: alpha -> IDEAction
- modeSelectedModuleName :: alpha -> IDEM (Maybe String)
- modeEditToCandy :: alpha -> (String -> Bool) -> IDEAction
- modeTransformToCandy :: forall beta . TextEditorBackend beta =>
+data BufferMode beta = BufferMode {
+ bmName :: String,
+ -- ^ The name of this mode
+ bmEditComment :: IDEAction,
+ -- ^ Comment out the selected lines
+ bmEditUncomment :: IDEAction,
+ -- ^ Uncomment the selected lines
+ bmSelectedModuleName :: IDEM (Maybe String),
+ -- ^ Maybe this file offers a module name
+ bmGetRealText :: EditorBuffer beta -> IDEM String
+ -- ^ Get the real text to store
+}
+
+{--
+ bmEditToCandy :: alpha -> (String -> Bool) -> IDEAction
+ bmTransformToCandy :: forall beta . TextEditorBackend beta =>
alpha -> (String -> Bool) -> EditorBuffer beta -> IDEAction
- modeEditFromCandy :: alpha -> IDEAction
- modeEditKeystrokeCandy :: alpha -> Maybe Char -> (String -> Bool) -> IDEAction
- modeEditInsertCode :: forall beta . TextEditorBackend beta =>
+ bmEditFromCandy :: alpha -> IDEAction
+ bmEditKeystrokeCandy :: alpha -> Maybe Char -> (String -> Bool) -> IDEAction
+ bmEditInsertCode :: forall beta . TextEditorBackend beta =>
alpha -> String -> EditorIter beta -> EditorBuffer beta -> IDEAction
- modeEditInCommentOrString :: alpha -> String -> Bool
-
+ bmEditInCommentOrString :: alpha -> String -> Bool
+--}
-- * Buffer Basics
View
16 leksah-textedit-interface/src/Text/TextEditorInterface.hs
@@ -21,6 +21,7 @@ import Base
import Leksah (IDEM)
import Graphics.Pane (Connection)
import Data.Typeable (Typeable)
+import qualified Graphics.UI.Gtk as Gtk (Color(..))
--
@@ -28,12 +29,12 @@ import Data.Typeable (Typeable)
--
class Typeable alpha => TextEditorBackend alpha where
- data EditorBuffer alpha :: *
- data EditorView alpha :: *
- data EditorMark alpha :: *
- data EditorIter alpha :: *
- data EditorTagTable alpha :: *
- data EditorClipboard alpha :: *
+ data EditorBuffer alpha
+ data EditorView alpha
+ data EditorMark alpha
+ data EditorIter alpha
+ data EditorTagTable alpha
+ data EditorClipboard alpha
data EditorTag alpha
data EditorDrawWindow alpha
data EditorRectangle alpha
@@ -199,4 +200,5 @@ class Typeable alpha => TextEditorBackend alpha where
-> IDEM [Connection]
onLookupInfo :: EditorView alpha -> IDEM () -> IDEM [Connection]
onPopulatePopup :: EditorView alpha -> (EditorMenu alpha -> IDEM ()) -> IDEM [Connection]
-
+-- Conversion
+ fromGtkColor :: Gtk.Color -> EditorColor alpha
View
10 leksah-textedit/leksah-textedit.cabal
@@ -22,12 +22,12 @@ library
billeksah-services >=1.0.0 && <1.1, containers >=0.2 && <0.5,
directory >=1.1.0.0 && <1.2, filepath >=1.2.0.0 && <1.3,
glib >=0.12.0 && <0.13, gtk >=0.12.0 && <0.13,
- leksah-main >=1.0.0 && <1.1, leksah-textedit-interface -any,
- mtl >=1.1.0.2 && <2.1, old-time -any, parsec >=3.1.1 && <4,
- pretty >=1.0.1.0 && <1.1, transformers >=0.2.2.0 && <0.3
- exposed-modules: Graphics.Pane.TextEditor
+ leksah-main >=1.0.0 && <1.1, leksah-sourceview -any,
+ leksah-textedit-interface -any, mtl >=1.1.0.2 && <2.1,
+ old-time -any, parsec >=3.1.1 && <4, pretty >=1.0.1.0 && <1.1,
+ transformers >=0.2.2.0 && <0.3, utf8-string -any
+ exposed-modules: Graphics.Pane.TextEditor Plugin.TextEditor
exposed: True
buildable: True
hs-source-dirs: src
- other-modules: Types.TextEditor
View
277 leksah-textedit/src/Graphics/Pane/TextEditor.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE TypeFamilies, RankNTypes, DeriveDataTypeable #-}
+{-# LANGUAGE TypeFamilies, RankNTypes, DeriveDataTypeable, CPP #-}
-----------------------------------------------------------------------------
--
-- Module : Graphics.Pane.TextEditor
@@ -14,27 +14,61 @@
-----------------------------------------------------------------------------------
module Graphics.Pane.TextEditor (
+ allBuffers
+, IDEBuffer(..)
+ -- File menu
+, fileNew
+, fileOpen
+, fileRevert
+, fileSave
+, fileSaveAll
+, fileClose
+, fileCloseAll
+ -- Edit menu
+, editUndo
+, editRedo
+, editCut
+, editCopy
+, editPaste
+, editDelete
+, editSelectAll
+, editFindInc
+, editGotoLine
+
+, editComment
+, editUncomment
+
+, align
+
) where
import Base
import Leksah
import Graphics.Pane
-import Types.TextEditor
import Text.TextEditorInterface
import Text.BufferModeInterface
-import Graphics.UI.Gtk (ScrolledWindow, idleAdd, castToWidget)
+import qualified Graphics.UI.Gtk as Gtk hiding (eventKeyName)
import System.FilePath (takeFileName)
import Control.Monad.IO.Class (MonadIO(..))
import System.Glib.MainLoop (priorityDefaultIdle)
import Data.Typeable (Typeable)
import Data.IORef (IORef)
import System.Time (ClockTime)
+import qualified System.IO.UTF8 as UTF8
+import System.Directory (getModificationTime)
+import Control.Monad (when)
+import Paths_leksah_textedit
--
--- | A text editor pane description
+-- | Get all open textEditors
--
+allBuffers :: TextEditorBackend alpha => IDEM [IDEBuffer alpha]
+allBuffers = getPanes
+--
+-- | The state of a text editor pane
+--
data IDEBuffer alpha = IDEBuffer {
ibFileName :: Maybe FilePath
-- ^ Maybe a file on disk, which get edited here
@@ -44,32 +78,50 @@ data IDEBuffer alpha = IDEBuffer {
-- ^ An added index, if more files with this name are open
, ibSourceView :: TextEditorBackend alpha => EditorView alpha
-- ^ The actual view
-, ibScrolledWindow :: ScrolledWindow
+, ibScrolledWindow :: Gtk.ScrolledWindow
-- ^ The scrolled window
-, ibSodTime :: IORef (Maybe (ClockTime))
+, ibSaveTime :: IORef (Maybe (ClockTime))
-- ^ Maybe the last time the file has been saved
-, ibMode :: forall beta . BufferMode beta => beta
+, ibMode :: BufferMode alpha
-- ^ The editor mode
} deriving (Typeable)
+--
+-- | The arguments for the construction of an editor pane
+--
+data TextEditorArgs alpha = TextEditorArgs {
+ paCondMode :: Maybe (BufferMode alpha),
+ -- ^ Maybe a mode which should be used, otherwise the mode will be inferred from Filename...
+ paCondFileName :: Maybe FilePath,
+ -- ^ Maybe a file to open
+ paBufferName :: String,
+ -- ^ The name to use for this buffer
+ paAddedIndex :: Int
+ -- ^ An index which may be added to the name
+}
--
-- | A text pane is a pane!
--
+instance TextEditorBackend alpha => Pane (IDEBuffer alpha)
+
instance TextEditorBackend alpha => PaneInterface (IDEBuffer alpha) where
data PaneState (IDEBuffer alpha) =
BSBufferState {
- bsFilePath :: String,
- bsOffset :: Int}
-
- | BSBufferStateTrans {
- bsBufferName :: String,
- bsContents :: String,
- bsOffset :: Int}
-
+ bsFilePath :: String,
+ bsOffset :: Int,
+ bsModeName :: String}
+ | BSBufferStateTrans {
+ bsBufferName :: String,
+ bsContents :: String,
+ bsOffset :: Int,
+ bsModeName :: String}
deriving(Eq,Ord,Read,Show)
- type PaneArgs (IDEBuffer alpha) = ()
- getTopWidget = \ p -> castToWidget (ibScrolledWindow p)
+ -- ^ The description of the storable state of a pane
+ type PaneArgs (IDEBuffer alpha) = TextEditorArgs alpha
+ -- ^ The description of the arguments for the pane construction
+
+ getTopWidget = \ p -> Gtk.castToWidget (ibScrolledWindow p)
primPaneName = \ dp -> "Editor"
paneType = \ _ -> "**Editor"
saveState p = do buf <- getBuffer (ibSourceView p)
@@ -78,45 +130,211 @@ instance TextEditorBackend alpha => PaneInterface (IDEBuffer alpha) where
offset <- getOffset iter
case ibFileName p of
Nothing -> do
- text <- getCandylessText buf
- return (Just (BSBufferStateTrans (ibBufferName p) text offset))
- Just fn -> return (Just (BSBufferState fn offset))
- recoverState pp (BSBufferState n i) = do
- mbbuf <- newTextBuffer pp (takeFileName n) (Just n)
+ text <- bmGetRealText (ibMode p) buf
+ return (Just (BSBufferStateTrans{
+ bsBufferName = ibBufferName p,
+ bsContents = text,
+ bsOffset = offset,
+ bsModeName = bmName (ibMode p)}))
+ Just fn -> return (Just (BSBufferState {
+ bsFilePath = fn,
+ bsOffset = offset,
+ bsModeName = bmName (ibMode p)}))
+ recoverState pp BSBufferState{bsFilePath = fn,bsOffset = offset, bsModeName = modeName} = do
+ mbbuf <- newTextBuffer pp (takeFileName fn) (Just fn)
case mbbuf of
Just buf -> do
gtkBuf <- getBuffer (ibSourceView buf)
- iter <- getIterAtOffset gtkBuf i
+ iter <- getIterAtOffset gtkBuf offset
placeCursor gtkBuf iter
mark <- getInsertMark gtkBuf
reifyState (\ stateR ->
- liftIO $ idleAdd (do
+ liftIO $ Gtk.idleAdd (do
reflectState (scrollToMark (ibSourceView buf)
mark 0.0 (Just (0.3,0.3))) stateR
return False) priorityDefaultIdle)
return (Just buf)
Nothing -> return Nothing
- recoverState pp (BSBufferStateTrans bn text i) = do
- mbbuf <- newTextBuffer pp bn Nothing
+ recoverState pp BSBufferStateTrans{bsBufferName = bufferName,
+ bsContents = contents,
+ bsOffset = offset,
+ bsModeName = modeName} = do
+ mbbuf <- newTextBuffer pp bufferName Nothing
case mbbuf of
Just buf -> do
useCandy <- useCandyFor buf
gtkBuf <- getBuffer (ibSourceView buf)
- setText gtkBuf text
+ setText gtkBuf contents
-- when useCandy $ modeTransformToCandy (mode buf)
-- (modeEditInCommentOrString (mode buf)) gtkBuf
setCandyfullText
- iter <- getIterAtOffset gtkBuf i
+ iter <- getIterAtOffset gtkBuf offset
placeCursor gtkBuf iter
mark <- getInsertMark gtkBuf
reifyState (\ stateR ->
- liftIO $ idleAdd (do
+ liftIO $ Gtk.idleAdd (do
reflectState (scrollToMark (ibSourceView buf)
mark 0.0 (Just (0.3,0.3))) stateR
return False) priorityDefaultIdle)
return (Just buf)
Nothing -> return Nothing
builder = builder'
+
+builder' = undefined
+newTextBuffer = undefined
+useCandyFor = undefined
+setCandyfullText = undefined
+
+fileNew = undefined
+fileOpen = undefined
+fileRevert = undefined
+fileSave = undefined
+fileSaveAll = undefined
+fileClose = undefined
+fileCloseAll = undefined
+-- Edit menu
+editUndo = undefined
+editRedo = undefined
+editCut = undefined
+editCopy = undefined
+editPaste = undefined
+editDelete = undefined
+editSelectAll = undefined
+editFindInc = undefined
+editGotoLine = undefined
+
+editComment = undefined
+editUncomment = undefined
+
+align = undefined
+
+{--
+-- | Build a text editor pane
+builder' :: TextEditorArgs alpha
+ PanePath ->
+ Gtk.Notebook ->
+ Gtk.Window ->
+ StateM (Maybe IDEBuffer,Connections)
+builder' TextEditorArgs {paCondMode = condMode, paCondFileName = mbFileName,
+ paBufferName = bufferName, paAddedIndex = addedIndex} pp nb windows = do
+ -- load up and display a file
+ (fileContents,modTime) <- case mbFileName of
+ Just fn -> do
+ fc <- liftIO $ UTF8.readFile fn
+ mt <- liftIO $ getModificationTime fn
+ return (fc,Just mt)
+ Nothing -> return ("\n",Nothing)
+ dataDir <- getDataDir
+ buffer <- newBuffer mbFileName fileContents dataDir
+ tagTable <- getTagTable buffer
+ foundTag <- newTag tagTable "found"
+ background foundTag $ foundBackground prefs
+
+ beginNotUndoableAction buffer
+ let mod = modFromFileName mbfn
+ when (bs && isHaskellMode mod) $ modeTransformToCandy mod
+ (modeEditInCommentOrString mod) buffer
+ endNotUndoableAction buffer
+ setModified buffer False
+ siter <- getStartIter buffer
+ placeCursor buffer siter
+ iter <- getEndIter buffer
+
+ -- create a new SourceView Widget
+ sv <- newView buffer (textviewFont prefs)
+ setShowLineNumbers sv $ showLineNumbers prefs
+ setRightMargin sv $ case rightMargin prefs of
+ (False,_) -> Nothing
+ (True,v) -> Just v
+ setIndentWidth sv $ tabWidth prefs
+ setTabWidth sv $ 8 -- GHC treats tabs as 8 we should display them that way
+ drawTabs sv
+ setStyle buffer $ case sourceStyle prefs of
+ (False,_) -> Nothing
+ (True,v) -> Just v
+
+ -- put it in a scrolled window
+ sw <- getScrolledWindow sv
+ if wrapLines prefs
+ then liftIO $ scrolledWindowSetPolicy sw PolicyNever PolicyAutomatic
+ else liftIO $ scrolledWindowSetPolicy sw PolicyAutomatic PolicyAutomatic
+ liftIO $ scrolledWindowSetShadowType sw ShadowIn
+ modTimeRef <- liftIO $ newIORef modTime
+ let buf = IDEBuffer {
+ fileName = mbfn,
+ bufferName = bn,
+ addedIndex = ind,
+ sourceView =sv,
+ scrolledWindow = sw,
+ modTime = modTimeRef,
+ mode = mod}
+ -- events
+ ids1 <- sv `afterFocusIn` makeActive buf
+ ids2 <- onCompletion sv (Completion.complete sv False) Completion.cancel
+ ids3 <- sv `onButtonPress`
+ \event -> do
+ liftIO $ reflectIDE (do
+ case eventClick event of
+ DoubleClick -> do
+ (start, end) <- getIdentifierUnderCursor buffer
+ liftIO $ postGUIAsync $ reflectIDE (selectRange buffer start end) ideR
+ return False
+ _ -> return False) ideR
+ (GetTextPopup mbTpm) <- triggerEvent ideR (GetTextPopup Nothing)
+ ids4 <- case mbTpm of
+ Just tpm -> sv `onPopulatePopup` \menu -> liftIO $ (tpm ideR menu)
+ Nothing -> do
+ sysMessage Normal "SourceBuffer>> no text popup"
+ return []
+ ids5 <- sv `onKeyPress`
+ \name modifier keyval -> do
+ liftIO $ reflectIDE (do
+ let moveToNextWord iterOp sel = do
+ sel' <- iterOp sel
+ rs <- isRangeStart sel'
+ if rs then return sel' else moveToNextWord iterOp sel'
+ let calculateNewPosition iterOp = getInsertIter buffer >>= moveToNextWord iterOp
+ let continueSelection keepSelBound nsel = do
+ im <- getInsertMark buffer
+ moveMark buffer im nsel
+ scrollToIter sv nsel 0 Nothing
+ when (not keepSelBound) $ do
+ sb <- getSelectionBoundMark buffer
+ moveMark buffer sb nsel
+#if defined(darwin_HOST_OS)
+ let mapCommand GtkOld.Alt = GtkOld.Control
+ mapCommand x = x
+#else
+ let mapCommand = id
+#endif
+ case (name, map mapCommand modifier, keyval) of
+ ("Left",[GtkOld.Control],_) -> do
+ calculateNewPosition backwardCharC >>= continueSelection False
+ return True
+ ("Left",[GtkOld.Shift, GtkOld.Control],_) -> do
+ calculateNewPosition backwardCharC >>= continueSelection True
+ return True
+ ("Right",[GtkOld.Control],_) -> do
+ calculateNewPosition forwardCharC >>= continueSelection False --placeCursor buffer
+ return True
+ ("Right",[GtkOld.Shift, GtkOld.Control],_) -> do
+ calculateNewPosition forwardCharC >>= continueSelection True
+ return True
+ ("BackSpace",[GtkOld.Control],_) -> do -- delete word
+ here <- getInsertIter buffer
+ there <- calculateNewPosition backwardCharC
+ delete buffer here there
+ return True
+ ("minus",[GtkOld.Control],_) -> do
+ (start, end) <- getIdentifierUnderCursor buffer
+ slice <- getSlice buffer start end True
+ launchAutoCompleteDialog slice goToDefinition
+ return True
+ _ -> return False
+ ) ideR
+ return (Just buf,concat [ids1, ids2, ids3, ids4, ids5])
+
+
-- makeActive actbuf = do
-- ideR <- ask
-- let sv = sourceView actbuf
@@ -1175,3 +1393,4 @@ editCandy = do
else mapM_ (modeEditFromCandy . mode) buffers
--}
+--}
View
385 leksah-textedit/src/Plugin/TextEditor.hs
@@ -0,0 +1,385 @@
+{-# LANGUAGE EmptyDataDecls, TypeFamilies, DeriveDataTypeable, ScopedTypeVariables #-}
+-----------------------------------------------------------------------------
+--
+-- Module : Plugin.TextEditor
+-- Copyright : Juergen "jutaro" Nicklisch-Franken
+-- License : GPL Nothing
+--
+-- Maintainer : maintainer@leksah.org
+-- Stability :
+-- Portability :
+--
+-- |
+--
+-----------------------------------------------------------------------------
+
+module Plugin.TextEditor where
+
+import Graphics.Pane.TextEditor
+
+import Base
+import Graphics.Forms
+import Graphics.Frame
+import Graphics.Pane
+
+import Data.Version (Version(..))
+import Data.Typeable (Typeable)
+import qualified Graphics.UI.Gtk as Gtk
+import qualified Text.PrettyPrint as PP (text)
+import Text.TextEditorInterface
+ (background, lookupTag, getTagTable, setStyle, getBuffer,
+ setWrapMode, setIndentWidth, setRightMargin, setFont,
+ setShowLineNumbers, fromGtkColor, TextEditorBackend)
+import Graphics.UI.Gtk.General.Enums (ShadowType(..))
+import Control.Monad (forM_)
+import Text.ParserCombinators.Parsec (CharParser)
+import Text.Parsec (string)
+import qualified Text.Parsec.Token as P
+ (integer, makeTokenParser, TokenParser)
+import Text.TextEditor (GtkSourceView(..))
+
+
+-- ----------------------------------------------
+-- | It's a plugin
+--
+pluginName = "leksah-texteditor"
+
+leksahTexteditorInterface = do
+ fe <- makeEvent TexteditorSel
+ return $ PluginInterface {
+ piInit1 = init1,
+ piInit2 = init2,
+ piEvent = fe,
+ piName = pluginName,
+ piVersion = Version [1,0,0][]}
+
+init1 :: BaseEvent -> EventChannel TexteditorEvent -> StateM ()
+init1 baseEvent myEvent = message Debug ("init1 " ++ pluginName) >> return ()
+
+init2 :: BaseEvent -> EventChannel TexteditorEvent -> StateM ()
+init2 baseEvent myEvent = do
+ message Debug ("init2 " ++ pluginName)
+ getFormsEvent >>= \ev -> registerEvent ev formsEventHandler >> return ()
+ getFrameEvent >>= \ev -> registerEvent ev frameEventHandler >> return ()
+
+-- | Handle the registerPrefs event
+-- TODO: make backend configurable
+-- How do we know about it at this early point???
+formsEventHandler (RegisterPrefs prefs) = return (RegisterPrefs $ prefs ++
+ [("TextEditor",GenF (textEditorPrefsDescr GtkSourceView) defaultTextEditorPrefs)])
+formsEventHandler other = return other
+
+frameEventHandler (RegisterActions actions) = return (RegisterActions $ actions ++ myActions)
+frameEventHandler (RegisterPane paneTypes) = return (RegisterPane $ paneTypes ++ myPaneTypes GtkSourceView)
+
+myPaneTypes :: forall alpha . TextEditorBackend alpha => alpha -> [(String,GenPane)]
+myPaneTypes _ = map asRegisterType [undefined :: IDEBuffer alpha]
+
+-- -----------------------------------------------
+-- * Menu and Toolbar entries for Texteditor
+--
+
+myActions :: [ActionDescr]
+myActions =
+ [AD "File" "_File" Nothing Nothing (return ()) [] False
+ ,AD "FileNewTextFile" "_New Text File" Nothing Nothing
+ fileNew [] False
+ ,AD "FileOpen" "_Open..." Nothing (Just "gtk-open")
+ fileOpen [] False
+ ,AD "RecentFiles" "Open _Recent" Nothing Nothing (return ()) [] False
+ ,AD "FileRevert" "_Revert" Nothing Nothing
+ fileRevert [] False
+ ,AD "FileSave" "_Save" Nothing (Just "gtk-save")
+ (do fileSave False; return ()) [] False
+ ,AD "FileSaveAs" "Save _As..." Nothing (Just "gtk-save-as")
+ (do fileSave True; return ()) [] False
+ ,AD "FileSaveAll" "Save A_ll" Nothing Nothing
+ (do fileSaveAll (\ b -> return (ibBufferName b /= "_Eval.hs")); return ()) [] False
+ ,AD "FileClose" "_Close" Nothing (Just "gtk-close")
+ (do fileClose; return ()) [] False
+ ,AD "FileCloseAll" "Close All" Nothing Nothing
+ (do fileCloseAll (\ b -> return (ibBufferName b /= "_Eval.hs")); return ()) [] False
+
+ ,AD "Edit" "_Edit" Nothing Nothing (return ()) [] False
+ ,AD "EditUndo" "_Undo" Nothing (Just "gtk-undo")
+ editUndo [] False
+ ,AD "EditRedo" "_Redo" Nothing (Just "gtk-redo")
+ editRedo [] False
+ ,AD "EditCut" "Cu_t" Nothing (Just "gtk-cut")
+ editCut [] {--Just "<control>X"--} False
+ ,AD "EditCopy" "_Copy" Nothing (Just "gtk-copy")
+ editCopy [] {--Just "<control>C"--} False
+ ,AD "EditPaste" "_Paste" Nothing (Just "gtk-paste")
+ editPaste [] {--Just "<control>V"--} False
+ ,AD "EditDelete" "_Delete" Nothing (Just "gtk-delete")
+ editDelete [] False
+ ,AD "EditSelectAll" "Select_All" Nothing (Just "gtk-select-all")
+ editSelectAll [] False
+
+-- TODO Findbar
+-- ,AD "EditFind" "Find" Nothing (Just "gtk-find")
+-- (editFindInc Initial) [] False
+-- ,AD "EditFindNext" "Find _Next" Nothing (Just "gtk-find-next")
+-- (editFindInc Forward) [] False
+-- ,AD "EditFindPrevious" "Find _Previous" Nothing (Just "gtk-find-previous")
+-- (editFindInc Backward) [] False
+-- ,AD "EditGotoLine" "_Goto Line" Nothing (Just "gtk-jump")
+-- editGotoLine [] False
+
+ ,AD "EditComment" "_Comment" Nothing Nothing
+ editComment [] False
+ ,AD "EditUncomment" "_Uncomment" Nothing Nothing
+ editUncomment [] False
+
+ --,AD "Align" "_Align" Nothing Nothing (return ()) [] False
+ ,AD "EditAlignEqual" "Align _=" Nothing Nothing
+ (align '=') [] False
+ ,AD "EditAlignRightArrow" "Align -_>" Nothing Nothing
+ (align '>') [] False
+ ,AD "EditAlignLeftArrow" "Align _<-" Nothing Nothing
+ (align '<') [] False
+ ,AD "EditAlignTypeSig" "Align _::" Nothing Nothing
+ (align ':') [] False]
+
+-- -----------------------------------------------
+-- * Texteditor Events
+--
+data TexteditorSel = TexteditorSel
+ deriving(Typeable, Show, Ord, Eq)
+
+instance Selector TexteditorSel where
+ type ValueType TexteditorSel = EventChannel TexteditorEvent
+
+data TexteditorEvent
+
+-- -----------------------------------------------
+-- * Texteditor Preferences
+--
+-- | Define the prefs you need
+data TexteditorPrefs = TexteditorPrefs {
+ tepShowLineNumbers :: Bool
+ , tepRightMargin :: (Bool, Int)
+ , tepTabWidth :: Int
+ , tepWrapLines :: Bool
+ , tepSourceCandy :: (Bool,String)
+ , tepKeymapName :: String
+ , tepForceLineEnds :: Bool
+ , tepRemoveTBlanks :: Bool
+ , tepTextviewFont :: Maybe String
+ , tepSourceStyle :: (Bool, String)
+ , tepFoundBackground :: Gtk.Color
+ , tepContextBackground :: Gtk.Color
+ , tepBreakpointBackground :: Gtk.Color
+ , tepAutoLoad :: Bool
+ , tepUseYi :: Bool}
+ deriving (Eq,Typeable)
+
+defaultTextEditorPrefs = TexteditorPrefs {
+ tepShowLineNumbers = True
+ , tepRightMargin = (True,100)
+ , tepTabWidth = 4
+ , tepWrapLines = False
+ , tepSourceCandy = (False,"candy")
+ , tepKeymapName = "keymap"
+ , tepForceLineEnds = True
+ , tepRemoveTBlanks = True
+ , tepTextviewFont = Nothing
+ , tepSourceStyle = (False,"classic")
+ , tepFoundBackground = Gtk.Color 65535 65535 32768
+ , tepContextBackground = Gtk.Color 65535 49152 49152
+ , tepBreakpointBackground = Gtk.Color 65535 49152 32768
+ , tepUseYi = False
+ , tepAutoLoad = False}
+
+
+textEditorPrefsDescr :: forall alpha . TextEditorBackend alpha => alpha -> FieldDescription TexteditorPrefs
+textEditorPrefsDescr _ =
+ VertBox defaultParams [
+ mkField
+ (("Name", ParaString "Show line numbers")
+ <<< ("Synopsis", ParaString "(True/False)")
+ <<< defaultParams)
+ (PP.text . show)
+ boolParser
+ tepShowLineNumbers
+ (\ b a -> a{tepShowLineNumbers = b})
+ boolEditor
+ (\b -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ mapM_ (\buf -> setShowLineNumbers (ibSourceView buf) b) buffers)
+ , mkField
+ (("Name", ParaString "TextView Font") <<< defaultParams)
+ (\a -> PP.text (case a of Nothing -> show ""; Just s -> show s))
+ (do str <- stringParser
+ return (if null str then Nothing else Just (str)))
+ tepTextviewFont
+ (\ b a -> a{tepTextviewFont = b})
+ fontEditor
+ (\mbs -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ mapM_ (\buf -> setFont (ibSourceView buf) mbs) buffers)
+ , mkField
+ (("Name", ParaString "Right margin")
+ <<< ("Synopsis" , ParaString "Size or 0 for no right margin")
+ <<< ("Shadow" , ParaShadow ShadowIn) <<< defaultParams)
+ (PP.text . show)
+ readParser
+ tepRightMargin
+ (\b a -> a{tepRightMargin = b})
+ (disableEditor (intEditor (1.0, 200.0, 5.0), ("Name", ParaString "Position")
+ <<< defaultParams)
+ True "Show it ?")
+ (\b -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ mapM_ (\buf -> setRightMargin ( ibSourceView buf)
+ (case b of
+ (True,v) -> Just v
+ (False,_) -> Nothing)) buffers)
+ , mkField
+ (("Name", ParaString "Tab width") <<< defaultParams)
+ (PP.text . show)
+ intParser
+ tepTabWidth
+ (\b a -> a{tepTabWidth = b})
+ (intEditor (1.0, 20.0, 1.0))
+ (\i -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ mapM_ (\buf -> setIndentWidth ( ibSourceView buf) i) buffers)
+ , mkField
+ (("Name", ParaString "Wrap lines") <<< defaultParams)
+ (PP.text . show)
+ boolParser
+ tepWrapLines
+ (\b a -> a{tepWrapLines = b})
+ boolEditor
+ (\b -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ mapM_ (\buf -> setWrapMode ( ibSourceView buf) b) buffers)
+ , mkField
+ (("Name", ParaString "Use standard line ends even on windows") <<< defaultParams)
+ (PP.text . show)
+ boolParser
+ tepForceLineEnds
+ (\b a -> a{tepForceLineEnds = b})
+ boolEditor
+ (\i -> return ())
+ , mkField
+ (("Name", ParaString "Remove trailing blanks when saving a file") <<< defaultParams)
+ (PP.text . show)
+ boolParser
+ tepRemoveTBlanks
+ (\b a -> a{tepRemoveTBlanks = b})
+ boolEditor
+ (\i -> return ())
+ , mkField
+ (("Name", ParaString "Source candy")
+ <<< ("Synopsis", ParaString
+ "Empty for do not use or the name of a candy file in a config dir")
+ <<< ("Shadow", ParaShadow ShadowIn) <<< defaultParams)
+ (PP.text . show)
+ readParser
+ tepSourceCandy (\b a -> a{tepSourceCandy = b})
+ (disableEditor (stringEditor (\s -> not (null s)) True,
+ ("Name", ParaString "Candy specification") <<< defaultParams)
+ True "Use it ?")
+ (\cs -> return ())
+-- TODO: recover
+-- case cs of
+-- (False,_) -> do
+-- setCandyState False
+-- editCandy
+-- (True,name) -> do
+-- setCandyState True
+-- editCandy)
+-- TODO specialize on Sourceview
+{-- , mkField
+ (("Name", ParaString "Editor Style") <<< defaultParams)
+ (\a -> PP.text (case a of (False,_) -> show ""; (True, s) -> show s))
+ (do str <- stringParser
+ return (if null str then (False,"classic") else (True,str)))
+ tepSourceStyle
+ (\b a -> a{tepSourceStyle = b})
+ styleEditor
+ (\mbs -> do
+ buffers <- allBuffers
+ mapM_ (\buf -> do
+ ebuf <- getBuffer ( ibSourceView buf)
+ setStyle ebuf (case mbs of
+ (False,_) -> Nothing
+ (True,s) -> Just s)) buffers) --}
+ , mkField
+ (("Name", ParaString "Found Text Background") <<< defaultParams)
+ (PP.text . show)
+ colorParser
+ tepFoundBackground
+ (\ b a -> a{tepFoundBackground = b})
+ colorEditor
+ (\c -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ forM_ buffers $ \buf -> do
+ ebuf <- getBuffer ( ibSourceView buf)
+ tagTable <- getTagTable ebuf
+ mbTag <- lookupTag tagTable "found"
+ case mbTag of
+ Just tag -> background tag (fromGtkColor c)
+ Nothing -> return ())
+ , mkField
+ (("Name", ParaString "Execution Context Text Background") <<< defaultParams)
+ (PP.text . show)
+ colorParser
+ tepContextBackground
+ (\ b a -> a{tepContextBackground = b})
+ colorEditor
+ (\c -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ forM_ buffers $ \buf -> do
+ ebuf <- getBuffer ( ibSourceView buf)
+ tagTable <- getTagTable ebuf
+ -- TODO find and set the tag background
+ return ())
+ , mkField
+ (("Name", ParaString "Breakpoint Text Background") <<< defaultParams)
+ (PP.text . show)
+ colorParser
+ tepBreakpointBackground
+ (\ b a -> a{tepBreakpointBackground = b})
+ colorEditor
+ (\c -> do
+ buffers :: [IDEBuffer alpha] <- allBuffers
+ forM_ buffers $ \buf -> do
+ ebuf <- getBuffer ( ibSourceView buf)
+ tagTable <- getTagTable ebuf
+ -- TODO find and set the tag background
+ return ())
+ , mkField
+ (("Name", ParaString "Automatically load modified files modified outside of Leksah") <<< defaultParams)
+ (PP.text . show)
+ boolParser
+ tepAutoLoad
+ (\b a -> a{tepAutoLoad = b})
+ boolEditor
+ (\i -> return ())]
+
+colorParser :: CharParser () Gtk.Color
+colorParser = do
+ string "Color"
+ whiteSpace
+ r <- integer
+ whiteSpace
+ g <- integer
+ whiteSpace
+ b <- integer
+ return $ Gtk.Color (fromIntegral r) (fromIntegral g) (fromIntegral b)
+
+lexer :: P.TokenParser st
+lexer = P.makeTokenParser prefsStyle
+
+integer = P.integer lexer
+
+{--
+styleEditor :: Editor (Bool, String)
+styleEditor p n = do
+ styleManager <- sourceStyleSchemeManagerNew
+ ids <- sourceStyleSchemeManagerGetSchemeIds styleManager
+ disableEditor (comboSelectionEditor ids id, p) True "Select a special style?" p n
+--}
Please sign in to comment.
Something went wrong with that request. Please try again.