IDE: edit menus are now disabled if no selection available

git-svn-id: trunk@9533 -
This commit is contained in:
mattias 2006-07-01 10:24:17 +00:00
parent 051d30d599
commit 4052ced3e3
5 changed files with 135 additions and 53 deletions

View File

@ -1,19 +1,18 @@
object EncloseSelectionDialog: TEncloseSelectionDialog
Caption = 'Enclose Selection'
ClientHeight = 244
ClientWidth = 427
OnCreate = EncloseSelectionDialogCREATE
OnResize = EncloseSelectionDialogResize
PixelsPerInch = 112
Position = poScreenCenter
HorzScrollBar.Page = 426
VertScrollBar.Page = 243
Left = 319
Height = 244
Top = 231
Width = 427
HorzScrollBar.Page = 426
VertScrollBar.Page = 243
Caption = 'Enclose Selection'
OnCreate = EncloseSelectionDialogCREATE
OnResize = EncloseSelectionDialogResize
Position = poScreenCenter
object TypeRadiogroup: TRadioGroup
Left = 8
Height = 189
Top = 8
Width = 409
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFill = True
Caption = 'Type'
@ -26,29 +25,31 @@ object EncloseSelectionDialog: TEncloseSelectionDialog
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
TabOrder = 0
Left = 8
Height = 189
Top = 8
Width = 409
end
object btnOk: TButton
Anchors = [akLeft, akBottom]
Caption = 'Ok'
Default = True
OnClick = btnOkClick
TabOrder = 1
Left = 88
Height = 25
Top = 208
Width = 107
Anchors = [akLeft, akBottom]
BorderSpacing.InnerBorder = 2
Caption = 'Ok'
Default = True
ModalResult = 1
TabOrder = 1
end
object btnCancel: TButton
Left = 224
Height = 25
Top = 208
Width = 104
Anchors = [akLeft, akBottom]
BorderSpacing.InnerBorder = 2
Cancel = True
Caption = 'Cancel'
ModalResult = 2
TabOrder = 2
Left = 224
Height = 25
Top = 208
Width = 104
end
end

View File

@ -1,23 +1,23 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TEncloseSelectionDialog','FORMDATA',[
'TPF0'#23'TEncloseSelectionDialog'#22'EncloseSelectionDialog'#4'Left'#3'?'#1#6
+'Height'#3#244#0#3'Top'#3#231#0#5'Width'#3#171#1#18'HorzScrollBar.Page'#3#170
+#1#18'VertScrollBar.Page'#3#243#0#7'Caption'#6#17'Enclose Selection'#8'OnCre'
'TPF0'#23'TEncloseSelectionDialog'#22'EncloseSelectionDialog'#7'Caption'#6#17
+'Enclose Selection'#12'ClientHeight'#3#244#0#11'ClientWidth'#3#171#1#8'OnCre'
+'ate'#7#28'EncloseSelectionDialogCREATE'#8'OnResize'#7#28'EncloseSelectionDi'
+'alogResize'#8'Position'#7#14'poScreenCenter'#0#11'TRadioGroup'#14'TypeRadio'
+'group'#4'Left'#2#8#6'Height'#3#189#0#3'Top'#2#8#5'Width'#3#153#1#7'Anchors'
+#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#8'AutoFill'#9#7'Caption'#6#4
+'Type'#28'ChildSizing.LeftRightSpacing'#2#6#28'ChildSizing.TopBottomSpacing'
+#2#6#29'ChildSizing.EnlargeHorizontal'#7#24'crsHomogenousChildResize'#27'Chi'
+'ldSizing.EnlargeVertical'#7#24'crsHomogenousChildResize'#28'ChildSizing.Shr'
+'inkHorizontal'#7#14'crsScaleChilds'#26'ChildSizing.ShrinkVertical'#7#14'crs'
+'ScaleChilds'#18'ChildSizing.Layout'#7#29'cclLeftToRightThenTopToBottom'#27
+'ChildSizing.ControlsPerLine'#2#1#8'TabOrder'#2#0#0#0#7'TButton'#5'btnOk'#4
+'Left'#2'X'#6'Height'#2#25#3'Top'#3#208#0#5'Width'#2'k'#7'Anchors'#11#6'akLe'
+'ft'#8'akBottom'#0#25'BorderSpacing.InnerBorder'#2#2#7'Caption'#6#2'Ok'#7'De'
+'fault'#9#11'ModalResult'#2#1#8'TabOrder'#2#1#0#0#7'TButton'#9'btnCancel'#4
+'Left'#3#224#0#6'Height'#2#25#3'Top'#3#208#0#5'Width'#2'h'#7'Anchors'#11#6'a'
+'kLeft'#8'akBottom'#0#25'BorderSpacing.InnerBorder'#2#2#6'Cancel'#9#7'Captio'
+'n'#6#6'Cancel'#11'ModalResult'#2#2#8'TabOrder'#2#2#0#0#0
+'alogResize'#13'PixelsPerInch'#2'p'#8'Position'#7#14'poScreenCenter'#18'Horz'
+'ScrollBar.Page'#3#170#1#18'VertScrollBar.Page'#3#243#0#4'Left'#3'?'#1#6'Hei'
+'ght'#3#244#0#3'Top'#3#231#0#5'Width'#3#171#1#0#11'TRadioGroup'#14'TypeRadio'
+'group'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#8'AutoFill'
+#9#7'Caption'#6#4'Type'#28'ChildSizing.LeftRightSpacing'#2#6#28'ChildSizing.'
+'TopBottomSpacing'#2#6#29'ChildSizing.EnlargeHorizontal'#7#24'crsHomogenousC'
+'hildResize'#27'ChildSizing.EnlargeVertical'#7#24'crsHomogenousChildResize'
+#28'ChildSizing.ShrinkHorizontal'#7#14'crsScaleChilds'#26'ChildSizing.Shrink'
+'Vertical'#7#14'crsScaleChilds'#18'ChildSizing.Layout'#7#29'cclLeftToRightTh'
+'enTopToBottom'#27'ChildSizing.ControlsPerLine'#2#1#8'TabOrder'#2#0#4'Left'#2
+#8#6'Height'#3#189#0#3'Top'#2#8#5'Width'#3#153#1#0#0#7'TButton'#5'btnOk'#7'A'
+'nchors'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#2'Ok'#7'Default'#9#7'OnClic'
+'k'#7#10'btnOkClick'#8'TabOrder'#2#1#4'Left'#2'X'#6'Height'#2#25#3'Top'#3#208
+#0#5'Width'#2'k'#0#0#7'TButton'#9'btnCancel'#7'Anchors'#11#6'akLeft'#8'akBot'
+'tom'#0#6'Cancel'#9#7'Caption'#6#6'Cancel'#11'ModalResult'#2#2#8'TabOrder'#2
+#2#4'Left'#3#224#0#6'Height'#2#25#3'Top'#3#208#0#5'Width'#2'h'#0#0#0
]);

View File

@ -59,27 +59,26 @@ type
TypeRadiogroup: TRADIOGROUP;
procedure EncloseSelectionDialogCREATE(Sender: TObject);
procedure EncloseSelectionDialogResize(Sender: TObject);
procedure btnOkClick(Sender: TObject);
private
public
function GetEncloseType: TEncloseSelectionType;
end;
var
EncloseSelectionDialog: TEncloseSelectionDialog;
function EncloseSelectionTypeDescription(TheType: TEncloseSelectionType
): string;
function ShowEncloseSelectionDialog(var TheType: TEncloseSelectionType
): TModalResult;
): TModalResult;
function EncloseSelectionTypeDescription(TheType: TEncloseSelectionType
): string;
procedure GetEncloseSelectionParams(TheType: TEncloseSelectionType;
var Template: string);
var Template: string);
procedure EncloseTextSelection(const Template: string; Source: TStrings;
SelectionStart, SelectionEnd: TPoint;
Indent: integer;
var NewSelection: string; var NewCursor: TPoint);
SelectionStart, SelectionEnd: TPoint;
Indent: integer;
var NewSelection: string; var NewCursor: TPoint);
implementation
function EncloseSelectionTypeDescription(TheType: TEncloseSelectionType
): string;
begin
@ -428,6 +427,12 @@ begin
btnCancel.Width:=btnOk.Width;
end;
procedure TEncloseSelectionDialog.btnOkClick(Sender: TObject);
begin
if TypeRadiogroup.ItemIndex>=0 then
ModalResult:=mrOk;
end;
function TEncloseSelectionDialog.GetEncloseType: TEncloseSelectionType;
var
i: Integer;

View File

