protected void BuildGitInfoContextMenus() { _menu.Items.Clear(); var gitDir = GetGitDirectory(SelectedItemPaths.First()); if (string.IsNullOrEmpty(gitDir) || !Directory.Exists(gitDir)) { return; } var repo = new Repository(gitDir); var lastCommit = repo.Head.Tip; var mainMenu = new ToolStripMenuItem { Text = GitInfoMenuName, Image = Properties.Resources.Git }; mainMenu.DropDownItems.Add(new ToolStripMenuItem { Text = $@"Branch Name: {repo.Head.FriendlyName} <->{repo.Head.TrackedBranch?.FriendlyName}" }); mainMenu.DropDownItems.Add(new ToolStripMenuItem { Text = @"Branches Count: " + repo.Branches.Count().ToString() }); mainMenu.DropDownItems.Add(new ToolStripMenuItem { Text = @"Tags Count: " + repo.Tags.Count().ToString() }); mainMenu.DropDownItems.Add(new ToolStripSeparator()); mainMenu.DropDownItems.Add(new ToolStripMenuItem { Text = $@"Last Commit : {lastCommit.Message} {lastCommit.Author} {lastCommit.Author.When.ToString()}" }); _menu.Items.Clear(); _menu.Items.Add(mainMenu); repo.Dispose(); }
private void ShowItemPathLink() { // Builder for the output var builder = new StringBuilder(); // FileAttributes attr = File.GetAttributes(SelectedItemPaths.First()); // check if selected item is a directory. if (attr.HasFlag(FileAttributes.Directory)) { // builder.AppendLine(string.Format("{0}", Path.GetFullPath(SelectedItemPaths.First()))); } else { // builder.AppendLine(string.Format("{0}?Web=1", Path.GetFullPath(SelectedItemPaths.First()))); } // make link ConvertPathToURL(ref builder); // Show the output Clipboard.SetText(builder.ToString()); string outputMessage = string.Format("{0}{1}copied to clipboard", builder.ToString(), Environment.NewLine); MessageBox.Show(outputMessage); }
/// <summary> /// Opens selected item's location in Sharepoint web document library /// </summary> private void OpenLocationInBrowser() { // Builder for the output. var builder = new StringBuilder(); FileAttributes attr = File.GetAttributes(SelectedItemPaths.First()); // check if selected item is a directory. if (attr.HasFlag(FileAttributes.Directory)) { // Show folder name. builder.AppendLine(string.Format("{0}", Path.GetFullPath(SelectedItemPaths.First()))); } else { // Show folder name. builder.AppendLine(string.Format("{0}", Path.GetFullPath(SelectedItemPaths.First()).Replace(Path.GetFileName(SelectedItemPaths.First()), ""))); } // make link ConvertPathToURL(ref builder); // open in default web browser Process proc = new Process(); proc.StartInfo.UseShellExecute = true; proc.StartInfo.FileName = builder.ToString(); proc.Start(); }
protected override bool CanShowMenu() { return(Helios.IsInstalled && SelectedItemPaths.Count() == 1 && Profile.GetAllProfiles().Any() && Path.GetExtension(SelectedItemPaths.First())?.ToLower() == @".exe"); }
protected override ContextMenuStrip CreateMenu() { var menu = new ContextMenuStrip(); var baseItem = new ToolStripMenuItem("Gin Repository"); var client = ServiceClient.CreateServiceClient(this, 8741); try { baseItem.DropDownItems.AddRange(client.IsBasePath(SelectedItemPaths.First()) ? GetBaseDirectoryMenu() : GetFileMenu()); ((ICommunicationObject)client).Close(); } catch { ((ICommunicationObject)client).Abort(); } menu.Items.Add(new ToolStripSeparator()); menu.Items.Add(baseItem); menu.Items.Add(new ToolStripSeparator()); return(menu); }
protected override ContextMenuStrip CreateMenu() { var menu = new ContextMenuStrip(); var baseItem = new ToolStripMenuItem("Gin Repository"); var iContext = new InstanceContext(this); var myBinding = new WSDualHttpBinding(); var myEndpoint = new EndpointAddress("http://localhost:8733/Design_Time_Addresses/GinService/"); var myChannelFactory = new DuplexChannelFactory <IGinService>(iContext, myBinding, myEndpoint); var client = myChannelFactory.CreateChannel(); try { baseItem.DropDownItems.AddRange(client.IsBasePath(SelectedItemPaths.First()) ? GetBaseDirectoryMenu() : GetFileMenu()); ((ICommunicationObject)client).Close(); } catch { ((ICommunicationObject)client).Abort(); } return(menu); }
protected override bool CanShowMenu() { if (SelectedItemPaths.Count() != 1) { return(false); } return(isGitDir(SelectedItemPaths.First()) || isSvnDir(SelectedItemPaths.First())); }
/// <summary> /// 右键菜单点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Item_Click(object sender, EventArgs e) { var filePath = SelectedItemPaths.First(); var currentPath = Environment.CurrentDirectory; var appName = "FileChecker.exe"; var fullPath = Path.Combine(currentPath, appName); Process.Start(fullPath, filePath); }
// ReSharper disable once FlagArgument private void BindTo(string networkInterfaceId, bool asAdmin) { try { var executableAddress = GetNetworkAdapterSelectorAddress(); if (string.IsNullOrWhiteSpace(executableAddress)) { return; } var arguments = $"-n \"{networkInterfaceId}\" -e \"{SelectedItemPaths.First()}\""; #if DEBUG arguments += " -d"; #endif // Executing the "NetworkAdapterSelector.Hook" and passing the address of executable file. var processInfo = new ProcessStartInfo(executableAddress, arguments) { WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, UseShellExecute = true }; #if DEBUG processInfo.WindowStyle = ProcessWindowStyle.Normal; processInfo.CreateNoWindow = false; #endif if (asAdmin) { // Forcing administrator privileges processInfo.Verb = @"runas"; } Process.Start(processInfo); } catch (Exception e) { // Check if operation canceled by user if ((e as Win32Exception)?.NativeErrorCode == 1223) { return; } // Otherwise, show an error message to the user MessageBox.Show( e.ToString(), Resources.DynamicMenuExtension_BindTo_Network_Adapter_Selector, MessageBoxButtons.OK, MessageBoxIcon.Error ); } }
/// <summary> /// 是否显示上下文菜单 /// </summary> /// <returns></returns> protected override bool CanShowMenu() { if (SelectedItemPaths.Count() == 1 && File.Exists(SelectedItemPaths.First())) { return(true); } else { return(false); } }
protected override bool CanShowMenu() { // Only show the menu when application is installed, there is just one executable // file selected and some network interface to select from return(SelectedItemPaths.Count() == 1 && Path.GetExtension(SelectedItemPaths.First())?.ToLower() == ".exe" && !string.IsNullOrWhiteSpace(GetNetworkAdapterSelectorAddress()) && NetworkInterface.GetAllNetworkInterfaces() .Any(networkInterface => networkInterface.SupportsMulticast && networkInterface.OperationalStatus == OperationalStatus.Up)); }
protected override bool CanShowMenu() { if (SelectedItemPaths.Count() != 1) { return(false); } string path = SelectedItemPaths.First(); return(File.Exists(path + "\\CMakeLists.txt") || File.Exists(path + "\\CMakeCache.txt") || Control.ModifierKeys == Keys.Shift); }
private void FileHistory(object sender, EventArgs eventArgs) { if (_client == null) { _client = ServiceClient.CreateServiceClient(this, 8741); } _client.GetHistory(SelectedItemPaths.First()); ((ICommunicationObject)_client).Close(); _client = null; }
private void LoadAssemblyInfoProcess(object sender, EventArgs e) { const string ApplicationFile = "AssemblyInformation.exe"; var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var fullPath = Path.Combine(basePath, ApplicationFile); var firstSelectedFile = "\"" + SelectedItemPaths.First() + "\""; var processInfo = new ProcessStartInfo(fullPath) { Arguments = firstSelectedFile }; var process = Process.Start(processInfo); }
protected override bool CanShowMenu() { if (SelectedItemPaths.Count() == 1 && IsGitDirectory(SelectedItemPaths.First()))//选中一个目录时构建菜单并显示 { this.UpdateMenu(); return(true); } else { return(false); } }
/// <summary> /// Creates the context menu. This can be a single menu item or a tree of them. /// </summary> /// <returns> /// The context menu for the shell context menu. /// </returns> protected override ContextMenuStrip CreateMenu() { // Create the menu strip. var menu = new ContextMenuStrip(); // Create a menu item to hold all of the subitems. var advancedItem = new ToolStripMenuItem { Text = "Advanced", Image = Properties.Resources.Copy }; // Now add the child items. var readOnlyItem = new ToolStripMenuItem { Text = "Read Only", Checked = File.GetAttributes(SelectedItemPaths.First()).HasFlag(FileAttributes.ReadOnly) }; readOnlyItem.Click += (sender, args) => DoToggleReadOnly(); // Add the touch item. var touchItem = new ToolStripMenuItem { Text = "Touch", Enabled = !File.GetAttributes(SelectedItemPaths.First()).HasFlag(FileAttributes.ReadOnly) }; touchItem.Click += (sender, args) => DoTouch(); var copyPathItem = new ToolStripMenuItem { Text = "Copy Path", Image = Properties.Resources.Copy }; copyPathItem.Click += (sender, args) => DoCopyPath(); // Add the items. advancedItem.DropDownItems.Add(readOnlyItem); advancedItem.DropDownItems.Add(touchItem); advancedItem.DropDownItems.Add(new ToolStripSeparator()); advancedItem.DropDownItems.Add(copyPathItem); // Add the item to the context menu. menu.Items.Add(advancedItem); // Return the menu. return(menu); }
private void CopyFile() { try { if (!SelectedItemPaths.Any()) { return; } var location = new Uri(Assembly.GetExecutingAssembly().CodeBase); var info = new FileInfo(location.AbsolutePath).Directory; var json = File.ReadAllText(info.FullName + @"\config.json"); var objConfig = (Config)JsonConvert.DeserializeObject(json, typeof(Config)); var client = new RestClient($"{objConfig.Url}/api/clipboard") { UserAgent = "Sia-Agent" }; var request = new RestRequest() { Method = Method.POST, RequestFormat = DataFormat.Json }; request.AddJsonBody(SelectedItemPaths.First()); var response = client.Execute(request); switch (response.StatusCode) { case System.Net.HttpStatusCode.OK: MessageBox.Show("File Copied"); break; default: MessageBox.Show("Copy Failed :" + response.StatusCode); break; } } catch (System.Exception ex) { MessageBox.Show(ex.Message + "ERROR"); } }
private void ZipFile(bool encrypt) { try { if (SelectedItemPaths.Count() == 0) { return; } string destination = this.GetZipFileNamePath(SelectedItemPaths.First()); var window = new Compressor(destination, encrypt, SelectedItemPaths.ToArray()); window.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ZipMagikLITE: Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void CopyWslPathToClipboard() { if (!SelectedItemPaths.Any()) { return; } try { Clipboard.SetText(GetWslPath(SelectedItemPaths.First())); } catch { // die silently } }
protected override ContextMenuStrip CreateMenu() { ToolStripMenuItem ctxMenu = new ToolStripMenuItem { Text = "MyBackup", Image = new Bitmap(Properties.Resources.Backup, new Size(16, 16)) }; ToolStripMenuItem backup = new ToolStripMenuItem { Text = "Backup manually", }; backup.Click += (o, e) => { string workDir = SelectedItemPaths.First(); bool isGit = isGitDir(workDir); CallBackupTool((isGit ? "git" : "svn") + " manually " + workDir); }; ToolStripMenuItem backupAll = new ToolStripMenuItem { Text = "Backup All", }; backupAll.Click += (o, e) => { string workDir = SelectedItemPaths.First(); bool isGit = isGitDir(workDir); CallBackupTool((isGit ? "git" : "svn") + " all " + workDir); }; ToolStripMenuItem backupModified = new ToolStripMenuItem { Text = "Backup modified", }; backupModified.Click += (o, e) => { string workDir = SelectedItemPaths.First(); bool isGit = isGitDir(workDir); CallBackupTool((isGit ? "git" : "svn") + " modified " + workDir); }; ctxMenu.DropDownItems.Add(backup); ctxMenu.DropDownItems.Add(backupModified); ctxMenu.DropDownItems.Add(backupAll); m_Menu.Items.Clear(); m_Menu.Items.Add(ctxMenu); return(m_Menu); }
// <summary> // Shows name of selected files. // </summary> private void ShowItemPermaLink() { // Builder for the output var builder = new StringBuilder(); // builder.AppendLine(string.Format("{0}", Path.GetFullPath(SelectedItemPaths.First()))); // make link ConvertPathToURL(ref builder); // GetDocIDURL(ref builder); // Show the ouput. Clipboard.SetText(builder.ToString()); string outputMessage = string.Format("{0}{1}{1}copied to clipboard", builder.ToString(), Environment.NewLine); MessageBox.Show(outputMessage); }
// <summary> // Determines whether the menu item can be shown for the selected item. // </summary> // <returns> // <c>true</c> if item can be shown for the selected item for this instance.; // otherwise, <c>false</c>. // </returns> protected override bool CanShowMenu() { // We can show the item only for a single selection. // Make it only show for J, K and L mapped drives. var MappedDriveCheck = SelectedItemPaths.First().ToString().Substring(0, 1); if (SelectedItemPaths.Count() == 1 && (MappedDriveCheck == "J" || MappedDriveCheck == "K" || MappedDriveCheck == "L")) // if (SelectedItemPaths.Count() == 1) { this.UpdateMenu(); return(true); } else { return(false); } }
private ToolStripItem[] GetFileMenu() { if (SelectedItemPaths.Count() > 1) { var mItems = new List <ToolStripItem> { new ToolStripMenuItem("Download Files", null, FileDownload), new ToolStripMenuItem("Remove local contents", null, FileRemove), new ToolStripMenuItem("Upload files", null, FileUpload) }; return(mItems.ToArray()); } if (SelectedItemPaths.Count() == 1) { var mItems = new List <ToolStripItem>(); var file = SelectedItemPaths.First(); if (_fileStatus[file] == FileStatus.Directory) { mItems.Add(new ToolStripMenuItem("Download Files", null, FileDownload)); mItems.Add(new ToolStripMenuItem("Remove local contents", null, FileRemove)); mItems.Add(new ToolStripMenuItem("Upload files", null, FileUpload)); } if (_fileStatus[file] == FileStatus.InAnnex || _fileStatus[file] == FileStatus.InAnnexModified) { mItems.Add(new ToolStripMenuItem("Download File", null, FileDownload)); } if (_fileStatus[file] == FileStatus.OnDiskModified || _fileStatus[file] == FileStatus.Unknown) { mItems.Add(new ToolStripMenuItem("Upload file", null, FileUpload)); } if (_fileStatus[file] == FileStatus.OnDisk) { mItems.Add(new ToolStripMenuItem("Remove local content", null, FileRemove)); mItems.Add(new ToolStripMenuItem("Get older version", null, FileHistory)); } return(mItems.ToArray()); } return(new ToolStripItem[0]); }
/// <summary> /// The click event for the Gist File Item. /// </summary> /// <param name="sender">The ToolStripMenuItem that triggered the event</param> /// <param name="e">The event arguments</param> protected void DownloadGist(object sender, EventArgs e) { var item = (ToolStripMenuItem)sender; var url = item.Tag.ToString(); var fileContents = GetGist(url); if (fileContents == null) { MessageBox.Show("There was an un-expected error while retrieving your file...", "WinGitter", MessageBoxButtons.OK, MessageBoxIcon.Error); } string selectedPath; if (SelectedItemPaths.Count() > 0) { selectedPath = SelectedItemPaths.First(); } else { selectedPath = this.FolderPath; } FileAttributes attr = File.GetAttributes(selectedPath); if (attr.HasFlag(FileAttributes.Directory)) { // DOES FILE ALREADY EXIST? var filePath = Path.Combine(selectedPath, item.Text); if (File.Exists(filePath)) { DialogResult dialogResult = MessageBox.Show("Would you like to overwrite the existing file?", "WinGitter", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.No) { return; } } File.WriteAllText(filePath, fileContents); } else { MessageBox.Show("Unexpected bahavior...", "WinGitter", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected override bool CanShowMenu() { var client = ServiceClient.CreateServiceClient(this, 8741); try { var result = client.IsManagedPath(SelectedItemPaths.First()); ((ICommunicationObject)client).Close(); return(result); } catch { ((ICommunicationObject)client).Abort(); return(false); } }
private void UnZipFiles() { try { if (SelectedItemPaths.Count() == 0) { return; } string[] aFilePath = SelectedItemPaths.First().Split('.'); string destinationFolder = string.Join(".", aFilePath.Take(aFilePath.Length - 1)); var window = new Compressor(destinationFolder, SelectedItemPaths.First()); window.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ZipMagikLITE: Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
// <summary> // Creates the context menu. This can be a single menu item or a tree of them. // Here we create the menu based on the type of item // </summary> // <returns> // The context menu for the shell context menu. // </returns> protected override ContextMenuStrip CreateMenu() { menu.Items.Clear(); FileAttributes attr = File.GetAttributes(SelectedItemPaths.First()); // check if the selected item is a directory if (attr.HasFlag(FileAttributes.Directory)) { this.MenuDirectory(); } else { this.MenuFiles(); } // return the menu item return(menu); }
protected void DoToggleReadOnly() { // Get the attributes. var path = SelectedItemPaths.First(); var attributes = File.GetAttributes(path); // Toggle the readonly flag. if ((attributes & FileAttributes.ReadOnly) != 0) { attributes &= ~FileAttributes.ReadOnly; } else { attributes |= FileAttributes.ReadOnly; } // Set the attributes. File.SetAttributes(path, attributes); }
private void EncryptFile(object sender, EventArgs eventArgs) { var viewModel = new EncryptDecryptViewModel(this.SelectedItemPaths.First(), EncryptDecryptViewModel.Functionality.Encrypt); var view = new EncryptDecryptView() { DataContext = viewModel }; Window window = new Window { Title = $"Encrypt file {SelectedItemPaths.First()}", Content = view, Height = view.Height, Width = view.Width }; window.ShowDialog(); }
protected override bool CanShowMenu() { try { _client = ServiceClient.CreateServiceClient(this, 8741); if (!_client.IsAlive()) { return(false); } var result = _client.IsManagedPath(SelectedItemPaths.First()); return(result); } catch { return(false); } }