From 11b8a510d78437b7acbe4bfeab76c93cb0abc05c Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Tue, 28 Mar 2017 12:00:59 +0200 Subject: [PATCH] Add menu to project nodes --- TSVN/Helpers/FileHelper.cs | 10 +++++++++- TSVN/TSVN.vsct | 8 ++++++++ TSVN/TSVNPackage.cs | 26 +++++++++++++------------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/TSVN/Helpers/FileHelper.cs b/TSVN/Helpers/FileHelper.cs index d8d3f7f..b1db168 100644 --- a/TSVN/Helpers/FileHelper.cs +++ b/TSVN/Helpers/FileHelper.cs @@ -1,4 +1,5 @@ -using EnvDTE; +using System.IO; +using EnvDTE; using Microsoft.Win32; namespace SamirBoulema.TSVN.Helpers @@ -21,5 +22,12 @@ public static void SaveAllFiles() { Dte.ExecuteCommand("File.SaveAll"); } + + public static string GetPath() + { + return Dte.SelectedItems.Item(1).ProjectItem == null + ? Path.GetDirectoryName(Dte.SelectedItems.Item(1).Project.FullName) + : Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + } } } diff --git a/TSVN/TSVN.vsct b/TSVN/TSVN.vsct index 65c4185..447c59e 100644 --- a/TSVN/TSVN.vsct +++ b/TSVN/TSVN.vsct @@ -34,6 +34,14 @@ TSVN + + + TextChanges + + TSVN + TSVN + + diff --git a/TSVN/TSVNPackage.cs b/TSVN/TSVNPackage.cs index 22f9a8a..23eb84d 100644 --- a/TSVN/TSVNPackage.cs +++ b/TSVN/TSVNPackage.cs @@ -133,7 +133,7 @@ private void UpdateCommand(object sender, EventArgs e) private void UpdateFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; Dte.ActiveDocument?.Save(); StartProcess(_tortoiseProc, $"/command:update /path:\"{_currentFilePath}\" /closeonend:0"); @@ -149,7 +149,7 @@ private void UpdateToRevisionCommand(object sender, EventArgs e) private void UpdateToRevisionFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; Dte.ActiveDocument?.Save(); StartProcess(_tortoiseProc, $"/command:update /path:\"{_currentFilePath}\" /rev /closeonend:0"); @@ -157,7 +157,7 @@ private void UpdateToRevisionFileCommand(object sender, EventArgs e) private void PropertiesCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:properties /path:\"{_currentFilePath}\" /closeonend:0"); } @@ -172,7 +172,7 @@ private void CommitCommand(object sender, EventArgs e) private void CommitFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; Dte.ActiveDocument?.Save(); StartProcess(_tortoiseProc, $"/command:commit /path:\"{_currentFilePath}\" /closeonend:0"); @@ -187,7 +187,7 @@ private void ShowLogCommand(object sender, EventArgs e) private void ShowLogFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:log /path:\"{_currentFilePath}\" /closeonend:0"); } @@ -225,14 +225,14 @@ private void RevertCommand(object sender, EventArgs e) private void RevertFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:revert /path:\"{_currentFilePath}\" /closeonend:0"); } private void AddFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; Dte.ActiveDocument?.Save(); StartProcess(_tortoiseProc, $"/command:add /path:\"{_currentFilePath}\" /closeonend:0"); @@ -246,7 +246,7 @@ private void DiskBrowserCommand(object sender, EventArgs e) } private void DiskBrowserFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess("explorer.exe", _currentFilePath); } @@ -260,7 +260,7 @@ private void RepoBrowserCommand(object sender, EventArgs e) private void RepoBrowserFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:repobrowser /path:\"{_currentFilePath}\""); } @@ -288,7 +288,7 @@ private void MergeCommand(object sender, EventArgs e) private void MergeFileCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:merge /path:\"{_currentFilePath}\""); } @@ -302,21 +302,21 @@ private void CleanupCommand(object sender, EventArgs e) private void DifferencesCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:diff /path:\"{_currentFilePath}\""); } private void DiffPreviousCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:prevdiff /path:\"{_currentFilePath}\""); } private void BlameCommand(object sender, EventArgs e) { - _currentFilePath = Dte.SelectedItems.Item(1).ProjectItem.FileNames[0]; + _currentFilePath = FileHelper.GetPath(); var currentLineIndex = ((TextDocument) Dte.ActiveDocument?.Object(string.Empty))?.Selection.CurrentLine ?? 0; if (string.IsNullOrEmpty(_currentFilePath)) return; StartProcess(_tortoiseProc, $"/command:blame /path:\"{_currentFilePath}\" /line:{currentLineIndex}");