/// <summary> /// Adds the given working directory to the list of Recent for future quick access. /// </summary> public void AddToRecent(string workingDir) { if (!IsSupported) { return; } if (!ToolbarButtonsCreated) { _deferredAddToRecent = workingDir; return; } if (string.IsNullOrWhiteSpace(workingDir)) { throw new ArgumentException(nameof(workingDir)); } SafeInvoke(() => { string repositoryDescription = _repositoryDescriptionProvider.Get(workingDir); if (string.IsNullOrWhiteSpace(repositoryDescription)) { return; } string baseFolder = Path.Combine(AppSettings.ApplicationDataPath.Value, "Recent"); if (!Directory.Exists(baseFolder)) { Directory.CreateDirectory(baseFolder); } // sanitise StringBuilder sb = new(repositoryDescription); foreach (char c in Path.GetInvalidFileNameChars()) { sb.Replace(c, '_'); } string path = Path.Combine(baseFolder, $"{sb}.gitext"); File.WriteAllText(path, workingDir); JumpList.AddToRecent(path); if (!ToolbarButtonsCreated) { return; } Validates.NotNull(_commitButton); Validates.NotNull(_pushButton); Validates.NotNull(_pullButton); _commitButton.Enabled = true; _pushButton.Enabled = true; _pullButton.Enabled = true; }, nameof(AddToRecent)); }
private void ReportUsage(string fileName) { // Report file usage to shell. Note: The dialog box automatically // reports usage to shell, but it's still recommeneded that the user // explicitly calls AddToRecent. Shell will automatically handle // duplicate additions. JumpList.AddToRecent(fileName); UpdateStatusBar("File added to recent documents"); }
public void AddToRecent([NotNull] string workingDir) { if (!IsSupported) { return; } if (string.IsNullOrWhiteSpace(workingDir)) { throw new ArgumentException(nameof(workingDir)); } try { string repositoryDescription = _repositoryDescriptionProvider.Get(workingDir); if (string.IsNullOrWhiteSpace(repositoryDescription)) { return; } string baseFolder = Path.Combine(AppSettings.ApplicationDataPath.Value, "Recent"); if (!Directory.Exists(baseFolder)) { Directory.CreateDirectory(baseFolder); } // sanitise var sb = new StringBuilder(repositoryDescription); foreach (char c in Path.GetInvalidFileNameChars()) { sb.Replace(c, '_'); } string path = Path.Combine(baseFolder, $"{sb}.gitext"); File.WriteAllText(path, workingDir); JumpList.AddToRecent(path); } catch (Exception ex) when( // reported in https://github.com/gitextensions/gitextensions/issues/2269 ex is COMException || // reported in https://github.com/gitextensions/gitextensions/issues/6767 ex is UnauthorizedAccessException || // reported in https://github.com/gitextensions/gitextensions/issues/4549 // looks like a regression in Windows 10.0.16299 (1709) ex is IOException) { Trace.WriteLine(ex.Message, "UpdateJumplist"); } }
private void AddToJumplist(string fileName) { if (TaskbarManager.IsPlatformSupported) { JumpList.AddToRecent(fileName); if (this.Visible) { var jumplist = JumpList.CreateJumpList(); jumplist.Refresh(); } } }
private void Open(string file) { try { if (!string.IsNullOrEmpty(file) && File.Exists(file)) { textBox1.Text = File.ReadAllText(file); if (TaskbarManager.IsPlatformSupported) { jumpList.AddToRecent(file); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void RecentFile(string path) { if (TaskbarManager.IsPlatformSupported) { //Elevation.RegisterFileType(System.IO.Path.GetExtension(path)); JumpList.AddToRecent(path); _jumpList.Refresh(); } var recents = SettingsManager.RecentFiles.OrderBy(x => x.Order).Where(x => x.Location != path).Take(9).ToList(); recents.Insert(0, new RecentFile { Location = path }); for (var i = 0; i < recents.Count; i++) { recents[i].Order = i; } SettingsManager.RecentFiles.Clear(); SettingsManager.RecentFiles.AddRange(recents); SettingsManager.Write(); UpdateRecentFiles(); }
public void AddToRecent(string destination) { list.AddToRecent(destination); list.Refresh(); }
public static void AddToRecent(string path) { JumpList.AddToRecent(path); }
public void OpenProject(string path, bool isFromRecentFilesList) { Main.Logger.Info("Opening project at path: {0}".FormatString(path)); DialogResult result = ConfirmProjectClosing(); if (result == DialogResult.Yes) { Save(); } else if (result == DialogResult.Cancel) { return; } if (!File.Exists(path)) { Logger.Info("File does not exist."); if (isFromRecentFilesList && MessageBox.Show("Could not find file \"{0}\". Would you like to remove it from the Recent Projects list?".FormatString(path), null, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.Yes) { Configuration.Instance.RecentProjects.Remove(path); InitializeRecentProjectsMenu(); } else if (!isFromRecentFilesList) { MessageBox.Show("Could not find file \"{0}\".".FormatString(path), null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return; } using (new Wait()) { Project project = null; Regex userSettingsFileCheckRegex = new Regex(@"(\.(?:dfp|cgp))u$", RegexOptions.IgnoreCase); string projectPath = path; string userSettingsPath = null; Version productVersion = new Version(Application.ProductVersion); Version projectVersion; if (userSettingsFileCheckRegex.IsMatch(projectPath)) { projectPath = userSettingsFileCheckRegex.Replace(projectPath, "$1"); } userSettingsPath = "{0}u".FormatString(projectPath); projectVersion = UpgradeManager.GetVersion(projectPath); Main.Logger.Info("Project path: {0}".FormatString(projectPath)); Main.Logger.Info("User Settings path: {0}".FormatString(userSettingsPath)); Main.Logger.Info("Version: {0}".FormatString(projectVersion)); //Upgrade if needed. if (productVersion < projectVersion) { Logger.Info("Project is from newer version of CodeGenerator (v{0}).".FormatString(projectVersion)); //Just because the project is from a newer version does not mean that the schema changed and the project can't be opened. if (!UpgradeManager.IsVersionCompatible(projectVersion)) { MessageBox.Show("The project you are opening is from a newer version of CodeGenerator and therefore cannot be opened."); return; } } else if (productVersion > projectVersion) { Logger.Info("Project is from older version of CodeGenerator (v{0}).".FormatString(projectVersion)); //Don't try to upgrade the project unless there is an actual upgrade to apply. if (UpgradeManager.CanUpgrade(projectVersion)) { if (MessageBox.Show("The project you are opening is from an older version of CodeGenerator and therefore must be upgraded. Would you like to upgrade the project now?", "Upgrade Required", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } Logger.Info("Project is being upgraded."); try { UpgradeManager.Upgrade(projectPath, userSettingsPath); } catch (Exception ex) { Logger.Error(ex); MessageBox.Show("An error occurred while upgrading the project: {0}".FormatString(ex.Message), "Upgrade Failed", MessageBoxButtons.OK); return; } } } try { project = Project.Open(projectPath); } catch (Exception ex) { Logger.Error("Error opening project.", ex); if (MessageBox.Show("An error occurred while opening the project:\n\n{0}{1}".FormatString(ex.Message, (isFromRecentFilesList ? "\n\nWould you like to remove it from the Recent Projects list?" : "")), null, (isFromRecentFilesList ? MessageBoxButtons.YesNo : MessageBoxButtons.OK)) == System.Windows.Forms.DialogResult.Yes) { Configuration.Instance.RecentProjects.Remove(path); InitializeRecentProjectsMenu(); } return; } if (project != null) { ProjectContext.Initialize(project); this.ProjectPath = projectPath; _unsavedChanges = false; UpdateTitle(); LoadTreeView(); contentSplitContainer.Visible = true; Configuration.Instance.AddRecentProject(projectPath); Configuration.Instance.Save(); //Try to add the file to the Jump List. if (TaskbarManager.IsPlatformSupported) { JumpList.AddToRecent(projectPath); } InitializeRecentProjectsMenu(); if (productVersion > projectVersion) { Logger.Info("Upgrading templates."); try { UpgradeManager.UpgradeTemplates(projectVersion, project.Templates); } catch (Exception ex) { Logger.Error(ex); MessageBox.Show("An error occurred while upgrading the templates: {0}".FormatString(ex.Message), "Upgrade Failed", MessageBoxButtons.OK); } } } } }