public void Remove(IWorkItem workItemToRemove) { Entities.WorkItems.Shortcuts shortcutsListToRemove = workItemToRemove as Entities.WorkItems.Shortcuts; string retiredFilePath = Path.Combine(Settings.Current.EnsoLearnAsOpenCommandsRetiredFilesFolder, Path.GetFileName(shortcutsListToRemove.shortcutsFilePath)); System.IO.File.Move(shortcutsListToRemove.shortcutsFilePath, retiredFilePath); SuggestionsCache.DropCache(this.GetType()); }
public static void SaveAllTabs(bool saveInOneFile, Extension.IEnsoService service, string caption, string shortcutsFolder, string commandProviderNameForLog) { string clipboardText = CraftSynth.BuildingBlocks.IO.Clipboard.GetTextFromClipboard(); clipboardText = clipboardText.Trim(); if (string.IsNullOrEmpty(clipboardText)) { MessagesHandler.Display("Error: Clipboard empty.", saveAllTabsUserManual); } else { Entities.WorkItems.Shortcuts shortcuts = null; try { shortcuts = new Entities.WorkItems.Shortcuts(caption, clipboardText); if (shortcuts.shortcuts.Count == 0) { throw new ApplicationException("No urls in clipboard."); } } catch (Exception) { MessagesHandler.Display("Error: Invalid text format in clipboard.", saveAllTabsUserManual); Logging.AddErrorLog(commandProviderNameForLog + ": Error: Invalid text format in clipboard"); } if (shortcuts != null && shortcuts.shortcuts.Count > 0) { if (string.IsNullOrEmpty(shortcutsFolder)) { shortcutsFolder = Settings.Current.EnsoLearnAsOpenCommandsFolder; } CraftSynth.BuildingBlocks.IO.FileSystem.CreateFolderIfItDoesNotExist(shortcutsFolder); if (saveInOneFile) { shortcuts.Save(shortcutsFolder); SuggestionsCache.DropCache(typeof(WorkItemsProviders.Shortcuts.ShortcutsLists)); Logging.AddActionLog(string.Format(commandProviderNameForLog + ": {0} tabs saved in '{1}'.", shortcuts.shortcuts.Count, Path.Combine(shortcutsFolder, caption))); MessagesHandler.Display(string.Format("{0} tabs saved in one shortcut {1}.", shortcuts.shortcuts.Count, caption)); } else { shortcuts.SaveAsSeparateShortcuts(shortcutsFolder); Logging.AddActionLog(string.Format(commandProviderNameForLog + ": {0} tabs saved as separate files in '{1}'.", shortcuts.shortcuts.Count, shortcutsFolder)); MessagesHandler.Display(string.Format("{0} shortcuts saved in category {1}.", shortcuts.shortcuts.Count, caption)); } } } }
public static List <Entities.WorkItems.Shortcuts> GetAll() { List <Entities.WorkItems.Shortcuts> shortcutsLists = new List <Entities.WorkItems.Shortcuts>(); string shortcutsFolder = Settings.Current.EnsoLearnAsOpenCommandsFolder; CraftSynth.BuildingBlocks.IO.FileSystem.CreateFolderIfItDoesNotExist(shortcutsFolder); List <string> shortcutsListsFilesPaths = CraftSynth.BuildingBlocks.IO.FileSystem.GetFilePaths(shortcutsFolder, false, "*." + Entities.WorkItems.Shortcuts.extension); foreach (var shortcutListFilePath in shortcutsListsFilesPaths) { Entities.WorkItems.Shortcuts shortcutsList = new Entities.WorkItems.Shortcuts(shortcutListFilePath); shortcutsLists.Add(shortcutsList); } return(shortcutsLists); }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("BookmarkManager: Executing command '{0}' ...", command.Name)); if (command.Name == "bookmark as") { //MessagesHandler.Display( "Loading bookmark folders ..."); this.service = service; OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, false, false, false, false, "[New Category]", false, new OSD.Menu.MenuItemChosenDelegate(MenuItemChoosen)); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { string bookmarkFilePath = Path.Combine((string)selectedMenuItem.tag, command.parametersOnExecute[0].GetValueAsText() + ".url"); BookmarkManager.SaveLinkFile(bookmarkFilePath, command.parametersOnExecute[1].GetValueAsText()); string message = command.parametersOnExecute[1].GetValueAsText(); MessagesHandler.Display(string.Format("{0} saved as bookmark.", message)); } } else if (command.Name == "bookmark all tabs as") { this.service = service; OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, false, false, false, false, "[New Category]", false, new OSD.Menu.MenuItemChosenDelegate(MenuItemChoosen)); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { //string bookmarkFilePath = Path.Combine((string)selectedMenuItem.tag, command.parametersOnExecute[0].GetCaption() + "."+Entities.WorkItems.Shortcuts.extension); CommandsProviders.FOpener.FOpener.SaveAllTabs(true, service, command.parametersOnExecute[0].GetCaption(), (string)selectedMenuItem.tag, "BookmarkManager"); } } else if (command.Name == "bookmark all tabs in one category") { this.service = service; OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, false, false, false, false, "[New Category]", false, new OSD.Menu.MenuItemChosenDelegate(MenuItemChoosen)); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { //string bookmarkFilePath = Path.Combine((string)selectedMenuItem.tag, command.parametersOnExecute[0].GetCaption() + "."+Entities.WorkItems.Shortcuts.extension); CommandsProviders.FOpener.FOpener.SaveAllTabs(false, service, Path.GetFileNameWithoutExtension(selectedMenuItem.tag.ToString()), (string)selectedMenuItem.tag, "BookmarkManager"); } } else if (command.Name == "open bookmark") { //MessagesHandler.Display( "Loading bookmark folders ..."); OSD.OSD.SettingsFilePath = "OSD.Bookmarks.ini"; OSD.Menu.Menu bookmarkMenu = new OSD.Menu.Menu(null, "Bookmarks", Settings.Current.EnsoLearnAsOpenCommandsFolder, true, false, true, false, "[All From This Category]", false, null); Thread bringToFrontAssistant = new Thread(BringToFront); bringToFrontAssistant.Start("OSD"); OSD.Menu.MenuItem selectedMenuItem = OSD.Menu.Menu.ShowMenu(bookmarkMenu); if (selectedMenuItem != null) { List <string> filePathsToOpen = new List <string>(); if (selectedMenuItem.text == "[All From This Category]") { List <string> filePathsInFolder = CraftSynth.BuildingBlocks.IO.FileSystem.GetFilePaths(selectedMenuItem.tag.ToString()); foreach (string filePathInFolder in filePathsInFolder) { if (filePathInFolder.EndsWith(Entities.WorkItems.Shortcuts.extension, StringComparison.InvariantCultureIgnoreCase) || filePathInFolder.EndsWith("lnk", StringComparison.InvariantCultureIgnoreCase) || filePathInFolder.EndsWith("url", StringComparison.InvariantCultureIgnoreCase) ) { filePathsToOpen.Add(filePathInFolder); } } } else { filePathsToOpen.Add(selectedMenuItem.tag.ToString()); } foreach (string filePathToOpen in filePathsToOpen) { if (filePathToOpen.EndsWith(Entities.WorkItems.Shortcuts.extension, StringComparison.OrdinalIgnoreCase)) { Entities.WorkItems.Shortcuts shortcuts = new Entities.WorkItems.Shortcuts(filePathToOpen); Logging.AddActionLog(string.Format("BookmarkManager: Opening '{0}' in Firefox ...", shortcuts.shortcutsFilePath)); MessagesHandler.Display(string.Format("Opening {0} ...", shortcuts.caption)); foreach (Shortcut shortcut in shortcuts.shortcuts) { Logging.AddActionLog(string.Format("BookmarkManager: Opening '{0}' in Firefox ...", shortcut.targetPath)); CommandsProviders.FOpener.FOpener.OpenInFirefox(shortcut.targetPath, true); } } else { MessagesHandler.Display(string.Format("Opening {0} ...", filePathToOpen)); CraftSynth.BuildingBlocks.WindowsNT.Misc.OpenFile(filePathToOpen); } } } } else // if (command.Name == "command name" && command.Postfix == "postfix [item] [item2]") //{ // MessagesHandler.Display( string.Format("Executing {0} ...", command.Name)); //} else { throw new ApplicationException(string.Format("BookmarkManager: Command not found. Command: {0} {1}", command.Name, command.Postfix)); } }
public void ExecuteCommand(Extension.IEnsoService service, Command command) { Logging.AddActionLog(string.Format("COpener: Executing command '{0}' ...", command.Name)); if (command.Name == "copen in new window" || command.Name == "copen in new tab" || command.Name == "copen in new incognito window" || command.Name == "copen in new incognito tab") { if (command.parametersOnExecute[0] is Entities.WorkItems.Shortcuts) { Entities.WorkItems.Shortcuts shortcuts = command.parametersOnExecute[0] as Entities.WorkItems.Shortcuts; Logging.AddActionLog(string.Format("COpener: Opening '{0}' in Chrome ...", shortcuts.shortcutsFilePath)); MessagesHandler.Display(string.Format("Opening {0} ...", shortcuts.caption)); foreach (Shortcut shortcut in shortcuts.shortcuts) { Logging.AddActionLog(string.Format("COpener: Opening '{0}' in Chrome ...", shortcut.targetPath)); OpenInChrome(shortcut.targetPath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } } else { Logging.AddActionLog(string.Format("COpener: Opening '{0}' in Chrome ...", command.parametersOnExecute[0].GetValueAsText())); MessagesHandler.Display(string.Format("Opening {0} ...", command.parametersOnExecute[0].GetValueAsText())); OpenInChrome(command.parametersOnExecute[0].GetValueAsText(), command.Name.Contains("tab"), command.Name.Contains("incognito")); } } else if (command.Name == "preview in chrome" || command.Name == "preview in new tab of chrome") { string filePath = Common.Helper.GetEnsoTempraryFilePath("htm"); File.WriteAllText(filePath, command.parametersOnExecute[0].GetValueAsText()); OpenInChrome(filePath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } else if (command.Name == "test js in chrome in new window" || command.Name == "test js in chrome in new tab") { string filePath = Common.Helper.GetEnsoTempraryFilePath("htm"); string js = command.parametersOnExecute[0].GetValueAsText(); string templatePath = Path.Combine(Common.Helper.GetEnsoPlusWorkingFolder(), @"Resources\TemplateJavascriptTest.htm"); string template = File.ReadAllText(templatePath); string html = template.Replace("{0}", js); File.WriteAllText(filePath, html); OpenInChrome(filePath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } if (command.Name == "test js function in chrome in new window" || command.Name == "test js function in chrome in new tab") { string filePath = Common.Helper.GetEnsoTempraryFilePath("htm"); string functionName = command.parametersOnExecute[0].GetValueAsText(); string js = command.parametersOnExecute[1].GetValueAsText(); string templatePath = Path.Combine(Common.Helper.GetEnsoPlusWorkingFolder(), @"Resources\TemplateJavascriptFunctionTest.htm"); string template = File.ReadAllText(templatePath); if (js.IndexOf(functionName, StringComparison.OrdinalIgnoreCase) > 0) { functionName = js.Substring(js.IndexOf(functionName, StringComparison.OrdinalIgnoreCase), functionName.Length); } string html = template.Replace("{0}", functionName); html = html.Replace("{1}", js); File.WriteAllText(filePath, html); OpenInChrome(filePath, command.Name.Contains("tab"), command.Name.Contains("incognito")); } }