mirror of https://gitlab.com/basile.b/dexed.git
added support for ICEMultiDocHandler in all the widgets
This commit is contained in:
parent
7ea99ede61
commit
75bafb1b89
|
@ -19,7 +19,7 @@ type
|
|||
procedure SetVisible(Value: Boolean); override;
|
||||
end;
|
||||
|
||||
TCEEditorWidget = class(TCEWidget, ICEMultiDocObserver)
|
||||
TCEEditorWidget = class(TCEWidget, ICEMultiDocObserver, ICEMultiDocHandler)
|
||||
imgList: TImageList;
|
||||
PageControl: TExtendedNotebook;
|
||||
macRecorder: TSynMacroRecorder;
|
||||
|
@ -51,9 +51,6 @@ type
|
|||
procedure memoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
procedure memoCtrlClick(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
procedure memoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
||||
function getEditor(index: Integer): TCESynMemo;
|
||||
function getEditorCount: Integer;
|
||||
function getEditorIndex: Integer;
|
||||
procedure getCompletionList;
|
||||
procedure getSymbolLoc;
|
||||
procedure focusedEditorChanged;
|
||||
|
@ -62,21 +59,21 @@ type
|
|||
procedure docClosing(aDoc: TCESynMemo);
|
||||
procedure docFocused(aDoc: TCESynMemo);
|
||||
procedure docChanged(aDoc: TCESynMemo);
|
||||
//
|
||||
function SingleServiceName: string;
|
||||
function documentCount: Integer;
|
||||
function getDocument(index: Integer): TCESynMemo;
|
||||
function findDocument(aFilename: string): TCESynMemo;
|
||||
procedure openDocument(aFilename: string);
|
||||
function closeDocument(index: Integer): boolean;
|
||||
public
|
||||
constructor create(aOwner: TComponent); override;
|
||||
destructor destroy; override;
|
||||
//
|
||||
property editor[index: Integer]: TCESynMemo read getEditor;
|
||||
property editorCount: Integer read getEditorCount;
|
||||
property editorIndex: Integer read getEditorIndex;
|
||||
end;
|
||||
|
||||
implementation
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
ce_main;
|
||||
|
||||
procedure TCEEditorPage.SetVisible(Value: Boolean);
|
||||
var
|
||||
i: integer;
|
||||
|
@ -113,6 +110,7 @@ begin
|
|||
{$ENDIF}
|
||||
//
|
||||
EntitiesConnector.addObserver(self);
|
||||
EntitiesConnector.addSingleService(self);
|
||||
end;
|
||||
|
||||
destructor TCEEditorWidget.destroy;
|
||||
|
@ -201,6 +199,62 @@ begin
|
|||
end;
|
||||
{$ENDREGION}
|
||||
|
||||
{$REGION ICEMultiDocHandler ----------------------------------------------------}
|
||||
function TCEEditorWidget.SingleServiceName: string;
|
||||
begin
|
||||
exit('ICEMultiDocHandler');
|
||||
end;
|
||||
|
||||
function TCEEditorWidget.documentCount: Integer;
|
||||
begin
|
||||
exit(PageControl.PageCount);
|
||||
end;
|
||||
|
||||
function TCEEditorWidget.getDocument(index: Integer): TCESynMemo;
|
||||
begin
|
||||
exit(TCESynMemo(pageControl.Pages[index].Controls[0]));
|
||||
end;
|
||||
|
||||
function TCEEditorWidget.findDocument(aFilename: string): TCESynMemo;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 0 to PageControl.PageCount-1 do
|
||||
begin
|
||||
result := getDocument(i);
|
||||
if result.fileName = aFilename then
|
||||
exit;
|
||||
end;
|
||||
result := nil;
|
||||
end;
|
||||
|
||||
procedure TCEEditorWidget.openDocument(aFilename: string);
|
||||
var
|
||||
doc: TCESynMemo;
|
||||
begin
|
||||
doc := findDocument(aFilename);
|
||||
if doc <> nil then begin
|
||||
PageControl.ActivePage := TTabSheet(doc.Parent);
|
||||
exit;
|
||||
end;
|
||||
doc := TCESynMemo.Create(nil);
|
||||
fDoc.loadFromFile(aFilename);
|
||||
end;
|
||||
|
||||
function TCEEditorWidget.closeDocument(index: Integer): boolean;
|
||||
var
|
||||
doc: TCESynMemo;
|
||||
begin
|
||||
doc := getDocument(index);
|
||||
if doc.modified then if dlgOkCancel(format(
|
||||
'The latest "%s" mofifications are not saved, continue ?',
|
||||
[shortenPath(doc.fileName,25)])) = mrCancel then exit(false);
|
||||
doc.Free;
|
||||
result := true;
|
||||
end;
|
||||
{$ENDREGION}
|
||||
|
||||
|
||||
{$REGION PageControl/Editor things ---------------------------------------------}
|
||||
{$IFDEF LINUX}
|
||||
procedure TCEEditorWidget.pageCloseBtnClick(Sender: TObject);
|
||||
|
@ -209,24 +263,6 @@ begin
|
|||
end;
|
||||
{$ENDIF}
|
||||
|
||||
function TCEEditorWidget.getEditorCount: Integer;
|
||||
begin
|
||||
result := pageControl.PageCount;
|
||||
end;
|
||||
|
||||
function TCEEditorWidget.getEditorIndex: Integer;
|
||||
begin
|
||||
if pageControl.PageCount > 0 then
|
||||
result := pageControl.PageIndex
|
||||
else
|
||||
result := -1;
|
||||
end;
|
||||
|
||||
function TCEEditorWidget.getEditor(index: Integer): TCESynMemo;
|
||||
begin
|
||||
result := TCESynMemo(pageControl.Pages[index].Controls[0]);
|
||||
end;
|
||||
|
||||
procedure TCEEditorWidget.focusedEditorChanged;
|
||||
begin
|
||||
if fDoc = nil then exit;
|
||||
|
@ -306,7 +342,7 @@ begin
|
|||
//
|
||||
DcdWrapper.getDeclFromCursor(fname, srcpos);
|
||||
if fname <> fDoc.fileName then if fileExists(fname) then
|
||||
CEMainForm.openFile(fname);
|
||||
openDocument(fname);
|
||||
if srcpos <> -1 then
|
||||
begin
|
||||
//fDoc.SelStart := srcpos;
|
||||
|
|
101
src/ce_main.pas
101
src/ce_main.pas
|
@ -178,6 +178,7 @@ type
|
|||
private
|
||||
|
||||
fDoc: TCESynMemo;
|
||||
fMultidoc: ICEMultiDocHandler;
|
||||
fUpdateCount: NativeInt;
|
||||
fProject: TCEProject;
|
||||
fProjMru: TMruFileList;
|
||||
|
@ -249,9 +250,8 @@ type
|
|||
|
||||
// file sub routines
|
||||
procedure newFile;
|
||||
function findFile(const aFilename: string): NativeInt;
|
||||
procedure saveFile(const edIndex: NativeInt);
|
||||
procedure saveFileAs(const edIndex: NativeInt; const aFilename: string);
|
||||
procedure saveFile(aDocument: TCESynMemo);
|
||||
procedure openFile(const aFilename: string);
|
||||
|
||||
// project sub routines
|
||||
procedure saveProjSource(const aEditor: TCESynMemo);
|
||||
|
@ -278,10 +278,6 @@ type
|
|||
constructor create(aOwner: TComponent); override;
|
||||
destructor destroy; override;
|
||||
procedure UpdateDockCaption(Exclude: TControl = nil); override;
|
||||
//
|
||||
procedure openFile(const aFilename: string);
|
||||
//
|
||||
property processInput: TCEProcInputWidget read fPrInpWidg;
|
||||
end;
|
||||
|
||||
var
|
||||
|
@ -306,6 +302,7 @@ begin
|
|||
InitDocking;
|
||||
InitSettings;
|
||||
layoutUpdateMenu;
|
||||
fMultidoc := getMultiDocHandler;
|
||||
//
|
||||
newProj;
|
||||
checkCompilo;
|
||||
|
@ -660,22 +657,18 @@ end;
|
|||
|
||||
procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
||||
var
|
||||
i: NativeInt;
|
||||
ed: TCESynMemo;
|
||||
i: Integer;
|
||||
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;
|
||||
if ce_common.dlgOkCancel(
|
||||
'last project modifications are not saved, quit anyway ?') <> mrOK then
|
||||
exit;
|
||||
for i := 0 to fMultidoc.documentCount-1 do
|
||||
if not fMultidoc.closeDocument(i) then exit;
|
||||
canClose := true;
|
||||
// saving doesnt work when csDestroying in comp.state.
|
||||
|
||||
// saving doesnt work when csDestroying in comp.state (in Free)
|
||||
SaveDocking;
|
||||
end;
|
||||
|
||||
|
@ -930,62 +923,18 @@ begin
|
|||
TCESynMemo.Create(nil);
|
||||
end;
|
||||
|
||||
function TCEMainForm.findFile(const aFilename: string): NativeInt;
|
||||
var
|
||||
i: NativeInt;
|
||||
begin
|
||||
result := -1;
|
||||
if fEditWidg = nil then exit;
|
||||
for i := 0 to fEditWidg.editorCount-1 do begin
|
||||
if SameText(fEditWidg.editor[i].fileName, aFilename) then exit(i);
|
||||
if SameText(fEditWidg.editor[i].tempFilename, aFilename) then exit(i);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.openFile(const aFilename: string);
|
||||
var
|
||||
i: NativeInt;
|
||||
begin
|
||||
if fEditWidg = nil then exit;
|
||||
//
|
||||
i := findFile(aFilename);
|
||||
if i > -1 then
|
||||
begin
|
||||
fEditWidg.PageControl.PageIndex := i;
|
||||
exit;
|
||||
end;
|
||||
TCESynMemo.Create(nil);
|
||||
if fDoc = nil then exit;
|
||||
fDoc.loadFromFile(aFilename);
|
||||
fMultidoc.openDocument(aFilename);
|
||||
fFileMru.Insert(0, aFilename);
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.saveFile(const edIndex: NativeInt);
|
||||
var
|
||||
str: string;
|
||||
procedure TCEMainForm.saveFile(aDocument: TCESynMemo);
|
||||
begin
|
||||
if fEditWidg = nil then exit;
|
||||
if edIndex >= fEditWidg.editorCount then exit;
|
||||
//
|
||||
if fEditWidg.editor[edIndex].Highlighter = LfmSyn then
|
||||
begin
|
||||
saveProjSource(fEditWidg.editor[edIndex]);
|
||||
exit;
|
||||
end;
|
||||
//
|
||||
str := fEditWidg.editor[edIndex].fileName;
|
||||
if str = '' then exit;
|
||||
fEditWidg.editor[edIndex].save;
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.saveFileAs(const edIndex: NativeInt; const aFilename: string);
|
||||
begin
|
||||
if fEditWidg = nil then exit;
|
||||
if edIndex < 0 then exit;
|
||||
if edIndex >= fEditWidg.editorCount then exit;
|
||||
//
|
||||
fEditWidg.editor[edIndex].saveToFile(aFilename);
|
||||
fFileMru.Insert(0, aFilename);
|
||||
if aDocument.Highlighter = LfmSyn then
|
||||
saveProjSource(aDocument)
|
||||
else if aDocument.fileName <> '' then
|
||||
aDocument.save;
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.mruFileItemClick(Sender: TObject);
|
||||
|
@ -1043,14 +992,14 @@ end;
|
|||
|
||||
procedure TCEMainForm.actFileSaveAsExecute(Sender: TObject);
|
||||
begin
|
||||
if fEditWidg = nil then exit;
|
||||
if fEditWidg.editorIndex < 0 then exit;
|
||||
if fDoc = nil then exit;
|
||||
//
|
||||
with TSaveDialog.Create(nil) do
|
||||
try
|
||||
Filter := DdiagFilter;
|
||||
if execute then
|
||||
saveFileAs(fEditWidg.editorIndex, filename);
|
||||
fDoc.saveToFile(filename);
|
||||
fFileMru.Insert(0, filename);
|
||||
finally
|
||||
free;
|
||||
end;
|
||||
|
@ -1064,7 +1013,7 @@ begin
|
|||
//
|
||||
str := fDoc.fileName;
|
||||
if (str <> fDoc.tempFilename) and (fileExists(str)) then
|
||||
saveFile(fEditWidg.editorIndex)
|
||||
saveFile(fDoc)
|
||||
else actFileSaveAs.Execute;
|
||||
end;
|
||||
|
||||
|
@ -1091,10 +1040,10 @@ end;
|
|||
|
||||
procedure TCEMainForm.actFileSaveAllExecute(Sender: TObject);
|
||||
var
|
||||
i: NativeInt;
|
||||
i: Integer;
|
||||
begin
|
||||
for i:= 0 to fEditWidg.editorCount-1 do
|
||||
saveFile(i);
|
||||
for i:= 0 to fMultidoc.documentCount-1 do
|
||||
saveFile(fMultidoc.document[i]);
|
||||
end;
|
||||
|
||||
procedure TCEMainForm.FormDropFiles(Sender: TObject;const FileNames: array of String);
|
||||
|
|
|
@ -106,9 +106,6 @@ type
|
|||
implementation
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
ce_main;
|
||||
|
||||
{$REGION Standard Comp/Obj------------------------------------------------------}
|
||||
constructor TCEMessagesWidget.create(aOwner: TComponent);
|
||||
begin
|
||||
|
@ -667,7 +664,7 @@ begin
|
|||
ext := extractFileExt(ident);
|
||||
if dExtList.IndexOf(ext) = -1 then
|
||||
exit;
|
||||
CEMainForm.openFile(ident);
|
||||
getMultiDocHandler.openDocument(ident);
|
||||
result := true;
|
||||
end;
|
||||
ident += aMessage[i];
|
||||
|
|
|
@ -69,9 +69,6 @@ type
|
|||
implementation
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
ce_main;
|
||||
|
||||
{$REGION Standard Comp/Obj------------------------------------------------------}
|
||||
constructor TCEMiniExplorerWidget.create(aIwner: TComponent);
|
||||
var
|
||||
|
@ -109,6 +106,7 @@ begin
|
|||
// http://bugs.freepascal.org/view.php?id=27137
|
||||
// TODO-cLCL&LAZ-specific: remove comment after next Laz release
|
||||
// TODO-cLCL&LAZ-specific, try the new TListViewFilterEdit here.
|
||||
// TODO-cLCL&LAZ-specific, the align/anchors of filterxxx must be redefined, previously there was a bug.
|
||||
lstFilter.FilteredListbox := nil;
|
||||
lstFilter.onChange := @lstFilterChange;
|
||||
//
|
||||
|
@ -293,7 +291,7 @@ begin
|
|||
if lstFiles.Selected.Data = nil then exit;
|
||||
fname := PString(lstFiles.Selected.Data)^;
|
||||
if not fileExists(fname) then exit;
|
||||
CEMainForm.openFile(fname);
|
||||
getMultiDocHandler.openDocument(fname);
|
||||
end;
|
||||
|
||||
procedure TCEMiniExplorerWidget.lstFilesDblClick(Sender: TObject);
|
||||
|
|
|
@ -20,7 +20,8 @@ type
|
|||
end;
|
||||
|
||||
(**
|
||||
* Manages the connections between the observers and their subjects in the whole program.
|
||||
* Manages the connections between the observers and their subjects in the
|
||||
* whole program.
|
||||
*)
|
||||
TCEEntitiesConnector = class
|
||||
private
|
||||
|
|
|
@ -59,7 +59,7 @@ implementation
|
|||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
ce_main, ce_symstring;
|
||||
ce_symstring;
|
||||
|
||||
{$REGION Standard Comp/Obj------------------------------------------------------}
|
||||
constructor TCEProjectInspectWidget.create(aOwner: TComponent);
|
||||
|
@ -203,7 +203,7 @@ begin
|
|||
fname := fProject.getAbsoluteSourceName(i);
|
||||
if dExtList.IndexOf(ExtractFileExt(fname)) <> -1 then
|
||||
if fileExists(fname) then
|
||||
CEMainForm.openFile(fname);
|
||||
getMultiDocHandler.openDocument(fname);
|
||||
end
|
||||
else if Tree.Selected.Parent = fConfNode then
|
||||
begin
|
||||
|
@ -311,12 +311,16 @@ end;
|
|||
procedure TCEProjectInspectWidget.FormDropFiles(Sender: TObject; const FileNames: array of String);
|
||||
var
|
||||
fname: string;
|
||||
multidoc: ICEMultiDocHandler;
|
||||
begin
|
||||
CEMainForm.FormDropFiles(Sender, Filenames);
|
||||
if fProject = nil then exit;
|
||||
multidoc := getMultiDocHandler;
|
||||
for fname in Filenames do
|
||||
if FileExists(fname) then
|
||||
begin
|
||||
multidoc.openDocument(fname);
|
||||
fProject.addSource(fname);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCEProjectInspectWidget.UpdateByEvent;
|
||||
|
|
|
@ -6,8 +6,9 @@ interface
|
|||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, TreeFilterEdit, ListFilterEdit, Forms, Controls,
|
||||
Graphics, Dialogs, ExtCtrls, Menus, Buttons, StdCtrls, ComCtrls, asyncprocess,
|
||||
ce_widget, process, ce_common, ce_interfaces, ce_synmemo, ce_project, ce_symstring;
|
||||
strutils, Graphics, Dialogs, ExtCtrls, Menus, Buttons, StdCtrls, ComCtrls,
|
||||
asyncprocess, ce_widget, process, ce_common, ce_interfaces, ce_synmemo,
|
||||
ce_project, ce_symstring;
|
||||
|
||||
type
|
||||
|
||||
|
@ -109,9 +110,6 @@ type
|
|||
implementation
|
||||
{$R *.lfm}
|
||||
|
||||
uses
|
||||
ce_main, strutils;
|
||||
|
||||
const
|
||||
ToolExeName = 'cetodo' + exeExt;
|
||||
|
||||
|
@ -182,6 +180,7 @@ begin
|
|||
// http://bugs.freepascal.org/view.php?id=27137
|
||||
// TODO-cLCL&LAZ-specific: remove comment after next Laz release
|
||||
// TODO-cLCL&LAZ-specific, try the new TListViewFilterEdit here.
|
||||
// TODO-cLCL&LAZ-specific, the align/anchors of filterxxx must be redefined, previously there was a bug.
|
||||
lstfilter.OnChange:= @filterItems;
|
||||
//
|
||||
png := TPortableNetworkGraphic.Create;
|
||||
|
@ -462,7 +461,7 @@ begin
|
|||
itm := TTodoItem(lstItems.Selected.Data);
|
||||
fname := itm.filename;
|
||||
ln := itm.line;
|
||||
CEMainForm.openFile(fname);
|
||||
getMultiDocHandler.openDocument(fname);
|
||||
//
|
||||
if fDoc = nil then exit;
|
||||
fDoc.CaretY := strToInt(ln);
|
||||
|
|
Loading…
Reference in New Issue