added support for ICEMultiDocHandler in all the widgets

This commit is contained in:
Basile Burg 2015-02-18 06:43:39 +01:00
parent 7ea99ede61
commit 75bafb1b89
7 changed files with 108 additions and 124 deletions

View File

@ -19,7 +19,7 @@ type
procedure SetVisible(Value: Boolean); override; procedure SetVisible(Value: Boolean); override;
end; end;
TCEEditorWidget = class(TCEWidget, ICEMultiDocObserver) TCEEditorWidget = class(TCEWidget, ICEMultiDocObserver, ICEMultiDocHandler)
imgList: TImageList; imgList: TImageList;
PageControl: TExtendedNotebook; PageControl: TExtendedNotebook;
macRecorder: TSynMacroRecorder; macRecorder: TSynMacroRecorder;
@ -51,9 +51,6 @@ type
procedure memoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure memoMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure memoCtrlClick(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); procedure memoMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
function getEditor(index: Integer): TCESynMemo;
function getEditorCount: Integer;
function getEditorIndex: Integer;
procedure getCompletionList; procedure getCompletionList;
procedure getSymbolLoc; procedure getSymbolLoc;
procedure focusedEditorChanged; procedure focusedEditorChanged;
@ -62,21 +59,21 @@ type
procedure docClosing(aDoc: TCESynMemo); procedure docClosing(aDoc: TCESynMemo);
procedure docFocused(aDoc: TCESynMemo); procedure docFocused(aDoc: TCESynMemo);
procedure docChanged(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 public
constructor create(aOwner: TComponent); override; constructor create(aOwner: TComponent); override;
destructor destroy; override; destructor destroy; override;
//
property editor[index: Integer]: TCESynMemo read getEditor;
property editorCount: Integer read getEditorCount;
property editorIndex: Integer read getEditorIndex;
end; end;
implementation implementation
{$R *.lfm} {$R *.lfm}
uses
ce_main;
procedure TCEEditorPage.SetVisible(Value: Boolean); procedure TCEEditorPage.SetVisible(Value: Boolean);
var var
i: integer; i: integer;
@ -113,6 +110,7 @@ begin
{$ENDIF} {$ENDIF}
// //
EntitiesConnector.addObserver(self); EntitiesConnector.addObserver(self);
EntitiesConnector.addSingleService(self);
end; end;
destructor TCEEditorWidget.destroy; destructor TCEEditorWidget.destroy;
@ -201,6 +199,62 @@ begin
end; end;
{$ENDREGION} {$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 ---------------------------------------------} {$REGION PageControl/Editor things ---------------------------------------------}
{$IFDEF LINUX} {$IFDEF LINUX}
procedure TCEEditorWidget.pageCloseBtnClick(Sender: TObject); procedure TCEEditorWidget.pageCloseBtnClick(Sender: TObject);
@ -209,24 +263,6 @@ begin
end; end;
{$ENDIF} {$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; procedure TCEEditorWidget.focusedEditorChanged;
begin begin
if fDoc = nil then exit; if fDoc = nil then exit;
@ -306,7 +342,7 @@ begin
// //
DcdWrapper.getDeclFromCursor(fname, srcpos); DcdWrapper.getDeclFromCursor(fname, srcpos);
if fname <> fDoc.fileName then if fileExists(fname) then if fname <> fDoc.fileName then if fileExists(fname) then
CEMainForm.openFile(fname); openDocument(fname);
if srcpos <> -1 then if srcpos <> -1 then
begin begin
//fDoc.SelStart := srcpos; //fDoc.SelStart := srcpos;

View File

@ -178,6 +178,7 @@ type
private private
fDoc: TCESynMemo; fDoc: TCESynMemo;
fMultidoc: ICEMultiDocHandler;
fUpdateCount: NativeInt; fUpdateCount: NativeInt;
fProject: TCEProject; fProject: TCEProject;
fProjMru: TMruFileList; fProjMru: TMruFileList;
@ -249,9 +250,8 @@ type
// file sub routines // file sub routines
procedure newFile; procedure newFile;
function findFile(const aFilename: string): NativeInt; procedure saveFile(aDocument: TCESynMemo);
procedure saveFile(const edIndex: NativeInt); procedure openFile(const aFilename: string);
procedure saveFileAs(const edIndex: NativeInt; const aFilename: string);
// project sub routines // project sub routines
procedure saveProjSource(const aEditor: TCESynMemo); procedure saveProjSource(const aEditor: TCESynMemo);
@ -278,10 +278,6 @@ type
constructor create(aOwner: TComponent); override; constructor create(aOwner: TComponent); override;
destructor destroy; override; destructor destroy; override;
procedure UpdateDockCaption(Exclude: TControl = nil); override; procedure UpdateDockCaption(Exclude: TControl = nil); override;
//
procedure openFile(const aFilename: string);
//
property processInput: TCEProcInputWidget read fPrInpWidg;
end; end;
var var
@ -306,6 +302,7 @@ begin
InitDocking; InitDocking;
InitSettings; InitSettings;
layoutUpdateMenu; layoutUpdateMenu;
fMultidoc := getMultiDocHandler;
// //
newProj; newProj;
checkCompilo; checkCompilo;
@ -660,22 +657,18 @@ end;
procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean); procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
var var
i: NativeInt; i: Integer;
ed: TCESynMemo;
begin begin
canClose := false; canClose := false;
if fProject <> nil then if fProject.modified then if fProject <> nil then if fProject.modified then
if ce_common.dlgOkCancel('last project modifications are not saved, quit anyway ?') if ce_common.dlgOkCancel(
<> mrOK then exit; 'last project modifications are not saved, quit anyway ?') <> mrOK then
for i := 0 to fEditWidg.editorCount-1 do exit;
begin for i := 0 to fMultidoc.documentCount-1 do
ed := fEditWidg.editor[i]; if not fMultidoc.closeDocument(i) then exit;
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; canClose := true;
// saving doesnt work when csDestroying in comp.state.
// saving doesnt work when csDestroying in comp.state (in Free)
SaveDocking; SaveDocking;
end; end;
@ -930,62 +923,18 @@ begin
TCESynMemo.Create(nil); TCESynMemo.Create(nil);
end; 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); procedure TCEMainForm.openFile(const aFilename: string);
var
i: NativeInt;
begin begin
if fEditWidg = nil then exit; fMultidoc.openDocument(aFilename);
//
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);
fFileMru.Insert(0, aFilename); fFileMru.Insert(0, aFilename);
end; end;
procedure TCEMainForm.saveFile(const edIndex: NativeInt); procedure TCEMainForm.saveFile(aDocument: TCESynMemo);
var
str: string;
begin begin
if fEditWidg = nil then exit; if aDocument.Highlighter = LfmSyn then
if edIndex >= fEditWidg.editorCount then exit; saveProjSource(aDocument)
// else if aDocument.fileName <> '' then
if fEditWidg.editor[edIndex].Highlighter = LfmSyn then aDocument.save;
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);
end; end;
procedure TCEMainForm.mruFileItemClick(Sender: TObject); procedure TCEMainForm.mruFileItemClick(Sender: TObject);
@ -1043,14 +992,14 @@ end;
procedure TCEMainForm.actFileSaveAsExecute(Sender: TObject); procedure TCEMainForm.actFileSaveAsExecute(Sender: TObject);
begin begin
if fEditWidg = nil then exit; if fDoc = nil then exit;
if fEditWidg.editorIndex < 0 then exit;
// //
with TSaveDialog.Create(nil) do with TSaveDialog.Create(nil) do
try try
Filter := DdiagFilter; Filter := DdiagFilter;
if execute then if execute then
saveFileAs(fEditWidg.editorIndex, filename); fDoc.saveToFile(filename);
fFileMru.Insert(0, filename);
finally finally
free; free;
end; end;
@ -1064,7 +1013,7 @@ begin
// //
str := fDoc.fileName; str := fDoc.fileName;
if (str <> fDoc.tempFilename) and (fileExists(str)) then if (str <> fDoc.tempFilename) and (fileExists(str)) then
saveFile(fEditWidg.editorIndex) saveFile(fDoc)
else actFileSaveAs.Execute; else actFileSaveAs.Execute;
end; end;
@ -1091,10 +1040,10 @@ end;
procedure TCEMainForm.actFileSaveAllExecute(Sender: TObject); procedure TCEMainForm.actFileSaveAllExecute(Sender: TObject);
var var
i: NativeInt; i: Integer;
begin begin
for i:= 0 to fEditWidg.editorCount-1 do for i:= 0 to fMultidoc.documentCount-1 do
saveFile(i); saveFile(fMultidoc.document[i]);
end; end;
procedure TCEMainForm.FormDropFiles(Sender: TObject;const FileNames: array of String); procedure TCEMainForm.FormDropFiles(Sender: TObject;const FileNames: array of String);

