Commit 6c638b67 authored by Kurt B. Kaiser's avatar Kurt B. Kaiser

Bruce Sherwood RFE/Patch

SF 661318

Adds autosave capability to IDLE and IDLE configuration dialog.

User can Run/F5 without explicit save dialog.

The default is to require the user to confirm the save.

M ScriptBinding.py
M config-main.def
M configDialog.py
parent 4ee6eef2
...@@ -24,6 +24,8 @@ import tokenize ...@@ -24,6 +24,8 @@ import tokenize
import tkMessageBox import tkMessageBox
import PyShell import PyShell
from configHandler import idleConf
IDENTCHARS = string.ascii_letters + string.digits + "_" IDENTCHARS = string.ascii_letters + string.digits + "_"
indent_message = """Error: Inconsistent indentation detected! indent_message = """Error: Inconsistent indentation detected!
...@@ -144,26 +146,36 @@ class ScriptBinding: ...@@ -144,26 +146,36 @@ class ScriptBinding:
The debugger requires a source file. Make sure there is one, and that The debugger requires a source file. Make sure there is one, and that
the current version of the source buffer has been saved. If the user the current version of the source buffer has been saved. If the user
declines to save or cancels the Save As dialog, return None. declines to save or cancels the Save As dialog, return None.
If the user has configured IDLE for Autosave, the file will be
silently saved if it already exists and is dirty.
""" """
filename = self.editwin.io.filename
if not self.editwin.get_saved(): if not self.editwin.get_saved():
msg = """Source Must Be Saved autosave = idleConf.GetOption('main', 'General',
OK to Save?""" 'autosave', type='bool')
mb = tkMessageBox.Message( if autosave and filename:
title="Save Before Run or Check", self.editwin.io.save(None)
else:
reply = self.ask_save_dialog()
self.editwin.text.focus_set()
if reply == "ok":
self.editwin.io.save(None)
filename = self.editwin.io.filename
else:
filename = None
return filename
def ask_save_dialog(self):
msg = "Source Must Be Saved\n" + 5*' ' + "OK to Save?"
mb = tkMessageBox.Message(title="Save Before Run or Check",
message=msg, message=msg,
icon=tkMessageBox.QUESTION, icon=tkMessageBox.QUESTION,
type=tkMessageBox.OKCANCEL, type=tkMessageBox.OKCANCEL,
default=tkMessageBox.OK, default=tkMessageBox.OK,
master=self.editwin.text) master=self.editwin.text)
reply = mb.show() return mb.show()
if reply == "ok":
self.editwin.io.save(None)
else:
return None
# filename is None if file doesn't exist
filename = self.editwin.io.filename
self.editwin.text.focus_set()
return filename
def errorbox(self, title, message): def errorbox(self, title, message):
# XXX This should really be a function of EditorWindow... # XXX This should really be a function of EditorWindow...
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
[General] [General]
editor-on-startup= 0 editor-on-startup= 0
autosave= 0
print-command-posix=lpr %s print-command-posix=lpr %s
print-command-win=start /min notepad /p %s print-command-win=start /min notepad /p %s
...@@ -49,7 +50,7 @@ height= 30 ...@@ -49,7 +50,7 @@ height= 30
font= courier font= courier
font-size= 12 font-size= 12
font-bold= 0 font-bold= 0
encoding=none encoding= none
[Indent] [Indent]
use-spaces= 1 use-spaces= 1
......
...@@ -334,6 +334,7 @@ class ConfigDialog(Toplevel): ...@@ -334,6 +334,7 @@ class ConfigDialog(Toplevel):
self.winWidth=StringVar(self) self.winWidth=StringVar(self)
self.winHeight=StringVar(self) self.winHeight=StringVar(self)
self.startupEdit=IntVar(self) self.startupEdit=IntVar(self)
self.autoSave=IntVar(self)
self.encoding=StringVar(self) self.encoding=StringVar(self)
self.userHelpBrowser=BooleanVar(self) self.userHelpBrowser=BooleanVar(self)
self.helpBrowser=StringVar(self) self.helpBrowser=StringVar(self)
...@@ -342,16 +343,24 @@ class ConfigDialog(Toplevel): ...@@ -342,16 +343,24 @@ class ConfigDialog(Toplevel):
frame=self.tabPages.pages['General']['page'] frame=self.tabPages.pages['General']['page']
#body section frames #body section frames
frameRun=Frame(frame,borderwidth=2,relief=GROOVE) frameRun=Frame(frame,borderwidth=2,relief=GROOVE)
frameSave=Frame(frame,borderwidth=2,relief=GROOVE)
frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE) frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE)
frameEncoding=Frame(frame,borderwidth=2,relief=GROOVE) frameEncoding=Frame(frame,borderwidth=2,relief=GROOVE)
frameHelp=Frame(frame,borderwidth=2,relief=GROOVE) frameHelp=Frame(frame,borderwidth=2,relief=GROOVE)
#frameRun #frameRun
labelRunTitle=Label(frameRun,text='Startup Preferences') labelRunTitle=Label(frameRun,text='Startup Preferences')
labelRunChoiceTitle=Label(frameRun,text='On Startup : ') labelRunChoiceTitle=Label(frameRun,text='At Startup')
radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit, radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit,
value=1,command=self.SetKeysType,text="Open Edit Window") value=1,command=self.SetKeysType,text="Open Edit Window")
radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit, radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit,
value=0,command=self.SetKeysType,text='Open Shell Window') value=0,command=self.SetKeysType,text='Open Shell Window')
#frameSave
labelSaveTitle=Label(frameSave,text='Autosave Preference')
labelRunSaveTitle=Label(frameSave,text='At Start of Run (F5) ')
radioSaveAsk=Radiobutton(frameSave,variable=self.autoSave,
value=0,command=self.SetKeysType,text="Prompt to Save")
radioSaveAuto=Radiobutton(frameSave,variable=self.autoSave,
value=1,command=self.SetKeysType,text='No Prompt')
#frameWinSize #frameWinSize
labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+ labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+
' (in characters)') ' (in characters)')
...@@ -370,7 +379,7 @@ class ConfigDialog(Toplevel): ...@@ -370,7 +379,7 @@ class ConfigDialog(Toplevel):
radioEncNone=Radiobutton(frameEncoding,variable=self.encoding, radioEncNone=Radiobutton(frameEncoding,variable=self.encoding,
value="none",text="None") value="none",text="None")
#frameHelp #frameHelp
labelHelpTitle=Label(frameHelp,text='Help Options') ##labelHelpTitle=Label(frameHelp,text='Help Options')
frameHelpList=Frame(frameHelp) frameHelpList=Frame(frameHelp)
frameHelpListButtons=Frame(frameHelpList) frameHelpListButtons=Frame(frameHelpList)
labelHelpListTitle=Label(frameHelpList,text='Additional Help Sources:') labelHelpListTitle=Label(frameHelpList,text='Additional Help Sources:')
...@@ -396,14 +405,20 @@ class ConfigDialog(Toplevel): ...@@ -396,14 +405,20 @@ class ConfigDialog(Toplevel):
#widget packing #widget packing
#body #body
frameRun.pack(side=TOP,padx=5,pady=5,fill=X) frameRun.pack(side=TOP,padx=5,pady=5,fill=X)
frameSave.pack(side=TOP,padx=5,pady=5,fill=X)
frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X) frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X)
frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X) frameEncoding.pack(side=TOP,padx=5,pady=5,fill=X)
frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
#frameRun #frameRun
labelRunTitle.pack(side=TOP,anchor=W,padx=5,pady=5) labelRunTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
radioStartupEdit.pack(side=LEFT,anchor=W,padx=5,pady=5) radioStartupShell.pack(side=RIGHT,anchor=W,padx=5,pady=5)
radioStartupShell.pack(side=LEFT,anchor=W,padx=5,pady=5) radioStartupEdit.pack(side=RIGHT,anchor=W,padx=5,pady=5)
#frameSave
labelSaveTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
labelRunSaveTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
radioSaveAuto.pack(side=RIGHT,anchor=W,padx=5,pady=5)
radioSaveAsk.pack(side=RIGHT,anchor=W,padx=5,pady=5)
#frameWinSize #frameWinSize
labelWinSizeTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) labelWinSizeTitle.pack(side=LEFT,anchor=W,padx=5,pady=5)
entryWinHeight.pack(side=RIGHT,anchor=E,padx=10,pady=5) entryWinHeight.pack(side=RIGHT,anchor=E,padx=10,pady=5)
...@@ -416,7 +431,7 @@ class ConfigDialog(Toplevel): ...@@ -416,7 +431,7 @@ class ConfigDialog(Toplevel):
radioEncUTF8.pack(side=RIGHT,anchor=E,pady=5) radioEncUTF8.pack(side=RIGHT,anchor=E,pady=5)
radioEncLocale.pack(side=RIGHT,anchor=E,pady=5) radioEncLocale.pack(side=RIGHT,anchor=E,pady=5)
#frameHelp #frameHelp
labelHelpTitle.pack(side=TOP,anchor=W,padx=5,pady=5) ##labelHelpTitle.pack(side=TOP,anchor=W,padx=5,pady=5)
frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y) frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y)
frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH)
labelHelpListTitle.pack(side=TOP,anchor=W) labelHelpListTitle.pack(side=TOP,anchor=W)
...@@ -448,6 +463,7 @@ class ConfigDialog(Toplevel): ...@@ -448,6 +463,7 @@ class ConfigDialog(Toplevel):
self.winWidth.trace_variable('w',self.VarChanged_winWidth) self.winWidth.trace_variable('w',self.VarChanged_winWidth)
self.winHeight.trace_variable('w',self.VarChanged_winHeight) self.winHeight.trace_variable('w',self.VarChanged_winHeight)
self.startupEdit.trace_variable('w',self.VarChanged_startupEdit) self.startupEdit.trace_variable('w',self.VarChanged_startupEdit)
self.autoSave.trace_variable('w',self.VarChanged_autoSave)
self.encoding.trace_variable('w',self.VarChanged_encoding) self.encoding.trace_variable('w',self.VarChanged_encoding)
def VarChanged_fontSize(self,*params): def VarChanged_fontSize(self,*params):
...@@ -542,6 +558,10 @@ class ConfigDialog(Toplevel): ...@@ -542,6 +558,10 @@ class ConfigDialog(Toplevel):
value=self.startupEdit.get() value=self.startupEdit.get()
self.AddChangedItem('main','General','editor-on-startup',value) self.AddChangedItem('main','General','editor-on-startup',value)
def VarChanged_autoSave(self,*params):
value=self.autoSave.get()
self.AddChangedItem('main','General','autosave',value)
def VarChanged_encoding(self,*params): def VarChanged_encoding(self,*params):
value=self.encoding.get() value=self.encoding.get()
self.AddChangedItem('main','EditorWindow','encoding',value) self.AddChangedItem('main','EditorWindow','encoding',value)
...@@ -1038,11 +1058,15 @@ class ConfigDialog(Toplevel): ...@@ -1038,11 +1058,15 @@ class ConfigDialog(Toplevel):
#startup state #startup state
self.startupEdit.set(idleConf.GetOption('main','General', self.startupEdit.set(idleConf.GetOption('main','General',
'editor-on-startup',default=1,type='bool')) 'editor-on-startup',default=1,type='bool'))
#autosave state
self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave',
default=0, type='bool'))
#initial window size #initial window size
self.winWidth.set(idleConf.GetOption('main','EditorWindow','width')) self.winWidth.set(idleConf.GetOption('main','EditorWindow','width'))
self.winHeight.set(idleConf.GetOption('main','EditorWindow','height')) self.winHeight.set(idleConf.GetOption('main','EditorWindow','height'))
# default source encoding # default source encoding
self.encoding.set(idleConf.GetOption('main','EditorWindow','encoding')) self.encoding.set(idleConf.GetOption('main', 'EditorWindow',
'encoding', default='none'))
# additional help sources # additional help sources
self.userHelpList = idleConf.GetAllExtraHelpSourcesList() self.userHelpList = idleConf.GetAllExtraHelpSourcesList()
for helpItem in self.userHelpList: for helpItem in self.userHelpList:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment