/// <summary> /// Finishes initializing this instance. Is called once, after the app's main window has loaded. /// Registers commands and calls LoadSettings().</summary> void IInitializable.Initialize() { // register our menu commands if (CommandService != null && RegisterMenuCommands) { if (m_settingService.AllowUserEdits) { CommandService.RegisterCommand( CommandId.EditPreferences, StandardMenu.Edit, StandardCommandGroup.EditPreferences, "Preferences...".Localize("Edit user preferences"), "Edit user preferences".Localize(), this); } if (m_settingService.AllowUserLoadSave) { CommandService.RegisterCommand( CommandId.EditImportExportSettings, StandardMenu.Edit, StandardCommandGroup.EditPreferences, "Load or Save Settings...".Localize(), "User can save or load application settings from files".Localize(), this); } } // load settings as late as possible, so that other components have a chance to // register their settings first m_settingService.LoadSettings(); }
/// <summary> /// Initialize</summary> public override void Initialize() { base.Initialize(); if (CommandService == null) { return; } CommandService.RegisterCommand( Command.SaveLayoutAs, StandardMenu.Window, StandardCommandGroup.UILayout, string.Format("{0}{1}{2}", MenuName, MenuSeparator, MenuSaveLayoutAs), "Save layout as...".Localize(), Input.Keys.None, null, CommandVisibility.Menu, this); CommandService.RegisterCommand( Command.ManageLayouts, StandardMenu.Window, StandardCommandGroup.UILayout, string.Format("{0}{1}{2}", MenuName, MenuSeparator, MenuManageLayouts), "Manage layouts...".Localize(), Input.Keys.None, null, CommandVisibility.Menu, this); }
void IInitializable.Initialize() { // build dictionary to map file types to document clients m_typeToClientMap.Clear(); foreach (Lazy <IDocumentClient> lazy in m_documentClients) { IDocumentClient client = lazy.Value; m_typeToClientMap.Add(client.Info.FileType, client); } // register standard file menu commands if ((RegisterCommands & CommandRegister.FileSave) == CommandRegister.FileSave) { CommandService.RegisterCommand(CommandInfo.FileSave, this); } if ((RegisterCommands & CommandRegister.FileSaveAs) == CommandRegister.FileSaveAs) { CommandService.RegisterCommand(CommandInfo.FileSaveAs, this); } if ((RegisterCommands & CommandRegister.FileSaveAll) == CommandRegister.FileSaveAll) { CommandService.RegisterCommand(CommandInfo.FileSaveAll, this); } if ((RegisterCommands & CommandRegister.FileClose) == CommandRegister.FileClose) { CommandService.RegisterCommand(CommandInfo.FileClose, this); } RegisterClientCommands(); Initialize(); }
private void RegisterClientCommands() { int clientCount = m_documentClients.Length; // for each document client, build file/new and file/open commands int index = 0; foreach (Lazy <IDocumentClient> lazy in m_documentClients) { IDocumentClient client = lazy.Value; Keys newShortcut = Keys.None; Keys openShortcut = Keys.None; if (index == 0) { newShortcut = Keys.Control | Keys.N; openShortcut = Keys.Control | Keys.O; } string newIconName = client.Info.NewIconName; if ((RegisterCommands & CommandRegister.FileNew) == CommandRegister.FileNew) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileNew, client), StandardMenu.File, StandardCommandGroup.FileNew, clientCount > 1 ? "New".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("New {0}".Localize(), client.Info.FileType), string.Format("Creates a new {0} document".Localize("{0} is the type of document to create"), client.Info.FileType), newShortcut, newIconName, (!string.IsNullOrEmpty(newIconName)) ? CommandVisibility.All : CommandVisibility.Menu), this); } string openIconName = client.Info.OpenIconName; if ((RegisterCommands & CommandRegister.FileOpen) == CommandRegister.FileOpen) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileOpen, client), StandardMenu.File, StandardCommandGroup.FileNew, clientCount > 1 ? "Open".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("Open {0}".Localize(), client.Info.FileType), string.Format("Open an existing {0} document".Localize(), client.Info.FileType), openShortcut, openIconName, (!string.IsNullOrEmpty(openIconName)) ? CommandVisibility.All : CommandVisibility.Menu), this); } index++; } }
/// <summary> /// Updates recent file menu items</summary> protected virtual void UpdateRecentFilesMenuItems() { if (CommandService != null) { var newCommandInfos = new List <CommandInfo>(); foreach (RecentDocumentInfo info in m_recentDocuments) { if (m_registeredRecentDocs.Contains(info)) { CommandService.UnregisterCommand(info, this); m_registeredRecentDocs.Remove(info); } } if (m_recentDocuments.Count > 0) { // Remove the "empty" entry from the MRU, since we have at least one document now. if (m_emptyMruCommandInfo != null) { CommandService.UnregisterCommand(m_emptyMruCommandInfo.CommandTag, this); m_emptyMruCommandInfo = null; } } foreach (RecentDocumentInfo info in m_recentDocuments.MostRecentOrder) { if (!m_registeredRecentDocs.Contains(info)) { string pathName = info.Uri.LocalPath; // replace slashes, so command service doesn't create hierarchical menu; actual path // is set in our UpdateCommand method. pathName = pathName.Replace("/", "-"); pathName = pathName.Replace("\\", "-"); var commandInfo = new CommandInfo( info, StandardMenu.File, StandardCommandGroup.FileRecentlyUsed, "Recent Files".Localize() + "/" + pathName, "Open a recently used file".Localize(), Keys.None); commandInfo.ImageName = info.Pinned ? Resources.PinGreenImage : Resources.PinGreyImage; commandInfo.ShortcutsEditable = false; CommandService.RegisterCommand( commandInfo, this); newCommandInfos.Add(commandInfo); m_registeredRecentDocs.Add(info); } } CommandInfos = newCommandInfos; } }
/// <summary> /// Finishes initializing component by setting up settings service and registering commands</summary> public virtual void Initialize() { if (m_settingsService != null) { BoundPropertyDescriptor recentDocumentCount = new BoundPropertyDescriptor(this, () => RecentDocumentCount, "Recent Files Count".Localize("Number of recent files to display in File Menu"), null, "Number of recent files to display in File Menu".Localize()); BoundPropertyDescriptor recentDocuments = new BoundPropertyDescriptor(this, () => RecentDocumentsAsCsv, "RecentDocuments", null, null); // Using the type name so that derived classes don't lose old user settings m_settingsService.RegisterSettings("Sce.Atf.Applications.RecentDocumentCommands", recentDocumentCount, recentDocuments); m_settingsService.RegisterUserSettings( "Documents".Localize(), recentDocumentCount); } if (CommandService != null) { var commandInfo = new CommandInfo(Command.Pin, StandardMenu.File, null, "Pin file".Localize("Pin active file to the recent files list"), "Pin active file to the recent files list".Localize(), Keys.None, Resources.PinGreenImage, CommandVisibility.Menu); CommandService.RegisterCommand(commandInfo, this); // Add an empty entry so the Recent Files menu shows up even if there are no // files in the list. This gets removed as soon as a file is added. m_emptyMruCommandInfo = new CommandInfo(Command.EmptyMru, StandardMenu.File, StandardCommandGroup.FileRecentlyUsed, "Recent Files".Localize() + "/(" + "empty".Localize() + ")", "No entries in recent files list".Localize(), Keys.None); CommandService.RegisterCommand( m_emptyMruCommandInfo, this); } }
/// <summary> /// Initializes this component</summary> public virtual void Initialize() { CommandInfo helpCommandInfo = CommandService.RegisterCommand(Commands.OpenHelpPage, StandardMenu.Help, StandardCommandGroup.HelpAbout, "Online Help".Localize(), "Opens an online help page for this app".Localize(), Keys.F1, null, CommandVisibility.ApplicationMenu, this); // We need to listen to the MenuItem's Click event, rather than the normal and otherwise // better way of using DoCommand, because the currently active Control might have a // WebHelp attached and it should take precedence if the user presses F1 but not if the // user uses the help menu command. CommandService.CommandControls controls = CommandService.GetCommandControls(helpCommandInfo); controls.MenuItem.Click += MenuItemOnClick; m_webHelp = MainForm.AddHelp(Url); }
/// <summary> /// Finishes initializing component by registering OSC commands</summary> public virtual void Initialize() { CommandService.RegisterCommand( Command.OscInfo, StandardMenu.File, CommandGroups.Osc, "OSC Info", "Displays the status of the OSC service and lists the available OSC addresses and associated properties", Keys.None, null, this); CommandService.RegisterCommand( Command.CopyOscAddressOfPropertyDescriptor, null, null, s_copyOscAddressText, "Copies the OSC address of this property to the clipboard".Localize(), Keys.None, null, CommandVisibility.ContextMenu, // context menu only this); }
/// <summary> /// Finishes initializing component by registering tab commands</summary> public virtual void Initialize() { CommandService.RegisterCommand( Command.CloseCurrentTab, null, null, "Close".Localize(), "Closes the current Tab panel".Localize(), Keys.None, null, CommandVisibility.ContextMenu, this); CommandService.RegisterCommand( Command.CloseOtherTabs, null, null, "Close All But This".Localize(), "Closes all but the current Tab panel".Localize(), Keys.None, null, CommandVisibility.ContextMenu, this); CommandService.RegisterCommand( Command.CopyFullPath, null, null, "Copy Full Path".Localize(), "Copies the file path for the document".Localize(), Keys.None, null, CommandVisibility.ContextMenu, this); CommandService.RegisterCommand( Command.OpenContainingFolder, null, null, "Open Containing Folder".Localize(), "Opens the folder containing the document in Windows Explorer".Localize(), Keys.None, null, CommandVisibility.ContextMenu, this); ControlRegistry.ActiveControlChanged += (sender, args) => { m_documentExists = false; if (IsDocumentControl(ControlRegistry.ActiveControl)) { string documentPath = GetDocumentPath(ControlRegistry.ActiveControl); try { // for example, circuit group windows are titled "MyFileName:MyGroupName" if (PathUtil.IsValidPath(documentPath)) { m_documentExists = File.Exists(documentPath); } } catch (IOException) { } } }; }
private void RegisterClientCommands() { var clientList = m_documentClients.Select(l => l.Value) .Where(dc => dc.Info.AllowStandardFileCommands) .ToList(); // for each document client, build file/new and file/open commands var index = 0; foreach (var client in clientList) { Keys newShortcut = Keys.None; Keys openShortcut = Keys.None; if (index == 0) { newShortcut = Keys.Control | Keys.N; openShortcut = Keys.Control | Keys.O; } object newIconKey = client.Info.NewIconKey; string newIconName = client.Info.NewIconName; if ((RegisterCommands & CommandRegister.FileNew) == CommandRegister.FileNew) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileNew, client), StandardMenu.File, StandardCommandGroup.FileNew, clientList.Count > 1 ? "New".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("New {0}".Localize(), client.Info.FileType), string.Format("Creates a new {0} document".Localize("{0} is the type of document to create"), client.Info.FileType), newShortcut, (newIconKey != null) ? newIconKey : newIconName, ((!string.IsNullOrEmpty(newIconName)) || (newIconKey != null)) ? CommandVisibility.All : CommandVisibility.Menu), this); } object openIconKey = client.Info.OpenIconKey; string openIconName = client.Info.OpenIconName; if ((RegisterCommands & CommandRegister.FileOpen) == CommandRegister.FileOpen) { CommandService.RegisterCommand( new CommandInfo( new FileCommandTag(Command.FileOpen, client), StandardMenu.File, StandardCommandGroup.FileNew, clientList.Count > 1 ? "Open".Localize("Name of a command") + '/' + client.Info.FileType : string.Format("Open {0}".Localize(), client.Info.FileType), string.Format("Open an existing {0} document".Localize(), client.Info.FileType), openShortcut, (openIconKey != null) ? openIconKey : openIconName, ((!string.IsNullOrEmpty(openIconName)) || (openIconKey != null)) ? CommandVisibility.All : CommandVisibility.Menu), this); } index++; } }