{-# LINE 2 "./Graphics/UI/Gtk/SourceView/SourceUndoManager.chs" #-}
-- -*-haskell-*-
-- GIMP Toolkit (GTK) SourceUndoManager
--
-- Author : Andy Stewart
--
-- Created: 08 Aug 2010
--
-- Copyright (C) 2010 Andy Stewart
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- |
-- Maintainer : gtk2hs-users@lists.sourceforge.net
-- Stability : provisional
-- Portability : portable (depends on GHC)
--
module Graphics.UI.Gtk.SourceView.SourceUndoManager (
-- * Description
-- | The 'SourceUndoManager' interface can be implemented to provide custom undo management to a
-- 'SourceBuffer'. Use 'sourceBufferSetUndoManager' to install a custom undo manager for a
-- particular source buffer.
--
-- Use 'sourceUndoManagerCanUndoChanged' and 'sourceUndoManagerCanRedoChanged' when
-- respectively the undo state or redo state of the undo stack has changed.

-- * Types
    SourceUndoManager,
    SourceUndoManagerClass,

-- * Methods
    sourceUndoManagerCanUndo,
    sourceUndoManagerCanRedo,
    sourceUndoManagerUndo,
    sourceUndoManagerRedo,
    sourceUndoManagerBeginNotUndoableAction,
    sourceUndoManagerEndNotUndoableAction,

-- * Signals
    sourceUndoManagerCanRedoChanged,
    sourceUndoManagerCanUndoChanged,
) where

import Control.Monad (liftM)

import System.Glib.Attributes
import System.Glib.FFI
import System.Glib.Properties
import System.Glib.UTFString

import Graphics.UI.Gtk.SourceView.Signals
{-# LINE 60 "./Graphics/UI/Gtk/SourceView/SourceUndoManager.chs" #-}
import Graphics.UI.Gtk.SourceView.Types
{-# LINE 61 "./Graphics/UI/Gtk/SourceView/SourceUndoManager.chs" #-}


{-# LINE 63 "./Graphics/UI/Gtk/SourceView/SourceUndoManager.chs" #-}

-- | Get whether there are undo operations available.
sourceUndoManagerCanUndo :: SourceUndoManagerClass sum => sum
                         -> IO Bool -- ^ returns 'True' if there are undo operations available, 'False' otherwise
sourceUndoManagerCanUndo sm =
  liftM toBool $
  (\(SourceUndoManager arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_undo_manager_can_undo argPtr1) (toSourceUndoManager sm)

-- | Get whether there are redo operations available.
sourceUndoManagerCanRedo :: SourceUndoManagerClass sum => sum
                         -> IO Bool -- ^ returns 'True' if there are redo operations available, 'False' otherwise
sourceUndoManagerCanRedo sm =
  liftM toBool $
  (\(SourceUndoManager arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_undo_manager_can_redo argPtr1) (toSourceUndoManager sm)

-- | Perform a single undo. Calling this function when there are no undo operations available is an
-- error. Use @gtkSourceUndoManagerCanUndo@ to find out if there are undo operations available.
sourceUndoManagerUndo :: SourceUndoManagerClass sum => sum -> IO ()
sourceUndoManagerUndo sm =
  (\(SourceUndoManager arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_undo_manager_undo argPtr1) (toSourceUndoManager sm)

-- | Perform a single redo. Calling this function when there are no redo operations available is an
-- error. Use @gtkSourceUndoManagerCanRedo@ to find out if there are redo operations available.
sourceUndoManagerRedo :: SourceUndoManagerClass sum => sum -> IO ()
sourceUndoManagerRedo sm =
  (\(SourceUndoManager arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_undo_manager_redo argPtr1) (toSourceUndoManager sm)

-- | Begin a not undoable action on the buffer. All changes between this call and the call to
-- @gtkSourceUndoManagerEndNotUndoableAction@ cannot be undone. This function should be
-- re-entrant.
sourceUndoManagerBeginNotUndoableAction :: SourceUndoManagerClass sum => sum -> IO ()
sourceUndoManagerBeginNotUndoableAction sm =
  (\(SourceUndoManager arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_undo_manager_begin_not_undoable_action argPtr1) (toSourceUndoManager sm)

-- | Ends a not undoable action on the buffer.
sourceUndoManagerEndNotUndoableAction :: SourceUndoManagerClass sum => sum -> IO ()
sourceUndoManagerEndNotUndoableAction sm =
  (\(SourceUndoManager arg1) -> withForeignPtr arg1 $ \argPtr1 ->gtk_source_undo_manager_end_not_undoable_action argPtr1) (toSourceUndoManager sm)

-- | Emitted when the ability to redo has changed.
--
sourceUndoManagerCanRedoChanged :: SourceUndoManagerClass sum => Signal sum (IO ())
sourceUndoManagerCanRedoChanged = Signal $ connect_NONE__NONE "can-redo-changed"

-- | Emitted when the ability to undo has changed.
--
sourceUndoManagerCanUndoChanged :: SourceUndoManagerClass sum => Signal sum (IO ())
sourceUndoManagerCanUndoChanged = Signal $ connect_NONE__NONE "can-undo-changed"

foreign import ccall safe "gtk_source_undo_manager_can_undo"
  gtk_source_undo_manager_can_undo :: ((Ptr SourceUndoManager) -> (IO CInt))

foreign import ccall safe "gtk_source_undo_manager_can_redo"
  gtk_source_undo_manager_can_redo :: ((Ptr SourceUndoManager) -> (IO CInt))

foreign import ccall safe "gtk_source_undo_manager_undo"
  gtk_source_undo_manager_undo :: ((Ptr SourceUndoManager) -> (IO ()))

foreign import ccall safe "gtk_source_undo_manager_redo"
  gtk_source_undo_manager_redo :: ((Ptr SourceUndoManager) -> (IO ()))

foreign import ccall safe "gtk_source_undo_manager_begin_not_undoable_action"
  gtk_source_undo_manager_begin_not_undoable_action :: ((Ptr SourceUndoManager) -> (IO ()))

foreign import ccall safe "gtk_source_undo_manager_end_not_undoable_action"
  gtk_source_undo_manager_end_not_undoable_action :: ((Ptr SourceUndoManager) -> (IO ()))