Skip to content

Commit bdf87b4

Browse files
Fix LT-21904: Allow duplicating a phonological rule (#470)
* Move code from FdoUiCore to RecordClerk * Improve duplication * Incorporate new liblcm * Add UpdateItemCheckedState message Co-authored-by: Jason Naylor <jason_naylor@sil.org>
1 parent 699d1ad commit bdf87b4

7 files changed

Lines changed: 124 additions & 29 deletions

File tree

Build/mkall.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
<ChorusNugetVersion>5.2.0-beta0003</ChorusNugetVersion>
235235
<PalasoNugetVersion>15.0.0-beta0117</PalasoNugetVersion>
236236
<ParatextNugetVersion>9.4.0.1-beta</ParatextNugetVersion>
237-
<LcmNugetVersion>11.0.0-beta0135</LcmNugetVersion>
237+
<LcmNugetVersion>11.0.0-beta0136</LcmNugetVersion>
238238
<IcuNugetVersion>70.1.123</IcuNugetVersion>
239239
<HermitCrabNugetVersion>3.7.4</HermitCrabNugetVersion>
240240
<IPCFrameworkVersion>1.1.1-beta0001</IPCFrameworkVersion>

Build/nuget-common/packages.config

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@
5050
<package id="SIL.Core" version="8.1.0-beta0035" targetFramework="net461" />
5151
<package id="SIL.DesktopAnalytics" version="4.0.0" targetFramework="net461" />
5252
<package id="SIL.FLExBridge.IPCFramework" version="1.1.1-beta0001" targetFramework="net461" />
53-
<package id="SIL.LCModel.Build.Tasks" version="11.0.0-beta0135" targetFramework="net461" />
54-
<package id="SIL.LCModel.Core.Tests" version="11.0.0-beta0135" targetFramework="net461" />
55-
<package id="SIL.LCModel.Core" version="11.0.0-beta0135" targetFramework="net461" />
56-
<package id="SIL.LCModel.FixData" version="11.0.0-beta0135" targetFramework="net461" />
57-
<package id="SIL.LCModel.Tests" version="11.0.0-beta0135" targetFramework="net461" />
58-
<package id="SIL.LCModel.Tools" version="11.0.0-beta0135" targetFramework="net461" />
59-
<package id="SIL.LCModel.Utils.Tests" version="11.0.0-beta0135" targetFramework="net461" />
60-
<package id="SIL.LCModel.Utils" version="11.0.0-beta0135" targetFramework="net461" />
61-
<package id="SIL.LCModel" version="11.0.0-beta0135" targetFramework="net461" />
53+
<package id="SIL.LCModel.Build.Tasks" version="11.0.0-beta0136" targetFramework="net461" />
54+
<package id="SIL.LCModel.Core.Tests" version="11.0.0-beta0136" targetFramework="net461" />
55+
<package id="SIL.LCModel.Core" version="11.0.0-beta0136" targetFramework="net461" />
56+
<package id="SIL.LCModel.FixData" version="11.0.0-beta0136" targetFramework="net461" />
57+
<package id="SIL.LCModel.Tests" version="11.0.0-beta0136" targetFramework="net461" />
58+
<package id="SIL.LCModel.Tools" version="11.0.0-beta0136" targetFramework="net461" />
59+
<package id="SIL.LCModel.Utils.Tests" version="11.0.0-beta0136" targetFramework="net461" />
60+
<package id="SIL.LCModel.Utils" version="11.0.0-beta0136" targetFramework="net461" />
61+
<package id="SIL.LCModel" version="11.0.0-beta0136" targetFramework="net461" />
6262
<package id="SIL.Lexicon" version="15.0.0-beta0117" targetFramework="net462" />
6363
<package id="SIL.libpalaso.l10ns" version="6.0.0" targetFramework="net461" />
6464
<package id="SIL.Lift" version="15.0.0-beta0117" targetFramework="net462" />

DistFiles/Language Explorer/Configuration/Main.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
</command>
254254
<!-- This is on the popup menu, and is for non-record level objects. -->
255255
<command id="CmdDeleteSelectedObject" label="Delete selected {0}" message="DeleteSelectedItem"/>
256+
<command id="CmdDuplicateSelectedObject" label="Duplicate selected {0}" message="DuplicateSelectedItem"/>
256257
<command id="CmdAlwaysVisible" label="Always visible" message="ShowFieldAlwaysVisible"/>
257258
<command id="CmdIfData" label="Normally hidden, unless non-empty" message="ShowFieldIfData"/>
258259
<command id="CmdNormallyHidden" label="Normally hidden" message="ShowFieldNormallyHidden"/>
@@ -654,6 +655,7 @@
654655
<item command="CmdEnvironmentsJumpToDefault"/>
655656
<item label="-" translate="do not translate"/>
656657
<item command="CmdDeleteSelectedObject"/>
658+
<item command="CmdDuplicateSelectedObject"/>
657659
</menu>
658660

659661
<menu id="mnuBrowseView">
@@ -674,6 +676,7 @@
674676
<item command="CmdEnvironmentsJumpToDefault"/>
675677
<item label="-" translate="do not translate"/>
676678
<item command="CmdDeleteSelectedObject"/>
679+
<item command="CmdDuplicateSelectedObject"/>
677680
</menu>
678681
<!-- The following commands are involked/displayed on a right click on a slice on at Possibility list item.
679682

Src/Common/Controls/XMLViews/BrowseViewer.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
// This software is licensed under the LGPL, version 2.1 or later
33
// (http://www.gnu.org/licenses/lgpl-2.1.html)
44

5+
using SIL.FieldWorks.Common.FwUtils;
6+
using SIL.FieldWorks.Common.RootSites;
7+
using SIL.FieldWorks.Common.ViewsInterfaces;
8+
using SIL.FieldWorks.Filters;
9+
using SIL.FieldWorks.Resources;
10+
using SIL.LCModel;
11+
using SIL.LCModel.Application;
12+
using SIL.LCModel.Core.KernelInterfaces;
13+
using SIL.LCModel.Core.WritingSystems;
14+
using SIL.LCModel.DomainServices;
15+
using SIL.LCModel.Utils;
16+
using SIL.PlatformUtilities;
17+
using SIL.Reporting;
18+
using SIL.Utils;
519
using System;
620
using System.Collections;
721
using System.Collections.Generic;
@@ -11,20 +25,6 @@
1125
using System.Text;
1226
using System.Windows.Forms;
1327
using System.Xml;
14-
using SIL.LCModel.Core.WritingSystems;
15-
using SIL.LCModel.Core.KernelInterfaces;
16-
using SIL.FieldWorks.Common.ViewsInterfaces;
17-
using SIL.FieldWorks.Common.FwUtils;
18-
using SIL.FieldWorks.Common.RootSites;
19-
using SIL.LCModel;
20-
using SIL.LCModel.Application;
21-
using SIL.LCModel.DomainServices;
22-
using SIL.FieldWorks.Filters;
23-
using SIL.FieldWorks.Resources;
24-
using SIL.Reporting;
25-
using SIL.LCModel.Utils;
26-
using SIL.PlatformUtilities;
27-
using SIL.Utils;
2828
using XCore;
2929

3030
namespace SIL.FieldWorks.Common.Controls
@@ -328,6 +328,19 @@ protected override void OnGotFocus(EventArgs e)
328328
m_xbv.Focus();
329329
}
330330

