Skip to content

Commit

Permalink
Merge pull request #315 from mcorino/develop
Browse files Browse the repository at this point in the history
fix  Single- and MultiChoiceDialog global methods
  • Loading branch information
mcorino authored Oct 9, 2024
2 parents cbd2cf3 + f9b7598 commit 3c1d668
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
17 changes: 7 additions & 10 deletions lib/wx/core/choicedlg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ def self.get_single_choice(message,
choices,
parent = nil,
initial_selection: 0,
x: Wx::DEFAULT_COORD,
y: Wx::DEFAULT_COORD)
dialog = Wx::SingleChoiceDialog.new(parent, message, caption, choices, nil, Wx::CHOICEDLG_STYLE, [x, y])
pos: Wx::DEFAULT_POSITION)
dialog = Wx::SingleChoiceDialog.new(parent, message, caption, choices, Wx::CHOICEDLG_STYLE, pos)

dialog.selection = initial_selection
return dialog.show_modal == Wx::ID_OK ? dialog.get_string_selection : ''
Expand All @@ -28,9 +27,8 @@ def self.get_single_choice_index(message,
choices,
parent = nil,
initial_selection: 0,
x: Wx::DEFAULT_COORD,
y: Wx::DEFAULT_COORD)
dialog = Wx::SingleChoiceDialog.new(parent, message, caption, choices, nil, Wx::CHOICEDLG_STYLE, [x, y])
pos: Wx::DEFAULT_POSITION)
dialog = Wx::SingleChoiceDialog.new(parent, message, caption, choices, Wx::CHOICEDLG_STYLE, pos)

dialog.selection = initial_selection
return dialog.show_modal == Wx::ID_OK ? dialog.get_selection : -1
Expand All @@ -43,16 +41,15 @@ def self.get_selected_choices(message,
choices,
parent = nil,
initial_selections: [],
x: Wx::DEFAULT_COORD,
y: Wx::DEFAULT_COORD)
dialog = Wx::MultiChoiceDialog.new(parent, message, caption, choices, Wx::CHOICEDLG_STYLE, [x, y])
pos: Wx::DEFAULT_POSITION)
dialog = Wx::MultiChoiceDialog.new(parent, message, caption, choices, Wx::CHOICEDLG_STYLE, pos)

# call this even if selections array is empty and this then (correctly)
# deselects the first item which is selected by default
dialog.selections = initial_selections

if dialog.show_modal != Wx::ID_OK
return []
return nil
end

dialog.get_selections
Expand Down
38 changes: 35 additions & 3 deletions lib/wx/doc/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,41 @@ def self.get_mouse_state; end
# @!group Dialog shortcuts

# @return [Array<Integer>] Selected choices
def self.get_selected_choices(message, caption, choices,
parent = nil, x = Wx::DEFAULT_COORD, y = Wx::DEFAULT_COORD,
centre = true, width = Wx::CHOICE_WIDTH, height = Wx::CHOICE_HEIGHT) end

# Get the user selection as a string.
# @param [String] message
# @param [String] caption
# @param [Array<String>] choices choice strings
# @param [Wx::Window,nil] parent
# @param [Integer] initial_selection initial choice index
# @param [Wx::Point,Array(Integer,Integer)] pos
# @return [String] selected choice or '' if cancelled
def self.get_single_choice(message, caption, choices, parent = nil,
initial_selection: 0,
pos: Wx::DEFAULT_POSITION) end

# Get the user selection as an index.
# @param [String] message
# @param [String] caption
# @param [Array<String>] choices choice strings
# @param [Wx::Window,nil] parent
# @param [Integer] initial_selection
# @param [Wx::Point,Array(Integer,Integer)] pos
# @return [Integer] selected choice index or -1 if cancelled
def self.get_single_choice_index(message, caption, choices, parent = nil,
initial_selection: 0,
pos: Wx::DEFAULT_POSITION) end

# @param [String] message
# @param [String] caption
# @param [Array<String>] choices choice strings
# @param [Wx::Window,nil] parent
# @param [Array<Integer>] initial_selections array of initial choice indexes
# @param [Wx::Point,Array(Integer,Integer)] pos
# @return [Array<Integer>,nil] selected choice indexes (can be empty array if none selected) or nil if cancelled
def self.get_selected_choices(message, caption, choices, parent = nil,
initial_selections: [],
pos: Wx::DEFAULT_POSITION) end

# Pops up a file selector box.
#
Expand Down
7 changes: 0 additions & 7 deletions rakelib/lib/director/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,6 @@ def setup
when 'wxMultiChoiceDialog'
# unnneeded and unwanted for Ruby
spec.ignore 'wxMultiChoiceDialog::wxMultiChoiceDialog(wxWindow *,const wxString &,const wxString &,int,const wxString *,long,const wxPoint &)'
# Wx's MultiChoiceDialog offers the possibility of attaching client
# data to each choice. However this would need memory management, and a
# pure ruby implementation is trivial and likely to be more convenient
# on a per-case basis so just ignore this argument for Ruby.
spec.map 'char** clientData' do
map_in ignore: true, code: '$1 = (char **)NULL;'
end
spec.do_not_generate(:functions, :enums, :defines)
when 'wxDirDialog'
when 'wxProgressDialog'
Expand Down
12 changes: 0 additions & 12 deletions rakelib/lib/director/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ def setup
wxWindow * wxGetActiveWindow();
// Dialog shortcuts
VOID_INT wxGetSelectedChoices(wxArrayInt& selections,
const wxString& message,
const wxString& caption,
int n, const wxString *choices,
wxWindow *parent = NULL,
int x = wxDefaultCoord,
int y = wxDefaultCoord,
bool centre = true,
int width = wxCHOICE_WIDTH,
int height = wxCHOICE_HEIGHT);
wxString wxFileSelector (const wxString &message,
const wxString &default_path=wxEmptyString,
const wxString &default_filename=wxEmptyString,
Expand Down

0 comments on commit 3c1d668

Please sign in to comment.