Skip to content

Commit

Permalink
Refactor some more. [#4]
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Nov 19, 2009
1 parent de8378e commit 28b0e8f
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/application_controller.rb
Expand Up @@ -16,20 +16,29 @@ def self.reset
# TODO: Should this be in its own class? Should it return the File object itself?
def self.choose_file
if $MOCK_FILE_CHOOSERS # Fake the dialog since Swinger can't drive AWT widgets
filename = javax.swing.JOptionPane.show_input_dialog(nil, _('Enter file path:'), _('New'), javax.swing.JOptionPane::QUESTION_MESSAGE)
if filename.nil?
return nil
else
return File.expand_path filename
end
choose_file_mock
else
dialog = java.awt.FileDialog.new(nil, _('New'), java.awt.FileDialog::SAVE)
dialog.show
if dialog.file.nil?
# User cancelled without selecting a file
return nil
end
return dialog.directory + dialog.file
choose_file_awt
end
end

protected

def self.choose_file_awt
dialog = java.awt.FileDialog.new(nil, _('New'), java.awt.FileDialog::SAVE)
dialog.show
if dialog.file.nil? # User cancelled without selecting a file
return nil
end
return dialog.directory + dialog.file
end

def self.choose_file_mock
filename = javax.swing.JOptionPane.show_input_dialog(nil, _('Enter file path:'), _('New'), javax.swing.JOptionPane::QUESTION_MESSAGE)
if filename.nil? # User cancelled
return nil
else
return File.expand_path filename
end
end
end

0 comments on commit 28b0e8f

Please sign in to comment.