@ -138,6 +138,7 @@ type
procedure OnScreenRemoveForm(Sender: TObject; AForm: TCustomForm);
// file menu
procedure mnuFileClicked(Sender: TObject);
procedure mnuNewUnitClicked(Sender: TObject);
procedure mnuNewFormClicked(Sender: TObject);
procedure mnuNewOtherClicked(Sender: TObject);
@ -154,6 +155,7 @@ type
procedure mnuQuitClicked(Sender: TObject);
// edit menu
procedure mnuEditClicked(Sender: TObject);
procedure mnuEditUndoClicked(Sender: TObject);
procedure mnuEditRedoClicked(Sender: TObject);
procedure mnuEditCutClicked(Sender: TObject);
@ -1899,6 +1901,7 @@ procedure TMainIDE.SetupFileMenu;
begin
inherited SetupFileMenu;
with MainIDEBar do begin
mnuFile.OnClick:=@mnuFileClicked;
itmFileNewUnit.OnClick := @mnuNewUnitClicked;
itmFileNewForm.OnClick := @mnuNewFormClicked;
itmFileNewOther.OnClick := @mnuNewOtherClicked;
@ -1922,6 +1925,7 @@ procedure TMainIDE.SetupEditMenu;
begin
inherited SetupEditMenu;
with MainIDEBar do begin
mnuEdit.OnClick:=@mnuEditClicked;
itmEditUndo.OnClick:=@mnuEditUndoClicked;
itmEditRedo.OnClick:=@mnuEditRedoClicked;
itmEditCut.OnClick:=@mnuEditCutClicked;
@ -2872,6 +2876,68 @@ begin
{$ENDIF}
end;
procedure TMainIDE.mnuEditClicked(Sender: TObject);
var
ASrcEdit: TSourceEditor;
AnUnitInfo: TUnitInfo;
Editable: Boolean;
SelAvail: Boolean;
SelEditable: Boolean;
begin
GetCurrentUnit(ASrcEdit,AnUnitInfo);
Editable:=(ASrcEdit<>nil) and (not ASrcEdit.ReadOnly);
SelAvail:=(ASrcEdit<>nil) and (ASrcEdit.SelectionAvailable);
SelEditable:=Editable and SelAvail;
with MainIDEBar do begin
itmEditUndo.Enabled:=Editable;
itmEditRedo.Enabled:=Editable;
//itmEditClipboard: TIDEMenuSection;
itmEditCut.Enabled:=SelEditable;
itmEditCopy.Enabled:=SelAvail;
itmEditPaste.Enabled:=Editable;
//itmEditBlockIndentation: TIDEMenuSection;
itmEditIndentBlock.Enabled:=SelEditable;
itmEditUnindentBlock.Enabled:=SelEditable;
itmEditEncloseBlock.Enabled:=SelEditable;
itmEditCommentBlock.Enabled:=SelEditable;
itmEditUncommentBlock.Enabled:=SelEditable;
itmEditConditionalBlock.Enabled:=SelEditable;
itmEditSortBlock.Enabled:=SelEditable;
//itmEditBlockCharConversion: TIDEMenuSection;
itmEditUpperCaseBlock.Enabled:=SelEditable;
itmEditLowerCaseBlock.Enabled:=SelEditable;
itmEditTabsToSpacesBlock.Enabled:=SelEditable;
itmEditSelectionBreakLines.Enabled:=SelEditable;
//itmEditSelect: TIDEMenuSection;
//itmEditSelectAll: TIDEMenuCommand;
//itmEditSelectToBrace: TIDEMenuCommand;
//itmEditSelectCodeBlock: TIDEMenuCommand;
//itmEditSelectLine: TIDEMenuCommand;
//itmEditSelectParagraph: TIDEMenuCommand;
//itmEditInsertions: TIDEMenuSection;
itmEditInsertCharacter.Enabled:=Editable;
//itmEditInsertText: TIDEMenuSection;
//itmEditInsertCVSKeyWord: TIDEMenuSection;
itmEditInsertCVSAuthor.Enabled:=Editable;
itmEditInsertCVSDate.Enabled:=Editable;
itmEditInsertCVSHeader.Enabled:=Editable;
itmEditInsertCVSID.Enabled:=Editable;
itmEditInsertCVSLog.Enabled:=Editable;
itmEditInsertCVSName.Enabled:=Editable;
itmEditInsertCVSRevision.Enabled:=Editable;
itmEditInsertCVSSource.Enabled:=Editable;
//itmEditInsertGeneral: TIDEMenuSection;
itmEditInsertGPLNotice.Enabled:=Editable;
itmEditInsertLGPLNotice.Enabled:=Editable;
itmEditInsertUsername.Enabled:=Editable;
itmEditInsertDateTime.Enabled:=Editable;
itmEditInsertChangeLogEntry.Enabled:=Editable;
//itmEditMenuCodeTools: TIDEMenuSection;
itmEditCompleteCode.Enabled:=Editable;
itmEditExtractProc.Enabled:=SelEditable;
end;
end;
{------------------------------------------------------------------------------}
procedure TMainIDE.mnuViewInspectorClicked(Sender: TObject);
begin
@ -12130,6 +12196,18 @@ begin
EnvironmentOptions.IDEWindowLayoutList.CloseForm(AForm);
end;
procedure TMainIDE.mnuFileClicked(Sender: TObject);
var
ASrcEdit: TSourceEditor;
AnUnitInfo: TUnitInfo;
begin
GetCurrentUnit(ASrcEdit,AnUnitInfo);
with MainIDEBar do begin
itmFileClose.Enabled := ASrcEdit<>nil;
itmFileCloseAll.Enabled := ASrcEdit<>nil;
end;
end;
function TMainIDE.ProjInspectorAddUnitToProject(Sender: TObject;
AnUnitInfo: TUnitInfo): TModalresult;
var

View File

@ -2232,10 +2232,8 @@ var
NewCaretXY: TPoint;
begin
if ReadOnly then exit;
if not FEditor.SelAvail then begin
FEditor.BlockBegin:=FEditor.LogicalCaretXY;
FEditor.BlockEnd:=FEditor.BlockBegin;
end;
if not FEditor.SelAvail then
exit;
if ShowEncloseSelectionDialog(EncloseType)<>mrOk then exit;
GetEncloseSelectionParams(EncloseType,EncloseTemplate);
EncloseTextSelection(EncloseTemplate,FEditor.Lines,