Merge lp://qastaging/~edgar-b-dsouza/acire/save_snippet_as into lp://qastaging/acire

Proposed by Ed S
Status: Merged
Merged at revision: not available
Proposed branch: lp://qastaging/~edgar-b-dsouza/acire/save_snippet_as
Merge into: lp://qastaging/acire
Diff against target: 124 lines (+82/-0)
2 files modified
bin/acire (+62/-0)
data/ui/AcireWindow.ui (+20/-0)
To merge this branch: bzr merge lp://qastaging/~edgar-b-dsouza/acire/save_snippet_as
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+18824@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Ed S (edgar-b-dsouza) wrote :

Changes:
- Implemented Save As button (shortcut Ctrl+S), as per Bug #514124, with gtk.FileChooserDialog; default folder is user home folder, filename is basename of snippet's original filename.
- Implemented copy_snippet() handler for Copy button (though gtksourceview editor already provides copy functionality, the button is single-step vs. Select All+Copy in the editor)
- Added shortcut Ctrl+C for Copy button. Enables snippet copying when editor does not have focus.
- Added shortcut F5 for Execute button. Focus can remain in the editor widget, enables edit-run-fix-rerun with only keyboard.

Please review.

Thanks,
Ed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/acire'
--- bin/acire 2010-02-07 11:05:09 +0000
+++ bin/acire 2010-02-08 06:21:15 +0000
@@ -26,6 +26,13 @@
26import gnome.vfs26import gnome.vfs
27import pango27import pango
28import tempfile #Used in run_snippet to run user-modded snippet28import tempfile #Used in run_snippet to run user-modded snippet
29###Needed to check for GTK version, gtk.FileChooserDialog available, see save_snippet()
30import pygtk
31pygtk.require('2.0')
32if gtk.pygtk_version < (2,3,90):
33 print "PyGtk ver. 2.3.90 or later required for FileChooserDialog, to save snippets."
34###/Needed to check for GTK version
35
2936
30# Check if we are working in the source tree or from the installed 37# Check if we are working in the source tree or from the installed
31# package and mangle the python path accordingly38# package and mangle the python path accordingly
@@ -249,6 +256,61 @@
249 #For now, leaving the file(s) there; need ideas for cleanup - on app shutdown?256 #For now, leaving the file(s) there; need ideas for cleanup - on app shutdown?
250 ###os.unlink(tmp_sn_filename)257 ###os.unlink(tmp_sn_filename)
251 258
259 def save_snippet(self, widget, data=None):
260 if not self.current_filename:
261 md = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_INFO,
262 gtk.BUTTONS_CLOSE, "Please choose a snippet first.")
263 md.run()
264 md.destroy()
265 return
266 if gtk.pygtk_version < (2,3,90):
267 md = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR,
268 gtk.BUTTONS_CLOSE, "Sorry, PyGTK must be at least version 2.4 to display the Save As dialog!")
269 md.run()
270 md.destroy()
271 return
272
273 dialog = gtk.FileChooserDialog("Save Snippet As...",
274 None,
275 gtk.FILE_CHOOSER_ACTION_SAVE,
276 (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
277 gtk.STOCK_SAVE_AS, gtk.RESPONSE_OK))
278 dialog.set_default_response(gtk.RESPONSE_OK)
279
280 filter = gtk.FileFilter()
281 filter.set_name("All files")
282 filter.add_pattern("*")
283 dialog.add_filter(filter)
284
285 filter = gtk.FileFilter()
286 filter.set_name("Python scripts")
287 filter.add_mime_type("application/x-python")
288 filter.add_mime_type("text/plain")
289 filter.add_mime_type("application/octet-stream")
290 filter.add_pattern("*.py")
291 dialog.add_filter(filter)
292
293 if os.getenv("HOME"):
294 dialog.set_current_folder(os.getenv("HOME"))
295 dialog.set_current_name(os.path.basename(self.current_filename))
296 dialog.set_do_overwrite_confirmation(True)
297
298 response = dialog.run()
299 if response == gtk.RESPONSE_OK:
300 saveas_filename = dialog.get_filename()
301 saveas_file = open(saveas_filename, 'w', False)
302 e = self.editor_buffer
303 saveas_file.write(e.get_text(e.get_start_iter(), e.get_end_iter()))
304 saveas_file.close()
305 dialog.destroy()
306
307 def copy_snippet(self, widget, data=None):
308 clpb = gtk.Clipboard()
309 #self.editor_buffer.copy_clipboard(clpb)
310 e = self.editor_buffer
311 textdata = e.get_text(e.get_start_iter(), e.get_end_iter())
312 clpb.set_text(textdata, len=-1)
313
252 def get_snippets_file_list(self):314 def get_snippets_file_list(self):
253 """Read in the snippets directory and put all Python files into a list."""315 """Read in the snippets directory and put all Python files into a list."""
254316
255317
=== modified file 'data/ui/AcireWindow.ui'
--- data/ui/AcireWindow.ui 2010-02-05 06:57:45 +0000
+++ data/ui/AcireWindow.ui 2010-02-08 06:21:15 +0000
@@ -206,6 +206,7 @@
206 <property name="can_focus">True</property>206 <property name="can_focus">True</property>
207 <property name="receives_default">True</property>207 <property name="receives_default">True</property>
208 <property name="use_stock">True</property>208 <property name="use_stock">True</property>
209 <accelerator key="F5" signal="clicked"/>
209 <signal name="clicked" handler="run_snippet"/>210 <signal name="clicked" handler="run_snippet"/>
210 </object>211 </object>
211 <packing>212 <packing>
@@ -221,6 +222,8 @@
221 <property name="can_focus">True</property>222 <property name="can_focus">True</property>
222 <property name="receives_default">True</property>223 <property name="receives_default">True</property>
223 <property name="use_stock">True</property>224 <property name="use_stock">True</property>
225 <accelerator key="c" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
226 <signal name="clicked" handler="copy_snippet"/>
224 </object>227 </object>
225 <packing>228 <packing>
226 <property name="expand">False</property>229 <property name="expand">False</property>
@@ -228,6 +231,23 @@
228 <property name="position">1</property>231 <property name="position">1</property>
229 </packing>232 </packing>
230 </child>233 </child>
234 <child>
235 <object class="GtkButton" id="saveas_button">
236 <property name="label">gtk-save-as</property>
237 <property name="visible">True</property>
238 <property name="can_focus">True</property>
239 <property name="receives_default">True</property>
240 <property name="use_stock">True</property>
241 <property name="image_position">top</property>
242 <accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
243 <signal name="clicked" handler="save_snippet"/>
244 </object>
245 <packing>
246 <property name="expand">False</property>
247 <property name="fill">False</property>
248 <property name="position">2</property>
249 </packing>
250 </child>
231 </object>251 </object>
232 <packing>252 <packing>
233 <property name="expand">False</property>253 <property name="expand">False</property>

Subscribers

People subscribed via source and target branches

to all changes: