/// <summary> /// Activates the Switch Windows functional agent to enable the /// user to switch windows/apps. If taskname /// is not null, it only shows windows belonging to the task (eg /// notepad, word) /// </summary> /// <param name="taskName">filter by this process name</param> public static async void ShowTaskSwitcher(string taskName = "") { try { if (!Context.AppAgentMgr.CanActivateFunctionalAgent()) { return; } IApplicationAgent switchWindowsAgent = Context.AppAgentMgr.GetAgentByCategory("SwitchWindowsAgent"); if (switchWindowsAgent == null) { return; } IExtension extension = switchWindowsAgent; extension.GetInvoker().SetValue("FilterByProcessName", taskName); await Context.AppAgentMgr.ActivateAgent(switchWindowsAgent as IFunctionalAgent); Log.Debug("Returned from activate agent"); } catch (Exception ex) { Log.Debug(ex.ToString()); } }
/// <summary> /// Executes the command /// </summary> /// <param name="handled">set to true if the command was handled</param> /// <returns>true on success</returns> public override bool Execute(ref bool handled) { bool retVal = true; handled = true; Form form = Dispatcher.Scanner.Form; form.Invoke(new MethodInvoker(delegate() { IApplicationAgent switchWindowsAgent = Context.AppAgentMgr.GetAgentByName("Switch Windows Agent"); if (switchWindowsAgent == null) { retVal = false; } else { Context.AppTalkWindowManager.CloseTalkWindow(); IntPtr foregroundWindow = Windows.GetForegroundWindow(); var process = WindowActivityMonitor.GetProcessForWindow(foregroundWindow); IExtension extension = switchWindowsAgent; extension.GetInvoker().SetValue("FilterByProcessName", process.ProcessName); Context.AppAgentMgr.ActivateAgent(switchWindowsAgent as IFunctionalAgent); WindowActivityMonitor.GetActiveWindow(); } })); return(retVal); }
/// <summary> /// Launches lecture manager with text from the MS Word window. This /// function returns only after lecture manager has exited /// </summary> /// <returns>task</returns> protected async void launchLectureManager(String fileName, String text) { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("Lecture Manager Agent"); if (agent != null) { IExtension extension = agent; extension.GetInvoker().SetValue("LoadFromFile", false); if (!String.IsNullOrEmpty(fileName)) { extension.GetInvoker().SetValue("LectureFile", fileName); } extension.GetInvoker().SetValue("LectureText", text); await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <summary> /// Launches lecture manager with text from the wordpad window. This /// function returns only after lecture manager has exited /// </summary> /// <returns>task</returns> private async Task launchLectureManager() { IApplicationAgent agent = Context.AppAgentMgr.GetAgentByCategory("LectureManagerAgent"); if (agent != null) { IExtension extension = agent; extension.GetInvoker().SetValue("LoadFromFile", false); String fileName = getFileNameFromWindow(); if (!String.IsNullOrEmpty(fileName)) { extension.GetInvoker().SetValue("LectureFile", fileName); } extension.GetInvoker().SetValue("LectureText", TextControlAgent.GetText()); await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); } }
/// <summary> /// Launches the lecture manager. First launches the /// file browser to get lecture file and then launches lecture /// manager with the file. /// </summary> /// <param name="form">scanner form</param> private async void launchLectureManager(Form form) { // First launch the file browser to get // the file name from the user IApplicationAgent fileBrowserAgent = Context.AppAgentMgr.GetAgentByName("FileBrowser Agent"); if (fileBrowserAgent == null) { return; } fileBrowserAgent.GetInvoker().SetValue("AutoLaunchFile", false); fileBrowserAgent.GetInvoker().SetValue("SelectActionOpen", true); fileBrowserAgent.GetInvoker().SetValue("Folders", Common.AppPreferences.GetFavoriteFolders());//.AppPreferences.FavoriteFolders.Split(';')); fileBrowserAgent.GetInvoker().SetValue("IncludeFileExtensions", new[] { "*.", "txt", "doc", "docx" }); fileBrowserAgent.GetInvoker().SetValue("ExcludeFileExtensions", getExcludeExtensions()); await Context.AppAgentMgr.ActivateAgent(fileBrowserAgent as IFunctionalAgent); String selectedFile = fileBrowserAgent.GetInvoker().GetStringValue("SelectedFile"); if (!String.IsNullOrEmpty(selectedFile)) { // now launch lecture manager for the selected file IApplicationAgent agent = Context.AppAgentMgr.GetAgentByName("Lecture Manager Agent"); if (agent != null) { Windows.CloseForm(form); IExtension extension = agent as IExtension; extension.GetInvoker().SetValue("LoadFromFile", true); extension.GetInvoker().SetValue("LectureFile", selectedFile); Log.Debug("Invoking LectureManager agent"); await Context.AppAgentMgr.ActivateAgent(agent as IFunctionalAgent); Log.Debug("Returned from LectureManager agent"); } } }
/// <summary> /// Displays the task switcher form which is the Alt-Tab /// equivalent to switch between application windows. If taskname /// is not null, it only shows windows belonging to the task (eg /// notepad, word) /// </summary> /// <param name="taskName">filter by this process name</param> public static void ShowTaskSwitcherAltTab(String taskName = "") { try { //Context.AppTalkWindowManager.CloseTalkWindow(); Form taskSwitcherForm = Context.AppPanelManager.CreatePanel("TaskSwitcherForm"); if (taskSwitcherForm != null) { if (!String.IsNullOrEmpty(taskName) && taskSwitcherForm is IExtension) { IExtension extension = taskSwitcherForm as IExtension; extension.GetInvoker().SetValue("FilterProcessName", taskName); } Context.AppPanelManager.ShowDialog(taskSwitcherForm as IPanel); } } catch (Exception e) { Log.Debug("Error creating task switcher dialog. Exception: " + e); } }