Mercurial > hg > octave-nkf
annotate scripts/gui/listdlg.m @ 20291:8bfadb26afcd
Allow case-insensitive SelectionMode value in listdlg (bug #44822).
* dialog.cc (ListDialog): Check for lower case selection mode "single" and
"multiple".
* listdlg.m: Use tolower() to guarantee SelectionMode is lower case.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 16 Apr 2015 09:35:01 -0700 |
parents | 501cbbaafc56 |
children | 777f26aa8e3e |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17700
diff
changeset
|
1 ## Copyright (C) 2010, 2013 Martin Hepperle |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 ## |
15746
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
3 ## This file is part of Octave. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 ## |
15746
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
8 ## your option) any later version. |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
9 ## |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
13 ## General Public License for more details. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 ## |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
15746
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
da26f72408a7
update copyright statements in newly added java files
John W. Eaton <jwe@octave.org>
parents:
15709
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{sel}, @var{ok}] =} listdlg (@var{key}, @var{value}, @dots{}) |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19088
diff
changeset
|
21 ## Return user inputs from a list dialog box in a vector of |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
22 ## selection indices @var{sel} and a flag @var{ok} indicating how the |
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
23 ## user closed the dialog box. The value of @var{ok} is 1 if the user |
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
24 ## closed the box with the OK button, otherwise it is 0 and @var{sel} is |
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
25 ## empty. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 ## |
16392
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
27 ## The indices in @var{sel} are 1-based. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 ## |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19088
diff
changeset
|
29 ## The arguments are specified in form of @var{key}, @var{value} pairs. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
30 ## The @qcode{"ListString"} argument pair must be specified. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 ## |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
32 ## Valid @var{key} and @var{value} pairs are: |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 ## |
16392
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
34 ## @table @asis |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
35 ## @item @qcode{"ListString"} |
16392
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
36 ## a cell array of strings comprising the content of the list. |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
37 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
38 ## @item @qcode{"SelectionMode"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
39 ## can be either @qcode{"Single"} or @qcode{"Multiple"} (default). |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
40 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
41 ## @item @qcode{"ListSize"} |
16392
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
42 ## a vector with two elements @var{width} and @var{height} defining |
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
43 ## the size of the list field in pixels. Default is [160 300]. |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
44 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
45 ## @item @qcode{"InitialValue"} |
16392
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
46 ## a vector containing 1-based indices of preselected elements. Default |
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
47 ## is 1 (first item). |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
48 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
49 ## @item @qcode{"Name"} |
16392
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
50 ## a string to be used as the dialog caption. Default is "". |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
51 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
52 ## @item @qcode{"PromptString"} |
16392
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
53 ## a cell array of strings to be displayed above the list field. Default |
801297f14e4b
doc: Improve documentation for Java chapter and java functions.
Rik <rik@octave.org>
parents:
15806
diff
changeset
|
54 ## is @{@}. |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
55 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
56 ## @item @qcode{"OKString"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
57 ## a string used to label the OK button. Default is @qcode{"OK"}. |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
58 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
59 ## @item @qcode{"CancelString"} |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16933
diff
changeset
|
60 ## a string used to label the Cancel button. Default is @qcode{"Cancel"}. |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 ## @end table |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 ## |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 ## Example: |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 ## |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 ## @example |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
66 ## @group |
15806
01d4f742d75d
doc: Re-organize and improve Java Interface documentation.
Rik <rik@octave.org>
parents:
15790
diff
changeset
|
67 ## [sel, ok] = listdlg ("ListString", @{"An item", "another", "yet another"@}, |
01d4f742d75d
doc: Re-organize and improve Java Interface documentation.
Rik <rik@octave.org>
parents:
15790
diff
changeset
|
68 ## "SelectionMode", "Multiple"); |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
69 ## if (ok == 1) |
15806
01d4f742d75d
doc: Re-organize and improve Java Interface documentation.
Rik <rik@octave.org>
parents:
15790
diff
changeset
|
70 ## for i = 1:numel (sel) |
15750
05c781cca57e
use numel instead of length in newly imported java functions
John W. Eaton <jwe@octave.org>
parents:
15748
diff
changeset
|
71 ## disp (sel(i)); |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
72 ## endfor |
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
73 ## endif |
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
74 ## @end group |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 ## @end example |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
76 ## |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
18718
diff
changeset
|
77 ## @seealso{menu, errordlg, helpdlg, inputdlg, msgbox, questdlg, warndlg} |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 ## @end deftypefn |
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 |
16512
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
80 function [sel, ok] = listdlg (varargin) |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
82 if (nargin < 2) |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
83 print_usage (); |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
84 endif |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
85 |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
86 listcell = {""}; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
87 selmode = "Multiple"; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
88 listsize = [160, 300]; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
89 initialvalue = 1; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
90 name = ""; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
91 prompt = {}; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
92 okstring = "OK"; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
93 cancelstring = "Cancel"; |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
94 |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
95 ## handle key, value pairs |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
96 for i = 1:2:nargin-1 |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
97 if (strcmpi (varargin{i}, "ListString")) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
98 listcell = varargin{i+1}; |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
99 elseif (strcmpi (varargin{i}, "SelectionMode")) |
20291
8bfadb26afcd
Allow case-insensitive SelectionMode value in listdlg (bug #44822).
Rik <rik@octave.org>
parents:
20135
diff
changeset
|
100 selmode = tolower (varargin{i+1}); |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
101 elseif (strcmpi (varargin{i}, "ListSize")) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
102 listsize = varargin{i+1}; |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
103 elseif (strcmpi (varargin{i}, "InitialValue")) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
104 initialvalue = varargin{i+1}; |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
105 elseif (strcmpi (varargin{i}, "Name")) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
106 name = varargin{i+1}; |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
107 elseif (strcmpi (varargin{i}, "PromptString")) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
108 prompt = varargin{i+1}; |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
109 elseif (strcmpi (varargin{i}, "OKString")) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
110 okstring = varargin{i+1}; |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
111 elseif (strcmpi (varargin{i}, "CancelString")) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
112 cancelstring = varargin{i+1}; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
113 endif |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
114 endfor |
15625
acf0addfc610
include Octave Forge java package in core Octave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
116 ## make sure prompt strings are a cell array |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
117 if (! iscell (prompt)) |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
118 prompt = {prompt}; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
119 endif |
16512
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
120 |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
121 ## make sure listcell strings are a cell array |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
122 if (! iscell (listcell)) |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
123 listcell = {listcell}; |
20135
501cbbaafc56
listdlg.m: Accept cell array with single cellstr entry from menu for Matlab compatibility (bug #44501).
Rik <rik@octave.org>
parents:
20053
diff
changeset
|
124 elseif (iscellstr (listcell{1})) |
501cbbaafc56
listdlg.m: Accept cell array with single cellstr entry from menu for Matlab compatibility (bug #44501).
Rik <rik@octave.org>
parents:
20053
diff
changeset
|
125 listcell = listcell{1}; |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
126 endif |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
127 |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
128 ## make sure valid selection mode |
20291
8bfadb26afcd
Allow case-insensitive SelectionMode value in listdlg (bug #44822).
Rik <rik@octave.org>
parents:
20135
diff
changeset
|
129 if (! strcmpi (selmode, "multiple") && ! strcmpi (selmode, "single")) |
8bfadb26afcd
Allow case-insensitive SelectionMode value in listdlg (bug #44822).
Rik <rik@octave.org>
parents:
20135
diff
changeset
|
130 error ("listdlg: invalid SelectionMode"); |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
131 endif |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
132 |
20053
9b7ca334a104
Backout cset a9952a647d52 and use __octave_link_enabled__ rather than isguirunning.
Rik <rik@octave.org>
parents:
20004
diff
changeset
|
133 if (__octave_link_enabled__ ()) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
134 [sel, ok] = __octave_link_list_dialog__ (listcell, selmode, listsize, |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
135 initialvalue, name, prompt, |
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
136 okstring, cancelstring); |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
137 elseif (__have_feature__ ("JAVA")) |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
138 ## transform matrices to cell arrays of strings |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
139 ## swap width and height to correct calling format for JDialogBox |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
140 listsize = {num2str(listsize(2)), num2str(listsize(1))}; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
141 initialvalue = arrayfun (@num2str, initialvalue, "UniformOutput", false); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
142 if (isempty (prompt)) |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
143 prompt = {""}; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
144 endif |
16512
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
145 |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
146 ret = javaMethod ("listdlg", "org.octave.JDialogBox", listcell, |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
147 selmode, listsize, initialvalue, name, prompt, |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
148 okstring, cancelstring); |
16512
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
149 |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
150 if (numel (ret) > 0) |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
151 sel = zeros (1, numel (ret)); |
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
152 ## for loop needed to convert Java array ret into Octave double sel |
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
153 for i = 1:numel (ret) |
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
154 sel(i) = ret(i); |
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
155 endfor |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
156 ok = 1; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
157 else |
18718
51a0d1c1023c
listdlg.m: return Octave value rather than Java int object.(bug #41931).
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
17744
diff
changeset
|
158 sel = []; |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
159 ok = 0; |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
160 endif |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
161 else |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
162 error ("listdlg is not available in this version of Octave"); |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
163 endif |
16512
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
164 |
15748
54e8c2527a9e
style and doc fixes for newly imported Java package .m files
John W. Eaton <jwe@octave.org>
parents:
15746
diff
changeset
|
165 endfunction |
15772
0f1a143e5002
Overhaul scripts/java directory to conform to Octave core.
Rik <rik@octave.org>
parents:
15750
diff
changeset
|
166 |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
167 |
16512
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
168 %!demo |
19088
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
169 %! disp ("- test listdlg with selectionmode single. No caption, no prompt."); |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
170 %! itemlist = {"An item \\alpha", "another", "yet another"}; |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
171 %! s = listdlg ("ListString", itemlist, "SelectionMode", "Single"); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
172 %! imax = numel (s); |
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
173 %! for i=1:1:imax |
19088
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
174 %! disp (["Selected: ", num2str(i), ": ", itemlist{s(i)}]); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
175 %! end |
16512
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
176 |
7f2395651a1c
dialog boxes with Qt widgets
Daniel J Sebald <daniel.sebald@ieee.org>, John W. Eaton <jwe@octave.org>
parents:
16505
diff
changeset
|
177 %!demo |
19088
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
178 %! disp ("- test listdlg with selectionmode and preselection. Has caption and two lines prompt."); |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
179 %! itemlist = {"An item \\alpha", "another", "yet another"}; |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
180 %! s = listdlg ("ListString", itemlist, ... |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
181 %! "SelectionMode", "Multiple", ... |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
182 %! "Name", "Selection Dialog", ... |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
183 %! "InitialValue", [1,2,3,4], |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
184 %! "PromptString", {"Select <b>an</b> item...", "...or <b>multiple</b> items"}); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
185 %! imax = numel (s); |
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
186 %! for i=1:1:imax |
19088
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
187 %! disp (["Selected: ", num2str(i), ": ", itemlist{s(i)}]); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
188 %! end |
16551
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
189 |
6ae555fc8c43
Add questdlg dialog function and fix variety of dialog bugs.
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16512
diff
changeset
|
190 %!demo |
19088
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
191 %! disp ("- test listdlg with listsize."); |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
192 %! itemlist = {"Neutron", "Electron", "Quark", "Proton", "Neutrino"}; |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
193 %! s = listdlg ("ListString", itemlist, |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
194 %! "Name", "Bits and Pieces", |
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
195 %! "ListSize", [200 75]); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
196 %! imax = numel (s); |
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
197 %! for i=1:1:imax |
19088
310fd62e9d4b
listdlg.m: convert SQ strings to DQ, fix num2str call in %!demos.
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
18829
diff
changeset
|
198 %! disp (["Selected: ", num2str(i), ": ", itemlist{s(i)}]); |
16933
e39f00a32dc7
maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents:
16551
diff
changeset
|
199 %! end |