From 2a0a3a9f917571b83a5ca1ae5684d222c0647a74 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sat, 2 May 2015 23:57:26 +0200 Subject: [PATCH] prevent category change if mod neither accepted nor canceled. --- src/ce_optionseditor.lfm | 7 ++++--- src/ce_optionseditor.pas | 29 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/ce_optionseditor.lfm b/src/ce_optionseditor.lfm index 21bafd0a..3b050c93 100644 --- a/src/ce_optionseditor.lfm +++ b/src/ce_optionseditor.lfm @@ -35,12 +35,13 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget Width = 140 Align = alLeft AutoExpand = True - DefaultItemHeight = 16 + DefaultItemHeight = 18 HideSelection = False ReadOnly = True ScrollBars = ssAutoBoth SortType = stText TabOrder = 0 + OnChanging = selCatChanging OnDeletion = selCatDeletion OnSelectionChanged = selCatSelectionChanged Options = [tvoAutoExpand, tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw] @@ -94,7 +95,7 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget object btnCancel: TSpeedButton Left = 484 Height = 24 - Hint = 'cancel and revert modifications' + Hint = 'cancel and revert the modifications of the category' Top = 3 Width = 30 Align = alRight @@ -105,7 +106,7 @@ inherited CEOptionEditorWidget: TCEOptionEditorWidget object btnAccept: TSpeedButton Left = 518 Height = 24 - Hint = 'accept modifications' + Hint = 'accept the modifications of the category' Top = 3 Width = 30 Align = alRight diff --git a/src/ce_optionseditor.pas b/src/ce_optionseditor.pas index 58e16710..5849f3df 100644 --- a/src/ce_optionseditor.pas +++ b/src/ce_optionseditor.pas @@ -36,11 +36,14 @@ type procedure inspectorEditorFilter(Sender: TObject; aEditor: TPropertyEditor; var aShow: boolean); procedure inspectorModified(Sender: TObject); + procedure selCatChanging(Sender: TObject; Node: TTreeNode; + var AllowChange: Boolean); procedure selCatDeletion(Sender: TObject; Node: TTreeNode); procedure selCatSelectionChanged(Sender: TObject); protected procedure UpdateShowing; override; private + fCatChanged: boolean; fEdOptsSubj: TCEEditableOptionsSubject; procedure updateCategories; function sortCategories(Cat1, Cat2: TTreeNode): integer; @@ -76,6 +79,7 @@ end; destructor TCEOptionEditorWidget.destroy; begin + fCatChanged := false; fEdOptsSubj.Free; inherited; end; @@ -119,12 +123,28 @@ begin Dispose(PCategoryData(node.Data)); 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); var dt: PCategoryData; begin - // remove either the control, the form or the inspector - // being used as editor. + // remove either the control, the form or the inspector used as editor. inspector.TIObject := nil; if pnlEd.ControlCount > 0 then pnlEd.Controls[0].Parent := nil; @@ -161,6 +181,7 @@ begin if selCat.Selected = nil then exit; if selcat.Selected.Data = nil then exit; // + fCatChanged := true; PCategoryData(selCat.Selected.Data)^ .observer .optionedEvent(oeeChange); @@ -171,6 +192,7 @@ begin if selCat.Selected = nil then exit; if selcat.Selected.Data = nil then exit; // + fCatChanged := false; if inspector.Parent <> nil then inspector.ItemIndex := -1; PCategoryData(selCat.Selected.Data)^ @@ -178,8 +200,6 @@ begin .optionedEvent(oeeCancel); end; - - procedure TCEOptionEditorWidget.inspectorEditorFilter(Sender: TObject;aEditor: TPropertyEditor; var aShow: boolean); begin @@ -197,6 +217,7 @@ begin if selCat.Selected = nil then exit; if selcat.Selected.Data = nil then exit; // + fCatChanged := false; if inspector.Parent <> nil then inspector.ItemIndex := -1; PCategoryData(selCat.Selected.Data)^