]>
Commit | Line | Data |
---|---|---|
1f780e48 RD |
1 | #---------------------------------------------------------------------------- |
2 | # Name: MarkerService.py | |
3 | # Purpose: Adding and removing line markers in text for easy searching | |
4 | # | |
5 | # Author: Morgan Hua | |
6 | # | |
7 | # Created: 10/6/03 | |
8 | # CVS-ID: $Id$ | |
9 | # Copyright: (c) 2004-2005 ActiveGrid, Inc. | |
10 | # License: wxWindows License | |
11 | #---------------------------------------------------------------------------- | |
12 | ||
13 | import wx | |
14 | import wx.stc | |
15 | import wx.lib.docview | |
16 | import wx.lib.pydocview | |
17 | import STCTextEditor | |
18 | _ = wx.GetTranslation | |
19 | ||
20 | ||
21 | class MarkerService(wx.lib.pydocview.DocService): | |
22 | MARKERTOGGLE_ID = wx.NewId() | |
23 | MARKERDELALL_ID = wx.NewId() | |
24 | MARKERNEXT_ID = wx.NewId() | |
25 | MARKERPREV_ID = wx.NewId() | |
26 | ||
27 | ||
28 | def __init__(self): | |
29 | pass | |
30 | ||
31 | def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None): | |
32 | if document and document.GetDocumentTemplate().GetDocumentType() != STCTextEditor.TextDocument: | |
33 | return | |
34 | if not document and wx.GetApp().GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI: | |
35 | return | |
36 | ||
37 | editMenu = menuBar.GetMenu(menuBar.FindMenu(_("&Edit"))) | |
38 | editMenu.AppendSeparator() | |
39 | editMenu.Append(MarkerService.MARKERTOGGLE_ID, _("Toggle &Marker\tCtrl+M"), _("Toggles a jump marker to text line")) | |
40 | wx.EVT_MENU(frame, MarkerService.MARKERTOGGLE_ID, frame.ProcessEvent) | |
41 | wx.EVT_UPDATE_UI(frame, MarkerService.MARKERTOGGLE_ID, frame.ProcessUpdateUIEvent) | |
42 | editMenu.Append(MarkerService.MARKERDELALL_ID, _("Clear Markers"), _("Removes all jump markers from selected file")) | |
43 | wx.EVT_MENU(frame, MarkerService.MARKERDELALL_ID, frame.ProcessEvent) | |
44 | wx.EVT_UPDATE_UI(frame, MarkerService.MARKERDELALL_ID, frame.ProcessUpdateUIEvent) | |
45 | editMenu.Append(MarkerService.MARKERNEXT_ID, _("Marker Next\tF4"), _("Moves to next marker in selected file")) | |
46 | wx.EVT_MENU(frame, MarkerService.MARKERNEXT_ID, frame.ProcessEvent) | |
47 | wx.EVT_UPDATE_UI(frame, MarkerService.MARKERNEXT_ID, frame.ProcessUpdateUIEvent) | |
48 | editMenu.Append(MarkerService.MARKERPREV_ID, _("Marker Previous\tShift+F4"), _("Moves to previous marker in selected file")) | |
49 | wx.EVT_MENU(frame, MarkerService.MARKERPREV_ID, frame.ProcessEvent) | |
50 | wx.EVT_UPDATE_UI(frame, MarkerService.MARKERPREV_ID, frame.ProcessUpdateUIEvent) | |
51 | ||
52 | ||
53 | def ProcessEvent(self, event): | |
54 | id = event.GetId() | |
55 | if id == MarkerService.MARKERTOGGLE_ID: | |
56 | wx.GetApp().GetDocumentManager().GetCurrentView().MarkerToggle() | |
57 | return True | |
58 | elif id == MarkerService.MARKERDELALL_ID: | |
59 | wx.GetApp().GetDocumentManager().GetCurrentView().MarkerDeleteAll() | |
60 | return True | |
61 | elif id == MarkerService.MARKERNEXT_ID: | |
62 | wx.GetApp().GetDocumentManager().GetCurrentView().MarkerNext() | |
63 | return True | |
64 | elif id == MarkerService.MARKERPREV_ID: | |
65 | wx.GetApp().GetDocumentManager().GetCurrentView().MarkerPrevious() | |
66 | return True | |
67 | else: | |
68 | return False | |
69 | ||
70 | ||
71 | def ProcessUpdateUIEvent(self, event): | |
72 | id = event.GetId() | |
73 | if id == MarkerService.MARKERTOGGLE_ID: | |
74 | view = wx.GetApp().GetDocumentManager().GetCurrentView() | |
75 | event.Enable(hasattr(view, "MarkerToggle")) | |
76 | return True | |
77 | elif id == MarkerService.MARKERDELALL_ID: | |
78 | view = wx.GetApp().GetDocumentManager().GetCurrentView() | |
79 | event.Enable(hasattr(view, "MarkerDeleteAll") and view.GetMarkerCount()) | |
80 | return True | |
81 | elif id == MarkerService.MARKERNEXT_ID: | |
82 | view = wx.GetApp().GetDocumentManager().GetCurrentView() | |
83 | event.Enable(hasattr(view, "MarkerNext") and view.GetMarkerCount()) | |
84 | return True | |
85 | elif id == MarkerService.MARKERPREV_ID: | |
86 | view = wx.GetApp().GetDocumentManager().GetCurrentView() | |
87 | event.Enable(hasattr(view, "MarkerPrevious") and view.GetMarkerCount()) | |
88 | return True | |
89 | else: | |
90 | return False | |
91 |