/// <summary> /// Return the index of the image that has the Shell Icon for the given file/directory. /// </summary> /// <param name="path">The full path to the file/directory</param> /// <returns>The index of the image or -1 if something goes wrong.</returns> public int GetImageIndex(string path) { if (System.IO.Directory.Exists(path)) { path = System.Environment.SystemDirectory; // optimization! give all directories the same image } else if (System.IO.Path.HasExtension(path)) { path = System.IO.Path.GetExtension(path); } if (this.SmallImageCollection.ContainsKey(path)) { return(this.SmallImageCollection.IndexOfKey(path)); } try { this.AddImageToCollection(path, this.SmallImageList, ShellApi.GetFileIcon(path, true, true)); this.AddImageToCollection(path, this.LargeImageList, ShellApi.GetFileIcon(path, false, true)); } catch (ArgumentNullException) { return(-1); } return(this.SmallImageCollection.IndexOfKey(path)); }
public static bool SetWindowsPlacementMaximized(IntPtr handle) { ShellApi.WINDOWPLACEMENT pc = new ShellApi.WINDOWPLACEMENT(); pc.length = Marshal.SizeOf(typeof(ShellApi.WINDOWPLACEMENT)); pc.showCmd = (int)ShellApi.ShowWindowCommands.SW_SHOWMAXIMIZED; ShellApi.SetWindowPlacement(handle, ref pc); return(true); }
static public bool RunExe(String path, String workingDir, String arguments, bool openMaximized, bool reopenMaximized, bool addToProcessList) { Log.ProcessDebug("RunExe. Сommand line: " + path + " Arguments: " + arguments); try { if (!Path.IsPathRooted(path)) { string root = System.Reflection.Assembly.GetExecutingAssembly().Location; root = Path.GetDirectoryName(root); path = Path.Combine(root, path); } FileInfo info = new FileInfo(path); if (info.Exists) { // todo string processName = info.Name.Substring(0, info.Name.Length - 4); Process[] processes = Process.GetProcessesByName(processName); if (processes.Length == 0) { ProcessStartInfo pi = new ProcessStartInfo(); pi.Verb = "open"; pi.FileName = path; if (openMaximized) { pi.WindowStyle = ProcessWindowStyle.Maximized; } if (workingDir != null) { pi.WorkingDirectory = workingDir; } if (arguments != null) { pi.Arguments = arguments; } Process p = new Process(); p.EnableRaisingEvents = true; p.Exited += myProcess_Exited; p.StartInfo = pi; p.Start(); if (addToProcessList) { lock (runningProcessesList) { clearExitedProcessses(); runningProcessesList.Add(p); } } } else { ShellApi.SetForegroundWindow(processes[0].MainWindowHandle); if (reopenMaximized) { ShellApi.SetWindowsPlacementMaximized(processes[0].MainWindowHandle); } } } else { throw new ArgumentException("File not found: " + path); } } catch (Exception ex) { Log.LogError("RunExe error. Сommand line: " + path + " Arguments: " + arguments, ex); return(false); } return(true); }
public SimpleAttachmentsDialog() { InitializeComponent(); this.Text = FrwCRUDRes.SimpleAttachmentsDialog_Attachments; ((System.ComponentModel.ISupportInitialize)(listView)).BeginInit(); //ovl settings listView.EmptyListMsg = FrwCRUDRes.List_No_Records; listView.EmptyListMsgFont = new Font("Tahoma", 9);//todo; listView.FullRowSelect = true; listView.UseCompatibleStateImageBehavior = false; listView.View = System.Windows.Forms.View.Details; listView.UseFiltering = true; listView.UseFilterIndicator = true; listView.AllowColumnReorder = true; listView.TriStateCheckBoxes = false; listView.CellEditUseWholeCell = false; listView.TintSortColumn = true; listView.ShowItemToolTips = true; listView.UseHotItem = true; listView.UseHyperlinks = true; listView.HyperlinkClicked += ListView_HyperlinkClicked; listView.ShowCommandMenuOnRightClick = true; listView.TintSortColumn = true; //special for selection list //listView.CheckBoxes = true; listView.CellEditActivation = ObjectListView.CellEditActivateMode.None; listView.CellToolTipShowing += delegate(object sender, ToolTipShowingEventArgs e) { if (e.Column.Text == FrwCRUDRes.SimpleAttachmentsDialog_Path) { JAttachment item = (JAttachment)e.Model; string path = Dm.Instance.GetRealPath(item.Path, SourceObject); FileSystemInfo x = GetFileSystemInfo(path); if (x != null) { e.Text = x.FullName; } //e.Text = String.Format("Tool tip for '{0}', column '{1}'\r\nValue shown: '{2}'", e.Model, e.Column.Text, e.SubItem.Text); } //else e.Text = }; SysImageListHelper helper = new SysImageListHelper(this.listView);//todo вынести в кешируемый уровень OLVColumn column = null; column = new OLVColumn(); column.AspectName = "Path"; column.Text = FrwCRUDRes.SimpleAttachmentsDialog_Path; column.Width = 350; column.Hyperlink = true; column.FillsFreeSpace = true; column.AspectGetter = delegate(object xx) { JAttachment item = (JAttachment)xx; if (item.Path != null && item.Path.StartsWith(Dm.STORAGE_PREFIX)) { string path = Dm.Instance.GetRealPath(item.Path, SourceObject); FileSystemInfo x = GetFileSystemInfo(path); if (x == null) { return(null); } return(x.Name); } else { return(item.Path); } }; column.ImageGetter = delegate(object x) { try { JAttachment item = (JAttachment)x; string path = Dm.Instance.GetRealPath(item.Path, SourceObject); FileSystemInfo fi = GetFileSystemInfo(path); if (fi == null) { return(null); } return(helper.GetImageIndex((fi).FullName)); } catch (Exception) { return(null); } }; AddColumnToList(column); column = new OLVColumn(); column.AspectName = "Path"; column.Text = FrwCRUDRes.SimpleAttachmentsDialog_Size; column.ButtonPadding = new Size(10, 10); column.HeaderTextAlign = HorizontalAlignment.Right; column.TextAlign = HorizontalAlignment.Right; column.Width = 80; column.AspectGetter = delegate(object xx) { JAttachment item = (JAttachment)xx; string path = Dm.Instance.GetRealPath(item.Path, SourceObject); FileSystemInfo x = GetFileSystemInfo(path); if (x == null) { return(null); } if (x is DirectoryInfo) { return((long)-1); } try { return(((FileInfo)x).Length); } catch (System.IO.FileNotFoundException) { // Mono 1.2.6 throws this for hidden files return((long)-2); } }; column.AspectToStringConverter = delegate(object x) { if (x == null) { return(null); //file not exist } long sizeInBytes = (long)x; if (sizeInBytes < 0) // folder or error { return(""); } return(FormatUtils.FormatFileSize(sizeInBytes)); }; AddColumnToList(column); column = new OLVColumn(); column.AspectName = "Path"; column.Text = FrwCRUDRes.SimpleAttachmentsDialog_CreationDate; column.Width = 130; column.AspectGetter = delegate(object xx) { JAttachment item = (JAttachment)xx; string path = Dm.Instance.GetRealPath(item.Path, SourceObject); FileSystemInfo x = GetFileSystemInfo(path); if (x == null) { return(null); } return(x.CreationTime); }; AddColumnToList(column); column = new OLVColumn(); column.AspectName = "Path"; column.Text = FrwCRUDRes.SimpleAttachmentsDialog_ModificationDate; column.Width = 130; column.AspectGetter = delegate(object xx) { JAttachment item = (JAttachment)xx; string path = Dm.Instance.GetRealPath(item.Path, SourceObject); FileSystemInfo x = GetFileSystemInfo(path); if (x == null) { return(null); } return(x.LastWriteTime); }; AddColumnToList(column); column = new OLVColumn(); column.AspectName = "Path"; column.Text = FrwCRUDRes.SimpleAttachmentsDialog_FileType; column.Width = 130; column.AspectGetter = delegate(object xx) { JAttachment item = (JAttachment)xx; string path = Dm.Instance.GetRealPath(item.Path, SourceObject); FileSystemInfo x = GetFileSystemInfo(path); if (x == null) { return(null); } return(ShellApi.GetFileType(((FileSystemInfo)x).FullName)); }; AddColumnToList(column); ((System.ComponentModel.ISupportInitialize)(listView)).EndInit(); }