[go: up one dir, main page]

Menu

[r18]: / gEcrit / bin / Menu.py  Maximize  Restore  History

Download this file

160 lines (132 with data), 6.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import os.path
from configClass import *
class MainMenu(wx.MenuBar):
def __init__(self, parent, id=wx.ID_ANY):
#creating application menu
self.parent = parent
menubar = wx.MenuBar()
self.recent_dict = {}
wx.MenuBar.__init__(self)
file = wx.Menu()
self.recent_files = wx.Menu()
edit = wx.Menu()
help = wx.Menu()
search = wx.Menu()
view = wx.Menu()
document = wx.Menu()
try: #in case that recent files list is empty
self.last_recent = Config.GetOption("RecentFiles")[-1]
except: self.last_recent = ""
file.Append(500, '&New Tab\tCtrl+N', 'Open a new tab.')
file.Append(501, '&Open\tCtrl+O', 'Open a new document.')
file.Append(502, '&Save\tCtrl+S', 'Save the document.')
file.Append(503, 'Save As',
'Save the document under a different name.')
file.Append(506, "Save All",
"Saves all the open documents that have a path.")
file.Append(504, '&Print\tCtrl+P', 'Print the current document.')
file.Append(505, 'Close &Tab\tCtrl+W', 'Close the current tab.')
self.recent_submenu = wx.Menu()
self.GenerateRecentFiles()
file.AppendMenu(700,"Recent files\tShow the last opened files.",self.recent_submenu)
file.AppendSeparator()
quit = wx.MenuItem(file, 506, '&Quit\tCtrl+Q', 'Quit gEcrit.')
file.AppendItem(quit)
edit.Append(520, "&Undo\tCtrl+Z", "Cancel the last action.")
edit.Append(521, "&Redo\tCtrl+Y", "Bring back the last action.")
edit.AppendSeparator()
edit.Append(522, "&Cut\tCtrl+X", "Cut the selection.")
edit.Append(523, "C&opy\tCtrl+C", "Copy the selection.")
edit.Append(524, "P&aste\tCtrl+V", "Paste the selection.")
edit.AppendSeparator()
edit.Append(525, "Select All\tCtrl+A",
"Select all the document.")
edit.AppendSeparator()
edit.Append(529, "Indent\tCtrl+K", "Indent the selected lines.")
edit.Append(528, "Dedent\tCtrl+J", "Dedent the selected lines.")
edit.AppendSeparator()
edit.Append(526, "Insert date",
"Insert the date at cursor position.")
edit.AppendSeparator()
edit.Append(527, "Preferences\tCtrl+E",
"Open the configuration window.")
search.Append(530, "Find\tCtrl+F",
"Search text in the current document.")
search.Append(531, "Find and Replace\tCtrl+H",
"Search and replace text in the current document.")
view.Append(535, "Zoom In\tCtrl++",
"Increase the size of the text.")
view.Append(536, "Zoom Out\tCtrl+-",
"Decrease the size of the text.")
view.Append(537, "Normal Size\tCtrl+0",
"Set the size of the text to normal.")
view.AppendSeparator()
view.AppendCheckItem(538, "Line Numbers",
"Show/Hide line numbers.").Check(Config.GetOption("LineNumbers"))
view.AppendCheckItem(539, "Fold Marks", "Show/Hide fold marks.").Check(Config.GetOption("FoldMarks"))
view.AppendCheckItem(540, "White Space",
"Show/Hide white spaces.").Check(Config.GetOption("Whitespace"))
view.AppendCheckItem(541, "Indentation Guides",
"Show/Hide indentation guides.").Check(Config.GetOption("IndetationGuides"))
view.AppendCheckItem(546, "Edge Line",
"Show/Hide the edge line.").Check(Config.GetOption("EdgeLine"))
view.AppendCheckItem(547, "Syntax Highlight",
"Enable/Disable Syntax Highlight.").Check(Config.GetOption("SyntaxHighlight"))
view.AppendSeparator()
view.AppendCheckItem(542, "Python Shell",
"Stop/Start a python shell.").Check(Config.GetOption("PythonShell"))
view.AppendCheckItem(543, "OS Shell", "Stop/Start an OS shell.").Check(Config.GetOption("BashShell"))
view.AppendCheckItem(544, "Source Browser",
"Show/Hide the source browser.").Check(Config.GetOption("SourceBrowser"))
view.AppendCheckItem(555, "FileTree",
"Show/Hide the file browser.").Check(Config.GetOption("FileTree"))
view.AppendCheckItem(545, "Statusbar", "Show/Hide statusbar.").Check(Config.GetOption("StatusBar"))
document.Append(549, "Send to Pastebin\tCtrl+I",
"Submit the current document to pastebin.com")
document.Append(548, "Check for errors\tCtrl+B",
"Check the current document for errors.(python only)")
help.Append(550, "About", "Open the about window.")
self.Append(file, '&File')
self.Append(edit, '&Edit')
self.Append(search, "&Search")
self.Append(view, "&View")
self.Append(document, "&Document")
self.Append(help, '&Help')
def NewTabHelper(self,event):
self.parent.NewTab(0,os.path.split(self.recent_dict[event.GetId()])[-1],
self.recent_dict[event.GetId()])
self.last_recent = self.recent_dict[event.GetId()]
def ClearRecentFiles(self):
#deleting items from menu
items = self.recent_submenu.GetMenuItems()
for i in items:
self.recent_submenu.DeleteItem(i)
def GenerateRecentFiles(self):
#generating new items
st_id = 701
last_nm = ""
#cleaning it first (must have less than 10 elements)
lst = Config.GetOption("RecentFiles")
if len(lst) >10:
while len(lst) > 10:
lst.remove(lst[0])
Config.ChangeOption("RecentFiles",lst)
lst = Config.GetOption("RecentFiles") # refreshing list
# creating recent file menu list
for i in lst:
if last_nm != i:
self.recent_submenu.Append(st_id,i)
st_id+=1
last_nm = i
#binding events
st_id = 701
items = self.recent_submenu.GetMenuItems()
for item in items:
self.parent.Bind(wx.EVT_MENU, self.NewTabHelper,id=item.GetId())
self.recent_dict[item.GetId()] = item.GetLabel()
def UpdateRecentFiles(self):
self.ClearRecentFiles()
self.GenerateRecentFiles()