Skip to content

Commit 18860ff

Browse files
DYN-9829: Avoid backup-on-backup creation and disable migration tooltip when inactive (#16755)
Co-authored-by: Ashish Aggarwal <[email protected]>
1 parent 571bb28 commit 18860ff

File tree

6 files changed

+30
-32
lines changed

6 files changed

+30
-32
lines changed

src/Libraries/PythonNodeModels/Properties/Resources.Designer.cs

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Libraries/PythonNodeModels/Properties/Resources.en-US.resx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,4 @@
226226
<data name="PythonScriptEditorEngineRequestToUpdatedBarText" xml:space="preserve">
227227
<value>Please update Python Engine to PythonNet3</value>
228228
</data>
229-
<data name="PythonScriptEditorMigrationAssistantButtonDisabledTooltip" xml:space="preserve">
230-
<value>Python engine has been updated to {0}. No conversion should be necessary. If the script shows errors from old IronPython2 syntax, switch the engine back to IronPython2 to re-enable the converter.</value>
231-
</data>
232-
</root>
229+
</root>

src/Libraries/PythonNodeModels/Properties/Resources.resx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,4 @@
227227
<data name="PythonScriptEditorEngineRequestToUpdatedBarText" xml:space="preserve">
228228
<value>Please update Python Engine to PythonNet3</value>
229229
</data>
230-
<data name="PythonScriptEditorMigrationAssistantButtonDisabledTooltip" xml:space="preserve">
231-
<value>Python engine has been updated to {0}. No conversion should be necessary. If the script shows errors from old IronPython2 syntax, switch the engine back to IronPython2 to re-enable the converter.</value>
232-
</data>
233230
</root>

src/Libraries/PythonNodeModelsWpf/ScriptEditorWindow.xaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,7 @@
301301
</ComboBox>
302302
<Button Style="{StaticResource IconButton}"
303303
Name="MigrationAssistantButton"
304-
Click="OnMigrationAssistantClicked"
305-
ToolTipService.ShowOnDisabled="True"
306-
ToolTipService.IsEnabled="True">
304+
Click="OnMigrationAssistantClicked">
307305
<Button.ToolTip>
308306
<ToolTip Style="{StaticResource GenericToolTipLight}"/>
309307
</Button.ToolTip>

src/Libraries/PythonNodeModelsWpf/ScriptEditorWindow.xaml.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ internal void Initialize(Guid workspaceGuid, Guid nodeGuid, string propName, str
159159
editText.SyntaxHighlighting = HighlightingLoader.Load(
160160
new XmlTextReader(elem), HighlightingManager.Instance);
161161

162+
// Set migrator tooltip
163+
var tooltip = MigrationAssistantButton.ToolTip as System.Windows.Controls.ToolTip;
164+
if (tooltip != null)
165+
{
166+
tooltip.Content = string.Format(
167+
PythonNodeModels.Properties.Resources.PythonScriptEditorMigrationAssistantButtonTooltip,
168+
PythonEngineManager.PythonNet3EngineName);
169+
}
170+
162171
// Add custom highlighting rules consistent with DesignScript
163172
CodeHighlightingRuleFactory.AddCommonHighlighingRules(editText, dynamoViewModel.EngineController);
164173

@@ -322,18 +331,8 @@ private bool ShouldUpdate()
322331
private void UpdateMigrationAssistantButtonEnabled()
323332
{
324333
var enable = CachedEngine == PythonEngineManager.IronPython2EngineName;
325-
326334
MigrationAssistantButton.IsEnabled = enable;
327-
328-
var tooltip = MigrationAssistantButton.ToolTip as System.Windows.Controls.ToolTip;
329-
var message = enable
330-
? String.Format(
331-
PythonNodeModels.Properties.Resources.PythonScriptEditorMigrationAssistantButtonTooltip,
332-
PythonEngineManager.PythonNet3EngineName)
333-
: String.Format(
334-
PythonNodeModels.Properties.Resources.PythonScriptEditorMigrationAssistantButtonDisabledTooltip,
335-
PythonEngineManager.PythonNet3EngineName);
336-
tooltip.Content = message;
335+
System.Windows.Controls.ToolTipService.SetIsEnabled(MigrationAssistantButton, enable);
337336
}
338337

339338
#region Text Zoom in Python Editor

src/PythonMigrationViewExtension/PythonMigrationViewExtension.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ private void OnCurrentWorkspaceChanged(IWorkspaceModel workspace)
272272
return;
273273
}
274274

275-
if (!string.IsNullOrEmpty(CurrentWorkspace.FileName))
275+
if (IsWorkspaceEligibleForBackup(CurrentWorkspace))
276276
{
277277
upgradeService.SaveMigrationBackup(
278278
CurrentWorkspace,
279279
CurrentWorkspace.FileName,
280280
PythonEngineManager.CPython3EngineName);
281-
}
281+
}
282282

283283
if (CurrentWorkspace is HomeWorkspaceModel hws)
284284
{
@@ -602,5 +602,21 @@ private void RecomputeEngineFlags()
602602
hasCPython3Engine = PythonEngineManager.Instance.AvailableEngines
603603
.Any(e => e.Name == PythonEngineManager.CPython3EngineName);
604604
}
605+
606+
private bool IsWorkspaceEligibleForBackup(WorkspaceModel workspace)
607+
{
608+
if ( workspace == null) return false;
609+
610+
var filePath = workspace.FileName;
611+
if (string.IsNullOrWhiteSpace(filePath)) return false;
612+
613+
var backupDir = LoadedParams?.StartupParams?.PathManager?.BackupDirectory;
614+
if (backupDir == null) return false;
615+
616+
var workspaceDir = System.IO.Path.GetDirectoryName(filePath);
617+
if (workspaceDir == null) return false;
618+
619+
return !backupDir.Equals(workspaceDir, StringComparison.OrdinalIgnoreCase);
620+
}
605621
}
606622
}

0 commit comments

Comments
 (0)