//
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Internal;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Windows;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System;
[assembly
: ExtensionApplication
(typeof(BlackBox
.AutoCAD.BlockEditorTools.Events))]
namespace BlackBox.AutoCAD.BlockEditorTools
{
public class Events : IExtensionApplication
{
private static DocumentCollection acDocs = acApp.DocumentManager;
private static RibbonTab blockEditorTab;
private static string tabName = "Block Editor";
void IExtensionApplication.Initialize()
{
acApp.Idle += onIdle;
}
void IExtensionApplication.Terminate()
{
if (blockEditorTab != null)
blockEditorTab.Title = tabName;
}
private static void onIdle(object sender, EventArgs e)
{
acApp.Idle -= onIdle;
Document doc = acDocs.MdiActiveDocument;
if (doc == null)
{
acDocs.DocumentCreated += onDocumentCreated;
return;
}
Register();
}
private static void onActivated(object sender, EventArgs e)
{
blockEditorTab.Activated -= onActivated;
blockEditorTab.Deactivated += onDeactivated;
string blockName = tabName + ": " + AcAeUtilities.GetBlockName();
blockEditorTab.Title = blockName;
acDocs.MdiActiveDocument.Editor.WriteMessage("\n{0} \n", blockName);
}
private static void onDeactivated(object sender, EventArgs e)
{
blockEditorTab.Deactivated -= onDeactivated;
blockEditorTab.Activated += onActivated;
blockEditorTab.Title = tabName;
}
private static void onDocumentCreated(object sender, DocumentCollectionEventArgs e)
{
Register();
}
private static void Register()
{
RibbonControl rc =
Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl;
blockEditorTab = rc.FindTab("ACAD.ID_BlockEditorTab");
if (blockEditorTab == null)
{
acDocs.MdiActiveDocument.Editor.WriteMessage(
"\n** \"Block Editor\" ribbon tab cannot be found ** \n");
return;
}
blockEditorTab.Activated += onActivated;
acDocs.MdiActiveDocument.Editor.WriteMessage(
"\nBlackBox Block Editor Tools loaded. \n");
}
}
}