Skip to content

Commit 2c113a8

Browse files
authored
LT-21491: Move DeleteRecord to Pub/Sub
Cherry-pick from the PubSub branch to the main branch using the following commands: git cherry-pick --no-commit 934ebfd git cherry-pick --no-commit ad97751 After the cherry-pick additional edits were made to: 1. resolve conflicts 2. standardize on the use of: using static SIL.FieldWorks.Common.FwUtils.FwUtils;
1 parent 69cda45 commit 2c113a8

5 files changed

Lines changed: 42 additions & 99 deletions

File tree

Src/Common/Controls/XMLViews/XmlBrowseRDEView.cs

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using SIL.LCModel.Core.Text;
1313
using SIL.LCModel.Core.KernelInterfaces;
1414
using SIL.FieldWorks.Common.FwUtils;
15+
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
1516
using SIL.LCModel;
1617
using SIL.FieldWorks.Common.RootSites;
1718
using SIL.LCModel.Application;
@@ -74,6 +75,8 @@ protected override void Dispose( bool disposing )
7475

7576
if( disposing )
7677
{
78+
Subscriber.Unsubscribe(EventConstants.DeleteRecord, DeleteRecord);
79+
7780
if (components != null)
7881
{
7982
components.Dispose();
@@ -99,6 +102,8 @@ public override void Init(XmlNode nodeSpec, int hvoRoot, int fakeFlid,
99102

100103
// Use the ones in fakeFlid, and any we create.
101104
base.Init(nodeSpec, hvoRoot, fakeFlid, cache, mediator, bv);
105+
106+
Subscriber.Subscribe(EventConstants.DeleteRecord, DeleteRecord);
102107
}
103108

104109
#endregion Construction, initialization, and disposal.
@@ -1059,12 +1064,22 @@ public bool OnDeleteRecordToolTip(object holder)
10591064

10601065
/// ------------------------------------------------------------------------------------
10611066
/// <summary>
1062-
/// Called when [delete record].
1067+
/// Method that handles the menu handling for deleting records.
1068+
/// Triggered from (DistFiles\Language Explorer\Configuration\Main.xml)
10631069
/// </summary>
10641070
/// <param name="commandObject">The command object.</param>
10651071
/// <returns></returns>
10661072
/// ------------------------------------------------------------------------------------
1067-
public override bool OnDeleteRecord(object commandObject)
1073+
public bool OnDeleteRecord(object commandObject)
1074+
{
1075+
DeleteRecord(commandObject);
1076+
return true;
1077+
}
1078+
1079+
/// <summary>
1080+
/// Method to handle published messages for DeleteRecord
1081+
/// </summary>
1082+
private void DeleteRecord(object _)
10681083
{
10691084
CheckDisposed();
10701085

@@ -1073,11 +1088,11 @@ public override bool OnDeleteRecord(object commandObject)
10731088

10741089
IVwSelection vwsel = m_rootb.Selection;
10751090
if (vwsel == null)
1076-
return false;
1091+
return;
10771092
ISilDataAccess sda = m_bv.SpecialCache;
10781093
List<XmlNode> columns = m_xbvvc.ColumnSpecs;
10791094
if (columns == null || columns.Count == 0)
1080-
return false; // Something is broken!
1095+
return; // Something is broken!
10811096

10821097
TextSelInfo tsi = new TextSelInfo(m_rootb.Selection);
10831098
if (tsi.ContainingObject(0) == XmlRDEBrowseViewVc.khvoNewItem)
@@ -1087,55 +1102,9 @@ public override bool OnDeleteRecord(object commandObject)
10871102
else
10881103
{
10891104
// 1. Remove the domain from the sense shown in the second column.
1090-
// 2. Delete the sense iff it is now empty except for the definition shown.
1091-
// 3. Delete the entry iff the entry now has no senses.
1092-
#if false // JohnT: don't understand the following code at all. In particular it makes no sense
1093-
// to use ihvoRoot to index rgvsli; ihvoRoot is always zero in this view, it has only one root.
1094-
// Possibly this was an unsuccessful attempt to adapt some generic code I wrote to this
1095-
// particular application involving senses and entries?
1096-
// I'm leaving it in existence for now in case the original author turns up and
1097-
// can explain what he was getting at.
1098-
int cLevels = vwsel.get_BoxDepth(true);
1099-
int iLevel;
1100-
int cBoxes = -1;
1101-
int iBox = -1;
1102-
VwBoxType[] rgvbt = new VwBoxType[cLevels];
1103-
VwBoxType vbt = VwBoxType.kvbtUnknown;
1104-
for (iLevel = 0; iLevel < cLevels; ++iLevel)
1105-
{
1106-
vbt = vwsel.get_BoxType(false, iLevel);
1107-
if (vbt == VwBoxType.kvbtTableCell)
1108-
{
1109-
cBoxes = vwsel.get_BoxCount(true, iLevel);
1110-
iBox = vwsel.get_BoxIndex(true, iLevel);
1111-
break;
1112-
}
1113-
}
1114-
Debug.Assert(cBoxes == 2);
1115-
Debug.Assert(iBox != -1);
1116-
int hvoEntry;
1117-
int hvoSense;
1118-
if (iBox == 0)
1119-
{
1120-
hvoEntry = rgvsli[ihvoRoot].hvo;
1121-
IVwSelection vwsel2 = m_rootb.MakeSelInBox(vwsel, false, iLevel, 1,
1122-
true, false, false);
1123-
SelLevInfo[] rgvsli2 = SelLevInfo.AllTextSelInfo(vwsel, vwsel2.CLevels(false) - 1,
1124-
out ihvoRoot, out tag, out cpropPrevious, out ichAnchor, out ichEnd,
1125-
out ws, out fAssocPrev, out ihvoEnd, out ttp);
1126-
hvoSense = rgvsli2[ihvoRoot].hvo;
1127-
}
1128-
else
1129-
{
1130-
hvoSense = rgvsli[ihvoRoot].hvo;
1131-
IVwSelection vwsel2 = m_rootb.MakeSelInBox(vwsel, false, iLevel, 0,
1132-
true, false, false);
1133-
SelLevInfo[] rgvsli2 = SelLevInfo.AllTextSelInfo(vwsel, vwsel2.CLevels(false) - 1,
1134-
out ihvoRoot, out tag, out cpropPrevious, out ichAnchor, out ichEnd,
1135-
out ws, out fAssocPrev, out ihvoEnd, out ttp);
1136-
hvoEntry = rgvsli2[ihvoRoot].hvo;
1137-
}
1138-
#else
1105+
// 2. Delete the sense if it is now empty except for the definition shown.
1106+
// 3. Delete the entry if the entry now has no senses.
1107+
11391108
int cvsli = tsi.Levels(false) - 1;
11401109
int tag = tsi.ContainingObjectTag(cvsli - 1);
11411110
Debug.Assert(cvsli >= 1); // there should be at least one level (each row is a sense)
@@ -1144,7 +1113,7 @@ public override bool OnDeleteRecord(object commandObject)
11441113
// want to process.
11451114
int hvoSense = tsi.ContainingObject(cvsli - 1);
11461115
int hvoEntry = m_cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(hvoSense).Owner.Hvo;
1147-
#endif
1116+
11481117
// If this was an editable object, it no longer is, because it's about to no longer exist.
11491118
RDEVc.EditableObjectsRemove(hvoSense);
11501119

@@ -1227,7 +1196,6 @@ public override bool OnDeleteRecord(object commandObject)
12271196
}
12281197
});
12291198
}
1230-
return true;
12311199
}
12321200

