You've already forked lazarus-ccr
LazEdit: disable HTML-actions if editor is not Html.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7254 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -45,7 +45,7 @@ uses
|
|||||||
LCLProc, Menus, ActnList, ClipBrd, LclIntf,
|
LCLProc, Menus, ActnList, ClipBrd, LclIntf,
|
||||||
LazFileUtils, LazUtf8,
|
LazFileUtils, LazUtf8,
|
||||||
LMessages, {for overridden IsShortCut}
|
LMessages, {for overridden IsShortCut}
|
||||||
SynEdit, SynEditTypes,
|
SynEdit, SynEditTypes, SynHighLighterHtml {because we need the type TSynHTMLSyn in code somewhere},
|
||||||
EditorPageControl,
|
EditorPageControl,
|
||||||
lazedit_config, HtmlCode, HtmlDialogs, lazedit_constants,
|
lazedit_config, HtmlCode, HtmlDialogs, lazedit_constants,
|
||||||
lazedit_translations, lazedit_about, mrulists;
|
lazedit_translations, lazedit_about, mrulists;
|
||||||
@ -454,7 +454,7 @@ type
|
|||||||
procedure GatherAppOptions(var Options: TLazEditOptions);
|
procedure GatherAppOptions(var Options: TLazEditOptions);
|
||||||
|
|
||||||
procedure TagMenuItemsAndActions;
|
procedure TagMenuItemsAndActions;
|
||||||
procedure UpdateMenuItems;
|
procedure UpdateMenuItemsAndActions;
|
||||||
procedure CreateMruMenuItemsArray;
|
procedure CreateMruMenuItemsArray;
|
||||||
function TryHlMenuTagToFileType(ATag: PtrInt; out AFileType: TEditorFileType): Boolean;
|
function TryHlMenuTagToFileType(ATag: PtrInt; out AFileType: TEditorFileType): Boolean;
|
||||||
function TryLangMenuTagToLangId(ATag: PtrInt; out ALangId: TLanguageIds): Boolean;
|
function TryLangMenuTagToLangId(ATag: PtrInt; out ALangId: TLanguageIds): Boolean;
|
||||||
@ -523,6 +523,7 @@ type
|
|||||||
|
|
||||||
//NoteBook and Editor Events
|
//NoteBook and Editor Events
|
||||||
procedure OnEditorStatusChange(Sender: TObject; Changes: TSynStatusChanges);
|
procedure OnEditorStatusChange(Sender: TObject; Changes: TSynStatusChanges);
|
||||||
|
procedure OnPageChange(Sender: TObject);
|
||||||
procedure OnBeforeCloseEditor(Sender: TTabSheet; var Cancel: Boolean);
|
procedure OnBeforeCloseEditor(Sender: TTabSheet; var Cancel: Boolean);
|
||||||
procedure OnCharsetChange(Sender: TEditor; const OldCharset, NewCharset: String; const LineNr: Integer);
|
procedure OnCharsetChange(Sender: TEditor; const OldCharset, NewCharset: String; const LineNr: Integer);
|
||||||
procedure OnMruListChange(Sender: TObject);
|
procedure OnMruListChange(Sender: TObject);
|
||||||
@ -546,11 +547,13 @@ const pXY = 0; //Panels constanten
|
|||||||
pIns = 2;
|
pIns = 2;
|
||||||
pName = 3;
|
pName = 3;
|
||||||
|
|
||||||
|
//Initial text for FileNew commands+ //High(Tag) = 7FFFFFFF [01111111111111111111111111111111]
|
||||||
|
// 1 shl (8+0..15) used for Highlighter menu
|
||||||
tgNeedsEditor = $01;
|
tgNeedsEditor = $01;
|
||||||
tgNeedsSelection = $02;
|
tgNeedsSelection = $02;
|
||||||
tgNeedsClipPaste = $04;
|
tgNeedsClipPaste = $04;
|
||||||
|
tgHtmlOnly = (1 shl 3) or tgNeedsEditor;
|
||||||
|
|
||||||
//Initial text for FileNew commands
|
|
||||||
itXml = '<?xml version="1.0"?>';
|
itXml = '<?xml version="1.0"?>';
|
||||||
itBat = '@echo off';
|
itBat = '@echo off';
|
||||||
itUnixShellScript = '#!/bin/bash';
|
itUnixShellScript = '#!/bin/bash';
|
||||||
@ -741,7 +744,7 @@ end;
|
|||||||
|
|
||||||
procedure TLazEditMainForm.TopLevelMenuClick(Sender: TObject);
|
procedure TLazEditMainForm.TopLevelMenuClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
UpdateMenuItems;
|
UpdateMenuItemsAndActions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazEditMainForm.mnuEditCutClick(Sender: TObject);
|
procedure TLazEditMainForm.mnuEditCutClick(Sender: TObject);
|
||||||
@ -1146,6 +1149,7 @@ begin
|
|||||||
NoteBook.OnStatusChange := @OnEditorStatusChange;
|
NoteBook.OnStatusChange := @OnEditorStatusChange;
|
||||||
NoteBook.OnBeforeCloseEditor := @OnBeforeCloseEditor;
|
NoteBook.OnBeforeCloseEditor := @OnBeforeCloseEditor;
|
||||||
NoteBook.OnEditorCharsetChange := @OnCharsetChange;
|
NoteBook.OnEditorCharsetChange := @OnCharsetChange;
|
||||||
|
NoteBook.OnChange := @OnPageChange;
|
||||||
NoteBook.EditorPopUpMenu := EditorPopupMenu;
|
NoteBook.EditorPopUpMenu := EditorPopupMenu;
|
||||||
|
|
||||||
//Creating dialogs
|
//Creating dialogs
|
||||||
@ -1720,13 +1724,14 @@ begin
|
|||||||
if (C is TAction) or (C is TMenuItem) then
|
if (C is TAction) or (C is TMenuItem) then
|
||||||
begin
|
begin
|
||||||
C.Tag := 0; //initialize all Tags to 0
|
C.Tag := 0; //initialize all Tags to 0
|
||||||
//Things that need an open editor
|
//Things that need an open editor and maybe OnlyHtml
|
||||||
if Pos('LAYOUT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('LAYOUT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgHtmlOnly;
|
||||||
|
if Pos('INSERT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgHtmlOnly;
|
||||||
if Pos('EDIT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('EDIT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
||||||
if Pos('INSERT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('INSERT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
||||||
if Pos('FILESAVE',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('FILESAVE',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
||||||
if Pos('CURRENT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('CURRENT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
||||||
if Pos('GROUPING',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('GROUPING',UpperCase(N)) > 0 then C.Tag := C.Tag or tgHtmlOnly;
|
||||||
if Pos('HIGHLIGHTER',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('HIGHLIGHTER',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
||||||
if Pos('FONT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('FONT',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
||||||
if Pos('VIEWHL',UpperCase(N)) > 0 then
|
if Pos('VIEWHL',UpperCase(N)) > 0 then
|
||||||
@ -1766,6 +1771,8 @@ begin
|
|||||||
//needs to be _after_ 'OPEN'
|
//needs to be _after_ 'OPEN'
|
||||||
if Pos('BROWSER',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
if Pos('BROWSER',UpperCase(N)) > 0 then C.Tag := C.Tag or tgNeedsEditor;
|
||||||
end;
|
end;
|
||||||
|
mnuFileOpenInBrowser.Tag := tgHtmlOnly;
|
||||||
|
|
||||||
//Top level menus
|
//Top level menus
|
||||||
mnuFile.Tag := 0;
|
mnuFile.Tag := 0;
|
||||||
mnuEdit.Tag := 0;
|
mnuEdit.Tag := 0;
|
||||||
@ -1773,6 +1780,7 @@ begin
|
|||||||
mnuGrouping.Tag := 0;
|
mnuGrouping.Tag := 0;
|
||||||
mnuView.Tag := 0;
|
mnuView.Tag := 0;
|
||||||
mnuAbout.Tag := 0;
|
mnuAbout.Tag := 0;
|
||||||
|
mnuLayout.Tag := 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
if (C is TMenuItem) or (C is TAction) then
|
if (C is TMenuItem) or (C is TAction) then
|
||||||
@ -1788,12 +1796,12 @@ begin
|
|||||||
acEditCopy.Caption := 'Kopiëren';
|
acEditCopy.Caption := 'Kopiëren';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazEditMainForm.UpdateMenuItems;
|
procedure TLazEditMainForm.UpdateMenuItemsAndActions;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
C: TComponent;
|
C: TComponent;
|
||||||
HasEditor, HasSelection, HasClipPaste: Boolean;
|
HasEditor, HasSelection, HasClipPaste: Boolean;
|
||||||
NeedsEditor, NeedsSelection, NeedsClipPaste: Boolean;
|
NeedsEditor, NeedsSelection, NeedsClipPaste, HtmlOnly, DoEnable: Boolean;
|
||||||
AFileType: TEditorFileType;
|
AFileType: TEditorFileType;
|
||||||
Ed: TEditor;
|
Ed: TEditor;
|
||||||
begin
|
begin
|
||||||
@ -1804,14 +1812,20 @@ begin
|
|||||||
for i := 0 to ComponentCount - 1 do
|
for i := 0 to ComponentCount - 1 do
|
||||||
begin
|
begin
|
||||||
C := Components[i];
|
C := Components[i];
|
||||||
if (C is TMenuItem) then
|
if (C is TMenuItem) or (C is TAction) then
|
||||||
begin
|
begin
|
||||||
NeedsEditor := (C.Tag and tgNeedsEditor) > 0;
|
NeedsEditor := (C.Tag and tgNeedsEditor) > 0;
|
||||||
NeedsSelection := (C.Tag and tgNeedsSelection) > 0;
|
NeedsSelection := (C.Tag and tgNeedsSelection) > 0;
|
||||||
NeedsClipPaste := (C.Tag and tgNeedsClipPaste) > 0;
|
NeedsClipPaste := (C.Tag and tgNeedsClipPaste) > 0;
|
||||||
TMenuItem(C).Enabled := ((NeedsEditor and HasEditor) or (not NeedsEditor)) and
|
HtmlOnly := (C.Tag and tgHtmlOnly) = tgHtmlOnly;
|
||||||
((NeedsSelection and HasSelection) or (not NeedsSelection)) and
|
DoEnable := ((NeedsEditor and HasEditor) or (not NeedsEditor)) and
|
||||||
((NeedsClipPaste and HasClipPaste) or (not NeedsClipPaste));
|
((HtmlOnly and HasEditor and ((Ed.FileType=eftHtml) or (Ed.Highlighter is TSynHTMLSyn))) or (not HtmlOnly)) and
|
||||||
|
((NeedsSelection and HasSelection) or (not NeedsSelection)) and
|
||||||
|
((NeedsClipPaste and HasClipPaste) or (not NeedsClipPaste));
|
||||||
|
if (C is TMenuItem) then
|
||||||
|
TMenuItem(C).Enabled := DoEnable
|
||||||
|
else
|
||||||
|
TAction(C).Enabled := DoEnable;
|
||||||
|
|
||||||
if HasEditor and (Pos('MNUVIEWHL', UpperCase(C.Name)) = 1) then
|
if HasEditor and (Pos('MNUVIEWHL', UpperCase(C.Name)) = 1) then
|
||||||
begin
|
begin
|
||||||
@ -1893,6 +1907,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLazEditMainForm.OnPageChange(Sender: TObject);
|
||||||
|
begin
|
||||||
|
UpdateMenuItemsAndActions;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TLazEditMainForm.OnCharsetChange(Sender: TEditor; const OldCharset, NewCharset: String; const LineNr: Integer);
|
procedure TLazEditMainForm.OnCharsetChange(Sender: TEditor; const OldCharset, NewCharset: String; const LineNr: Integer);
|
||||||
begin
|
begin
|
||||||
MessageDlg(Format('Let op: html charset is gewijzigd van %s naar %s'^m'(Regel %d)',[OldCharset, NewCharset, LineNr]),
|
MessageDlg(Format('Let op: html charset is gewijzigd van %s naar %s'^m'(Regel %d)',[OldCharset, NewCharset, LineNr]),
|
||||||
@ -2073,6 +2092,7 @@ begin
|
|||||||
Result := False;
|
Result := False;
|
||||||
//OnEditorStatusChange(nil, scAll);
|
//OnEditorStatusChange(nil, scAll);
|
||||||
end;
|
end;
|
||||||
|
UpdateMenuItemsAndActions;
|
||||||
end
|
end
|
||||||
else Result := False;
|
else Result := False;
|
||||||
end;
|
end;
|
||||||
@ -2095,6 +2115,7 @@ begin
|
|||||||
Result := IoFail;
|
Result := IoFail;
|
||||||
//OnEditorStatusChange(nil, scAll);
|
//OnEditorStatusChange(nil, scAll);
|
||||||
end;
|
end;
|
||||||
|
UpdateMenuItemsAndActions;
|
||||||
end
|
end
|
||||||
else Result := IoFail;
|
else Result := IoFail;
|
||||||
end;
|
end;
|
||||||
@ -2107,6 +2128,8 @@ begin
|
|||||||
|
|
||||||
Idx := NoteBook.ActivePageIndex;
|
Idx := NoteBook.ActivePageIndex;
|
||||||
Result := NoteBook.ClosePage(Idx);
|
Result := NoteBook.ClosePage(Idx);
|
||||||
|
if Result then
|
||||||
|
UpdateMenuItemsAndActions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLazEditMainForm.TryFileSaveAll(out Failures: String): Boolean;
|
function TLazEditMainForm.TryFileSaveAll(out Failures: String): Boolean;
|
||||||
@ -2237,6 +2260,7 @@ begin
|
|||||||
Ed.TextBetweenPoints[Point(0,0),Point(0,0)] := InitialText
|
Ed.TextBetweenPoints[Point(0,0),Point(0,0)] := InitialText
|
||||||
else
|
else
|
||||||
Ed.Modified := False;
|
Ed.Modified := False;
|
||||||
|
UpdateMenuItemsAndActions;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user