Exemple #1
0
        public MainWindow()
        {
            Stopwatch.Start();

            InitializeComponent();

            Stopwatch.Stop();
            Timings.Add("1: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            this.Loaded += new RoutedEventHandler(OnLoad);

            if (CommandLineArgs.Length > 1)
            {
                try {
                    //	//Manually parse command line arguments
                    //	string rawCommandLine = Environment.CommandLine.Trim();
                    //	string rawArgs;
                    //	if (rawCommandLine[0] == '"') rawArgs = rawCommandLine.Substring(rawCommandLine.IndexOf('"', 1) + 1);
                    //	else rawArgs = rawCommandLine.Substring(rawCommandLine.IndexOf(' ') + 1);
                    //	string trimmedArgs = rawArgs.Trim();
                    //	string firstArg;
                    //	if (trimmedArgs[0] == '"') firstArg = trimmedArgs.Substring(1, trimmedArgs.IndexOf('"', 1) - 1);
                    //	else firstArg = trimmedArgs.Substring(trimmedArgs.IndexOf(' '));
                    //
                    //	string trimmedArg = firstArg.Trim('"', ' ');
                    string trimmedArg     = CommandLineArgs[1].Trim('"', ' ');
                    string envVarExpanded = Environment.ExpandEnvironmentVariables(trimmedArg);
                    if (Path.GetDirectoryName(envVarExpanded) == null)                       //If it is a root, eg "C:\"
                    {
                        FolderPath = envVarExpanded;
                    }
                    else
                    {
                        FolderPath = Path.GetFullPath(envVarExpanded);
                    }
                } catch {
                    FolderPath = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Desktop");
                    InitMessages.Add(new Tuple <string, string, MessageBoxButton, MessageBoxImage>(
                                         "The target path provided for the desktop folder is invalid.", "Desktop Folders", MessageBoxButton.OK, MessageBoxImage.Exclamation
                                         ));
                }
            }
            else
            {
                FolderPath = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Desktop");
                InitMessages.Add(new Tuple <string, string, MessageBoxButton, MessageBoxImage>(
                                     "No target path was provided for the desktop folder.", "Desktop Folders", MessageBoxButton.OK, MessageBoxImage.Exclamation
                                     ));
            }

            Stopwatch.Stop();
            Timings.Add("2: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            //Set start size and position
            SetStartSize();
            SetStartPosition();

            Stopwatch.Stop();
            Timings.Add("3: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            //Allow the window to be dragged via the title bar.
            TitleBar.MouseDown += new MouseButtonEventHandler(
                (object sender, MouseButtonEventArgs e) => {
                if (e.ChangedButton == MouseButton.Left)
                {
                    DragMove();
                }
            }
                );

            //Setup titlebar
            //	try {
            if (Path.GetDirectoryName(FolderPath) == null)               //If it is a root, eg "C:\"
            {
                TBName.Text = FolderPath;
            }
            else
            {
                TBName.Text = Path.GetFileName(
                    //Get the correctly-capitalised name
                    Directory.GetDirectories(
                        Path.GetDirectoryName(FolderPath),
                        Path.GetFileName(FolderPath)
                        ).FirstOrDefault()
                    );
            }
            //	} catch { } //Just leave the default value
            this.Title = TBName.Text;
            //	this.ToolTip = FolderPath;

            this.PreviewKeyDown += new KeyEventHandler(MainWindow_PreviewKeyDown);

            Stopwatch.Stop();
            Timings.Add("4: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            //Setup window chrome (allows resizing +)
            windowChrome.CaptionHeight         = 0;
            windowChrome.CornerRadius          = new CornerRadius(0);
            windowChrome.GlassFrameThickness   = new Thickness(0, 0, 0, 0);
            windowChrome.ResizeBorderThickness = new Thickness(8);
            windowChrome.UseAeroCaptionButtons = true;
            WindowChrome.SetWindowChrome(this, windowChrome);

            Stopwatch.Stop();
            Timings.Add("5: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            //Set max height (to avoid getting too big when maximized)
            System.Drawing.Rectangle workingArea = System.Windows.Forms.Screen.GetWorkingArea(
                new System.Drawing.Rectangle(
                    new System.Drawing.Point(
                        (int)Math.Round(this.Left),
                        (int)Math.Round(this.Top)
                        ),
                    new System.Drawing.Size(
                        (int)Math.Round(this.Width), (int)Math.Round(this.Height)
                        )
                    )
                );
            this.MaxHeight = workingArea.Height + 6;             //When it's maximised, three pixels of each edge are cropped off for some reason
            this.MaxWidth  = workingArea.Width + 6;

            //	SetupSystemMenu();

            Stopwatch.Stop();
            Timings.Add("6: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            AlwaysAboveDesktop.AddHook(Process.GetCurrentProcess(), this);
            this.Closed += (s, e) => { AlwaysAboveDesktop.RemoveHook(); };

            Stopwatch.Stop();
            Timings.Add("7: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            BPin_HighlightManager = new ControlHighlightManager(
                BPin,
                BPin,
                null,
                new ControlHighlightManager.BrushGroup(
                    new ControlHighlightManager.HighlightStateBrushes(
                        new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)),
                        null,                        //Transparent
                        null                         //Doesn't matter
                        ),
                    new ControlHighlightManager.HighlightStateBrushes(
                        null,                         //Transparent //new SolidColorBrush(Color.FromArgb(100, 255, 255, 255)),
                        new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)),
                        null
                        ),
                    new ControlHighlightManager.HighlightStateBrushes(
                        new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)),
                        new SolidColorBrush(Color.FromArgb(150, 255, 255, 255)),
                        null
                        ),
                    null                     //Transparent, transparent, doesn't matter
                    )
                );

            BPin.MouseEnter += (s, e) => { BPin_HighlightManager.Highlight(); };
            //	BPin.MouseLeave       += (s, e) => { if (!BPin.IsFocused) BPin_HighlightManager.Unhighlight(); };
            BPin.MouseLeave += (s, e) => { BPin_HighlightManager.Unhighlight(); };
            BPin.Click      += (s, e) => { BPin_HighlightManager.ToggleSelect(); };
            //	BPin.GotKeyboardFocus += (s, e) => {
            //		//Only fire if the tab key caused the focus
            //		if (e.KeyboardDevice.GetKeyStates(Key.Tab) != KeyStates.None)
            //		{
            //			BPin_HighlightManager.Highlight();
            //		}
            //	};
            //	BPin.LostFocus      += (s, e) => { if (!BPin.IsMouseOver) BPin_HighlightManager.Unhighlight(); };
            BPin.PreviewKeyDown += BPin_PreviewKeyDown;

            LocalIconCacheDir = Path.Combine(
                RootIconCacheDir,
                FolderPath
                .RegexReplace(@"(\:|\\|\/)", ";")
                .RegexReplace(@"(\s|a|e|i|o|u)", "")
                .RegexReplace(@"(\<|\>|\?|\*|\|)", "-")
                .RegexReplace("\"", "-")
                //"(item1|item2|item3)" means match "item1", "item2", or "item3"
                //"\x" means escape character 'x', so if it is a letter it has a special meaning,
                //or if not it is stopped from having a special meaning. So "\s" means "whitespace character",
                //and "\|" means "pipe character with no special meaning"
                );

            Stopwatch.Stop();
            Timings.Add("8: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            SetColours();

            Stopwatch.Stop();
            Timings.Add("9: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            List <FileData> fileDataList = GetFileData(FolderPath);

            Stopwatch.Stop();
            Timings.Add("10: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            PopulateGrid(fileDataList);

            Stopwatch.Stop();
            Timings.Add("11: " + Stopwatch.ElapsedMilliseconds);
            Stopwatch.Restart();

            //	//Setup and start IconLoadWorker
            //	//	GetFileGridItemCount = () => { return FileGrid.Children.Count; };
            //	//	//	GetFileGridItemIcon = (i) => { return (FileGrid.Children[i] as FileGridItem)?.FileIcon; };
            //	//	GetFileGridItemIsValid = (i) => { return (FileGrid.Children[i] as FileGridItem) != null; };
            //	//	GetFileGridItemPath = (i) => { return (FileGrid.Children[i] as FileGridItem)?.FilePath; };
            //	//	SetFileGridItemIcon = (i, icon) => {
            //	//		FileGridItem fileGridItem = FileGrid.Children[i] as FileGridItem;
            //	//		if (fileGridItem != null) fileGridItem.FileIcon = icon;
            //	//	};
            //	IconLoadWorker.DoWork += LoadIcon;
            //	IconLoadWorker.RunWorkerCompleted += SwitchToNextIcon;
            //	//Find first valid FileGridItem
            //	int count = FileGrid.Children.Count;
            //	while (iconLoadIndex < count && !(FileGrid.Children[iconLoadIndex] is FileGridItem)) {
            //		iconLoadIndex++;
            //	}
            //	//Check that not at end
            //	if (iconLoadIndex < count) {
            //		//Start icon load
            //		string filePath = (FileGrid.Children[iconLoadIndex] as FileGridItem).FilePath;
            //		IconLoadWorker.RunWorkerAsync(filePath);
            //	}
        }
Exemple #2
0
 private void DoPin(object sender, RoutedEventArgs e)
 {
     BPin_HighlightManager.ToggleSelect();
 }