This commit is contained in:
Basile Burg 2014-07-17 04:47:43 +02:00
parent 2cc2ad3b9d
commit 1f07bdf5aa
6 changed files with 228 additions and 79 deletions

View File

@ -44,6 +44,9 @@
<OverflowChecks Value="True"/>
<StackChecks Value="True"/>
</Checks>
<Optimizations>
<OptimizationLevel Value="0"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>

View File

@ -43,7 +43,7 @@ type
end;
(**
* TProcess with assign() overriden.
* TProcess with assign() 'overriden'.
*)
TProcessEx = class helper for TProcess
public

View File

@ -40,7 +40,6 @@ type
function getEditor(index: NativeInt): TCESynMemo;
function getEditorCount: NativeInt;
function getEditorIndex: NativeInt;
procedure identifierToD2Syn(const aMemo: TCESynMemo);
public
constructor create(aOwner: TComponent); override;
destructor destroy; override;
@ -121,11 +120,6 @@ begin
curr := getCurrentEditor;
macRecorder.Editor := curr;
fSyncEdit.Editor := curr;
if curr <> nil then
begin
identifierToD2Syn(curr);
curr.checkFileDate;
end;
//
if pageControl.ActivePageIndex <> -1 then
mainForm.docFocusedNotify(Self, pageControl.ActivePageIndex);
@ -164,7 +158,10 @@ begin
memo.OnKeyUp := @memoKeyDown;
memo.OnKeyPress := @memoKeyPress;
memo.OnMouseDown := @memoMouseDown;
memo.OnChange := @memoChange;
// http://forum.lazarus.freepascal.org/index.php/topic,25213.0.html
//memo.OnChange := @memoChange;
memo.OnMouseMove := @memoMouseMove;
//
pageControl.ActivePage := sheet;
@ -180,19 +177,11 @@ begin
pageControl.Pages[aIndex].Free;
end;
procedure TCEEditorWidget.identifierToD2Syn(const aMemo: TCESynMemo);
begin
D2Syn.CurrentIdentifier := aMemo.GetWordAtRowCol(aMemo.LogicalCaretXY);
end;
procedure TCEEditorWidget.memoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
UpdateByEvent;
if (sender is TCESynMemo) then
identifierToD2Syn(TCESynMemo(Sender));
case Byte(Key) of
VK_CLEAR,VK_RETURN,VK_BACK : fKeyChanged := true;
//else fKeyChanged := false;
end;
if fKeyChanged then
beginUpdateByDelay;
@ -206,8 +195,6 @@ end;
procedure TCEEditorWidget.memoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (sender is TCESynMemo) then
identifierToD2Syn(TCESynMemo(Sender));
beginUpdateByDelay;
UpdateByEvent;
end;
@ -221,11 +208,7 @@ begin
end;
procedure TCEEditorWidget.memoChange(Sender: TObject);
var
ed: TCESynMemo;
begin
ed := TCESynMemo(sender);
ed.modified := true;
fKeyChanged := true;
beginUpdateByDelay;
UpdateByEvent;

View File

