updated options editor interface

- custom editor can indicated if there are any unvalidated modifications
- shortcuts editor modifications can be canceled
This commit is contained in:
Basile Burg 2015-05-26 11:08:45 +02:00
parent 915f168a0c
commit e2e9aa8bfe
9 changed files with 168 additions and 34 deletions

View File

@ -21,6 +21,7 @@ type
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
function optionedOptionsModified: boolean;
// //
procedure doChanged(Sender: TObject); procedure doChanged(Sender: TObject);
public public
@ -110,6 +111,11 @@ begin
end; end;
end; end;
function TDockOptionsEditor.optionedOptionsModified: boolean;
begin
exit(false);
end;
procedure TDockOptionsEditor.doChanged(Sender: TObject); procedure TDockOptionsEditor.doChanged(Sender: TObject);
var var
hasHeaders: boolean; hasHeaders: boolean;

View File

@ -103,6 +103,7 @@ type
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
function optionedOptionsModified: boolean;
// //
procedure docNew(aDoc: TCESynMemo); procedure docNew(aDoc: TCESynMemo);
procedure docFocused(aDoc: TCESynMemo); procedure docFocused(aDoc: TCESynMemo);
@ -439,6 +440,10 @@ begin
end; end;
end; end;
function TCEEditorOptions.optionedOptionsModified: boolean;
begin
exit(false);
end;
{$ENDREGION} {$ENDREGION}
{$REGION ICEEditableOptions ----------------------------------------------------} {$REGION ICEEditableOptions ----------------------------------------------------}

View File

