@@ -101,11 +101,14 @@ public class DebugStatusLineElement implements StatusLineElementProvider {
101101 private static final String DEBUG_FALSE = "false" ; // NOI18N
102102 private static final String WP_DEBUG_FORMAT = "define('WP_DEBUG', %s);" ; // NOI18N
103103 private static final String DEBUG_REGEX = "^define\\ (\\ s*'WP_DEBUG',\\ s*(true|false)\\ s*\\ );$" ; // NOI18N
104+ private static final String VERSION_REGEX = "^\\ $wp_version\\ s*=\\ s*'(.+)';$" ; // NOI18N
104105 private static final Map <String , String > debugLevel = new HashMap <String , String >();
105106 private static final String WP_CONFIG_PHP = "wp-config.php" ; // NOI18N
107+ private static final String WP_VERSION_PHP = "wp-includes/version.php" ; // NOI18N
106108 private final ImageIcon icon = ImageUtilities .loadImageIcon (WordPress .WP_ICON_16 , true );
107109 private final Lookup .Result <FileObject > result ;
108110 private final JLabel debugLabel = new JLabel ("" ); // NOI18N
111+ private final JLabel versionLabel = new JLabel ("" ); // NOI18N
109112 private final DefaultListModel model ;
110113 private PhpModule phpModule ;
111114 private JList list ;
@@ -137,7 +140,7 @@ public void mouseClicked(MouseEvent e) {
137140 int x = Math .min (labelStart .x , labelStart .x + debugLabel .getSize ().width - list .getPreferredSize ().width );
138141 int y = labelStart .y - list .getPreferredSize ().height ;
139142 if (popup == null ) {
140- popup = PopupFactory .getSharedInstance ().getPopup (debugLabel , list , x + 16 , y );
143+ popup = PopupFactory .getSharedInstance ().getPopup (debugLabel , list , x , y );
141144 }
142145 list .addListSelectionListener (new ListSelectionListener () {
143146 @ Override
@@ -234,10 +237,37 @@ private Component panelWithSeparator(JLabel cell) {
234237
235238 JPanel panel = new JPanel (new BorderLayout ());
236239 panel .add (separator , BorderLayout .WEST );
237- panel .add (cell );
240+ panel .add (versionLabel , BorderLayout .CENTER );
241+ panel .add (cell , BorderLayout .EAST );
238242 return panel ;
239243 }
240244
245+ /**
246+ * Get WordPress version
247+ *
248+ * @param version version.php
249+ * @return version
250+ */
251+ public String getVersion (FileObject version ) {
252+ String versionNumber = "" ; // NOI18N
253+ Pattern pattern = Pattern .compile (VERSION_REGEX );
254+
255+ try {
256+ List <String > lines = version .asLines ();
257+ for (String line : lines ) {
258+ Matcher matcher = pattern .matcher (line );
259+ if (matcher .find ()) {
260+ versionNumber = matcher .group (1 );
261+ break ;
262+ }
263+ }
264+ } catch (IOException ex ) {
265+ Exceptions .printStackTrace (ex );
266+ }
267+
268+ return versionNumber ;
269+ }
270+
241271 /**
242272 * Get debug level
243273 *
@@ -275,15 +305,25 @@ private void setDebugLevelLabel(String debugLv) {
275305 } else {
276306 debugLabel .setText (debugLv );
277307 }
278- debugLabel .setIcon (icon );
308+ }
309+
310+ /**
311+ * Set version versionLv.
312+ *
313+ * @param versionNumber
314+ */
315+ private void setVersionLabel (String versionNumber ) {
316+ versionLabel .setText (versionNumber );
317+ versionLabel .setIcon (icon );
279318 }
280319
281320 /**
282321 * Clear debug label
283322 */
284323 private void clearLabel () {
285324 debugLabel .setText ("" ); //NOI18N
286- debugLabel .setIcon (null );
325+ versionLabel .setText ("" ); // NOI18N
326+ versionLabel .setIcon (null );
287327 }
288328
289329 public void setLevel (String level ) {
@@ -364,7 +404,16 @@ public void resultChanged(LookupEvent lookupEvent) {
364404
365405 String level = getDebugLevel (config );
366406 setLevel (level );
407+ list .setSelectedValue (level , true );
367408 setDebugLevelLabel (level );
409+
410+ // version
411+ FileObject version = WPFileUtils .getDirectory (phpModule , WP_VERSION_PHP );
412+ String versionNumber = "" ; // NOI18N
413+ if (version != null ) {
414+ versionNumber = getVersion (version ) + ":" ; // NOI18N
415+ }
416+ setVersionLabel (versionNumber );
368417 }
369418
370419 private void removeFileChangeListenerForConfig (PhpModule pm ) {
0 commit comments