prevent category change if mod neither accepted nor canceled.

This commit is contained in:
Basile Burg 2015-05-02 23:57:26 +02:00
parent d4e484da3b
commit 2a0a3a9f91
2 changed files with 29 additions and 7 deletions

View File

@ -35,12 +35,13 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget
Width = 140 Width = 140
Align = alLeft Align = alLeft
AutoExpand = True AutoExpand = True
DefaultItemHeight = 16 DefaultItemHeight = 18
HideSelection = False HideSelection = False
ReadOnly = True ReadOnly = True
ScrollBars = ssAutoBoth ScrollBars = ssAutoBoth
SortType = stText SortType = stText
TabOrder = 0 TabOrder = 0
OnChanging = selCatChanging
OnDeletion = selCatDeletion OnDeletion = selCatDeletion
OnSelectionChanged = selCatSelectionChanged OnSelectionChanged = selCatSelectionChanged
Options = [tvoAutoExpand, tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw] Options = [tvoAutoExpand, tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw]
@ -94,7 +95,7 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget
object btnCancel: TSpeedButton object btnCancel: TSpeedButton
Left = 484 Left = 484
Height = 24 Height = 24
Hint = 'cancel and revert modifications' Hint = 'cancel and revert the modifications of the category'
Top = 3 Top = 3
Width = 30 Width = 30
Align = alRight Align = alRight
@ -105,7 +106,7 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget
object btnAccept: TSpeedButton object btnAccept: TSpeedButton
Left = 518 Left = 518
Height = 24 Height = 24
Hint = 'accept modifications' Hint = 'accept the modifications of the category'
Top = 3 Top = 3
Width = 30 Width = 30
Align = alRight Align = alRight

View File

@ -36,11 +36,14 @@ type
procedure inspectorEditorFilter(Sender: TObject; aEditor: TPropertyEditor; procedure inspectorEditorFilter(Sender: TObject; aEditor: TPropertyEditor;
var aShow: boolean); var aShow: boolean);
procedure inspectorModified(Sender: TObject); procedure inspectorModified(Sender: TObject);
procedure selCatChanging(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
procedure selCatDeletion(Sender: TObject; Node: TTreeNode); procedure selCatDeletion(Sender: TObject; Node: TTreeNode);
procedure selCatSelectionChanged(Sender: TObject); procedure selCatSelectionChanged(Sender: TObject);
protected protected
procedure UpdateShowing; override; procedure UpdateShowing; override;
private private
fCatChanged: boolean;
fEdOptsSubj: TCEEditableOptionsSubject; fEdOptsSubj: TCEEditableOptionsSubject;
procedure updateCategories; procedure updateCategories;
function sortCategories(Cat1, Cat2: TTreeNode): integer; function sortCategories(Cat1, Cat2: TTreeNode): integer;
@ -76,6 +79,7 @@ end;
destructor TCEOptionEditorWidget.destroy; destructor TCEOptionEditorWidget.destroy;
begin begin
fCatChanged := false;
fEdOptsSubj.Free; fEdOptsSubj.Free;
inherited; inherited;
end; end;
@ -119,12 +123,28 @@ begin
Dispose(PCategoryData(node.Data)); Dispose(PCategoryData(node.Data));
end; end;
procedure TCEOptionEditorWidget.selCatChanging(Sender: TObject;
Node: TTreeNode; var AllowChange: Boolean);
begin
if selCat.Selected = nil then exit;
if selCat.Selected.Data = nil then exit;
// accept/cancel is relative to a single category
if fCatChanged then begin
AllowChange := dlgOkCancel(
'The modifications of the current category are not validated, ' +
'discard them and continue ?'
) = mrOk;
fCatChanged := not AllowChange;
if AllowChange then
btnCancelClick(nil);
end;
end;
procedure TCEOptionEditorWidget.selCatSelectionChanged(Sender: TObject); procedure TCEOptionEditorWidget.selCatSelectionChanged(Sender: TObject);
var var
dt: PCategoryData; dt: PCategoryData;
begin begin
// remove either the control, the form or the inspector // remove either the control, the form or the inspector used as editor.
// being used as editor.
inspector.TIObject := nil; inspector.TIObject := nil;
if pnlEd.ControlCount > 0 then if pnlEd.ControlCount > 0 then
pnlEd.Controls[0].Parent := nil; pnlEd.Controls[0].Parent := nil;
@ -161,6 +181,7 @@ begin
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;
// //
fCatChanged := true;
PCategoryData(selCat.Selected.Data)^ PCategoryData(selCat.Selected.Data)^
.observer .observer
.optionedEvent(oeeChange); .optionedEvent(oeeChange);
@ -171,6 +192,7 @@ begin
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;
// //
fCatChanged := false;
if inspector.Parent <> nil then if inspector.Parent <> nil then
inspector.ItemIndex := -1; inspector.ItemIndex := -1;
PCategoryData(selCat.Selected.Data)^ PCategoryData(selCat.Selected.Data)^
@ -178,8 +200,6 @@ begin
.optionedEvent(oeeCancel); .optionedEvent(oeeCancel);
end; end;
procedure TCEOptionEditorWidget.inspectorEditorFilter(Sender: TObject;aEditor: procedure TCEOptionEditorWidget.inspectorEditorFilter(Sender: TObject;aEditor:
TPropertyEditor; var aShow: boolean); TPropertyEditor; var aShow: boolean);
begin begin
@ -197,6 +217,7 @@ begin
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;
// //
fCatChanged := false;
if inspector.Parent <> nil then if inspector.Parent <> nil then
inspector.ItemIndex := -1; inspector.ItemIndex := -1;
PCategoryData(selCat.Selected.Data)^ PCategoryData(selCat.Selected.Data)^