View File

@ -106,9 +106,6 @@ type
implementation implementation
{$R *.lfm} {$R *.lfm}
uses
ce_main;
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEMessagesWidget.create(aOwner: TComponent); constructor TCEMessagesWidget.create(aOwner: TComponent);
begin begin
@ -667,7 +664,7 @@ begin
ext := extractFileExt(ident); ext := extractFileExt(ident);
if dExtList.IndexOf(ext) = -1 then if dExtList.IndexOf(ext) = -1 then
exit; exit;
CEMainForm.openFile(ident); getMultiDocHandler.openDocument(ident);
result := true; result := true;
end; end;
ident += aMessage[i]; ident += aMessage[i];

View File

@ -69,9 +69,6 @@ type
implementation implementation
{$R *.lfm} {$R *.lfm}
uses
ce_main;
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEMiniExplorerWidget.create(aIwner: TComponent); constructor TCEMiniExplorerWidget.create(aIwner: TComponent);
var var
@ -109,6 +106,7 @@ begin
// http://bugs.freepascal.org/view.php?id=27137 // http://bugs.freepascal.org/view.php?id=27137
// TODO-cLCL&LAZ-specific: remove comment after next Laz release // TODO-cLCL&LAZ-specific: remove comment after next Laz release
// TODO-cLCL&LAZ-specific, try the new TListViewFilterEdit here. // 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.FilteredListbox := nil;
lstFilter.onChange := @lstFilterChange; lstFilter.onChange := @lstFilterChange;
// //
@ -293,7 +291,7 @@ begin
if lstFiles.Selected.Data = nil then exit; if lstFiles.Selected.Data = nil then exit;
fname := PString(lstFiles.Selected.Data)^; fname := PString(lstFiles.Selected.Data)^;
if not fileExists(fname) then exit; if not fileExists(fname) then exit;
CEMainForm.openFile(fname); getMultiDocHandler.openDocument(fname);
end; end;
procedure TCEMiniExplorerWidget.lstFilesDblClick(Sender: TObject); procedure TCEMiniExplorerWidget.lstFilesDblClick(Sender: TObject);

