#   Programmer: Daniel Pozmanter
#   E-mail:     drpython@bluebottle.com
#   Note:       You must reply to the verification e-mail to get through.
#
#   Copyright 2003-2004 Daniel Pozmanter
#
#   Distributed under the terms of the GPL (GNU Public License)
#
#    DrPython is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#Plugin
#Chop Menu

import wx
import wx.lib.dialogs

def OnAbout(DrFrame):
    Version = "Shell Menu: Version: 0.0.1\n"
    AboutString = Version + "By Daniel Pozmanter\n\nReleased under the GPL."
    d = wx.lib.dialogs.ScrolledMessageDialog(DrFrame, AboutString, "About")
    d.ShowModal()
    d.Destroy()

def Plugin(DrFrame):
    def OnChopBeginning(event):
        if DrFrame.txtPrompt.GetSTCFocus():
            stc = DrFrame.txtPrompt
            isprompt = True
        else:
            stc = DrFrame.txtDocument
            isprompt = False
        curline = stc.GetCurrentLine()
        if isprompt:
            targetStart = DrFrame.txtPrompt.GetEditPoint()
        else:
            if curline > 1:
                targetStart = stc.GetLineEndPosition(curline - 1)+len(stc.GetEndOfLineCharacter())
            else:
                targetStart = 0

        stc.SetTargetStart(targetStart)
        stc.SetTargetEnd(stc.GetCurrentPos())
        stc.ReplaceTarget("")

    def OnChopEnd(event):
        if DrFrame.txtPrompt.GetSTCFocus():
            stc = DrFrame.txtPrompt
        else:
            stc = DrFrame.txtDocument
        curline = stc.GetCurrentLine()
        stc.SetTargetEnd(stc.GetLineEndPosition(curline))
        stc.SetTargetStart(stc.GetCurrentPos())
        stc.ReplaceTarget("")

    ID_CHOP_BEGINNING = DrFrame.GetNewId()
    ID_CHOP_END = DrFrame.GetNewId()


    chopmenu = wx.Menu()
    chopmenu.Append(ID_CHOP_BEGINNING, "Beginning")
    chopmenu.Append(ID_CHOP_END, "End")

    DrFrame.editmenu.AppendSeparator()
    DrFrame.editmenu.AppendMenu(DrFrame.GetNewId(), "Chop", chopmenu)

    DrFrame.Bind(wx.EVT_MENU, OnChopBeginning, id=ID_CHOP_BEGINNING)
    DrFrame.Bind(wx.EVT_MENU, OnChopEnd, id=ID_CHOP_END)

    DrFrame.AddPluginShortcutFunction("ChopMenu", "OnChopBeginning", OnChopBeginning)
    DrFrame.AddPluginShortcutFunction("ChopMenu", "OnChopEnd", OnChopEnd)
    DrFrame.LoadPluginShortcuts('ChopMenu')
