using System; using System.IO; using Autodesk.Revit.DB.Events; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Events; using SAGY.DotNetUtils; using SAGY.RevitMenu.Configuration; using SAGY.RevitUtils; using SAGY.RevitUtils.Extends; using TSZ.RevitMenu; using TSZ.RevitMenu.Configuration; namespace SAGY.RevitMenu { public class Globals : IRegisterDockpaneApp { private static ScreenMenu _dockMenu = null; private static bool _mIsHide; public const string ApplicationName = "屏幕菜单"; public const string DiagnosticsPanelName = "屏幕菜单"; public static ExternalCommandData ExtCmdData = null; public static DockablePaneId MLeftDockablePanelId = new DockablePaneId(new Guid("7EB1ED3F-0993-4540-B291-D17FF539F5B9")); public const string ScreenMenuState = "TSZ.ScreenMenu.State"; public static UIControlledApplication UiApp = null; private void application_ApplicationClosing(object sender, ApplicationClosingEventArgs e) { _mIsHide = false; if (GetState()) { PressHelper.KeyPress("HIDMENU"); _mIsHide = true; } SaveState(_mIsHide); } private void ControlledApplication_DocumentCreated(object sender, DocumentCreatedEventArgs e) { if (!e.Document.IsFamilyDocument) { _mIsHide = GetState(); IntPtr mainWindowHandle = RevitProcess.GetMainWindowHandle(); if (_mIsHide) { PressHelper.KeyPress(mainWindowHandle, "SHOMENU"); } else { PressHelper.KeyPress(mainWindowHandle, "HIDMENU"); } } } private void ControlledApplication_DocumentOpened(object sender, DocumentOpenedEventArgs e) { if (!e.Document.IsFamilyDocument) { IntPtr mainWindowHandle = RevitProcess.GetMainWindowHandle(); _mIsHide = GetState(); if (_mIsHide) { PressHelper.KeyPress(mainWindowHandle, "SHOMENU"); } else { PressHelper.KeyPress("HIDMENU"); } AppRegister.RegisterStructRebarCount(e.Document); } } public static bool GetState() { try { IniFileOperate operate = new IniFileOperate(Path.Combine(AppBaseInfo.AppTempFilePath, "TSZ.ScreenMenu.State.ini")); return operate.ReadValue("RevitMenu", "TSZ.ScreenMenu.State").ToBool(); } catch (Exception exception) { MessageShow.Show(exception, true, ""); } return true; } public static void HidePanels(ExternalCommandData cmdData) { SetWindowVisibility(cmdData, MLeftDockablePanelId, false); } public static void HidePanels(UIControlledApplication application) { SetWindowVisibility(application, MLeftDockablePanelId, false); } public bool RegisterApp(UIControlledApplication application) { try { UiApp = application; _dockMenu = new ScreenMenu(); _dockMenu.SetInitialDockingParameters(0, 150, 0, 700, DockPosition.Bottom, Guid.Empty); application.RegisterDockablePane(MLeftDockablePanelId, "屏幕菜单", _dockMenu); application.ControlledApplication.DocumentCreated += new EventHandler(this.ControlledApplication_DocumentCreated); application.ControlledApplication.DocumentOpened += new EventHandler(this.ControlledApplication_DocumentOpened); application.ApplicationClosing += new EventHandler(this.application_ApplicationClosing); } catch (Exception exception) { MessageShow.Show(exception, false, ""); return false; } return true; } public static void SaveState(bool state) { try { new IniFileOperate(Path.Combine(AppBaseInfo.AppTempFilePath, "TSZ.ScreenMenu.State.ini")).WriteValue("RevitMenu", "TSZ.ScreenMenu.State", state.ToString()); } catch (Exception exception) { MessageShow.Show(exception, true, ""); } } private static void SetWindowVisibility(ExternalCommandData cmdData, DockablePaneId dockablePaneId, bool state) { try { DockablePane dockablePane = cmdData.Application.GetDockablePane(dockablePaneId); if (dockablePane != null) { if (state) { _dockMenu.SetCmdData(cmdData); dockablePane.Show(); } else { _dockMenu.SetCmdData(cmdData); dockablePane.Hide(); } } } catch (Exception exception) { MessageShow.Show(exception, false, ""); } } private static void SetWindowVisibility(UIControlledApplication application, DockablePaneId dockablePaneId, bool state) { try { DockablePane dockablePane = application.GetDockablePane(dockablePaneId); if (dockablePane != null) { if (state) { dockablePane.Show(); } else { dockablePane.Hide(); } } } catch (Exception exception) { MessageShow.Show(exception, false, ""); } } public static void ShowPanels(ExternalCommandData cmdData) { SetWindowVisibility(cmdData, MLeftDockablePanelId, true); } public static void ShowPanels(UIControlledApplication application) { SetWindowVisibility(application, MLeftDockablePanelId, true); } } }