#   Programmer:  Franz Steinhaeusler
#   E-mail:      francescoa@users.sourceforge.net
#   Note:        Initial Release 18/7/2004
#
#   Copyright 2004-2005 Franz Steinhaeusler
#
#   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

#Version: 0.0.1:
# - no global variables, new DrFrame member variables in form of DrFrame.<PluginNme>_var

#Version: 0.0.2:
# - Added Popup function

#Version: 0.0.3, 07.08.2004:
# - quickmarker for every document with dictionary, where the keyvalue is the filename

#Version: 0.0.4, 25.09.2004:
# - rewritten, see changelog.txt

#Version: 0.0.5, 20.10.2004:
# - see changelog.txt

#Plugin
#QuickMarker

#This plugin allows to quick set and retrieve a textpostion.

import wx
import drScrolledMessageDialog

def OnAbout(DrFrame):
    QuickMarker_Verision = "0.0.5"
    NameAndVersion = "QuickMarker:\n\nVersion: " + QuickMarker_Verision + "\n"
    AboutString = NameAndVersion + "By Franz Steinhaeusler\n\nReleased under the GPL."
    drScrolledMessageDialog.ShowMessage(DrFrame, AboutString, "About")

def OnHelp(DrFrame):
    drScrolledMessageDialog.ShowMessage(DrFrame, "Set and retrieve position in text", "Help")

def Plugin(DrFrame):
    DrFrame.QuickMarker_BOOKMARKMASK = 2
    DrFrame.QuickMarker_BOOKMARKNUMBER = 1

    def OnSetQuickMarker (event):
        DrFrame.txtDocument.MarkerDefine(DrFrame.QuickMarker_BOOKMARKNUMBER, wx.stc.STC_MARK_CIRCLE, 'black', 'white')
        oldLineNo = DrFrame.txtDocument.MarkerNext(1, DrFrame.QuickMarker_BOOKMARKMASK)
        DrFrame.txtDocument.MarkerDelete(oldLineNo, DrFrame.QuickMarker_BOOKMARKNUMBER)
        newLineNo = DrFrame.txtDocument.GetCurrentLine()
        DrFrame.txtDocument.MarkerAdd(newLineNo, DrFrame.QuickMarker_BOOKMARKNUMBER)
        DrFrame.SetStatusText("QuickMarker: Set Line %s"% str(newLineNo + 1), 2)

    def OnGetQuickMarker (event):
        newLineNo = DrFrame.txtDocument.MarkerNext(0, DrFrame.QuickMarker_BOOKMARKMASK)
        if newLineNo != -1:
            DrFrame.txtDocument.GotoLine(newLineNo)
            DrFrame.txtDocument.EnsureVisible(DrFrame.txtDocument.GetCurrentLine())
            DrFrame.txtDocument.EnsureCaretVisible()
            DrFrame.SetStatusText("QuickMarker: Get Line %s"% str(newLineNo + 1), 2)
        else:
            DrFrame.SetStatusText("No QuickMarker set", 2)


    ID_SETQUICKMARKER = DrFrame.GetNewId()
    ID_GETQUICKMARKER = DrFrame.GetNewId()

    DrFrame.Bind(wx.EVT_MENU, OnGetQuickMarker, id=ID_GETQUICKMARKER)
    DrFrame.Bind(wx.EVT_MENU, OnSetQuickMarker, id=ID_SETQUICKMARKER)

    DrFrame.AddPluginShortcutFunction("QuickMarker", "Get Quickmarker", OnGetQuickMarker)
    DrFrame.AddPluginShortcutFunction("QuickMarker", "Set Quickmarker", OnSetQuickMarker)

    DrFrame.AddPluginPopUpMenuFunction("QuickMarker", "Get Quickmarker", OnGetQuickMarker)
    DrFrame.AddPluginPopUpMenuFunction("QuickMarker", "Set Quickmarker", OnSetQuickMarker)

    DrFrame.LoadPluginShortcuts('QuickMarker')
    quickmarkermenu = wx.Menu()
    quickmarkermenu.Append(ID_GETQUICKMARKER, DrFrame.GetPluginMenuLabel('QuickMarker', 'Get Quickmarker', 'Get Quickmarker'))
    quickmarkermenu.Append(ID_SETQUICKMARKER, DrFrame.GetPluginMenuLabel('QuickMarker', 'Set Quickmarker', 'Set Quickmarker'))

    DrFrame.viewmenu.AppendSeparator()
    DrFrame.viewmenu.AppendMenu(DrFrame.GetNewId(), "Quick Marker", quickmarkermenu)


