Skip to content

Commit

Permalink
Save/Load view extension size and location (#11278)
Browse files Browse the repository at this point in the history
Information of where an extension control was last shown is saved and
retrieved as preference settings. These are actually not directly
visible for the user and are updating automatically, just like the main
Dynamo window size. These settings are used when showing the extension
control, to restore it to how it used to be before closing it.

The available information for each view extension is:

1. How it is shown. For now this can be either as a floating window or
docked to the right-side panel.

2. In case it is shown as a floating window, the following information
about the window is saved:
- Location by Top/Left coordinates
- Size by Width/Height
- Whether the window is maximized
  • Loading branch information
mmisol authored Nov 30, 2020
1 parent c47ad9f commit 8bfad9b
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 77 deletions.
6 changes: 6 additions & 0 deletions src/DynamoCore/Configuration/PreferenceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ public string DefaultPythonEngine
[XmlIgnore]
public bool NamespacesToExcludeFromLibrarySpecified { get; set; }

/// <summary>
/// Settings that apply to view extensions.
/// </summary>
public List<ViewExtensionSettings> ViewExtensionSettings { get; set; }

#endregion

/// <summary>
Expand Down Expand Up @@ -415,6 +420,7 @@ public PreferenceSettings()
ShowTabsAndSpacesInScriptEditor = false;
EnableNodeAutoComplete = false;
DefaultPythonEngine = string.Empty;
ViewExtensionSettings = new List<ViewExtensionSettings>();
}

/// <summary>
Expand Down
86 changes: 86 additions & 0 deletions src/DynamoCore/Configuration/ViewExtensionSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
namespace Dynamo.Configuration
{
/// <summary>
/// Settings that apply to a view extension specifically.
/// </summary>
public class ViewExtensionSettings
{
/// <summary>
/// Name of the view extension.
/// </summary>
public string Name { get; set; }
/// <summary>
/// UniqueId of the view extension.
/// </summary>
public string UniqueId { get; set; }
/// <summary>
/// Specifies how an extension UI control should be displayed.
/// </summary>
public ViewExtensionDisplayMode DisplayMode { get; set; }
/// <summary>
/// Window settings for the extension control when displayed in FloatingWindow mode.
/// </summary>
public WindowSettings WindowSettings { get; set; }
}

/// <summary>
/// Possible display modes for an extension UI control.
/// </summary>
public enum ViewExtensionDisplayMode
{
/// <summary>
/// Not really a display mode but rather the absence of one.
/// </summary>
Unspecified,
/// <summary>
/// Extension control should be displayed docked to the right side.
/// </summary>
DockRight,
/// <summary>
/// Extension control should be displayed in a floating window.
/// </summary>
FloatingWindow
}

/// <summary>
/// Settings that define how to display an extension control in floating window mode.
/// </summary>
public class WindowSettings
{
/// <summary>
/// Status of the window, i.e. whether it is maximized.
/// </summary>
public WindowStatus Status { get; set; }
/// <summary>
/// Coordinates of the leftmost side of the window.
/// </summary>
public int Left { get; set; }
/// <summary>
/// Coordinates of the topmost side of the window.
/// </summary>
public int Top { get; set; }
/// <summary>
/// Width of the window.
/// </summary>
public int Width { get; set; }
/// <summary>
/// Height of the window.
/// </summary>
public int Height { get; set; }
}

/// <summary>
/// Possible status of a floating window.
/// </summary>
public enum WindowStatus
{
/// <summary>
/// The window can be moved and resized.
/// </summary>
Normal,
/// <summary>
/// The window is maximized.
/// </summary>
Maximized
}
}
1 change: 1 addition & 0 deletions src/DynamoCore/DynamoCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ limitations under the License.
<Link>Properties\AssemblySharedInfo.cs</Link>
</Compile>
<Compile Include="Configuration\ExecutionSession.cs" />
<Compile Include="Configuration\ViewExtensionSettings.cs" />
<Compile Include="Core\CrashPromptArgs.cs" />
<Compile Include="Configuration\DebugSettings.cs" />
<Compile Include="Configuration\Context.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/Extensions/ViewLoadedParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public void AddMenuItem(MenuBarType type, MenuItem menuItem, int index = -1)
/// <returns></returns>
public void AddToExtensionsSideBar(IViewExtension viewExtension, ContentControl contentControl)
{
TabItem tabItem = dynamoView.AddExtensionTabItem(viewExtension, contentControl);
bool added = dynamoView.AddOrFocusExtensionControl(viewExtension, contentControl);

if (tabItem != null)
if (added)
{
dynamoViewModel.Model.Logger.Log(Wpf.Properties.Resources.ExtensionAdded);
}
Expand Down
Loading

0 comments on commit 8bfad9b

Please sign in to comment.