View File

@ -20,7 +20,8 @@ type
end; 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 TCEEntitiesConnector = class
private private

View File

@ -59,7 +59,7 @@ implementation
{$R *.lfm} {$R *.lfm}
uses uses
ce_main, ce_symstring; ce_symstring;
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEProjectInspectWidget.create(aOwner: TComponent); constructor TCEProjectInspectWidget.create(aOwner: TComponent);
@ -203,7 +203,7 @@ begin
fname := fProject.getAbsoluteSourceName(i); fname := fProject.getAbsoluteSourceName(i);
if dExtList.IndexOf(ExtractFileExt(fname)) <> -1 then if dExtList.IndexOf(ExtractFileExt(fname)) <> -1 then
if fileExists(fname) then if fileExists(fname) then
CEMainForm.openFile(fname); getMultiDocHandler.openDocument(fname);
end end
else if Tree.Selected.Parent = fConfNode then else if Tree.Selected.Parent = fConfNode then
begin begin
@ -311,12 +311,16 @@ end;
procedure TCEProjectInspectWidget.FormDropFiles(Sender: TObject; const FileNames: array of String); procedure TCEProjectInspectWidget.FormDropFiles(Sender: TObject; const FileNames: array of String);
var var
fname: string; fname: string;
multidoc: ICEMultiDocHandler;
begin begin
CEMainForm.FormDropFiles(Sender, Filenames);
if fProject = nil then exit; if fProject = nil then exit;
multidoc := getMultiDocHandler;
for fname in Filenames do for fname in Filenames do
if FileExists(fname) then if FileExists(fname) then
begin
multidoc.openDocument(fname);
fProject.addSource(fname); fProject.addSource(fname);
end;
end; end;
procedure TCEProjectInspectWidget.UpdateByEvent; procedure TCEProjectInspectWidget.UpdateByEvent;

View File

@ -6,8 +6,9 @@ interface
uses uses
Classes, SysUtils, FileUtil, TreeFilterEdit, ListFilterEdit, Forms, Controls, Classes, SysUtils, FileUtil, TreeFilterEdit, ListFilterEdit, Forms, Controls,
Graphics, Dialogs, ExtCtrls, Menus, Buttons, StdCtrls, ComCtrls, asyncprocess, strutils, Graphics, Dialogs, ExtCtrls, Menus, Buttons, StdCtrls, ComCtrls,
ce_widget, process, ce_common, ce_interfaces, ce_synmemo, ce_project, ce_symstring; asyncprocess, ce_widget, process, ce_common, ce_interfaces, ce_synmemo,
ce_project, ce_symstring;
type type
@ -109,9 +110,6 @@ type
implementation implementation
{$R *.lfm} {$R *.lfm}
uses
ce_main, strutils;
const const
ToolExeName = 'cetodo' + exeExt; ToolExeName = 'cetodo' + exeExt;
@ -182,6 +180,7 @@ begin
// http://bugs.freepascal.org/view.php?id=27137 // http://bugs.freepascal.org/view.php?id=27137
// TODO-cLCL&LAZ-specific: remove comment after next Laz release // TODO-cLCL&LAZ-specific: remove comment after next Laz release
// TODO-cLCL&LAZ-specific, try the new TListViewFilterEdit here. // 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; lstfilter.OnChange:= @filterItems;
// //
png := TPortableNetworkGraphic.Create; png := TPortableNetworkGraphic.Create;
@ -462,7 +461,7 @@ begin
itm := TTodoItem(lstItems.Selected.Data); itm := TTodoItem(lstItems.Selected.Data);
fname := itm.filename; fname := itm.filename;
ln := itm.line; ln := itm.line;
CEMainForm.openFile(fname); getMultiDocHandler.openDocument(fname);
// //
if fDoc = nil then exit; if fDoc = nil then exit;
fDoc.CaretY := strToInt(ln); fDoc.CaretY := strToInt(ln);