331+
/// <summary>
332+
/// Update the selected cache for the given item.
333+
/// </summary>
334+
public void OnUpdateItemCheckedState(object obj)
335+
{
336+
if (obj is ICmObject)
337+
{
338+
int hvoItem = ((ICmObject)obj).Hvo;
339+
int currentValue = GetCheckState(hvoItem);
340+
SetItemCheckedState(hvoItem, currentValue, false);
341+
}
342+
}
343+
331344
/// <summary>
332345
/// This supports external clients using the Bulk Edit Preview functionality.
333346
/// To turn on, set to the index of the column that should have the preview

Src/LexText/Lexicon/ReversalEntryBulkEdit.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ public override bool CanInsertClass(string className)
4949
return className == "ReversalIndexEntry";
5050
}
5151

52-
public override bool CreateAndInsert(string className)
52+
public override bool CreateAndInsert(string className, out ICmObject newObj)
5353
{
5454
if (className != "ReversalIndexEntry")
55-
return base.CreateAndInsert(className);
55+
return base.CreateAndInsert(className, out newObj);
5656
m_newItem = m_cache.ServiceLocator.GetInstance<IReversalIndexEntryFactory>().Create();
57+
newObj = m_newItem;
5758
var ri = (IReversalIndex)m_owningObject;
5859
ri.EntriesOC.Add(m_newItem);
5960
var extensions = m_cache.ActionHandlerAccessor as IActionHandlerExtensions;

Src/xWorks/RecordClerk.cs

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ public bool OnInsertItemInVector(object argument)
25362536
UndoableUnitOfWorkHelper.Do(string.Format(xWorksStrings.ksUndoInsert, command.UndoRedoTextInsert),
25372537
string.Format(xWorksStrings.ksRedoInsert, command.UndoRedoTextInsert), Cache.ActionHandlerAccessor, () =>
25382538
{
2539-
result = m_list.CreateAndInsert(className);
2539+
result = m_list.CreateAndInsert(className, out _);
25402540
});
25412541
}
25422542
catch (ApplicationException ae)
@@ -2612,6 +2612,83 @@ public bool OnDuplicateItemInVector(object argument)
26122612
return result;
26132613
}
26142614