@ -1,13 +1,14 @@
object CEMainForm: TCEMainForm
Left = 1122
Left = 1435
Height = 53
Top = 26
Top = 140
Width = 745
AllowDropFiles = True
Caption = 'Coedit'
ChildSizing.Layout = cclTopToBottomThenLeftToRight
DockSite = True
Menu = mainMenu
OnCloseQuery = FormCloseQuery
OnDropFiles = FormDropFiles
Position = poMainFormCenter
ShowHint = True
@ -818,6 +819,15 @@ object CEMainForm: TCEMainForm
FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00
}
end
object MenuItem56: TMenuItem
Caption = '-'
end
object MenuItem57: TMenuItem
Action = actEdFind
end
object MenuItem58: TMenuItem
Action = actEdFindNext
end
end
object MenuItem14: TMenuItem
Caption = 'Project'
@ -1882,11 +1892,25 @@ object CEMainForm: TCEMainForm
ImageIndex = 21
OnExecute = actProjRunWithArgsExecute
end
object actEdFind: TAction
Category = 'Edit'
Caption = 'Find...'
ImageIndex = 28
OnExecute = actEdFindExecute
ShortCut = 16454
end
object actEdFindNext: TAction
Category = 'Edit'
Caption = 'Find next'
ImageIndex = 28
OnExecute = actEdFindNextExecute
ShortCut = 114
end
end
object imgList: TImageList
left = 64
Bitmap = {
4C691C0000001000000010000000008F4E00008C4AB000965DFF00935AFF0093
4C691D0000001000000010000000008F4E00008C4AB000965DFF00935AFF0093
59FF009359FF009359FF009359FF009359FF00945AFF008743FF008945FF008A
49A8FFFFFF00008F4E00008F4F00008E4E00008A47FF66E2D0FF62DDCAFF62DD
C8FF62DDC8FF62DDC8FF62DDC8FF62DDC8FF62DDC9FF61E0CAFF62DEC8FF3ABA
@ -2782,7 +2806,39 @@ object CEMainForm: TCEMainForm
ABFFB0B0ACFFAFAFABFFAEAEABFFADADABFFAEAEABFFAFAFABFFAFAFACFFB0B0
ADFFA4A4A2C0FFFFFF00FFFFFF00FFFFFF000000002300000033000000330000
0033000000330000003300000033000000330000003300000033000000330000
003300000023FFFFFF00FFFFFF00
003300000023FFFFFF00FFFFFF007B7977007B7977007B7977FF73716FFF6D6B
69FF696665FF625F5EFF615E5D007E7C7A007B7977FF73716FFF6D6B69FF6966
65FF63605FFF64616000646160007B7977007B7977007A7976FF908D8CFF908E
8CFF656461FF615E5DFF615E5D007D7B7900797775FF8E8B8AFF918F8DFF6866
64FF63605FFF64616000646160007B7977007B79770000000033787574FFCBCA
C7FF9B9A99FF625E5DFF625F5E007D7A7900787574FFCAC8C6FF989796FF605D
5CFF0000003364616000646160007B797700797875AE716E6DFF696665FF6460
5FFF625E5DFF545251AA7B7A7700656361006A6967AA6F6C6BFF696665FF6764
63FF656261FF63605FAE646160007C797800787574FFBDBBB9FFCECCCBFFA5A3
A2FF7E7C7BFF5E5B5AFF7B7977FF646260FF797675FFBCBBB8FFCECCCBFFA6A4
A3FF807E7DFF605D5CFF63605F007B787700777473FFB9B7B5FFC9C7C6FFA2A0
9FFF7D7B7AFF5C5858FF777472FF615F5DFF777473FFB9B8B5FFC9C7C6FFA2A0
9FFF7E7C7BFF605D5CFF63605F007B797700777473FFBCBAB8FFCDCBCAFFA5A3
A2FF7E7C7BFF595655FFD6D5D3FF8C8C89FF767372FFBCBAB7FFCCCAC9FFA4A2
A1FF7E7C7BFF5F5C5BFF625F5E007A7876FF6F6D6BFF666261FF605D5CFF5E5C
5AFF5E5A5AFF4946469BD3D2D0FF8A8987FF62615F9B6C6A68FF646160FF625F
5EFF615F5DFF615E5DFF615E5DA8777472FFDEDDDDFFEBEBE9FFDBDAD9FFCAC9
C8FFBBBAB9FF575453FFD6D5D3FF8C8B89FF757371FFDEDDDCFFEBEBE9FFDBDA
D9FFCAC9C8FFBCBCBBFF5E5B5AFF767472FFB3B0AEFFCAC9C7FFB0ADADFF9190
8EFF757472FF5B5857FF767472FF615F5DFF767472FFB3B1AFFFCAC9C7FFB0AD
ADFF91908EFF757573FF5F5C5BFF767472FFB3B1AFFFCAC9C7FFB1AEAEFF9392
90FF777674FF5E5A59FF7A7876FF646260FF777573FFB3B1AFFFCAC9C7FFB1AE
AEFF939290FF777674FF605D5CFF767472FFB3B1AFFFCAC9C7FFB0AEADFF9190
8EFF757472FF5E5A59FF0000003300000033777573FFB3B1AFFFCAC9C7FFB0AE
ADFF91908EFF757572FF5F5C5BFF777573FFCFCFCFFFD9D7D6FFD0CFCEFFC8C8
C7FFC3C1C1FF5E5A59FF5F5C5B007E7C7A00777573FFD0CFCFFFD9D7D6FFD0CF
CEFFC8C8C7FFC3C1C1FF5E5B5AFF7A7876FF817E7DFF9C9996FF898583FF716F
6CFF595756FF605D5CFF605D5C007F7D7B007A7876FF817E7DFF9C9996FF8985
83FF716F6CFF595756FF615E5DFF716F6DC0767472FF706D6CFF6D6A69FF6967
65FF666362FF5A5756C0605D5C007E7C7A00716F6DC0767472FF706D6CFF6D6A
69FF696765FF666362FF5A5756C0000000000000003300000033000000330000
0033000000330000000000000000000000000000000000000033000000330000
0033000000330000003300000000
}
end
object ApplicationProperties1: TApplicationProperties

