using System.Windows;
using ZwSoft.ZwCAD.Runtime;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(ZwCadUISample.Palette.Commands))]
namespace ZwCadUISample.Palette
{
internal class Commands
{
// static field
static CustomPaletteSet palette;
/// <summary>
/// Command to show the palette.
/// </summary>
[CommandMethod("CMD_PALETTE", CommandFlags.Modal)]
public void ShowPaletteSet()
{
// creation of the palette at the first call of the command
if (palette == null)
palette = new CustomPaletteSet();
palette.Visible = true;
}
}
}
using System;
using ZwSoft.ZwCAD.Windows;
using ZwApp = ZwSoft.ZwCAD.ApplicationServices.Application;
namespace ZwCadUISample.Palette
{
internal class CustomPaletteSet : PaletteSet
{
// static field
static bool wasVisible;
/// <summary>
/// Creates a new instance of CustomPaletteSet.
/// </summary>
public CustomPaletteSet()
: base ("Palette", "CMD_PALETTE", new Guid("{D89DDA33-318B-47F5-A264-F7EECDC2A876}"))
{
Style =
PaletteSetStyles.ShowAutoHideButton |
PaletteSetStyles.ShowCloseButton |
PaletteSetStyles.ShowPropertiesMenu;
MinimumSize = new System.Drawing.Size(250, 150);
Add("ShowTest", new PaletteTab());
// automatically hide the palette while none document is active (no document state)
var docs = ZwApp.DocumentManager;
docs.DocumentBecameCurrent += (s, e) => Visible = e.Document == null ? false : wasVisible;
docs.DocumentCreated += (s, e) => Visible = wasVisible;
docs.DocumentToBeDeactivated += (s, e) => wasVisible = Visible;
docs.DocumentToBeDestroyed += (s, e) =>
{
wasVisible = Visible;
if (docs.Count == 1)
Visible = false;
};
}
}
}
Hi,
You can use event handler methods instead of the lambda expressions so the you can set break points to check the value of the 'wasVisible' static field.Code - C#: [Select]
public CustomPaletteSet() { Style = PaletteSetStyles.ShowAutoHideButton | PaletteSetStyles.ShowCloseButton | PaletteSetStyles.ShowPropertiesMenu; // masquage automatique de la palette quand aucune instance de Document n'est active (no document state) var docs = Application.DocumentManager; docs.DocumentBecameCurrent += Docs_DocumentBecameCurrent; docs.DocumentCreated += Docs_DocumentCreated; docs.DocumentToBeDeactivated += Docs_DocumentToBeDeactivated; docs.DocumentToBeDestroyed += Docs_DocumentToBeDestroyed; } private void Docs_DocumentBecameCurrent(object sender, DocumentCollectionEventArgs e) => Visible = e.Document == null ? false : wasVisible; private void Docs_DocumentCreated(object sender, DocumentCollectionEventArgs e) => Visible = wasVisible; private void Docs_DocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e) => wasVisible = Visible; private void Docs_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e) { wasVisible = Visible; if (Application.DocumentManager.Count == 1) Visible = false; }
Hi,
You can use event handler methods instead of the lambda expressions so the you can set break points to check the value of the 'wasVisible' static field.Code - C#: [Select]
public CustomPaletteSet() { Style = PaletteSetStyles.ShowAutoHideButton | PaletteSetStyles.ShowCloseButton | PaletteSetStyles.ShowPropertiesMenu; // masquage automatique de la palette quand aucune instance de Document n'est active (no document state) var docs = Application.DocumentManager; docs.DocumentBecameCurrent += Docs_DocumentBecameCurrent; docs.DocumentCreated += Docs_DocumentCreated; docs.DocumentToBeDeactivated += Docs_DocumentToBeDeactivated; docs.DocumentToBeDestroyed += Docs_DocumentToBeDestroyed; } private void Docs_DocumentBecameCurrent(object sender, DocumentCollectionEventArgs e) => Visible = e.Document == null ? false : wasVisible; private void Docs_DocumentCreated(object sender, DocumentCollectionEventArgs e) => Visible = wasVisible; private void Docs_DocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e) => wasVisible = Visible; private void Docs_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e) { wasVisible = Visible; if (Application.DocumentManager.Count == 1) Visible = false; }
Hi Gile
I edited the file, but the problem persists.
The palette is not loaded when the last document is closed and a new document is created.
You need to understand how the program is supposed to work with this static 'wasVisible' field to be able to diagnose what's wrong with ZwCad.
When a document is about to be closed (DocumentToBeDestroyed) the program stores the current value of the Visible property in the 'wasVisible' field, and if this document is the only one open, the Visible property is set to false to hide the palette.
When a new document is opened (DocumentCreated), the program sets the Visible property to the value stored in the 'wasVisible' field.
So, if the palette is visible when you close the last opened document, 'wasVisible' is set to true and the Palette hides (No document state). When you open a document, the Visible property should be se to true (the value stored in 'wasVisible').
Knowing this, you should be able to diagnose what's wrong with ZwCad.
You need to understand how the program is supposed to work with this static 'wasVisible' field to be able to diagnose what's wrong with ZwCad.
When a document is about to be closed (DocumentToBeDestroyed) the program stores the current value of the Visible property in the 'wasVisible' field, and if this document is the only one open, the Visible property is set to false to hide the palette.
When a new document is opened (DocumentCreated), the program sets the Visible property to the value stored in the 'wasVisible' field.
So, if the palette is visible when you close the last opened document, 'wasVisible' is set to true and the Palette hides (No document state). When you open a document, the Visible property should be se to true (the value stored in 'wasVisible').
Knowing this, you should be able to diagnose what's wrong with ZwCad.
docs.DocumentToBeDestroyed += (s, e) =>
{
wasVisible = Visible;
if (docs.Count == 1)
Visible = false;
};
public void Docs_DocumentToBeDeactivated(object sender, DocumentCollectionEventArgs e)
{
if (ZwApp.DocumentManager.Count != 1)
{
wasVisible = Visible;
}
}