12331201
#endregion Other message handlers

Src/Common/Controls/XMLViews/XmlBrowseViewBase.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,21 +2063,6 @@ public virtual bool OnDisplayDeleteRecord(object commandObject,
20632063
return false;
20642064
}
20652065

2066-
/// ------------------------------------------------------------------------------------
2067-
/// <summary>
2068-
/// Called when [delete record].
2069-
/// </summary>
2070-
/// <param name="commandObject">The command object.</param>
2071-
/// <returns></returns>
2072-
/// ------------------------------------------------------------------------------------
2073-
public virtual bool OnDeleteRecord(object commandObject)
2074-
{
2075-
CheckDisposed();
2076-
2077-
return false;
2078-
}
2079-
2080-
20812066
/// <summary>
20822067
/// Allows xCore-specific initialization. We don't need any.
20832068
/// </summary>

Src/FdoUi/FdoUiCore.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,9 +1021,7 @@ public bool DeleteUnderlyingObject()
10211021
object command = this;
10221022
if (m_command != null)
10231023
command = m_command;
1024-
#pragma warning disable 618 // suppress obsolete warning
1025-
m_mediator.SendMessage("DeleteRecord", command);
1026-
#pragma warning restore 618
1024+
Publisher.Publish(new PublisherParameterObject(EventConstants.DeleteRecord, command));
10271025
}
10281026
else
10291027
{

Src/xWorks/RecordClerk.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ public virtual void Init(Mediator mediator, PropertyTable propertyTable, XmlNode
421421
StoreClerkInPropertyTable(clerkConfiguration);
422422

423423
SetupDataContext(false);
424-
425424
}
426425

427426
/// <summary>
@@ -1469,7 +1468,20 @@ private bool ShouldNotHandleDeletionMessage
14691468
get { return Id != "AllReversalEntries" && (!Editable || !IsPrimaryClerk || !m_shouldHandleDeletion); }
14701469
}
14711470