View File

@ -63,6 +63,8 @@ type
actFileSaveAs: TAction;
actFileSave: TAction;
actFileCompAndRunWithArgs: TAction;
actEdFind: TAction;
actEdFindNext: TAction;
actProjOptView: TAction;
actProjSource: TAction;
actProjRun: TAction;
@ -138,6 +140,9 @@ type
MenuItem53: TMenuItem;
MenuItem54: TMenuItem;
MenuItem55: TMenuItem;
MenuItem56: TMenuItem;
MenuItem57: TMenuItem;
MenuItem58: TMenuItem;
mnuItemMruFile: TMenuItem;
mnuItemMruProj: TMenuItem;
mnuItemWin: TMenuItem;
@ -148,6 +153,8 @@ type
MenuItem8: TMenuItem;
MenuItem9: TMenuItem;
LfmSyn: TSynLFMSyn;
procedure actEdFindExecute(Sender: TObject);
procedure actEdFindNextExecute(Sender: TObject);
procedure actFileAddToProjExecute(Sender: TObject);
procedure actFileCloseExecute(Sender: TObject);
procedure actFileCompAndRunExecute(Sender: TObject);
@ -182,6 +189,7 @@ type
procedure actProjSourceExecute(Sender: TObject);
procedure actEdUnIndentExecute(Sender: TObject);
procedure ApplicationProperties1Exception(Sender: TObject; E: Exception);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
private
fUpdateCount: NativeInt;
@ -284,8 +292,6 @@ begin
fWidgList.addWidget(@fStExpWidg);
fWidgList.addWidget(@fFindWidg);
for widg in fWidgList do widg.Show;
for widg in fWidgList do
begin
act := TAction.Create(self);
@ -298,6 +304,7 @@ begin
itm.Action := act;
itm.Tag := ptrInt(widg);
mnuItemWin.Add(itm);
widg.Show
end;
Height := 0;
@ -360,6 +367,25 @@ begin
else fMesgWidg.addCeErr(E.Message);
end;
procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
var
i: NativeInt;
ed: TCESynMemo;
begin
canClose := false;
if fProject <> nil then if fProject.modified then
if ce_common.dlgOkCancel('last project modifications are not saved, quit anyway ?')
<> mrOK then exit;
for i := 0 to fEditWidg.editorCount-1 do
begin
ed := fEditWidg.editor[i];
if ed.modified then if ce_common.dlgOkCancel(format
('last "%s" modifications are not saved, quit anyway ?',
[shortenPath(ed.fileName, 25)])) <> mrOK then exit;
end;
canClose := true;
end;
procedure TCEMainForm.ActionsUpdate(AAction: TBasicAction; var Handled: Boolean);
var
curr: TCESynMemo;
@ -514,24 +540,9 @@ end;
{$REGION file ******************************************************************}
procedure TCEMainForm.newFile;
var
i, j: NativeInt;
str: string;
begin
if fEditWidg = nil then exit;
//
i := fEditWidg.editorCount;
fEditWidg.addEditor;
j := 0;
while(true) do
begin
str := format('<new %d>',[j]);
if findFile(str) = -1 then break;
if j >= high(NativeInt) then break;
j += 1;
end;
fEditWidg.editor[i].fileName := str;
fEditWidg.editor[i].modified := false;
fEditWidg.focusedEditorChanged;
end;
@ -559,8 +570,7 @@ begin
end;
i := fEditWidg.editorCount;
fEditWidg.addEditor;
fEditWidg.editor[i].Lines.LoadFromFile(aFilename);
fEditWidg.editor[i].fileName := aFilename;
fEditWidg.editor[i].loadFromFile(aFilename);
fEditWidg.focusedEditorChanged;
fFileMru.Insert(0,aFilename);
end;
@ -581,11 +591,7 @@ begin
//
str := fEditWidg.editor[edIndex].fileName;
if str = '' then exit;
try
fEditWidg.editor[edIndex].Lines.SaveToFile(str);
finally
fEditWidg.editor[edIndex].modified := false;
end;
fEditWidg.editor[edIndex].save;
//
for i := 0 to fWidgList.Count-1 do
fWidgList.widget[i].docChanged(fEditWidg.editor[edIndex]);
@ -597,13 +603,8 @@ begin
if edIndex < 0 then exit;
if edIndex >= fEditWidg.editorCount then exit;
//
try
fEditWidg.editor[edIndex].Lines.SaveToFile(aFilename);
finally
fEditWidg.editor[edIndex].fileName := aFilename;
fEditWidg.editor[edIndex].modified := false;
fFileMru.Insert(0,aFilename);
end;
fEditWidg.editor[edIndex].saveToFile(aFilename);
fFileMru.Insert(0, aFilename);
end;
procedure TCEMainForm.docChangeNotify(Sender: TObject; const aIndex: Integer);
@ -816,6 +817,31 @@ begin
curr := fEditWidg.currentEditor;
if assigned(curr) then curr.ExecuteCommand(ecBlockUnIndent, '', nil);
end;
procedure TCEMainForm.actEdFindExecute(Sender: TObject);
var
win: TAnchorDockHostSite;
ed: TCESynMemo;
str: string;
begin
win := DockMaster.GetAnchorSite(fFindWidg);
if win = nil then exit;
win.Show;
win.BringToFront;
ed := fEditWidg.currentEditor;
if ed = nil then exit;
if ed.SelAvail then
str := ed.SelText
else str := ed.Identifier;
ffindwidg.cbToFind.Text := str;
ffindwidg.cbToFindChange(nil);
end;
procedure TCEMainForm.actEdFindNextExecute(Sender: TObject);
begin
ffindwidg.actFindNextExecute(nil);
end;
{$ENDREGION}
{$REGION run ******************************************************************}
@ -1160,8 +1186,7 @@ begin
if fProject = nil then exit;
if fProject.fileName <> aEditor.fileName then exit;
//
aEditor.modified := false;
aEditor.Lines.SaveToFile(fProject.fileName);
aEditor.saveToFile(fProject.fileName);
openProj(fProject.fileName);
end;

