Added a new-file command with standard new-file keyboard shortcut

This commit is contained in:
Christophe Kamphaus 2016-02-28 23:33:18 +01:00
parent 53de782d3c
commit faf6c57069

View File

@ -159,6 +159,7 @@ class MainWindow(wx.Frame):
def CreateMenus(self): def CreateMenus(self):
menuBar = wx.MenuBar() menuBar = wx.MenuBar()
self.CreateMenu(menuBar, '&File', [ self.CreateMenu(menuBar, '&File', [
(wx.ID_NEW, '&New\tCTRL-N', 'Create a new file', self.OnNew),
(wx.ID_OPEN, '&Open\tCTRL-O', 'Open a new file', self.OnOpen), (wx.ID_OPEN, '&Open\tCTRL-O', 'Open a new file', self.OnOpen),
(wx.ID_SAVE, '&Save\tCTRL-S', 'Save the current file', self.OnSave), (wx.ID_SAVE, '&Save\tCTRL-S', 'Save the current file', self.OnSave),
(wx.ID_SAVEAS, 'Save &As', 'Save the file under a different name', (wx.ID_SAVEAS, 'Save &As', 'Save the file under a different name',
@ -267,6 +268,14 @@ class MainWindow(wx.Frame):
return True return True
return False return False
def OnNew(self, event):
if self.ConfirmLoss("Open"):
self.editor.SetText('')
self.filename = ''
self.editor.SetOpened()
return True
return False
def OnSave(self, event): def OnSave(self, event):
if self.filename=='': if self.filename=='':
return self.OnSaveAs(event) return self.OnSaveAs(event)