diff --git a/components/tvplanit/examples/fulldemo/demomain.pas b/components/tvplanit/examples/fulldemo/demomain.pas index b8c59c9e2..b3f27ad71 100644 --- a/components/tvplanit/examples/fulldemo/demomain.pas +++ b/components/tvplanit/examples/fulldemo/demomain.pas @@ -411,6 +411,7 @@ var begin datastore := VpControlLink1.Datastore; grp := datastore.Resources.AddResourceGroup('Res2 overlayed', [1, 2]); + grp.ReadOnly := true; if datastore.Resource <> nil then datastore.Resource.Group := grp else datastore.Resource.Group := nil; diff --git a/components/tvplanit/languages/vpsr.de.po b/components/tvplanit/languages/vpsr.de.po index 7cdce6c3c..c2185579d 100644 --- a/components/tvplanit/languages/vpsr.de.po +++ b/components/tvplanit/languages/vpsr.de.po @@ -188,6 +188,10 @@ msgctxt "vpsr.rscancelbtn" msgid "Cancel" msgstr "Abbrechen" +#: vpsr.rscannoteditoverlayedevent +msgid "Cannot edit this overlayed event." +msgstr "" + #: vpsr.rscaption msgctxt "vpsr.rscaption" msgid "Caption" diff --git a/components/tvplanit/languages/vpsr.fr.po b/components/tvplanit/languages/vpsr.fr.po index 5444ce868..a39ede3c0 100644 --- a/components/tvplanit/languages/vpsr.fr.po +++ b/components/tvplanit/languages/vpsr.fr.po @@ -194,6 +194,10 @@ msgctxt "vpsr.rscancelbtn" msgid "Cancel" msgstr "Annuler" +#: vpsr.rscannoteditoverlayedevent +msgid "Cannot edit this overlayed event." +msgstr "" + #: vpsr.rscaption msgctxt "vpsr.rscaption" msgid "Caption" diff --git a/components/tvplanit/languages/vpsr.nl.po b/components/tvplanit/languages/vpsr.nl.po index ab1f41bf2..753229210 100644 --- a/components/tvplanit/languages/vpsr.nl.po +++ b/components/tvplanit/languages/vpsr.nl.po @@ -188,6 +188,10 @@ msgctxt "vpsr.rscancelbtn" msgid "Cancel" msgstr "Afbreken" +#: vpsr.rscannoteditoverlayedevent +msgid "Cannot edit this overlayed event." +msgstr "" + #: vpsr.rscaption msgctxt "vpsr.rscaption" msgid "Caption" diff --git a/components/tvplanit/languages/vpsr.po b/components/tvplanit/languages/vpsr.po index c8e040def..8febe563c 100644 --- a/components/tvplanit/languages/vpsr.po +++ b/components/tvplanit/languages/vpsr.po @@ -178,6 +178,10 @@ msgctxt "vpsr.rscancelbtn" msgid "Cancel" msgstr "" +#: vpsr.rscannoteditoverlayedevent +msgid "Cannot edit this overlayed event." +msgstr "" + #: vpsr.rscaption msgctxt "vpsr.rscaption" msgid "Caption" diff --git a/components/tvplanit/languages/vpsr.ru.po b/components/tvplanit/languages/vpsr.ru.po index 132016bc9..4bd7f1dad 100644 --- a/components/tvplanit/languages/vpsr.ru.po +++ b/components/tvplanit/languages/vpsr.ru.po @@ -188,6 +188,10 @@ msgctxt "vpsr.rscancelbtn" msgid "Cancel" msgstr "Отмена" +#: vpsr.rscannoteditoverlayedevent +msgid "Cannot edit this overlayed event." +msgstr "" + #: vpsr.rscaption msgctxt "vpsr.rscaption" msgid "Caption" diff --git a/components/tvplanit/source/vpdata.pas b/components/tvplanit/source/vpdata.pas index b0d2b0004..f822fc90d 100644 --- a/components/tvplanit/source/vpdata.pas +++ b/components/tvplanit/source/vpdata.pas @@ -185,6 +185,7 @@ type FResourceID: Integer; FCaption: String; FIDs: Array of Integer; + FReadOnly: Boolean; function GetCount: integer; function GetItem(AIndex: Integer): TVpResource; public @@ -199,6 +200,7 @@ type property Count: Integer read GetCount; property Items[AIndex: Integer]: TVpResource read GetItem; default; property ResourceID: Integer read FResourceID; + property ReadOnly: boolean read FReadOnly write FReadOnly; end; TVpSchedule = class @@ -287,6 +289,8 @@ type public constructor Create(Owner: TVpSchedule); destructor Destroy; override; + function CanEdit: Boolean; + function GetResource: TVpResource; function IsOverlayed: Boolean; property Owner: TVpSchedule read FOwner; property ResourceID: Integer read FResourceID write FResourceID; @@ -1097,6 +1101,29 @@ begin inherited; end; +{ Returs false if the event cannot be edited. This is happens if the event is + overlayed and its resourcegroup is readonly } +function TVpEvent.CanEdit: Boolean; +var + res: TVpResource; + grp: TVpResourceGroup; +begin + Result := true; + if IsOverlayed then begin + res := GetResource; + if res <> nil then begin + grp := res.Group; + if grp.ReadOnly then Result := false; + end; + end; +end; + +{ Returns the resource to which the event belongs. } +function TVpEvent.GetResource: TVpResource; +begin + Result := FOwner.Owner; +end; + { The event is overlayed if its ResourceID is different from that of the resource to which it belongs. } function TVpEvent.IsOverlayed: Boolean; diff --git a/components/tvplanit/source/vpdayview.pas b/components/tvplanit/source/vpdayview.pas index 6312b3634..e323d2927 100644 --- a/components/tvplanit/source/vpdayview.pas +++ b/components/tvplanit/source/vpdayview.pas @@ -826,6 +826,8 @@ var begin if ReadOnly then Exit; + if (FActiveEvent <> nil) and (not FActiveEvent.CanEdit) then + exit; dvClickTimer.Enabled := false; EndEdit(self); @@ -888,7 +890,9 @@ procedure TVpDayView.InitializeDefaultPopup; var NewItem: TMenuItem; NewSubItem: TMenuItem; + canEdit: Boolean; begin + canEdit := (FActiveEvent <> nil) and FActiveEvent.CanEdit; FDefaultPopup.Items.Clear; if RSDayPopupAdd <> '' then begin @@ -902,6 +906,7 @@ begin if RSDayPopupEdit <> '' then begin NewItem := TMenuItem.Create(Self); NewItem.Caption := RSDayPopupEdit; + NewItem.Enabled := canEdit; NewItem.OnClick := PopupEditEvent; NewItem.Tag := 1; FDefaultPopup.Items.Add(NewItem); @@ -910,11 +915,16 @@ begin if RSDayPopupDelete <> '' then begin NewItem := TMenuItem.Create(Self); NewItem.Caption := RSDayPopupDelete; + NewItem.Enabled := canEdit; NewItem.OnClick := PopupDeleteEvent; NewItem.Tag := 1; FDefaultPopup.Items.Add(NewItem); end; + NewItem := TMenuItem.Create(Self); + NewItem.Caption := '-'; + FDefaultPopup.Items.Add(NewItem); + if RSDayPopupNav <> '' then begin NewItem := TMenuItem.Create(Self); NewItem.Caption := RSDayPopupNav; @@ -1634,7 +1644,8 @@ begin inherited MouseMove(Shift, X, Y); if (FActiveEvent <> nil) and (not ReadOnly) then begin if (not dvDragging) and dvMouseDown and - ((dvMouseDownPoint.x <> x) or (dvMouseDownPoint.y <> y)) + ((dvMouseDownPoint.x <> x) or (dvMouseDownPoint.y <> y)) and + FActiveEvent.CanEdit then begin dvDragging := true; dvClickTimer.Enabled := false; @@ -1800,6 +1811,11 @@ begin if (DataStore = nil) or (DataStore.Resource = nil) or ReadOnly then Exit; + if (not NewEvent) and (not FActiveEvent.CanEdit) then begin + MessageDlg(RSCannotEditOverlayedEvent, mtInformation, [mbOK], 0); + exit; + end; + AllowIt := false; if Assigned(FOwnerEditEvent) then FOwnerEditEvent(self, FActiveEvent, DataStore.Resource, AllowIt) @@ -1942,6 +1958,8 @@ begin Exit; if not FAllowInplaceEdit then Exit; + if (FActiveEvent <> nil) and (not FActiveEvent.CanEdit) then + Exit; { call the user defined BeforeEdit event } AllowIt := true; diff --git a/components/tvplanit/source/vpmisc.pas b/components/tvplanit/source/vpmisc.pas index 545f97d09..c2f63a926 100644 --- a/components/tvplanit/source/vpmisc.pas +++ b/components/tvplanit/source/vpmisc.pas @@ -716,10 +716,6 @@ begin try datastore.Resource.GetResourceGroups(list); if list.Count > 0 then begin - newItem := TMenuItem.Create(AMenu.Owner); - newItem.Caption := '-'; - AMenu.Add(newItem); - newItem := TMenuItem.Create(AMenu.Owner); newItem.Caption := RSPopupResourceGroups; newItem.Tag := 0; diff --git a/components/tvplanit/source/vpsr.inc b/components/tvplanit/source/vpsr.inc index 1c67114a0..fc71c6696 100644 --- a/components/tvplanit/source/vpsr.inc +++ b/components/tvplanit/source/vpsr.inc @@ -141,6 +141,7 @@ resourcestring RSConfirmDeleteEvent = 'Delete event from schedule?'; RSStartEndTimeError = 'Incorrect order of start and end times. ' + 'Do you want to flip them?'; + RSCannotEditOverlayedEvent= 'Cannot edit this overlayed event.'; {Task Specific} RSConfirmDeleteTask = 'Delete this task from your list?'; diff --git a/components/tvplanit/source/vpweekview.pas b/components/tvplanit/source/vpweekview.pas index f986c8514..3c5377960 100644 --- a/components/tvplanit/source/vpweekview.pas +++ b/components/tvplanit/source/vpweekview.pas @@ -605,6 +605,8 @@ var begin if ReadOnly then exit; + if (FActiveEvent <> nil) and (not FActiveEvent.CanEdit) then + exit; wvClickTimer.Enabled := false; EndEdit(nil); @@ -903,93 +905,101 @@ procedure TVpWeekView.InitializeDefaultPopup; var NewItem: TMenuItem; NewSubItem: TMenuItem; + canEdit: Boolean; begin + canEdit := (FActiveEvent <> nil) and FActiveEvent.CanEdit; FDefaultPopup.Items.Clear; if RSWeekPopupAdd <> '' then begin - NewItem := TMenuItem.Create (Self); + NewItem := TMenuItem.Create(Self); NewItem.Caption := RSWeekPopupAdd; NewItem.OnClick := PopupAddEvent; NewItem.Tag := 0; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); end; if RSWeekPopupEdit <> '' then begin - NewItem := TMenuItem.Create (Self); + NewItem := TMenuItem.Create(Self); NewItem.Caption := RSWeekPopupEdit; + NewItem.Enabled := canEdit; NewItem.OnClick := PopupEditEvent; NewItem.Tag := 1; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); end; if RSWeekPopupDelete <> '' then begin - NewItem := TMenuItem.Create (Self); + NewItem := TMenuItem.Create(Self); NewItem.Caption := RSWeekPopupDelete; + NewItem.Enabled := canEdit; NewItem.OnClick := PopupDeleteEvent; NewItem.Tag := 1; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); end; + NewItem := TMenuItem.Create(Self); + NewItem.Caption := '-'; + FDefaultPopup.Items.Add(NewItem); + if RSWeekPopupNav <> '' then begin - NewItem := TMenuItem.Create (Self); + NewItem := TMenuItem.Create(Self); NewItem.Caption := RSWeekPopupNav; NewItem.Tag := 0; - FDefaultPopup.Items.Add (NewItem); + FDefaultPopup.Items.Add(NewItem); if RSWeekPopupNavToday <> '' then begin - NewSubItem := TMenuItem.Create (Self); + NewSubItem := TMenuItem.Create(Self); NewSubItem.Caption := RSWeekPopupNavToday; NewSubItem.OnClick := PopupToday; NewSubItem.Tag := 0; - NewItem.Add (NewSubItem); + NewItem.Add(NewSubItem); end; if RSWeekPopupNavNextWeek <> '' then begin - NewSubItem := TMenuItem.Create (Self); + NewSubItem := TMenuItem.Create(Self); NewSubItem.Caption := RSWeekPopupNavNextWeek; NewSubItem.OnClick := PopupNextWeek; NewSubItem.Tag := 0; - NewItem.Add (NewSubItem); + NewItem.Add(NewSubItem); end; if RSWeekPopupNavPrevWeek <> '' then begin - NewSubItem := TMenuItem.Create (Self); + NewSubItem := TMenuItem.Create(Self); NewSubItem.Caption := RSWeekPopupNavPrevWeek; NewSubItem.OnClick := PopupPrevWeek; NewSubItem.Tag := 0; - NewItem.Add (NewSubItem); + NewItem.Add(NewSubItem); end; if RSWeekPopupNavNextMonth <> '' then begin - NewSubItem := TMenuItem.Create (Self); + NewSubItem := TMenuItem.Create(Self); NewSubItem.Caption := RSWeekPopupNavNextMonth; NewSubItem.OnClick := PopupNextMonth; NewSubItem.Tag := 0; - NewItem.Add (NewSubItem); + NewItem.Add(NewSubItem); end; if RSWeekPopupNavPrevMonth <> '' then begin - NewSubItem := TMenuItem.Create (Self); + NewSubItem := TMenuItem.Create(Self); NewSubItem.Caption := RSWeekPopupNavPrevMonth; NewSubItem.OnClick := PopupPrevMonth; NewSubItem.Tag := 0; - NewItem.Add (NewSubItem); + NewItem.Add(NewSubItem); end; if RSWeekPopupNavNextYear <> '' then begin - NewSubItem := TMenuItem.Create (Self); + NewSubItem := TMenuItem.Create(Self); NewSubItem.Caption := RSWeekPopupNavNextYear; NewSubItem.OnClick := PopupNextYear; NewSubItem.Tag := 0; - NewItem.Add (NewSubItem); + NewItem.Add(NewSubItem); end; if RSWeekPopupNavPrevYear <> '' then begin - NewSubItem := TMenuItem.Create (Self); + NewSubItem := TMenuItem.Create(Self); NewSubItem.Caption := RSWeekPopupNavPrevYear; NewSubItem.OnClick := PopupPrevYear; NewSubItem.Tag := 0; - NewItem.Add (NewSubItem); + NewItem.Add(NewSubItem); end; end; @@ -1138,6 +1148,11 @@ var begin if DataStore = nil then Exit; + if (not NewEvent) and (not ActiveEvent.CanEdit) then begin + MessageDlg(RSCannotEditOverlayedEvent, mtInformation, [mbOk], 0); + exit; + end; + AllowIt := false; if Assigned(FOwnerEditEvent) then FOwnerEditEvent(self, ActiveEvent, DataStore.Resource, AllowIt) @@ -1237,7 +1252,7 @@ var AllowIt: Boolean; begin if ActiveEvent <> nil then begin - if not FAllowInplaceEdit then + if (not FAllowInplaceEdit) or (not ActiveEvent.CanEdit) then exit; AllowIt := true; @@ -1450,7 +1465,8 @@ begin inherited MouseMove(Shift, X, Y); if (FActiveEvent <> nil) and (not ReadOnly) then begin if (not wvDragging) and wvMouseDown and - ((wvMouseDownPoint.x <> x) or (wvMouseDownPoint.y <> y)) + ((wvMouseDownPoint.x <> x) or (wvMouseDownPoint.y <> y)) and + FActiveEvent.CanEdit then begin wvDragging := true; wvClickTimer.Enabled := false;