1212using SIL . LCModel . Core . Text ;
1313using SIL . LCModel . Core . KernelInterfaces ;
1414using SIL . FieldWorks . Common . FwUtils ;
15+ using static SIL . FieldWorks . Common . FwUtils . FwUtils ;
1516using SIL . LCModel ;
1617using SIL . FieldWorks . Common . RootSites ;
1718using 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
0 commit comments