1471+
/// <summary>
1472+
/// Handler for the 'Delete ...' menu item.
1473+
/// Triggered from (DistFiles\Language Explorer\Configuration\Main.xml)
1474+
/// </summary>
14721475
public bool OnDeleteRecord(object commandObject)
1476+
{
1477+
DeleteRecord(commandObject);
1478+
return true;
1479+
}
1480+
1481+
/// <summary>
1482+
/// Method to handle published messages for DeleteRecord
1483+
/// </summary>
1484+
private void DeleteRecord(object commandObject)
14731485
{
14741486
CheckDisposed();
14751487

@@ -1481,21 +1493,21 @@ public bool OnDeleteRecord(object commandObject)
14811493
// The m_shouldHandleDeletion member was also added, so the "AllReversalEntries" clerk's primary clerk
14821494
// would not handle the message, and delete an entire reversal index.
14831495
if (ShouldNotHandleDeletionMessage)
1484-
return false;
1496+
return;
14851497

14861498
// It may be null:
14871499
// 1. if the objects are bing deleted using the keys,
14881500
// 2. the last one has been deleted, and
14891501
// 3. the user keeps pressing the del key.
14901502
// It looks like the command is not being disabled at all or fast enough.
14911503
if (CurrentObjectHvo == 0)
1492-
return true;
1504+
return;
14931505

14941506
// Don't allow an object to be deleted if it shouldn't be deleted.
14951507
if (!CanDelete())
14961508
{
14971509
ReportCannotDelete();
1498-
return true;
1510+
return;
14991511
}
15001512

15011513
ICmObject thingToDelete = GetObjectToDelete(CurrentObject);
@@ -1542,7 +1554,6 @@ public bool OnDeleteRecord(object commandObject)
15421554
#pragma warning restore 618
15431555
}
15441556
}
1545-
return true; //we handled this, no need to ask anyone else.
15461557
}
15471558

15481559
/// <summary>
@@ -1993,6 +2004,7 @@ public static RecordClerk FindClerk(PropertyTable propertyTable, string id)
19932004
protected virtual void RemoveNotification()
19942005
{
19952006
Subscriber.Unsubscribe(EventConstants.FilterListChanged, FilterListChanged);
2007+
Subscriber.Unsubscribe(EventConstants.DeleteRecord, DeleteRecord);
19962008

19972009
// We need the list to get the cache.
19982010
if (m_list == null || m_list.IsDisposed || Cache == null || Cache.IsDisposed || Cache.DomainDataByFlid == null)
@@ -2094,6 +2106,7 @@ virtual public void ActivateUI(bool useRecordTreeBar, bool updateStatusBar = tru
20942106
{
20952107
// RecordClerk only needs to handle changes if RecordClerk is being used in GUI
20962108
Subscriber.Subscribe(EventConstants.FilterListChanged, FilterListChanged);
2109+
Subscriber.Subscribe(EventConstants.DeleteRecord, DeleteRecord);
20972110

20982111
m_fIsActiveInGui = true;
20992112
CheckDisposed();

Src/xWorks/XmlDocView.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,27 +1367,6 @@ public virtual bool OnDisplayReplaceText(object commandObject, ref UIItemDisplay
13671367
return true; //we've handled this
13681368
}
13691369

1370-
/// <summary>
1371-
/// If this gets called (which it never should), just say we did it, unless we are in the context of reversal entries.
1372-
/// In the case of reversal entries, we say we did not do it, so the record clerk deals with it.
1373-
/// </summary>
1374-
/// <param name="commandObject"></param>
1375-
/// <returns></returns>
1376-
public bool OnDeleteRecord(object commandObject)
1377-
{
1378-
CheckDisposed();
1379-
1380-
if (Clerk.Id == "AllReversalEntries")
1381-
{
1382-
return false; // Let the clerk do it.
1383-
}
1384-
else
1385-
{
1386-
Debug.Assert(false);
1387-
}
1388-
return true;
1389-
}
1390-
13911370
public string FindTabHelpId
13921371
{
13931372
get { return XmlUtils.GetOptionalAttributeValue(m_configurationParameters, "findHelpId", null); }

0 commit comments

Comments
 (0)