├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── build.xml
├── manifest.mf
├── nbproject
├── build-impl.xml
├── genfiles.properties
├── platform.properties
├── project.properties
└── project.xml
├── pom.xml
├── release
└── modules
│ └── ext
│ ├── LICENSE
│ └── gson-2.2.4-for-php-enhancements.jar
├── src
└── com
│ └── junichi11
│ └── netbeans
│ └── php
│ └── enhancements
│ ├── Bundle.properties
│ ├── Installer.java
│ ├── editor
│ ├── completion
│ │ ├── Function.java
│ │ ├── Parameter.java
│ │ ├── ParameterCompletionProvider.java
│ │ ├── ParameterFilter.java
│ │ ├── Parameters.java
│ │ ├── SuperGlobalArray.java
│ │ ├── UppercaseCompletionItem.java
│ │ ├── UppercaseCompletionProvider.java
│ │ └── resources
│ │ │ ├── charsets.json
│ │ │ ├── date_formats.json
│ │ │ ├── encodings.json
│ │ │ ├── envs.json
│ │ │ ├── http_cache_control_directives.json
│ │ │ ├── http_charsets.json
│ │ │ ├── http_header_responses.json
│ │ │ ├── http_methods.json
│ │ │ ├── http_status_codes.json
│ │ │ ├── mb_get_info_types.json
│ │ │ ├── mb_http_input_types.json
│ │ │ ├── mb_kana_conversions.json
│ │ │ ├── mb_languages.json
│ │ │ ├── media_types.json
│ │ │ ├── phpini_directives.json
│ │ │ ├── session_cache_limiters.json
│ │ │ ├── setlocales.json
│ │ │ ├── substchars.json
│ │ │ └── timezones.json
│ ├── generator
│ │ ├── DummyTextGenerator.java
│ │ └── ui
│ │ │ ├── Bundle.properties
│ │ │ ├── DummyTextPanel.form
│ │ │ └── DummyTextPanel.java
│ └── typinghooks
│ │ └── PhpTypedTextInterceptorEx.java
│ ├── options
│ ├── Bundle.properties
│ ├── DummyImageOptions.java
│ ├── DummyTextOptions.java
│ ├── PHPEnhancementsOptions.java
│ ├── PHPEnhancementsOptionsPanelController.java
│ ├── PHPEnhancementsPanel.form
│ └── PHPEnhancementsPanel.java
│ ├── resources
│ ├── convert2htmlentities16.png
│ ├── entities2string16.png
│ ├── parameter16.png
│ └── uppercase16.png
│ ├── ui
│ └── actions
│ │ ├── Bundle.properties
│ │ ├── ConvertToAction.java
│ │ ├── ConvertToHtmlEntitiesAction.java
│ │ ├── ConvertToPhpShortArraySyntaxAction.java
│ │ ├── ConvertToStringAction.java
│ │ ├── DummyImagePanel.form
│ │ ├── DummyImagePanel.java
│ │ ├── GenerateDummyImageAction.java
│ │ └── SmartDeleteAction.java
│ └── utils
│ ├── DocUtils.java
│ └── Utils.java
└── test
└── unit
├── data
├── ArraySyntaxCastTest.php
├── ArraySyntaxIssue4Test.php
├── ArraySyntaxTest.php
└── ArraySyntaxTypeTest.php
└── src
└── com
└── junichi11
└── netbeans
└── php
└── enhancements
└── ui
└── actions
└── ConvertToPhpShortArraySyntaxActionTest.java
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: junichi11
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | nbproject/private
3 | lib
4 | pom.xml.asc
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NetBeans PHP Enhancements Plugin
2 |
3 | Support for some small features.
4 |
5 | ## Features
6 |
7 | - Smart delete (Ctrl + Shift + BACK_SPACE)
8 | - Generate dummy text (Alt + Insert > Dummy Text)
9 | - Generate dummy image
10 | - Convert to PHP short array syntax
11 | - Typing hooks
12 | - Code completion
13 | - Convert String to Html entities (name entities)
14 | - Convert Html eltities to String
15 |
16 | ### Smart delete
17 |
18 | This feature delete string between "" or '', variable name.
19 |
20 | #### delete string
21 |
22 | e.g.
23 |
24 | ```php
25 | ->
26 | ```
27 |
28 | #### delete variable name
29 |
30 | e.g.
31 |
32 | ```php
33 | ->
34 | ```
35 |
36 | ### Generate dummy text
37 |
38 | We can use this feature on PHP and Html editors.
39 | Please set base text on the Dialog. It will be looped with option.
40 |
41 | #### options
42 |
43 | - loop count
44 | - text length
45 |
46 | ### Generate dummy image
47 |
48 | We can generate a dummy image with this feature to specific folder.
49 | Please right-click a folder > `Generate dummy image`
50 |
51 | ### Convert to PHP short array syntax
52 |
53 | Convert array() to [].
54 | Right-click (file|directory) > Convert to php short array syntax
55 |
56 | ### Typing hooks
57 |
58 | If you want to enable this feature, Please check Options(Tools > Options > PHP > Enhancements).
59 |
60 | This is avaible with the following operators:
61 |
62 | - Object operator ->
63 | - Double arrow operator =>
64 |
65 | e.g. type `$this-` => `$this->`, type `array('key' =)` => `array('key' =>)`
66 |
67 | ```php
68 | $this->property;
69 | $array = array('key' => 'value');
70 | $a = ["foo" => "bar"];
71 | $f = fn() => "arrow function";
72 | $result = match ($condition) {
73 | 1, 2 => foo(),
74 | default => bar(),
75 | };
76 | ```
77 |
78 | #### Note:
79 |
80 | - If you want to type `==`, please type `=` after `=>`.
81 | - If you want to type `=`, please delete `>`. (It's difficult to handle all cases correctly...)
82 |
83 | ### Code completion
84 |
85 | #### Constant
86 |
87 | Please check `Tools > Options > PHP > Enhancements`
88 |
89 | - Change name for `define`, `defined` and `const` to uppercase name
90 |
91 | #### Function and method parameter
92 |
93 | - multibyte functions (e.g. mb_convert_encoding())
94 | - header
95 | - ini_set, ini_get, ini_alter, ini_restore
96 | - date_default_timezone_set
97 | - date, date_format
98 | - Datetime::format, DateTimeImmutable::format
99 | - htmlentities, htmlspecialchars
100 | - session_cache_limiter
101 |
102 | Please run code completion (Ctrl + Space) inside quotes.
103 |
104 | e.g.
105 | ```php
106 |
2 |
3 |
4 |
5 |
6 | Builds, tests, and runs the project com.junichi11.netbeans.php.enhancements.
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
31 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/manifest.mf:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | OpenIDE-Module: com.junichi11.netbeans.php.enhancements
3 | OpenIDE-Module-Install: com/junichi11/netbeans/php/enhancements/Installer.class
4 | OpenIDE-Module-Localizing-Bundle: com/junichi11/netbeans/php/enhancements/Bundle.properties
5 | OpenIDE-Module-Requires: org.openide.windows.WindowManager
6 | OpenIDE-Module-Specification-Version: 1.3.2
7 |
8 |
--------------------------------------------------------------------------------
/nbproject/build-impl.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/nbproject/genfiles.properties:
--------------------------------------------------------------------------------
1 | build.xml.data.CRC32=66d90770
2 | build.xml.script.CRC32=fcc7be51
3 | build.xml.stylesheet.CRC32=15ca8a54@2.75.1
4 | # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
5 | # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6 | nbproject/build-impl.xml.data.CRC32=cabe96e6
7 | nbproject/build-impl.xml.script.CRC32=17f3ae36
8 | nbproject/build-impl.xml.stylesheet.CRC32=49aa68b0@2.87
9 |
--------------------------------------------------------------------------------
/nbproject/platform.properties:
--------------------------------------------------------------------------------
1 | cluster.path=\
2 | ${nbplatform.active.dir}/nb:\
3 | ${nbplatform.active.dir}/platform:\
4 | ${nbplatform.active.dir}/apisupport:\
5 | ${nbplatform.active.dir}/php:\
6 | ${nbplatform.active.dir}/ide:\
7 | ${nbplatform.active.dir}/websvccommon:\
8 | ${nbplatform.active.dir}/webcommon:\
9 | ${nbplatform.active.dir}/harness
10 | nbplatform.active=default
11 |
--------------------------------------------------------------------------------
/nbproject/project.properties:
--------------------------------------------------------------------------------
1 | auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
2 | file.reference.gson-2.2.4-for-php-enhancements.jar=release/modules/ext/gson-2.2.4-for-php-enhancements.jar
3 | javac.source=1.8
4 | javac.compilerargs=-Xlint -Xlint:-serial
5 | license.file=LICENSE
6 | nbm.homepage=https://github.com/junichi11/netbeans-php-enhancements
7 | nbm.module.author=junichi11
8 | nbm.needs.restart=true
9 | project.license=apache20
10 | keystore=nbproject/private/keystore
11 | nbm_alias=phpenhancements
12 |
--------------------------------------------------------------------------------
/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.apisupport.project
4 |
5 |
6 | com.junichi11.netbeans.php.enhancements
7 |
8 |
9 |
10 | org.apache.commons.lang
11 |
12 |
13 |
14 | 2.4.0
15 |
16 |
17 |
18 | org.netbeans.api.annotations.common
19 |
20 |
21 |
22 | 1
23 | 1.23.1
24 |
25 |
26 |
27 | org.netbeans.api.progress
28 |
29 |
30 |
31 | 1
32 | 1.46.1
33 |
34 |
35 |
36 | org.netbeans.api.templates
37 |
38 |
39 |
40 | 1.6.1
41 |
42 |
43 |
44 | org.netbeans.modules.csl.api
45 |
46 |
47 |
48 | 2
49 | 2.46.1.2.1.1.8
50 |
51 |
52 |
53 | org.netbeans.modules.csl.types
54 |
55 |
56 |
57 | 1
58 | 1.0.1
59 |
60 |
61 |
62 | org.netbeans.modules.editor
63 |
64 |
65 |
66 | 3
67 | 1.71.2.5.21.40
68 |
69 |
70 |
71 | org.netbeans.modules.editor.codetemplates
72 |
73 |
74 |
75 | 1
76 | 1.30.1.1
77 |
78 |
79 |
80 | org.netbeans.modules.editor.completion
81 |
82 |
83 |
84 | 1
85 | 1.36.1.2
86 |
87 |
88 |
89 | org.netbeans.modules.editor.document
90 |
91 |
92 |
93 | 1.5.1.1
94 |
95 |
96 |
97 | org.netbeans.modules.editor.lib
98 |
99 |
100 |
101 | 3
102 | 3.46.1.22.43
103 |
104 |
105 |
106 | org.netbeans.modules.editor.lib2
107 |
108 |
109 |
110 | 1
111 | 2.4.1.44.1
112 |
113 |
114 |
115 | org.netbeans.modules.editor.mimelookup
116 |
117 |
118 |
119 | 1
120 | 1.29.1
121 |
122 |
123 |
124 | org.netbeans.modules.html.lexer
125 |
126 |
127 |
128 | 1
129 | 1.22.1
130 |
131 |
132 |
133 | org.netbeans.modules.lexer
134 |
135 |
136 |
137 | 2
138 | 1.53.1.1
139 |
140 |
141 |
142 | org.netbeans.modules.options.api
143 |
144 |
145 |
146 | 1
147 | 1.36.1
148 |
149 |
150 |
151 | org.netbeans.modules.parsing.api
152 |
153 |
154 |
155 | 1
156 | 9.5.1.8
157 |
158 |
159 |
160 | org.netbeans.modules.php.editor
161 |
162 |
163 |
164 | 2
165 |
166 |
167 |
168 |
169 | org.openide.awt
170 |
171 |
172 |
173 | 7.55.1
174 |
175 |
176 |
177 | org.openide.dialogs
178 |
179 |
180 |
181 | 7.28.1
182 |
183 |
184 |
185 | org.openide.filesystems
186 |
187 |
188 |
189 | 9.8.1
190 |
191 |
192 |
193 | org.openide.loaders
194 |
195 |
196 |
197 | 7.44.3
198 |
199 |
200 |
201 | org.openide.modules
202 |
203 |
204 |
205 | 7.63
206 |
207 |
208 |
209 | org.openide.nodes
210 |
211 |
212 |
213 | 7.33.2
214 |
215 |
216 |
217 | org.openide.text
218 |
219 |
220 |
221 | 6.54.2
222 |
223 |
224 |
225 | org.openide.util
226 |
227 |
228 |
229 | 8.29.3
230 |
231 |
232 |
233 | org.openide.util.lookup
234 |
235 |
236 |
237 | 8.19.1
238 |
239 |
240 |
241 | org.openide.util.ui
242 |
243 |
244 |
245 | 9.4.1
246 |
247 |
248 |
249 |
250 |
251 | unit
252 |
253 | org.netbeans.insane
254 |
255 |
256 |
257 | org.netbeans.libs.junit4
258 |
259 |
260 |
261 | org.netbeans.modules.nbjunit
262 |
263 |
264 |
265 |
266 |
267 |
268 | ext/gson-2.2.4-for-php-enhancements.jar
269 | release/modules/ext/gson-2.2.4-for-php-enhancements.jar
270 |
271 |
272 |
273 |
274 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.junichi11.netbeans.modules
5 | netbeans-php-enhancements
6 |
7 | 1.3.2
8 | nbm
9 | NetBeans PHP Enhancements
10 | https://github.com/junichi11/
11 | Support for some small features for PHP.
12 |
13 |
14 | junichi11
15 | Junichi Yamamoto
16 | https://github.com/junichi11
17 |
18 |
19 |
20 | scm:git:https://github.com/junichi11/netbeans-php-enhancements.git
21 | scm:git:https://github.com/junichi11/netbeans-php-enhancements.git
22 | https://github.com/junichi11/netbeans-php-enhancements
23 | HEAD
24 |
25 |
26 |
27 | Apache License, Version 2.0
28 | https://www.apache.org/licenses/LICENSE-2.0
29 |
30 |
31 |
32 |
33 | ossrh
34 | https://oss.sonatype.org/content/repositories/snapshots
35 |
36 |
37 | ossrh
38 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
39 |
40 |
41 |
42 |
43 |
44 | org.apache.maven.plugins
45 | maven-deploy-plugin
46 | 3.0.0-M1
47 |
48 |
49 | org.sonatype.plugins
50 | nexus-staging-maven-plugin
51 | 1.6.7
52 | true
53 |
54 | ossrh
55 | https://oss.sonatype.org/
56 | true
57 |
58 |
59 |
60 | org.apache.maven.plugins
61 | maven-compiler-plugin
62 | 3.8.1
63 |
64 | 1.8
65 | 1.8
66 |
67 |
68 |
69 | org.apache.maven.plugins
70 | maven-jar-plugin
71 | 3.1.2
72 |
73 |
74 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
75 |
76 |
77 |
78 |
79 | org.apache.maven.plugins
80 | maven-gpg-plugin
81 | 1.6
82 |
83 |
84 | sign-artifacts
85 | verify
86 |
87 | sign
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/release/modules/ext/LICENSE:
--------------------------------------------------------------------------------
1 | Google Gson
2 |
3 | Apache License
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
178 | END OF TERMS AND CONDITIONS
179 |
180 | APPENDIX: How to apply the Apache License to your work.
181 |
182 | To apply the Apache License to your work, attach the following
183 | boilerplate notice, with the fields enclosed by brackets "[]"
184 | replaced with your own identifying information. (Don't include
185 | the brackets!) The text should be enclosed in the appropriate
186 | comment syntax for the file format. We also recommend that a
187 | file or class name and description of purpose be included on the
188 | same "printed page" as the copyright notice for easier
189 | identification within third-party archives.
190 |
191 | Copyright 2008-2011 Google Inc.
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
204 |
--------------------------------------------------------------------------------
/release/modules/ext/gson-2.2.4-for-php-enhancements.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junichi11/netbeans-php-enhancements/bc50790a4ce485ea35819384f281fcfbeb1a73df/release/modules/ext/gson-2.2.4-for-php-enhancements.jar
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/Bundle.properties:
--------------------------------------------------------------------------------
1 | OpenIDE-Module-Display-Category=PHP
2 | OpenIDE-Module-Long-Description=\
3 | PHP Enhancements plugin\n\n
Headers sent<\/p>Expires: (sometime in the future, according session.cache_expire) Cache-Control: public, max-age=(sometime in the future, according to session.cache_expire) Last-Modified: (the timestamp of when the session was last saved)",
5 | "category": ""
6 | },
7 | {
8 | "name": "private_no_expire",
9 | "description": "
Headers sent<\/p>Cache-Control: private, max-age=(session.cache_expire in the future), pre-check=(session.cache_expire in the future) Last-Modified: (the timestamp of when the session was last saved)",
10 | "category": ""
11 | },
12 | {
13 | "name": "private",
14 | "description": "
Headers sent<\/p>Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: private, max-age=(session.cache_expire in the future), pre-check=(session.cache_expire in the future) Last-Modified: (the timestamp of when the session was last saved)",
15 | "category": ""
16 | },
17 | {
18 | "name": "nocache",
19 | "description": "
Headers sent<\/p>Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache",
20 | "category": ""
21 | }
22 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/setlocales.json:
--------------------------------------------------------------------------------
1 | [
2 |
3 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/substchars.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "none",
4 | "description": "no output",
5 | "category": ""
6 | },
7 | {
8 | "name": "long",
9 | "description": "Output character code value (Example: U+3000, JIS+7E7E)",
10 | "category": ""
11 | },
12 | {
13 | "name": "entity",
14 | "description": "Output character entity (Example: Ȁ)",
15 | "category": ""
16 | }
17 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/generator/DummyTextGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.generator;
17 |
18 | import com.junichi11.netbeans.php.enhancements.editor.generator.ui.DummyTextPanel;
19 | import java.awt.Dialog;
20 | import java.util.Collections;
21 | import java.util.List;
22 | import javax.swing.text.Document;
23 | import javax.swing.text.JTextComponent;
24 | import org.netbeans.api.editor.mimelookup.MimeRegistration;
25 | import org.netbeans.api.editor.mimelookup.MimeRegistrations;
26 | import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
27 | import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager;
28 | import org.netbeans.spi.editor.codegen.CodeGenerator;
29 | import org.netbeans.spi.editor.codegen.CodeGeneratorContextProvider;
30 | import org.openide.DialogDescriptor;
31 | import org.openide.DialogDisplayer;
32 | import org.openide.util.Lookup;
33 | import org.openide.util.NbBundle;
34 |
35 | public class DummyTextGenerator implements CodeGenerator {
36 |
37 | JTextComponent textComp;
38 |
39 | /**
40 | *
41 | * @param context containing JTextComponent and possibly other items
42 | * registered by {@link CodeGeneratorContextProvider}
43 | */
44 | private DummyTextGenerator(Lookup context) { // Good practice is not to save Lookup outside ctor
45 | textComp = context.lookup(JTextComponent.class);
46 | }
47 |
48 | @MimeRegistrations({
49 | @MimeRegistration(mimeType = "text/x-php5", service = CodeGenerator.Factory.class),
50 | @MimeRegistration(mimeType = "text/html", service = CodeGenerator.Factory.class)
51 | })
52 | public static class Factory implements CodeGenerator.Factory {
53 |
54 | @Override
55 | public List extends CodeGenerator> create(Lookup context) {
56 | JTextComponent jtc = context.lookup(JTextComponent.class);
57 | if (jtc == null) {
58 | return Collections.emptyList();
59 | }
60 | return Collections.singletonList(new DummyTextGenerator(context));
61 | }
62 | }
63 |
64 | /**
65 | * The name which will be inserted inside Insert Code dialog
66 | */
67 | @NbBundle.Messages("DummyTextGenerator.DisplayName=Dummy Text")
68 | @Override
69 | public String getDisplayName() {
70 | return Bundle.DummyTextGenerator_DisplayName();
71 | }
72 |
73 | /**
74 | * This will be invoked when user chooses this Generator from Insert Code
75 | * dialog
76 | */
77 | @Override
78 | public void invoke() {
79 | Document document = textComp.getDocument();
80 | if (document == null) {
81 | return;
82 | }
83 |
84 | // create dialog
85 | DummyTextPanel dummyTextPanel = DummyTextPanel.getDefault();
86 | DialogDescriptor descriptor = new DialogDescriptor(dummyTextPanel, Bundle.DummyTextGenerator_DisplayName());
87 | Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor);
88 | dialog.setVisible(true);
89 | dialog.dispose();
90 |
91 | if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
92 | // text for inserting
93 | String text = dummyTextPanel.getInsertText();
94 | if (text == null || text.isEmpty()) {
95 | return;
96 | }
97 |
98 | // insert code with CodeTemplateManager
99 | CodeTemplateManager templateManager = CodeTemplateManager.get(document);
100 | CodeTemplate codeTemplate = templateManager.createTemporary(text);
101 | codeTemplate.insert(textComp);
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/generator/ui/Bundle.properties:
--------------------------------------------------------------------------------
1 | DummyTextPanel.textLabel.text=Text:
2 | DummyTextPanel.loopCheckBox.text=&Loop:
3 | DummyTextPanel.textLengthRadioButton.text=Text Len>h
4 | DummyTextPanel.loopCountRadioButton.text=Loop &Count
5 | DummyTextPanel.saveAsDefaultButton.text=Save as Default
6 | DummyTextPanel.loadDefaultButton.text=Load Default
7 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/generator/ui/DummyTextPanel.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
182 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/Bundle.properties:
--------------------------------------------------------------------------------
1 | PHPEnhancementsPanel.doubleArrowOperatorCheckBox.text==> double arrow operator (array, foreach, fn, match)
2 | PHPEnhancementsPanel.typingHooksLabel.text=Typing hooks:
3 | PHPEnhancementsPanel.objectOperatorCheckBox.text=-> object operator (e.g. $this->)
4 | PHPEnhancementsPanel.codeCompletionLabel.text=Code Completion:
5 | PHPEnhancementsPanel.toUppercaseDefineCheckBox.text=To uppercase (define, defined)
6 | PHPEnhancementsPanel.toUppercaseConstCheckBox.text=To uppercase (const)
7 | PHPEnhancementsPanel.parametersCodeCompletionCheckBox.text=Function parameters
8 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/DummyImageOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.options;
17 |
18 | import java.util.prefs.Preferences;
19 | import org.openide.util.NbPreferences;
20 |
21 | /**
22 | *
23 | * @author junichi11
24 | */
25 | public final class DummyImageOptions {
26 |
27 | private static final DummyImageOptions INSTANCE = new DummyImageOptions();
28 | private static final String DUMMY_IMAGE = "dummy.image"; // NOI18N
29 | private static final String IMAGE_WIDTH = "image.width"; // NOI18N
30 | private static final String IMAGE_HEIGHT = "image.height"; // NOI18N
31 | private static final String IMAGE_OPACITY = "image.opacity"; // NOI18N
32 | private static final String IMAGE_COLOR = "image.color"; // NOI18N
33 | private static final String FILE_PREFIX = "file.prefix"; // NOI18N
34 | private static final String FILE_SUFFIX = "file.suffix"; // NOI18N
35 | private static final String FILE_OVERWRITE = "file.overwrite"; // NOI18N
36 |
37 | private DummyImageOptions() {
38 | }
39 |
40 | public static DummyImageOptions getInstance() {
41 | return INSTANCE;
42 | }
43 |
44 | public int getImageWidth() {
45 | return getPreferences().getInt(IMAGE_WIDTH, 640);
46 | }
47 |
48 | public void setImageWidth(int width) {
49 | getPreferences().putInt(IMAGE_WIDTH, width);
50 | }
51 |
52 | public int getImageHeight() {
53 | return getPreferences().getInt(IMAGE_HEIGHT, 480);
54 | }
55 |
56 | public void setImageHeight(int height) {
57 | getPreferences().putInt(IMAGE_HEIGHT, height);
58 | }
59 |
60 | public int getOpacity() {
61 | return getPreferences().getInt(IMAGE_OPACITY, 100);
62 | }
63 |
64 | public void setOpacity(int opacity) {
65 | getPreferences().putInt(IMAGE_OPACITY, opacity);
66 | }
67 |
68 | public String getColor() {
69 | return getPreferences().get(IMAGE_COLOR, "#c0c0c0"); // NOI18N
70 | }
71 |
72 | public void setColor(String color) {
73 | getPreferences().put(IMAGE_COLOR, color);
74 | }
75 |
76 | public String getFileNamePrefix() {
77 | return getPreferences().get(FILE_PREFIX, "dummy_"); // NOI18N
78 | }
79 |
80 | public void setFileNamePrefix(String prefix) {
81 | getPreferences().put(FILE_PREFIX, prefix);
82 | }
83 |
84 | public String getFileNameSuffix() {
85 | return getPreferences().get(FILE_SUFFIX, ""); // NOI18N
86 | }
87 |
88 | public void setFileNameSuffix(String suffix) {
89 | getPreferences().put(FILE_SUFFIX, suffix);
90 | }
91 |
92 | public boolean isOverwrite() {
93 | return getPreferences().getBoolean(FILE_OVERWRITE, false);
94 | }
95 |
96 | public void setOverwrite(boolean isOverwrite) {
97 | getPreferences().putBoolean(FILE_OVERWRITE, isOverwrite);
98 | }
99 |
100 | private Preferences getPreferences() {
101 | return NbPreferences.forModule(DummyImageOptions.class).node(DUMMY_IMAGE);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/DummyTextOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.options;
17 |
18 | import java.util.prefs.Preferences;
19 | import org.openide.util.NbPreferences;
20 |
21 | /**
22 | *
23 | * @author junichi11
24 | */
25 | public final class DummyTextOptions {
26 |
27 | private static final DummyTextOptions INSTANCE = new DummyTextOptions();
28 | private static final String DUMMY_TEXT = "dummy.text"; // NOI18N
29 | private static final String TEXT = "text"; // NOI18N
30 | private static final String LOOP_COUNT = "loop.count"; // NOI18N
31 | private static final String USE_LOOP_COUNT = "use.loop.count"; // NOI18N
32 | private static final String TEXT_LENGTH = "text.length"; // NOI18N
33 | private static final String USE_TEXT_LENGTH = "use.text.length"; // NOI18N
34 | private static final String LOOP = "loop"; // NOI18N
35 |
36 | private DummyTextOptions() {
37 | }
38 |
39 | public static DummyTextOptions getInstance() {
40 | return INSTANCE;
41 | }
42 |
43 | public String getText() {
44 | return getPreferences().get(TEXT, ""); // NOI18N
45 | }
46 |
47 | public void setText(String text) {
48 | getPreferences().put(TEXT, text); // NOI18N
49 | }
50 |
51 | public boolean isLoop() {
52 | return getPreferences().getBoolean(LOOP, true);
53 | }
54 |
55 | public void setLoop(boolean isLoop) {
56 | getPreferences().putBoolean(LOOP, isLoop);
57 | }
58 |
59 | public boolean isTextLength() {
60 | return getPreferences().getBoolean(USE_TEXT_LENGTH, true);
61 | }
62 |
63 | public void setTextLength(boolean isTextLength) {
64 | getPreferences().putBoolean(USE_TEXT_LENGTH, isTextLength);
65 | }
66 |
67 | public int getTextLength() {
68 | return getPreferences().getInt(TEXT_LENGTH, 100);
69 | }
70 |
71 | public void setTextLength(int length) {
72 | getPreferences().putInt(TEXT_LENGTH, length);
73 | }
74 |
75 | public boolean isLoopCount() {
76 | return getPreferences().getBoolean(USE_LOOP_COUNT, false);
77 | }
78 |
79 | public void setLoopCount(boolean isLoopCount) {
80 | getPreferences().putBoolean(USE_LOOP_COUNT, isLoopCount);
81 | }
82 |
83 | public int getLoopCount() {
84 | return getPreferences().getInt(LOOP_COUNT, 5);
85 | }
86 |
87 | public void setLoopCount(int count) {
88 | getPreferences().putInt(LOOP_COUNT, count);
89 | }
90 |
91 | private Preferences getPreferences() {
92 | return NbPreferences.forModule(DummyTextOptions.class).node(DUMMY_TEXT);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/PHPEnhancementsOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.options;
17 |
18 | import java.util.prefs.Preferences;
19 | import org.openide.util.NbPreferences;
20 |
21 | /**
22 | *
23 | * @author junichi11
24 | */
25 | public final class PHPEnhancementsOptions {
26 |
27 | private static final PHPEnhancementsOptions INSTANCE = new PHPEnhancementsOptions();
28 | private static final String OBJECT_OPERATOR_TYPINGHOOK = "object.operator.typinghook"; // NOI18N
29 | private static final String DOUBLE_ARROW_TYPINGHOOK = "double.arrow.operator.typinghook"; // NOI18N
30 | private static final String TO_UPPERCASE_CONST = "uppercase.const"; // NOI18N
31 | private static final String TO_UPPERCASE_DEFINE = "uppercase.define"; // NOI18N
32 | private static final String PARAMETERS_CODE_COMPLETION = "parameters.code.completion"; // NOI18N
33 |
34 | // cache
35 | private static volatile boolean isObjectOperator;
36 | private static volatile boolean isDoubleArrowOperator;
37 | private static volatile boolean isToUppercaseConst;
38 | private static volatile boolean isToUppercaseDefine;
39 | private static volatile boolean isParametersCodeCompletion;
40 |
41 | static {
42 | INSTANCE.initialize(OBJECT_OPERATOR_TYPINGHOOK);
43 | INSTANCE.initialize(DOUBLE_ARROW_TYPINGHOOK);
44 | INSTANCE.initialize(TO_UPPERCASE_CONST);
45 | INSTANCE.initialize(TO_UPPERCASE_DEFINE);
46 | INSTANCE.initialize(PARAMETERS_CODE_COMPLETION);
47 | }
48 |
49 | public static PHPEnhancementsOptions getInstance() {
50 | return INSTANCE;
51 | }
52 |
53 | private PHPEnhancementsOptions() {
54 | }
55 |
56 | public static boolean isPHPEnhancementsOptions(String key) {
57 | return OBJECT_OPERATOR_TYPINGHOOK.equals(key)
58 | || DOUBLE_ARROW_TYPINGHOOK.equals(key)
59 | || TO_UPPERCASE_CONST.equals(key)
60 | || TO_UPPERCASE_DEFINE.equals(key)
61 | || PARAMETERS_CODE_COMPLETION.equals(key);
62 | }
63 |
64 | public void initialize(String key) {
65 | switch (key) {
66 | case OBJECT_OPERATOR_TYPINGHOOK:
67 | isObjectOperator = isObjectOperator(true);
68 | break;
69 | case DOUBLE_ARROW_TYPINGHOOK:
70 | isDoubleArrowOperator = isDoubleArrowOperator(true);
71 | break;
72 | case TO_UPPERCASE_CONST:
73 | isToUppercaseConst = isToUppercaseConst(true);
74 | break;
75 | case TO_UPPERCASE_DEFINE:
76 | isToUppercaseDefine = isToUppercaseDefine(true);
77 | break;
78 | case PARAMETERS_CODE_COMPLETION:
79 | isParametersCodeCompletion = isParametersCodeCompletion(true);
80 | break;
81 | default:
82 | break;
83 | }
84 | }
85 |
86 | public boolean isObjectOperator(boolean force) {
87 | if (force) {
88 | return getPreferences().getBoolean(OBJECT_OPERATOR_TYPINGHOOK, false);
89 | }
90 | return isObjectOperator;
91 | }
92 |
93 | public boolean isObjectOperator() {
94 | return isObjectOperator(false);
95 | }
96 |
97 | public void setObjectOperator(boolean isObjectOperator) {
98 | getPreferences().putBoolean(OBJECT_OPERATOR_TYPINGHOOK, isObjectOperator);
99 | }
100 |
101 | public boolean isDoubleArrowOperator(boolean force) {
102 | if (force) {
103 | return getPreferences().getBoolean(DOUBLE_ARROW_TYPINGHOOK, false);
104 | }
105 | return isDoubleArrowOperator;
106 | }
107 |
108 | public boolean isDoubleArrowOperator() {
109 | return isDoubleArrowOperator(false);
110 | }
111 |
112 | public void setDoubleArrowOperator(boolean isDoubleArrowOperator) {
113 | getPreferences().putBoolean(DOUBLE_ARROW_TYPINGHOOK, isDoubleArrowOperator);
114 | }
115 |
116 | public boolean isToUppercaseConst(boolean force) {
117 | if (force) {
118 | return getPreferences().getBoolean(TO_UPPERCASE_CONST, false);
119 | }
120 | return isToUppercaseConst;
121 | }
122 |
123 | public boolean isToUppercaseConst() {
124 | return isToUppercaseConst(false);
125 | }
126 |
127 | public void setToUppercaseConst(boolean isToUppercaseConst) {
128 | getPreferences().putBoolean(TO_UPPERCASE_CONST, isToUppercaseConst);
129 | }
130 |
131 | public boolean isToUppercaseDefine(boolean force) {
132 | if (force) {
133 | return getPreferences().getBoolean(TO_UPPERCASE_DEFINE, false);
134 | }
135 | return isToUppercaseDefine;
136 | }
137 |
138 | public boolean isToUppercaseDefine() {
139 | return isToUppercaseDefine(false);
140 | }
141 |
142 | public void setToUppercaseDefine(boolean isToUppercaseDefine) {
143 | getPreferences().putBoolean(TO_UPPERCASE_DEFINE, isToUppercaseDefine);
144 | }
145 |
146 | public boolean isParametersCodeCompletion(boolean force) {
147 | if (force) {
148 | return getPreferences().getBoolean(PARAMETERS_CODE_COMPLETION, true);
149 | }
150 | return isParametersCodeCompletion;
151 | }
152 |
153 | public boolean isParametersCodeCompletion() {
154 | return isParametersCodeCompletion(false);
155 | }
156 |
157 | public void setParametersCodeCompletion(boolean isParameters) {
158 | getPreferences().putBoolean(PARAMETERS_CODE_COMPLETION, isParameters);
159 | }
160 |
161 | private Preferences getPreferences() {
162 | return NbPreferences.forModule(PHPEnhancementsOptions.class);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/PHPEnhancementsOptionsPanelController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.options;
17 |
18 | import java.beans.PropertyChangeListener;
19 | import java.beans.PropertyChangeSupport;
20 | import javax.swing.JComponent;
21 | import org.netbeans.spi.options.OptionsPanelController;
22 | import org.openide.util.HelpCtx;
23 | import org.openide.util.Lookup;
24 |
25 | @OptionsPanelController.SubRegistration(
26 | location = "org-netbeans-modules-php-project-ui-options-PHPOptionsCategory",
27 | displayName = "#AdvancedOption_DisplayName_PHPEnhancements",
28 | keywords = "#AdvancedOption_Keywords_PHPEnhancements",
29 | keywordsCategory = "org-netbeans-modules-php-project-ui-options-PHPOptionsCategory/PHPEnhancements"
30 | )
31 | @org.openide.util.NbBundle.Messages({"AdvancedOption_DisplayName_PHPEnhancements=Enhancements", "AdvancedOption_Keywords_PHPEnhancements=enhancement"})
32 | public final class PHPEnhancementsOptionsPanelController extends OptionsPanelController {
33 |
34 | private PHPEnhancementsPanel panel;
35 | private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
36 | private boolean changed;
37 |
38 | @Override
39 | public void update() {
40 | getPanel().load();
41 | changed = false;
42 | }
43 |
44 | @Override
45 | public void applyChanges() {
46 | getPanel().store();
47 | changed = false;
48 | }
49 |
50 | @Override
51 | public void cancel() {
52 | // need not do anything special, if no changes have been persisted yet
53 | }
54 |
55 | @Override
56 | public boolean isValid() {
57 | return getPanel().valid();
58 | }
59 |
60 | @Override
61 | public boolean isChanged() {
62 | return changed;
63 | }
64 |
65 | @Override
66 | public HelpCtx getHelpCtx() {
67 | return null; // new HelpCtx("...ID") if you have a help set
68 | }
69 |
70 | @Override
71 | public JComponent getComponent(Lookup masterLookup) {
72 | return getPanel();
73 | }
74 |
75 | @Override
76 | public void addPropertyChangeListener(PropertyChangeListener l) {
77 | pcs.addPropertyChangeListener(l);
78 | }
79 |
80 | @Override
81 | public void removePropertyChangeListener(PropertyChangeListener l) {
82 | pcs.removePropertyChangeListener(l);
83 | }
84 |
85 | private PHPEnhancementsPanel getPanel() {
86 | if (panel == null) {
87 | panel = new PHPEnhancementsPanel(this);
88 | }
89 | return panel;
90 | }
91 |
92 | void changed() {
93 | if (!changed) {
94 | changed = true;
95 | pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
96 | }
97 | pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/PHPEnhancementsPanel.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
113 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/PHPEnhancementsPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.options;
17 |
18 | import com.junichi11.netbeans.php.enhancements.editor.completion.Parameters;
19 |
20 | final class PHPEnhancementsPanel extends javax.swing.JPanel {
21 |
22 | private static final long serialVersionUID = -4525362573123684731L;
23 |
24 | private final PHPEnhancementsOptionsPanelController controller;
25 |
26 | PHPEnhancementsPanel(PHPEnhancementsOptionsPanelController controller) {
27 | this.controller = controller;
28 | initComponents();
29 | // TODO listen to changes in form fields and call controller.changed()
30 | }
31 |
32 | /**
33 | * This method is called from within the constructor to initialize the form.
34 | * WARNING: Do NOT modify this code. The content of this method is always
35 | * regenerated by the Form Editor.
36 | */
37 | // //GEN-BEGIN:initComponents
38 | private void initComponents() {
39 |
40 | typingHooksLabel = new javax.swing.JLabel();
41 | objectOperatorCheckBox = new javax.swing.JCheckBox();
42 | doubleArrowOperatorCheckBox = new javax.swing.JCheckBox();
43 | codeCompletionLabel = new javax.swing.JLabel();
44 | toUppercaseConstCheckBox = new javax.swing.JCheckBox();
45 | toUppercaseDefineCheckBox = new javax.swing.JCheckBox();
46 | parametersCodeCompletionCheckBox = new javax.swing.JCheckBox();
47 |
48 | org.openide.awt.Mnemonics.setLocalizedText(typingHooksLabel, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.typingHooksLabel.text")); // NOI18N
49 |
50 | org.openide.awt.Mnemonics.setLocalizedText(objectOperatorCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.objectOperatorCheckBox.text")); // NOI18N
51 |
52 | org.openide.awt.Mnemonics.setLocalizedText(doubleArrowOperatorCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.doubleArrowOperatorCheckBox.text")); // NOI18N
53 |
54 | org.openide.awt.Mnemonics.setLocalizedText(codeCompletionLabel, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.codeCompletionLabel.text")); // NOI18N
55 |
56 | org.openide.awt.Mnemonics.setLocalizedText(toUppercaseConstCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.toUppercaseConstCheckBox.text")); // NOI18N
57 |
58 | org.openide.awt.Mnemonics.setLocalizedText(toUppercaseDefineCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.toUppercaseDefineCheckBox.text")); // NOI18N
59 |
60 | org.openide.awt.Mnemonics.setLocalizedText(parametersCodeCompletionCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.parametersCodeCompletionCheckBox.text")); // NOI18N
61 |
62 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
63 | this.setLayout(layout);
64 | layout.setHorizontalGroup(
65 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
66 | .addGroup(layout.createSequentialGroup()
67 | .addContainerGap()
68 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
69 | .addComponent(typingHooksLabel)
70 | .addComponent(codeCompletionLabel)
71 | .addGroup(layout.createSequentialGroup()
72 | .addGap(12, 12, 12)
73 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
74 | .addComponent(doubleArrowOperatorCheckBox)
75 | .addComponent(objectOperatorCheckBox)
76 | .addComponent(toUppercaseConstCheckBox)
77 | .addComponent(toUppercaseDefineCheckBox)
78 | .addComponent(parametersCodeCompletionCheckBox))))
79 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
80 | );
81 | layout.setVerticalGroup(
82 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
83 | .addGroup(layout.createSequentialGroup()
84 | .addContainerGap()
85 | .addComponent(typingHooksLabel)
86 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
87 | .addComponent(objectOperatorCheckBox)
88 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
89 | .addComponent(doubleArrowOperatorCheckBox)
90 | .addGap(18, 18, 18)
91 | .addComponent(codeCompletionLabel)
92 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
93 | .addComponent(toUppercaseConstCheckBox)
94 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
95 | .addComponent(toUppercaseDefineCheckBox)
96 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
97 | .addComponent(parametersCodeCompletionCheckBox)
98 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
99 | );
100 | }// //GEN-END:initComponents
101 |
102 | void load() {
103 | PHPEnhancementsOptions options = PHPEnhancementsOptions.getInstance();
104 | objectOperatorCheckBox.setSelected(options.isObjectOperator());
105 | doubleArrowOperatorCheckBox.setSelected(options.isDoubleArrowOperator());
106 | toUppercaseConstCheckBox.setSelected(options.isToUppercaseConst());
107 | toUppercaseDefineCheckBox.setSelected(options.isToUppercaseDefine());
108 | parametersCodeCompletionCheckBox.setSelected(options.isParametersCodeCompletion());
109 | }
110 |
111 | void store() {
112 | PHPEnhancementsOptions options = PHPEnhancementsOptions.getInstance();
113 | options.setObjectOperator(objectOperatorCheckBox.isSelected());
114 | options.setDoubleArrowOperator(doubleArrowOperatorCheckBox.isSelected());
115 | options.setToUppercaseConst(toUppercaseConstCheckBox.isSelected());
116 | options.setToUppercaseDefine(toUppercaseDefineCheckBox.isSelected());
117 | options.setParametersCodeCompletion(parametersCodeCompletionCheckBox.isSelected());
118 | if (parametersCodeCompletionCheckBox.isSelected()) {
119 | Parameters.reload();
120 | } else {
121 | Parameters.clear();
122 | }
123 | }
124 |
125 | boolean valid() {
126 | // TODO check whether form is consistent and complete
127 | return true;
128 | }
129 |
130 | // Variables declaration - do not modify//GEN-BEGIN:variables
131 | private javax.swing.JLabel codeCompletionLabel;
132 | private javax.swing.JCheckBox doubleArrowOperatorCheckBox;
133 | private javax.swing.JCheckBox objectOperatorCheckBox;
134 | private javax.swing.JCheckBox parametersCodeCompletionCheckBox;
135 | private javax.swing.JCheckBox toUppercaseConstCheckBox;
136 | private javax.swing.JCheckBox toUppercaseDefineCheckBox;
137 | private javax.swing.JLabel typingHooksLabel;
138 | // End of variables declaration//GEN-END:variables
139 | }
140 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/resources/convert2htmlentities16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junichi11/netbeans-php-enhancements/bc50790a4ce485ea35819384f281fcfbeb1a73df/src/com/junichi11/netbeans/php/enhancements/resources/convert2htmlentities16.png
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/resources/entities2string16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junichi11/netbeans-php-enhancements/bc50790a4ce485ea35819384f281fcfbeb1a73df/src/com/junichi11/netbeans/php/enhancements/resources/entities2string16.png
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/resources/parameter16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junichi11/netbeans-php-enhancements/bc50790a4ce485ea35819384f281fcfbeb1a73df/src/com/junichi11/netbeans/php/enhancements/resources/parameter16.png
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/resources/uppercase16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/junichi11/netbeans-php-enhancements/bc50790a4ce485ea35819384f281fcfbeb1a73df/src/com/junichi11/netbeans/php/enhancements/resources/uppercase16.png
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/Bundle.properties:
--------------------------------------------------------------------------------
1 | DummyImagePanel.widthLabel.text=Width:
2 | DummyImagePanel.heightLabel.text=Height:
3 | DummyImagePanel.colorLabel.text=Color:
4 | DummyImagePanel.colorTextField.text=\#c0c0c0
5 | DummyImagePanel.overwriteCheckBox.text=Overwrite
6 | DummyImagePanel.opacityLabel.text=Opacity (%):
7 | DummyImagePanel.fileNameSuffixLabel.text=File Name Suffix:
8 | DummyImagePanel.fileNamePrefixTextField.text=dummy_
9 | DummyImagePanel.fileNamePrefixLabel.text=File Name Prefix:
10 | DummyImagePanel.fileNameSuffixTextField.text=
11 | DummyImagePanel.saveAsDefaultButton.text=Save as Default
12 | DummyImagePanel.loadDefaultButton.text=Load Default
13 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import java.awt.event.ActionEvent;
19 | import java.awt.event.ActionListener;
20 | import java.io.IOException;
21 | import javax.swing.text.BadLocationException;
22 | import javax.swing.text.JTextComponent;
23 | import javax.swing.text.StyledDocument;
24 | import org.apache.commons.lang.StringEscapeUtils;
25 | import org.netbeans.api.editor.EditorRegistry;
26 | import org.openide.cookies.EditorCookie;
27 | import org.openide.text.NbDocument;
28 | import org.openide.util.Exceptions;
29 |
30 | /**
31 | * Convert to action. Text must be selected.
32 | *
33 | * @author junichi11
34 | */
35 | abstract class ConvertToAction implements ActionListener {
36 |
37 | public enum TYPE {
38 |
39 | STRING_2_NAME_ENTITIES,
40 | NAME_ENTITIES_2_STRING
41 | }
42 | private final EditorCookie context;
43 |
44 | public ConvertToAction(EditorCookie context) {
45 | this.context = context;
46 | }
47 |
48 | public abstract TYPE getType();
49 |
50 | @Override
51 | public void actionPerformed(ActionEvent ev) {
52 | try {
53 | JTextComponent editor = EditorRegistry.lastFocusedComponent();
54 | if (editor == null) {
55 | return;
56 | }
57 | final StyledDocument document = context.openDocument();
58 | if (editor.getDocument() != document) {
59 | return;
60 | }
61 |
62 | final String selectedText = editor.getSelectedText();
63 | if (selectedText == null || selectedText.isEmpty()) {
64 | return;
65 | }
66 |
67 | final String convertedString = convert(selectedText);
68 | if (selectedText.equals(convertedString)) {
69 | return;
70 | }
71 |
72 | final int selectionStartPosition = editor.getSelectionStart();
73 | NbDocument.runAtomic(document, () -> {
74 | try {
75 | document.remove(selectionStartPosition, selectedText.length());
76 | document.insertString(selectionStartPosition, convertedString, null);
77 | } catch (BadLocationException ex) {
78 | Exceptions.printStackTrace(ex);
79 | }
80 | });
81 | } catch (IOException ex) {
82 | Exceptions.printStackTrace(ex);
83 | }
84 | }
85 |
86 | private String convert(String selectedText) throws AssertionError {
87 | String convertedString;
88 | switch (getType()) {
89 | case STRING_2_NAME_ENTITIES:
90 | // escape (name entities)
91 | convertedString = StringEscapeUtils.escapeHtml(selectedText);
92 | break;
93 | case NAME_ENTITIES_2_STRING:
94 | convertedString = StringEscapeUtils.unescapeHtml(selectedText);
95 | break;
96 | default:
97 | throw new AssertionError();
98 | }
99 | return convertedString;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToHtmlEntitiesAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import org.openide.awt.ActionID;
19 | import org.openide.awt.ActionReference;
20 | import org.openide.awt.ActionReferences;
21 | import org.openide.awt.ActionRegistration;
22 | import org.openide.cookies.EditorCookie;
23 | import org.openide.util.NbBundle;
24 |
25 | /**
26 | *
27 | * @author junichi11
28 | */
29 | @ActionID(
30 | category = "Edit",
31 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.ConvertToHtmlEntitiesAction"
32 | )
33 | @ActionRegistration(
34 | iconBase = "com/junichi11/netbeans/php/enhancements/resources/convert2htmlentities16.png",
35 | displayName = "#CTL_ConvertToHtmlEntitiesAction"
36 | )
37 | @ActionReferences({
38 | @ActionReference(path = "Menu/Edit", position = 3400),
39 | @ActionReference(path = "Editors/text/html/Popup", position = 4300),
40 | @ActionReference(path = "Editors/Toolbars/Default", position = 250000)
41 | })
42 | @NbBundle.Messages("CTL_ConvertToHtmlEntitiesAction=Convert to HTML Entities (name)")
43 | public class ConvertToHtmlEntitiesAction extends ConvertToAction {
44 |
45 | public ConvertToHtmlEntitiesAction(EditorCookie context) {
46 | super(context);
47 | }
48 |
49 | @Override
50 | public TYPE getType() {
51 | return TYPE.STRING_2_NAME_ENTITIES;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToPhpShortArraySyntaxAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import com.junichi11.netbeans.php.enhancements.utils.Utils;
19 | import java.awt.event.ActionEvent;
20 | import java.awt.event.ActionListener;
21 | import java.io.IOException;
22 | import java.util.Arrays;
23 | import java.util.LinkedList;
24 | import java.util.List;
25 | import javax.swing.text.BadLocationException;
26 | import javax.swing.text.StyledDocument;
27 | import org.netbeans.api.lexer.Token;
28 | import org.netbeans.api.lexer.TokenSequence;
29 | import org.netbeans.api.progress.ProgressHandle;
30 | import org.netbeans.modules.php.editor.lexer.LexUtilities;
31 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
32 | import org.openide.DialogDisplayer;
33 | import org.openide.NotifyDescriptor;
34 | import org.openide.awt.ActionID;
35 | import org.openide.awt.ActionReference;
36 | import org.openide.awt.ActionReferences;
37 | import org.openide.awt.ActionRegistration;
38 | import org.openide.cookies.EditorCookie;
39 | import org.openide.filesystems.FileObject;
40 | import org.openide.loaders.DataObject;
41 | import org.openide.loaders.DataObjectNotFoundException;
42 | import org.openide.text.NbDocument;
43 | import org.openide.util.Exceptions;
44 | import org.openide.util.NbBundle;
45 | import org.openide.util.NbBundle.Messages;
46 | import org.openide.util.RequestProcessor;
47 |
48 | @ActionID(
49 | category = "Refactoring",
50 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.ConvertToPhpShortArraySyntaxAction"
51 | )
52 | @ActionRegistration(
53 | displayName = "#CTL_ConvertToPhpShortArraySyntaxAction"
54 | )
55 | @ActionReferences({
56 | @ActionReference(path = "Menu/Edit", position = 3300),
57 | @ActionReference(path = "Projects/org-netbeans-modules-php-project/Actions", position = 1800),
58 | @ActionReference(path = "Loaders/text/x-php5/Actions", position = 1800),
59 | @ActionReference(path = "Loaders/folder/any/Actions", position = 1800),})
60 | @Messages("CTL_ConvertToPhpShortArraySyntaxAction=Convert to short array syntax")
61 | public final class ConvertToPhpShortArraySyntaxAction implements ActionListener {
62 |
63 | private final List context;
64 | private final StringBuilder sb = new StringBuilder();
65 | private final List balanceStack = new LinkedList<>();
66 | private boolean isArraySyntax = false;
67 | private boolean isChanged = false;
68 | private int arrayCount = 0;
69 | private int balance = 0;
70 | private TokenSequence ts;
71 |
72 | public ConvertToPhpShortArraySyntaxAction(List context) {
73 | this.context = context;
74 | }
75 |
76 | @NbBundle.Messages({
77 | "ConvertToPhpShortArraySyntaxAction.action.confirmation=If you select folders, run for all files within them recursively. Recommend to backup folders or to use version management system. Do you really want to run this action?",
78 | "ConvertToPhpShortArraySyntaxAction.action.complete=Convert to PHP short array syntax: complete",
79 | "ConvertToPhpShortArraySyntaxAction.perform.progress=Converting to short array syntax",})
80 | @Override
81 | public void actionPerformed(ActionEvent ev) {
82 | // confirmation if directories are selected
83 | for (DataObject dataObject : context) {
84 | FileObject fileObject = dataObject.getPrimaryFile();
85 | if (fileObject.isFolder()) {
86 | NotifyDescriptor.Confirmation confirmation = new NotifyDescriptor.Confirmation(
87 | Bundle.ConvertToPhpShortArraySyntaxAction_action_confirmation(),
88 | NotifyDescriptor.OK_CANCEL_OPTION
89 | );
90 | if (DialogDisplayer.getDefault().notify(confirmation) != NotifyDescriptor.OK_OPTION) {
91 | return;
92 | }
93 | break;
94 | }
95 | }
96 |
97 | // show progress bar
98 | RequestProcessor.getDefault().post(() -> {
99 | ProgressHandle handle = ProgressHandle.createHandle(Bundle.ConvertToPhpShortArraySyntaxAction_perform_progress());
100 | try {
101 | handle.start();
102 | context.forEach((dataObject) -> {
103 | actionPerformed(dataObject);
104 | });
105 | } finally {
106 | handle.finish();
107 | }
108 |
109 | // show complete dialog
110 | NotifyDescriptor.Message message = new NotifyDescriptor.Message(
111 | Bundle.ConvertToPhpShortArraySyntaxAction_action_complete(),
112 | NotifyDescriptor.INFORMATION_MESSAGE
113 | );
114 | DialogDisplayer.getDefault().notify(message);
115 | });
116 | }
117 |
118 | public void actionPerformed(DataObject dataObject) {
119 | // recursive
120 | FileObject fileObject = dataObject.getPrimaryFile();
121 | if (fileObject.isFolder()) {
122 | for (FileObject child : fileObject.getChildren()) {
123 | try {
124 | actionPerformed(DataObject.find(child));
125 | } catch (DataObjectNotFoundException ex) {
126 | Exceptions.printStackTrace(ex);
127 | }
128 | }
129 | }
130 |
131 | // get EditorCookie
132 | EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
133 | if (ec == null) {
134 | return;
135 | }
136 |
137 | try {
138 | // get document
139 | StyledDocument sdoc = getDocument(ec);
140 | if (!Utils.isPHP(sdoc)) {
141 | return;
142 | }
143 | convert(sdoc);
144 |
145 | // save
146 | if (isChanged) {
147 | ec.saveDocument();
148 | }
149 | } catch (IOException ex) {
150 | Exceptions.printStackTrace(ex);
151 | }
152 | }
153 |
154 | /**
155 | * Convert to short array syntax.
156 | *
157 | * @param sdoc
158 | */
159 | public void convert(final StyledDocument sdoc) {
160 | ts = Utils.getTokenSequence(sdoc, 0);
161 | if (ts == null) {
162 | return;
163 | }
164 | ts.move(0);
165 |
166 | NbDocument.runAtomic(sdoc, () -> {
167 | init();
168 |
169 | while (ts.moveNext()) {
170 | Token token = ts.token();
171 | handleToken(token);
172 | }
173 | if (!isChanged) {
174 | return;
175 | }
176 |
177 | try {
178 | // XXX line feed is added to last token when document is devided to tokens
179 | int length = sb.length();
180 | if (length > 0) {
181 | // delete last position
182 | sb.deleteCharAt(length - 1);
183 | }
184 | sdoc.remove(0, sdoc.getLength());
185 | sdoc.insertString(0, sb.toString(), null);
186 | } catch (BadLocationException ex) {
187 | Exceptions.printStackTrace(ex);
188 | }
189 | });
190 | }
191 |
192 | private void init() {
193 | isArraySyntax = false;
194 | isChanged = false;
195 | balance = 0;
196 | arrayCount = 0;
197 | balanceStack.clear();
198 | sb.setLength(0);
199 | }
200 |
201 | private StyledDocument getDocument(EditorCookie ec) throws IOException {
202 | StyledDocument document = ec.getDocument();
203 | if (document == null) {
204 | document = ec.openDocument();
205 | }
206 | return document;
207 | }
208 |
209 | private void handleToken(Token token) {
210 | // array
211 | PHPTokenId id = token.id();
212 | if (id == PHPTokenId.PHP_ARRAY) {
213 | handleArray();
214 | return;
215 | }
216 | CharSequence text = token.text();
217 | // #4 check TokenId
218 | if (arrayCount > 0 && id == PHPTokenId.PHP_TOKEN) {
219 | // open
220 | if (LexUtilities.textEquals(text, '(')) { // NOI18N
221 | handleOpen();
222 | return;
223 | }
224 |
225 | // close
226 | if (LexUtilities.textEquals(text, ')')) { // NOI18N
227 | handleClose();
228 | return;
229 | }
230 | }
231 |
232 | // default
233 | sb.append(text);
234 | }
235 |
236 | private void handleArray() {
237 | /*
238 | * case 1: function parameter type e.g. public function something(array $param){}
239 | * case 2: cast e.g. (array) $something
240 | * case 3: array('something');
241 | */
242 | Token extends PHPTokenId> nextToken = LexUtilities.findNext(ts, Arrays.asList(PHPTokenId.WHITESPACE, PHPTokenId.PHP_ARRAY));
243 | if (LexUtilities.textEquals(nextToken.text(), '(')) { // NOI18N
244 | isArraySyntax = true;
245 | arrayCount++;
246 | } else {
247 | sb.append("array"); // NOI18N
248 | }
249 | LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_ARRAY));
250 | }
251 |
252 | private void handleOpen() {
253 | if (isArraySyntax) {
254 | isChanged = true;
255 | isArraySyntax = false;
256 | balanceStack.add(0, balance);
257 | balance = 0;
258 | sb.append('['); // NOI18N
259 | return;
260 | }
261 | sb.append('('); // NOI18N
262 | balance++;
263 | }
264 |
265 | private void handleClose() {
266 | if (balance == 0) {
267 | sb.append(']'); // NOI18N
268 | arrayCount--;
269 | if (!balanceStack.isEmpty()) {
270 | balance = balanceStack.get(0);
271 | balanceStack.remove(0);
272 | }
273 | return;
274 | }
275 | sb.append(')'); // NOI18N
276 | balance--;
277 | }
278 |
279 | }
280 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToStringAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import org.openide.awt.ActionID;
19 | import org.openide.awt.ActionReference;
20 | import org.openide.awt.ActionReferences;
21 | import org.openide.awt.ActionRegistration;
22 | import org.openide.cookies.EditorCookie;
23 | import org.openide.util.NbBundle;
24 |
25 | /**
26 | *
27 | * @author junichi11
28 | */
29 | @ActionID(
30 | category = "Edit",
31 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.HtmlEntitiesToStringAction"
32 | )
33 | @ActionRegistration(
34 | iconBase = "com/junichi11/netbeans/php/enhancements/resources/entities2string16.png",
35 | displayName = "#CTL_HtmlEntitiesToStringAction"
36 | )
37 | @ActionReferences({
38 | @ActionReference(path = "Menu/Edit", position = 3500),
39 | @ActionReference(path = "Editors/text/html/Popup", position = 4400),
40 | @ActionReference(path = "Editors/Toolbars/Default", position = 250010)
41 | })
42 | @NbBundle.Messages("CTL_HtmlEntitiesToStringAction=Html Entities to String")
43 | public class ConvertToStringAction extends ConvertToAction {
44 |
45 | public ConvertToStringAction(EditorCookie context) {
46 | super(context);
47 | }
48 |
49 | @Override
50 | public TYPE getType() {
51 | return TYPE.NAME_ENTITIES_2_STRING;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/GenerateDummyImageAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import java.awt.Color;
19 | import java.awt.Font;
20 | import java.awt.Graphics2D;
21 | import java.awt.RenderingHints;
22 | import java.awt.event.ActionEvent;
23 | import java.awt.event.ActionListener;
24 | import java.awt.geom.Rectangle2D;
25 | import java.awt.image.BufferedImage;
26 | import java.io.IOException;
27 | import java.util.logging.Level;
28 | import java.util.logging.Logger;
29 | import javax.imageio.ImageIO;
30 | import org.openide.DialogDescriptor;
31 | import org.openide.DialogDisplayer;
32 | import org.openide.NotifyDescriptor;
33 | import org.openide.loaders.DataObject;
34 | import org.openide.awt.ActionID;
35 | import org.openide.awt.ActionReference;
36 | import org.openide.awt.ActionRegistration;
37 | import org.openide.filesystems.FileObject;
38 | import org.openide.filesystems.FileUtil;
39 | import org.openide.util.Exceptions;
40 | import org.openide.util.NbBundle;
41 | import org.openide.util.NbBundle.Messages;
42 |
43 | @ActionID(
44 | category = "Images",
45 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.GenerateDummyImageAction")
46 | @ActionRegistration(
47 | displayName = "#CTL_GenerateDummyImageAction")
48 | @ActionReference(path = "Loaders/folder/any/Actions", position = 1800)
49 | @Messages("CTL_GenerateDummyImageAction=Generate Dummy Image")
50 | public final class GenerateDummyImageAction implements ActionListener {
51 |
52 | private static final Logger LOGGER = Logger.getLogger(GenerateDummyImageAction.class.getName());
53 | private final DataObject context;
54 |
55 | public GenerateDummyImageAction(DataObject context) {
56 | this.context = context;
57 | }
58 | @NbBundle.Messages({
59 | "# {0} - file name",
60 | "GenerateDummyImageAction.File.Exists.Warning=File({0}) already exisits.",
61 | "GenerateDummyImageAction.File.Exists.Title=Warning"
62 | })
63 | @Override
64 | public void actionPerformed(ActionEvent ev) {
65 | FileObject directory = context.getPrimaryFile();
66 | if (directory == null) {
67 | return;
68 | }
69 |
70 | // panel
71 | DummyImagePanel panel = DummyImagePanel.getDefault();
72 | DialogDescriptor descriptor = panel.showDialog();
73 |
74 | if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
75 | int width = panel.getImageWidth();
76 | int height = panel.getImageHeight();
77 |
78 | BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
79 |
80 | // color
81 | Color color = panel.getColor();
82 | int alpha = (int) (255 * panel.getOpacity() * 0.01);
83 | color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
84 | Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
85 |
86 | // draw rectangular
87 | graphics.setColor(color);
88 | graphics.fillRect(0, 0, width, height);
89 |
90 | // draw size
91 | graphics.setColor(Color.decode("0xffffff")); // NOI18N
92 | graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
93 | Font font = new Font(Font.SANS_SERIF, Font.BOLD, getDrawStringFontSize(height));
94 | graphics.setFont(font);
95 | drawSize(width, height, font, graphics);
96 |
97 | graphics.dispose();
98 |
99 | // get file
100 | String fileNameWithExt = panel.getFileNameWithExt();
101 | FileObject fileObject = directory.getFileObject(fileNameWithExt);
102 |
103 | if (fileObject != null && !panel.isOverwrite()) {
104 | // show dialog
105 | showWarningDialog(fileNameWithExt);
106 | LOGGER.log(Level.WARNING, Bundle.GenerateDummyImageAction_File_Exists_Warning(fileNameWithExt));
107 | return;
108 | }
109 |
110 | try {
111 | // write
112 | FileObject createData = FileUtil.createData(directory, fileNameWithExt);
113 | ImageIO.write(bufferedImage, panel.getFormat(), FileUtil.toFile(createData));
114 | } catch (IOException ex) {
115 | Exceptions.printStackTrace(ex);
116 | }
117 | }
118 | }
119 |
120 | private int getDrawStringFontSize(int height) {
121 | int size = 15;
122 | if (height >= 600) {
123 | size = 30;
124 | } else if (height >= 300) {
125 | size = 20;
126 | }
127 | return size;
128 | }
129 |
130 | private void drawSize(int width, int height, Font font, Graphics2D graphics) {
131 | String drawString = width + " x " + height; // NOI18N
132 |
133 | Rectangle2D rectangle = font.getStringBounds(drawString, graphics.getFontRenderContext());
134 | int drawStringWidth = (int) rectangle.getWidth();
135 | int drawStringHeight = (int) rectangle.getHeight();
136 | if (width > drawStringWidth && height > drawStringHeight) {
137 | int prefferedWidth = (width - drawStringWidth) / 2;
138 | int prefferedHeight = height / 2;
139 | graphics.drawString(drawString, prefferedWidth, prefferedHeight);
140 | }
141 | }
142 |
143 | private void showWarningDialog(String fileNameWithExt) {
144 | NotifyDescriptor.Message message = new NotifyDescriptor.Message(
145 | Bundle.GenerateDummyImageAction_File_Exists_Warning(fileNameWithExt),
146 | NotifyDescriptor.WARNING_MESSAGE);
147 | Object response = DialogDisplayer.getDefault().notify(message);
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/SmartDeleteAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import com.junichi11.netbeans.php.enhancements.utils.DocUtils;
19 | import java.awt.event.ActionEvent;
20 | import java.awt.event.ActionListener;
21 | import java.util.Arrays;
22 | import java.util.HashSet;
23 | import java.util.Set;
24 | import javax.swing.text.AbstractDocument;
25 | import javax.swing.text.BadLocationException;
26 | import javax.swing.text.Document;
27 | import javax.swing.text.JTextComponent;
28 | import org.netbeans.api.annotations.common.CheckForNull;
29 | import org.netbeans.api.editor.EditorRegistry;
30 | import org.netbeans.api.html.lexer.HTMLTokenId;
31 | import org.netbeans.api.lexer.Token;
32 | import org.netbeans.api.lexer.TokenHierarchy;
33 | import org.netbeans.api.lexer.TokenId;
34 | import org.netbeans.api.lexer.TokenSequence;
35 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
36 | import org.openide.awt.ActionID;
37 | import org.openide.awt.ActionReference;
38 | import org.openide.awt.ActionRegistration;
39 | import org.openide.cookies.EditorCookie;
40 | import org.openide.util.Exceptions;
41 | import org.openide.util.NbBundle.Messages;
42 |
43 | @ActionID(
44 | category = "PHP",
45 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.SmartDeleteAction")
46 | @ActionRegistration(
47 | displayName = "#CTL_SmartDeleteAction")
48 | @ActionReference(path = "Shortcuts", name = "DS-BACK_SPACE")
49 | @Messages("CTL_SmartDeleteAction=Smart Delete")
50 | public final class SmartDeleteAction implements ActionListener {
51 |
52 | private final EditorCookie context;
53 | private static final Set extends TokenId> AVAILABLEIDS = new HashSet<>(Arrays.asList(
54 | PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING,
55 | PHPTokenId.PHP_VARIABLE,
56 | PHPTokenId.PHP_STRING,
57 | HTMLTokenId.VALUE));
58 |
59 | public SmartDeleteAction(EditorCookie context) {
60 | this.context = context;
61 | }
62 |
63 | @Override
64 | public void actionPerformed(ActionEvent ev) {
65 | JTextComponent editor = EditorRegistry.lastFocusedComponent();
66 | if (editor == null) {
67 | return;
68 | }
69 |
70 | Document document = editor.getDocument();
71 | if (document == null) {
72 | return;
73 | }
74 |
75 | // caret position is end of token
76 | // i.e. if it is start of next token, string is not removed.
77 | // so, caret position - 1
78 | // e.g. $something[caret is here]
79 | int offset = editor.getCaretPosition() - 1;
80 | if (offset < 0) {
81 | offset = 0;
82 | }
83 | // get token sequence
84 | TokenSequence extends TokenId> ts = getTokenSequence(document, offset);
85 | if (ts == null) {
86 | return;
87 | }
88 |
89 | Token extends TokenId> token = ts.token();
90 | TokenId id = token.id();
91 | String primaryCategory = id.primaryCategory();
92 | boolean isString = primaryCategory.equals("string"); // NOI18N
93 | if (!AVAILABLEIDS.contains(id) && !isString) {
94 | return;
95 | }
96 | String text = token.text().toString();
97 | int startOffset = ts.offset() + 1;
98 | int removeLength = 0;
99 | int textLength = text.length();
100 | // string
101 | // "something" or 'something' -> "" or ''
102 | if (isString || id == HTMLTokenId.VALUE) {
103 | if (wrapWith(text, "\"") || wrapWith(text, "'")) { // NOI18N
104 | if (textLength <= 2) {
105 | // "" or ''
106 | removeLength = textLength;
107 | startOffset = ts.offset();
108 | } else {
109 | removeLength = textLength - 2;
110 | }
111 | } else {
112 | removeLength = textLength;
113 | startOffset = ts.offset();
114 | }
115 | }
116 |
117 | // variable
118 | // $something -> $
119 | if (id == PHPTokenId.PHP_VARIABLE) {
120 | removeLength = textLength - 1;
121 | }
122 |
123 | // php string
124 | // e.g. DEFINE
125 | if (id == PHPTokenId.PHP_STRING) {
126 | startOffset = ts.offset();
127 | removeLength = textLength;
128 | }
129 |
130 | try {
131 | // remove string
132 | DocUtils.remove(startOffset, removeLength, document);
133 | } catch (BadLocationException ex) {
134 | Exceptions.printStackTrace(ex);
135 | }
136 | }
137 |
138 | private boolean wrapWith(String target, String wrapString) {
139 | return target.startsWith(wrapString) && target.endsWith(wrapString);
140 | }
141 |
142 | @CheckForNull
143 | private TokenSequence extends TokenId> getTokenSequence(Document document, int offset) {
144 | AbstractDocument ad = (AbstractDocument) document;
145 | ad.readLock();
146 | TokenSequence extends TokenId> tokenSequence;
147 | try {
148 | TokenHierarchy th = TokenHierarchy.get(document);
149 | if (th == null) {
150 | return null;
151 | }
152 | tokenSequence = th.tokenSequence();
153 | } finally {
154 | ad.readUnlock();
155 | }
156 | if (tokenSequence == null) {
157 | return null;
158 | }
159 | tokenSequence.move(offset);
160 | tokenSequence.moveNext();
161 |
162 | while (tokenSequence.embedded() != null) {
163 | tokenSequence = tokenSequence.embedded();
164 | tokenSequence.move(offset);
165 | tokenSequence.moveNext();
166 | }
167 | return tokenSequence;
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/utils/DocUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.utils;
17 |
18 | import javax.swing.text.BadLocationException;
19 | import javax.swing.text.Document;
20 |
21 | /**
22 | *
23 | * @author junichi11
24 | */
25 | public final class DocUtils {
26 |
27 | private DocUtils() {
28 | }
29 |
30 | public static void remove(int startOffset, int removeLength, Document document) throws BadLocationException {
31 | if (startOffset > 0 && removeLength > 0) {
32 | document.remove(startOffset, removeLength);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/utils/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.utils;
17 |
18 | import javax.swing.text.AbstractDocument;
19 | import javax.swing.text.Document;
20 | import javax.swing.text.JTextComponent;
21 | import org.netbeans.api.lexer.TokenSequence;
22 | import org.netbeans.modules.editor.NbEditorUtilities;
23 | import org.netbeans.modules.php.editor.lexer.LexUtilities;
24 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
25 |
26 | /**
27 | *
28 | * @author junichi11
29 | */
30 | public final class Utils {
31 |
32 | public static final String PHP_MIME_TYPE = "text/x-php5"; // NOI18N
33 | public static final String HTML_MIME_TYPE = "text/html"; // NOI18N
34 |
35 | private Utils() {
36 | }
37 |
38 | public static boolean isPHP(JTextComponent editor) {
39 | String mimeType = NbEditorUtilities.getMimeType(editor);
40 | if (mimeType == null || mimeType.isEmpty()) {
41 | return false;
42 | }
43 | return PHP_MIME_TYPE.equals(mimeType);
44 | }
45 |
46 | public static boolean isPHP(Document document) {
47 | return NbEditorUtilities.getMimeType(document).equals(PHP_MIME_TYPE);
48 | }
49 |
50 | public static boolean isHtml(JTextComponent editor) {
51 | String mimeType = NbEditorUtilities.getMimeType(editor);
52 | if (mimeType == null || mimeType.isEmpty()) {
53 | return false;
54 | }
55 | return HTML_MIME_TYPE.equals(mimeType);
56 | }
57 |
58 | public static TokenSequence getTokenSequence(Document document, int offset) {
59 | TokenSequence ts = null;
60 | AbstractDocument ad = (AbstractDocument) document;
61 | ad.readLock();
62 | try {
63 | ts = LexUtilities.getPHPTokenSequence(document, offset);
64 | } finally {
65 | ad.readUnlock();
66 | }
67 | return ts;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/test/unit/data/ArraySyntaxCastTest.php:
--------------------------------------------------------------------------------
1 |
4 |
5 | // expected
6 |
--------------------------------------------------------------------------------
/test/unit/data/ArraySyntaxIssue4Test.php:
--------------------------------------------------------------------------------
1 | selects=array("COUNT(DISTINCT $column)");
3 | ?>
4 |
5 | // expected
6 | selects=["COUNT(DISTINCT $column)"];
8 | ?>
--------------------------------------------------------------------------------
/test/unit/data/ArraySyntaxTest.php:
--------------------------------------------------------------------------------
1 | array(
4 | getMessage(array("test" => "array"))),
5 | "test" => array("test",
6 | array(getMessage(getMessage2()), array("array"))
7 | )
8 | ),
9 | );
10 | ?>
11 |
12 | // expected
13 | [
16 | getMessage(["test" => "array"])],
17 | "test" => ["test",
18 | [getMessage(getMessage2()), ["array"]]
19 | ]
20 | ],
21 | ];
22 | ?>
--------------------------------------------------------------------------------
/test/unit/data/ArraySyntaxTypeTest.php:
--------------------------------------------------------------------------------
1 |
4 |
5 | // expected
6 |
--------------------------------------------------------------------------------
/test/unit/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToPhpShortArraySyntaxActionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import javax.swing.text.BadLocationException;
21 | import javax.swing.text.DefaultStyledDocument;
22 | import org.junit.After;
23 | import org.junit.AfterClass;
24 | import org.junit.Before;
25 | import org.junit.BeforeClass;
26 | import org.junit.Test;
27 | import org.netbeans.api.lexer.Language;
28 | import org.netbeans.junit.NbTestCase;
29 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
30 | import org.openide.filesystems.FileObject;
31 | import org.openide.filesystems.FileUtil;
32 |
33 | /**
34 | *
35 | * @author junichi11
36 | */
37 | public class ConvertToPhpShortArraySyntaxActionTest extends NbTestCase {
38 |
39 | private FileObject testFile;
40 | private final StringBuilder expected = new StringBuilder();
41 | private final StringBuilder target = new StringBuilder();
42 |
43 | public ConvertToPhpShortArraySyntaxActionTest(String name) {
44 | super(name);
45 | }
46 |
47 | @BeforeClass
48 | public static void setUpClass() {
49 | }
50 |
51 | @AfterClass
52 | public static void tearDownClass() {
53 | }
54 |
55 | @Before
56 | @Override
57 | public void setUp() {
58 | }
59 |
60 | @After
61 | @Override
62 | public void tearDown() {
63 | target.setLength(0);
64 | expected.setLength(0);
65 | testFile = null;
66 | }
67 |
68 | /**
69 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
70 | *
71 | * @throws javax.swing.text.BadLocationException
72 | * @throws java.io.IOException
73 | */
74 | @Test
75 | public void testConvert() throws BadLocationException, IOException {
76 | testFile("ArraySyntaxTest.php");
77 | }
78 |
79 | /**
80 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
81 | *
82 | * @throws javax.swing.text.BadLocationException
83 | * @throws java.io.IOException
84 | */
85 | @Test
86 | public void testConvertArrayCast() throws BadLocationException, IOException {
87 | testFile("ArraySyntaxCastTest.php");
88 | }
89 |
90 | /**
91 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
92 | *
93 | * @throws javax.swing.text.BadLocationException
94 | * @throws java.io.IOException
95 | */
96 | @Test
97 | public void testConvertArrayType() throws BadLocationException, IOException {
98 | testFile("ArraySyntaxTypeTest.php");
99 | }
100 |
101 | /**
102 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
103 | *
104 | * @throws javax.swing.text.BadLocationException
105 | * @throws java.io.IOException
106 | * @see https://github.com/junichi11/netbeans-php-enhancements/issues/4
107 | */
108 | @Test
109 | public void testIssue4() throws BadLocationException, IOException {
110 | testFile("ArraySyntaxIssue4Test.php");
111 | }
112 |
113 | private void testFile(String fileName) throws IOException, BadLocationException {
114 | File dataDir = getDataDir();
115 | testFile = FileUtil.toFileObject(new File(dataDir, fileName));
116 | boolean isExpected = false;
117 | for (String line : testFile.asLines("UTF-8")) {
118 | if (line.isEmpty()) {
119 | continue;
120 | }
121 | if (line.startsWith("// expected")) {
122 | isExpected = true;
123 | continue;
124 | }
125 | if (isExpected) {
126 | expected.append(line).append("\n");
127 | } else {
128 | target.append(line).append("\n");
129 | }
130 | }
131 |
132 | DefaultStyledDocument document = new DefaultStyledDocument();
133 | document.putProperty(Language.class, PHPTokenId.language());
134 | document.insertString(0, target.toString(), null);
135 | ConvertToPhpShortArraySyntaxAction instance = new ConvertToPhpShortArraySyntaxAction(null);
136 | instance.convert(document);
137 | assertEquals(expected.toString(), document.getText(0, document.getLength()));
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------