@ -160,6 +160,8 @@ type
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
// the option editor informs that something has happened. // the option editor informs that something has happened.
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
// the option editor wants to know if an editor allows another category to be displayed (not called for oekGeneric).
function optionedOptionsModified: boolean;
end; end;
(** (**
* An implementer displays its observers editable options. * An implementer displays its observers editable options.
@ -199,7 +201,7 @@ type
// removes an entry. // removes an entry.
procedure removeProcess(aProcess: TProcess); procedure removeProcess(aProcess: TProcess);
// indicates the current process // indicates the current process
function process(): TProcess; function process: TProcess;
end; end;
@ -223,6 +225,21 @@ type
end; end;
(**
* Single service provided by the library manager
* In both cases, if someAliases is empty then all the available entries are passed.
*)
ICELibraryInformer = interface(ICESingleService)
// fills aList with the filenames of the static libraries matching to someAliases content.
procedure getLibsFiles(someAliases: TStrings; aList: TStrings);
// fills aList with the path to static libraries sources matching to someAliases content.
procedure getLibsPaths(someAliases: TStrings; aList: TStrings);
// fills aList with all the available libraries aliases.
procedure getLibsAliases(aList: TStrings);
end;
{ {
subject primitives: subject primitives:
@ -265,6 +282,9 @@ type
function getMultiDocHandler(var obj: ICEMultiDocHandler): ICEMultiDocHandler; overload; function getMultiDocHandler(var obj: ICEMultiDocHandler): ICEMultiDocHandler; overload;
function getMultiDocHandler: ICEMultiDocHandler; overload; function getMultiDocHandler: ICEMultiDocHandler; overload;
function getLibraryInformer(var obj: ICELibraryInformer): ICELibraryInformer; overload;
function getLibraryInformer: ICELibraryInformer; overload;
implementation implementation
{$REGION TCEMultiDocSubject ----------------------------------------------------} {$REGION TCEMultiDocSubject ----------------------------------------------------}
@ -411,6 +431,18 @@ function getMultiDocHandler: ICEMultiDocHandler;
begin begin
exit(EntitiesConnector.getSingleService('ICEMultiDocHandler') as ICEMultiDocHandler); exit(EntitiesConnector.getSingleService('ICEMultiDocHandler') as ICEMultiDocHandler);
end; end;
function getLibraryInformer(var obj: ICELibraryInformer): ICELibraryInformer;
begin
if obj = nil then
obj := EntitiesConnector.getSingleService('ICELibraryInformer') as ICELibraryInformer;
exit(obj);
end;
function getLibraryInformer: ICELibraryInformer;
begin
exit(EntitiesConnector.getSingleService('ICELibraryInformer') as ICELibraryInformer);
end;
{$ENDREGION} {$ENDREGION}
end. end.

View File

@ -107,6 +107,7 @@ type
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
function optionedOptionsModified: boolean;
// //
function singleServiceName: string; function singleServiceName: string;
procedure message(const aValue: string; aData: Pointer; aCtxt: TCEAppMessageCtxt; aKind: TCEAppMessageKind); procedure message(const aValue: string; aData: Pointer; aCtxt: TCEAppMessageCtxt; aKind: TCEAppMessageKind);
@ -389,6 +390,11 @@ begin
end; end;
fOptions.AssignTo(self); fOptions.AssignTo(self);
end; end;
function TCEMessagesWidget.optionedOptionsModified: boolean;
begin
exit(false);
end;
{$ENDREGION} {$ENDREGION}
{$REGION ICEContextualActions---------------------------------------------------} {$REGION ICEContextualActions---------------------------------------------------}

View File

@ -47,6 +47,7 @@ type
fCatChanged: boolean; fCatChanged: boolean;
fEdOptsSubj: TCEEditableOptionsSubject; fEdOptsSubj: TCEEditableOptionsSubject;
procedure updateCategories; procedure updateCategories;
function allowCategoryChange: boolean;
function sortCategories(Cat1, Cat2: TTreeNode): integer; function sortCategories(Cat1, Cat2: TTreeNode): integer;
public public
constructor create(aOwner: TComponent); override; constructor create(aOwner: TComponent); override;
@ -56,6 +57,9 @@ type
implementation implementation
{$R *.lfm} {$R *.lfm}
const
msg_mod = 'The current category modifications are not validated, discard them and continue ?';
{$REGION Standard Comp/Obj------------------------------------------------------} {$REGION Standard Comp/Obj------------------------------------------------------}
constructor TCEOptionEditorWidget.create(aOwner: TComponent); constructor TCEOptionEditorWidget.create(aOwner: TComponent);
var var
@ -124,23 +128,43 @@ begin
Dispose(PCategoryData(node.Data)); Dispose(PCategoryData(node.Data));
end; end;
procedure TCEOptionEditorWidget.selCatChanging(Sender: TObject; function TCEOptionEditorWidget.allowCategoryChange: boolean;
Node: TTreeNode; var AllowChange: Boolean); var
dt: PCategoryData;
begin begin
result := true;
if selCat.Selected = nil then exit; if selCat.Selected = nil then exit;
if selCat.Selected.Data = nil then exit; if selCat.Selected.Data = nil then exit;
// accept/cancel is relative to a single category // accept/cancel is relative to a single category
if fCatChanged then begin dt := PCategoryData(selCat.Selected.Data);
AllowChange := dlgOkCancel( // generic editor, changes are tracked directly here
'The modifications of the current category are not validated, ' + if dt^.kind = oekGeneric then
'discard them and continue ?' begin
) = mrOk; if fCatChanged then
fCatChanged := not AllowChange; begin
if AllowChange then result := dlgOkCancel(msg_mod) = mrOk;
btnCancelClick(nil); fCatChanged := not result;
if result then btnCancelClick(nil);
end;
// custom editor, changes are notified by optionedCatChange()
end else
begin
dt := PCategoryData(selCat.Selected.Data);
if dt^.container = nil then exit;
if dt^.observer.optionedOptionsModified() then
begin
result := dlgOkCancel(msg_mod) = mrOk;
if result then btnCancelClick(nil);
end;
end; end;
end; end;
procedure TCEOptionEditorWidget.selCatChanging(Sender: TObject;Node: TTreeNode;
var AllowChange: Boolean);
begin
AllowChange := allowCategoryChange;
end;
procedure TCEOptionEditorWidget.selCatSelectionChanged(Sender: TObject); procedure TCEOptionEditorWidget.selCatSelectionChanged(Sender: TObject);
var var
dt: PCategoryData; dt: PCategoryData;
@ -208,15 +232,7 @@ end;
procedure TCEOptionEditorWidget.FormCloseQuery(Sender: TObject; procedure TCEOptionEditorWidget.FormCloseQuery(Sender: TObject;
var CanClose: boolean); var CanClose: boolean);
begin begin
if fCatChanged then canClose := allowCategoryChange;
begin
CanClose := dlgOkCancel(
'The modifications of the current category are not validated, ' +
'discard them and continue ?' ) = mrOk;
if CanClose then
btnCancelClick(nil);
end
else CanClose := true;
end; end;
procedure TCEOptionEditorWidget.inspectorEditorFilter(Sender: TObject;aEditor: procedure TCEOptionEditorWidget.inspectorEditorFilter(Sender: TObject;aEditor:

View File

@ -66,16 +66,20 @@ type
fObservers: TCEEditableShortCutSubject; fObservers: TCEEditableShortCutSubject;
fShortcuts: TShortCutCollection; fShortcuts: TShortCutCollection;
fBackup: TShortCutCollection; fBackup: TShortCutCollection;
fHasChanged: boolean;
// //
function optionedWantCategory(): string; function optionedWantCategory(): string;
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
function optionedOptionsModified: boolean;
// //
function findCategory(const aName: string; aData: Pointer): TTreeNode; function findCategory(const aName: string; aData: Pointer): TTreeNode;
function findCategory(const aShortcutItem: TShortcutItem): string;
function sortCategories(Cat1, Cat2: TTreeNode): integer; function sortCategories(Cat1, Cat2: TTreeNode): integer;
procedure updateFromObservers; procedure receiveShortcuts;
procedure updateEditCtrls; procedure updateEditCtrls;
procedure sendShortcuts;
protected protected
procedure UpdateShowing; override; procedure UpdateShowing; override;
public public
@ -222,17 +226,33 @@ end;
function TCEShortcutEditor.optionedWantContainer: TPersistent; function TCEShortcutEditor.optionedWantContainer: TPersistent;
begin begin
updateFromObservers; receiveShortcuts;
exit(self); exit(self);
end; end;
procedure TCEShortcutEditor.optionedEvent(anEvent: TOptionEditorEvent); procedure TCEShortcutEditor.optionedEvent(anEvent: TOptionEditorEvent);
begin begin
case anEvent of case anEvent of
oeeSelectCat: updateFromObservers; oeeSelectCat: receiveShortcuts;
//TODO-cfeature: cancel modifications using fBackup oeeCancel:
begin
fShortcuts.assign(fBackup);
sendShortcuts;
fHasChanged := false;
end;
oeeAccept:
begin
fBackup.assign(fShortcuts);
sendShortcuts;
fHasChanged := false;
end;
end; end;
end; end;
function TCEShortcutEditor.optionedOptionsModified: boolean;
begin
exit(fHasChanged);
end;
{$ENDREGION} {$ENDREGION}
{$REGION shortcut editor things ------------------------------------------------} {$REGION shortcut editor things ------------------------------------------------}
@ -268,10 +288,11 @@ begin
if tree.Selected.Level = 0 then exit; if tree.Selected.Level = 0 then exit;
if tree.Selected.Data = nil then exit; if tree.Selected.Data = nil then exit;
// //
TShortcutItem(tree.Selected.Data).data := 0; if TShortcutItem(tree.Selected.Data).data <> 0 then
TShortcutItem(tree.Selected.Data).declarator.scedSendItem( begin
tree.Selected.Parent.Text, TShortcutItem(tree.Selected.Data).data := 0;
tree.Selected.Text, 0); fHasChanged := true;
end;
// //
updateEditCtrls; updateEditCtrls;
end; end;
@ -289,10 +310,11 @@ begin
else else
begin begin
sh := Shortcut(Key, Shift); sh := Shortcut(Key, Shift);
TShortcutItem(tree.Selected.Data).data := sh; if TShortcutItem(tree.Selected.Data).data <> sh then
TShortcutItem(tree.Selected.Data).declarator.scedSendItem( begin
tree.Selected.Parent.Text, TShortcutItem(tree.Selected.Data).data := sh;
tree.Selected.Text, sh ); fHasChanged := true;
end;
end; end;
// //
updateEditCtrls; updateEditCtrls;
@ -312,7 +334,7 @@ end;
function TCEShortcutEditor.findCategory(const aName: string; aData: Pointer): TTreeNode; function TCEShortcutEditor.findCategory(const aName: string; aData: Pointer): TTreeNode;
var var
i: Integer; i: integer;
begin begin
result := nil; result := nil;
for i:= 0 to tree.Items.Count-1 do for i:= 0 to tree.Items.Count-1 do
@ -321,12 +343,23 @@ begin
exit(tree.Items[i]); exit(tree.Items[i]);
end; end;
function TCEShortcutEditor.findCategory(const aShortcutItem: TShortcutItem): string;
var
i, j: integer;
begin
result := '';
for i := 0 to tree.Items.Count-1 do
for j:= 0 to tree.Items.Item[i].Count-1 do
if tree.Items.Item[i].Items[j].Data = Pointer(aShortcutItem) then
exit(tree.Items.Item[i].Text);
end;
function TCEShortcutEditor.sortCategories(Cat1, Cat2: TTreeNode): integer; function TCEShortcutEditor.sortCategories(Cat1, Cat2: TTreeNode): integer;
begin begin
result := CompareText(Cat1.Text, Cat2.Text); result := CompareText(Cat1.Text, Cat2.Text);
end; end;
procedure TCEShortcutEditor.updateFromObservers; procedure TCEShortcutEditor.receiveShortcuts;
var var
i: Integer; i: Integer;
obs: ICEEditableShortCut; obs: ICEEditableShortCut;
@ -372,6 +405,25 @@ begin
tree.Items.SortTopLevelNodes(@sortCategories); tree.Items.SortTopLevelNodes(@sortCategories);
fBackup.Assign(fShortcuts); fBackup.Assign(fShortcuts);
end; end;
procedure TCEShortcutEditor.sendShortcuts;
var
i: integer;
shc: TShortcutItem;
cat: string;
begin
for i := 0 to fShortcuts.count-1 do
begin
shc := fShortcuts[i];
cat := findCategory(shc);
if cat = '' then
continue;
if shc.declarator = nil then
continue;
shc.declarator.scedSendItem(cat, shc.identifier, shc.data);
end;
end;
{$ENDREGION} {$ENDREGION}
initialization initialization

View File

@ -65,6 +65,7 @@ type
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
function optionedOptionsModified: boolean;
// ICEEditableShortcut // ICEEditableShortcut
function scedWantFirst: boolean; function scedWantFirst: boolean;
function scedWantNext(out category, identifier: string; out aShortcut: TShortcut): boolean; function scedWantNext(out category, identifier: string; out aShortcut: TShortcut): boolean;
@ -296,6 +297,11 @@ begin
oeeChange: fOptions.AssignTo(self); oeeChange: fOptions.AssignTo(self);
end; end;
end; end;
function TCEStaticEditorMacro.optionedOptionsModified: boolean;
begin
exit(false);
end;
{$ENDREGION} {$ENDREGION}
{$REGION ICEEditableShortCut ---------------------------------------------------} {$REGION ICEEditableShortCut ---------------------------------------------------}

View File

@ -159,6 +159,7 @@ type
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
function optionedOptionsModified: boolean;
protected protected
procedure updateDelayed; override; procedure updateDelayed; override;
// //
@ -488,6 +489,11 @@ begin
fOptions.AssignTo(self); fOptions.AssignTo(self);
callToolProc; callToolProc;
end; end;
function TCESymbolListWidget.optionedOptionsModified: boolean;
begin
exit(false);
end;
{$ENDREGION} {$ENDREGION}
{$REGION ICEMultiDocObserver ---------------------------------------------------} {$REGION ICEMultiDocObserver ---------------------------------------------------}

View File

@ -104,6 +104,7 @@ type
function optionedWantEditorKind: TOptionEditorKind; function optionedWantEditorKind: TOptionEditorKind;
function optionedWantContainer: TPersistent; function optionedWantContainer: TPersistent;
procedure optionedEvent(anEvent: TOptionEditorEvent); procedure optionedEvent(anEvent: TOptionEditorEvent);
function optionedOptionsModified: boolean;
// TODOlist things // TODOlist things
function getContext: TTodoContext; function getContext: TTodoContext;
procedure killToolProcess; procedure killToolProcess;
@ -301,6 +302,10 @@ begin
fOptions.AssignTo(self); fOptions.AssignTo(self);
end; end;
function TCETodoListWidget.optionedOptionsModified: boolean;
begin
exit(false);
end;
{$ENDREGION} {$ENDREGION}
{$REGION ICEMultiDocObserver ---------------------------------------------------} {$REGION ICEMultiDocObserver ---------------------------------------------------}