@@ -379,33 +379,38 @@ private void UpdateMenuItems()
379379 refactorContextMenu . MoveMenuItem . Enabled = false ;
380380 this . surroundContextMenu . Enabled = false ;
381381 this . refactorMainMenu . SurroundMenu . Enabled = false ;
382- this . refactorContextMenu . ExtractMethodMenuItem . Enabled = false ;
383- this . refactorContextMenu . ExtractLocalVariableMenuItem . Enabled = false ;
384382 this . refactorMainMenu . ExtractMethodMenuItem . Enabled = false ;
383+ this . refactorContextMenu . ExtractMethodMenuItem . Enabled = false ;
385384 this . refactorMainMenu . ExtractLocalVariableMenuItem . Enabled = false ;
385+ this . refactorContextMenu . ExtractLocalVariableMenuItem . Enabled = false ;
386386 ITabbedDocument document = PluginBase . MainForm . CurrentDocument ;
387387 if ( document != null && document . IsEditable && langIsValid )
388388 {
389389 bool isValidFile = IsValidFile ( document . FileName ) ;
390390 refactorMainMenu . MoveMenuItem . Enabled = isValidFile ;
391391 refactorContextMenu . MoveMenuItem . Enabled = isValidFile ;
392- if ( document . SciControl . SelTextSize > 1 )
392+ var sci = document . SciControl ;
393+ if ( sci . SelTextSize > 0 )
393394 {
394- Int32 selEnd = document . SciControl . SelectionEnd ;
395- Int32 selStart = document . SciControl . SelectionStart ;
396- if ( ! document . SciControl . PositionIsOnComment ( selEnd ) || ! document . SciControl . PositionIsOnComment ( selStart ) )
395+ if ( ! sci . PositionIsOnComment ( sci . SelectionStart ) || ! sci . PositionIsOnComment ( sci . SelectionEnd ) )
397396 {
398397 this . surroundContextMenu . Enabled = true ;
399398 this . refactorMainMenu . SurroundMenu . Enabled = true ;
400- this . refactorContextMenu . ExtractMethodMenuItem . Enabled = true ;
401399 this . refactorMainMenu . ExtractMethodMenuItem . Enabled = true ;
402- this . refactorContextMenu . ExtractLocalVariableMenuItem . Enabled = true ;
400+ this . refactorContextMenu . ExtractMethodMenuItem . Enabled = true ;
401+ }
402+ var declAtSelStart = context . GetDeclarationAtLine ( sci . LineFromPosition ( sci . SelectionStart ) ) ;
403+ var declAtSelEnd = context . GetDeclarationAtLine ( sci . LineFromPosition ( sci . SelectionEnd ) ) ;
404+ if ( declAtSelStart != null && declAtSelStart . Member != null && ( declAtSelStart . Member . Flags & FlagType . Function ) > 0
405+ && declAtSelEnd != null && declAtSelStart . Member . Equals ( declAtSelEnd . Member ) )
406+ {
403407 this . refactorMainMenu . ExtractLocalVariableMenuItem . Enabled = true ;
408+ this . refactorContextMenu . ExtractLocalVariableMenuItem . Enabled = true ;
404409 }
405410 }
406411 }
407- this . refactorContextMenu . CodeGeneratorMenuItem . Enabled = isValid ;
408412 this . refactorMainMenu . CodeGeneratorMenuItem . Enabled = isValid ;
413+ this . refactorContextMenu . CodeGeneratorMenuItem . Enabled = isValid ;
409414 }
410415 catch { }
411416 }
0 commit comments