2615+
/// <summary>
2616+
/// see if it makes sense to provide the "duplicate XXX" command now
2617+
/// </summary>
2618+
/// <param name="commandObject"></param>
2619+
/// <param name="display"></param>
2620+
/// <returns></returns>
2621+
public virtual bool OnDisplayDuplicateSelectedItem(object commandObject, ref UIItemDisplayProperties display)
2622+
{
2623+
CheckDisposed();
2624+
2625+
string className = Cache.MetaDataCacheAccessor.GetClassName(m_list.ListItemsClass);
2626+
if (m_list.CurrentObject == null ||
2627+
!m_list.IsCurrentObjectValid() ||
2628+
!m_list.CanInsertClass(m_list.CurrentObject.ClassName) ||
2629+
!(m_list.CurrentObject is ICloneableCmObject))
2630+
{
2631+
display.Visible = display.Enabled = false;
2632+
}
2633+
else
2634+
{
2635+
display.Text = string.Format(display.Text, GetTypeNameForUi(m_list.CurrentObject));
2636+
}
2637+
2638+
return true;
2639+
}
2640+
2641+
/// <summary>
2642+
/// Duplicate selected item in a non-possibilities list.
2643+
/// </summary>
2644+
public bool OnDuplicateSelectedItem(object argument)
2645+
{
2646+
CheckDisposed();
2647+
2648+
if (!Editable)
2649+
return false;
2650+
2651+
if (m_list.CurrentObject == null ||
2652+
!m_list.IsCurrentObjectValid() ||
2653+
!m_list.CanInsertClass(m_list.CurrentObject.ClassName) ||
2654+
!(m_list.CurrentObject is ICloneableCmObject))
2655+
return false;
2656+
2657+
SaveOnChangeRecord();
2658+
2659+
var command = (Command)argument;
2660+
ICmObject selectedObject = m_list.CurrentObject;
2661+
string className = selectedObject.ClassName;
2662+
bool result = false;
2663+
m_suppressSaveOnChangeRecord = true;
2664+
ICmObject newObj = null;
2665+
2666+
try
2667+
{
2668+
UndoableUnitOfWorkHelper.Do(string.Format(xWorksStrings.ksUndoDuplicate, className),
2669+
string.Format(xWorksStrings.ksRedoDuplicate, className),
2670+
Cache.ActionHandlerAccessor, () =>
2671+
{
2672+
result = m_list.CreateAndInsert(className, out newObj);
2673+
((ICloneableCmObject)selectedObject).SetCloneProperties(newObj);
2674+
});
2675+
}
2676+
catch (ApplicationException ae)
2677+
{
2678+
throw new ApplicationException("Could not duplicate the item requested by the command " + command.ConfigurationNode, ae);
2679+
}
2680+
finally
2681+
{
2682+
m_suppressSaveOnChangeRecord = false;
2683+
}
2684+
2685+
if (newObj != null)
2686+
m_mediator.BroadcastMessage("UpdateItemCheckedState", newObj);
2687+
m_mediator.BroadcastMessage("FocusFirstPossibleSlice", null);
2688+
return result;
2689+
}
2690+
2691+
26152692
#endregion
26162693

26172694
/// <summary>

Src/xWorks/RecordList.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,10 +3215,11 @@ public static void SetUpConstChartTemplateTemplate(ICmPossibility templateRoot)
32153215
/// </summary>
32163216
/// <param name="className"></param>
32173217
/// <returns>true if successful (the class is known)</returns>
3218-
public virtual bool CreateAndInsert(string className)
3218+
public virtual bool CreateAndInsert(string className, out ICmObject newObj)
32193219
{
32203220
CheckDisposed();
32213221

3222+
newObj = null;
32223223
ClassAndPropInfo cpi = GetMatchingClass(className);
32233224
Debug.Assert(cpi != null, "This object should not have been asked to insert an object of the class " + className + ".");
32243225
if (cpi != null)
@@ -3245,7 +3246,7 @@ public virtual bool CreateAndInsert(string className)
32453246
cpiPath = new List<ClassAndPropInfo>(new ClassAndPropInfo[] { cpi });
32463247
#endif
32473248
var createAndInsertMethodObj = new CpiPathBasedCreateAndInsert(m_owningObject.Hvo, cpiPath, this);
3248-
var newObj = DoCreateAndInsert(createAndInsertMethodObj);
3249+
newObj = DoCreateAndInsert(createAndInsertMethodObj);
32493250
int hvoNew = newObj != null ? newObj.Hvo : 0;
32503251
return hvoNew != 0; // If we get zero, we couldn't do it for some reason.
32513252
}

0 commit comments

Comments
 (0)