#------------------------------------
#   Programmer:  Antonio Barbosa
#   E-mail:      ab@jn.pt
#   Note:        Initial Release 19 Fev 2006
#

#Plugin
#ShowLineinBrowser

#This plugin is only a Test: shows current line

import wx
import drScrolledMessageDialog
from drSourceBrowser import drSourceBrowserPanel

def OnAbout(DrFrame):
    Version = "0.0.1"
    NameAndVersion = "ShowLineinBrowser:\n\nVersion: " + Version + "\n"
    AboutString = NameAndVersion + "By Antonio Barbosa"
    drScrolledMessageDialog.ShowMessage(DrFrame, AboutString, "About")

def OnHelp(DrFrame):
    HelpString = "Shows current edit line in the browser tree"
    drScrolledMessageDialog.ShowMessage(DrFrame, HelpString, "Help")

def Plugin(DrFrame):

    def OnShowLineinBrowser(event):
        if not DrFrame.SourceBrowser:
            return
        browsepanel = DrFrame.SourceBrowser
        browsetree = browsepanel.classtree
        currentline = DrFrame.txtDocument.GetCurrentLine()
        currentpos = DrFrame.txtDocument.PositionFromLine(currentline)
        i = -1
        for pos in browsepanel.ItemsPos:
            i += 1
            if pos == currentpos:
                break
            elif pos > currentpos:
                i -= 1
                break
        if i < 0:
            i = 0
        treeindex=browsepanel.ItemsIndex[i]
        browsetree.SelectItem(treeindex, True)



    DrFrame.AddPluginShortcutFunction("ShowLineinBrowser", "Show Line in Browser", OnShowLineinBrowser)
    DrFrame.AddPluginPopUpMenuFunction("ShowLineinBrowser", "Show Line in Browser", OnShowLineinBrowser)

    DrFrame.LoadPluginShortcuts('ShowLineinBrowser')

    ID_MYLINE = DrFrame.GetNewId()
    DrFrame.viewmenu.Append(ID_MYLINE, DrFrame.GetPluginMenuLabel("ShowLineinBrowser", "Show Line in Browser", "Show Line in Browser"))
    DrFrame.Bind(wx.EVT_MENU, OnShowLineinBrowser, id=ID_MYLINE)