View File

@ -5,8 +5,9 @@ unit ce_synmemo;
interface
uses
Classes, SysUtils, SynEdit, SynMemo, ce_d2syn,
SynPluginSyncroEdit, SynEditKeyCmds, ce_project, ce_common;
Classes, SysUtils, SynEdit, SynMemo, ce_d2syn, SynEditTextBuffer,
SynEditHighlighter, controls, LazSynEditText, SynPluginSyncroEdit,
SynEditKeyCmds, ce_project, ce_common;
type
@ -17,19 +18,33 @@ type
fNoDateCheck: boolean;
fFileDate: double;
fAssocProject: TCEProject;
function getIfDSource: Boolean;
function getIfConfig: Boolean;
procedure setFilename(const aValue: string);
fIsDSource: boolean;
fIsConfig: boolean;
fIdentifier: string;
procedure changeNotify(Sender: TObject);
procedure identifierToD2Syn;
protected
procedure SetHighlighter(const Value: TSynCustomHighlighter); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:Integer); override;
public
constructor Create(aOwner: TComponent); override;
procedure checkFileDate;
procedure setFocus; override;
procedure UpdateShowing; override;
//
property fileName: string read fFilename write setFilename;
property modified: boolean read fModified write fModified;
procedure checkFileDate;
procedure loadFromFile(const aFilename: string);
procedure saveToFile(const aFilename: string);
procedure save;
//
property Identifier: string read fIdentifier;
property fileName: string read fFilename;
property modified: boolean read fModified;
property project: TCEProject read fAssocProject write fAssocProject;
//
property isDSource: boolean read getIfDSource;
property isProjectSource: boolean read getIfConfig;
property isDSource: boolean read fIsDSource;
property isProjectSource: boolean read fIsConfig;
end;
var
@ -38,7 +53,7 @@ var
implementation
uses
graphics, ce_main, controls;
graphics, ce_main;
constructor TCESynMemo.Create(aOwner: TComponent);
begin
@ -59,14 +74,73 @@ begin
Gutter.CodeFoldPart.MarkupInfo.Foreground := clGray;
//
Highlighter := D2Syn;
//
fFilename := '<new document>';
fModified := false;
// http://forum.lazarus.freepascal.org/index.php/topic,25213.0.html
//TSynEditStringList(Lines).AddNotifyHandler(senrUndoRedoAdded, @changeNotify);
onChange := @changeNotify;
end;
procedure TCESynMemo.setFilename(const aValue: string);
procedure TCESynMemo.setFocus;
begin
if fFilename = aValue then exit;
fNoDateCheck := false;
fFilename := aValue;
inherited;
checkFileDate;
identifierToD2Syn;
end;
procedure TCESynMemo.UpdateShowing;
begin
inherited;
if not Visible then exit;
checkFileDate;
identifierToD2Syn;
end;
procedure TCESynMemo.SetHighlighter(const Value: TSynCustomHighlighter);
begin
inherited;
fIsDSource := Highlighter = D2Syn;
fIsConfig := Highlighter = mainForm.LfmSyn;
end;
procedure TCESynMemo.identifierToD2Syn;
begin
fIdentifier := GetWordAtRowCol(LogicalCaretXY);
if fIsDSource then D2Syn.CurrentIdentifier := fIdentifier;
end;
procedure TCESynMemo.changeNotify(Sender: TObject);
begin
identifierToD2Syn;
fModified := true;
end;
procedure TCESynMemo.loadFromFile(const aFilename: string);
begin
Lines.LoadFromFile(aFilename);
fFilename := aFilename;
FileAge(fFilename, fFileDate);
fNoDateCheck := false;
fModified := false;
end;
procedure TCESynMemo.saveToFile(const aFilename: string);
begin
Lines.SaveToFile(aFilename);
fFilename := aFilename;
FileAge(fFilename, fFileDate);
fNoDateCheck := false;
fModified := false;
end;
procedure TCESynMemo.save;
begin
Lines.SaveToFile(fFilename);
FileAge(fFilename, fFileDate);
fNoDateCheck := false;
fModified := false;
end;
procedure TCESynMemo.checkFileDate;
@ -78,7 +152,7 @@ begin
if fFileDate <> 0.0 then
begin
if dlgOkCancel(format('"%s" has been modified by another program, load the new version ?',
[shortenPath(fFilename)])) = mrOk then
[shortenPath(fFilename, 25)])) = mrOk then
begin
Lines.LoadFromFile(fFilename);
fModified := false;
@ -88,14 +162,22 @@ begin
fFileDate := newDate;
end;
function TCESynMemo.getIfDSource: Boolean;
procedure TCESynMemo.KeyDown(var Key: Word; Shift: TShiftState);
begin
exit(Highlighter = D2Syn);
inherited;
identifierToD2Syn;
end;
function TCESynMemo.getIfConfig: Boolean;
procedure TCESynMemo.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
exit(Highlighter = mainForm.LfmSyn);
inherited;
identifierToD2Syn;
end;
procedure TCESynMemo.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:Integer);
begin
inherited;
identifierToD2Syn;
end;
initialization