Esempio n. 1
0
        /// <summary>
        /// Save settings when closing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closing(object sender, CancelEventArgs e)
        {
            // Close Extra windows when closing
            if (fake != null)
            {
                fake.Close();
            }

            Hide(); // Make it feel faster

            if (!Properties.Settings.Default.FitToWindow && !Properties.Settings.Default.Fullscreen)
            {
                Properties.Settings.Default.Top       = Top;
                Properties.Settings.Default.Left      = Left;
                Properties.Settings.Default.Height    = Height;
                Properties.Settings.Default.Width     = Width;
                Properties.Settings.Default.Maximized = WindowState == WindowState.Maximized;
            }

            Properties.Settings.Default.Save();
            DeleteTempFiles();
            RecentFiles.WriteToFile();
            Environment.Exit(0);
        }
Esempio n. 2
0
        /// <summary>
        /// Attemps to download image and display it
        /// </summary>
        /// <param name="path"></param>
        internal static async void PicWeb(string path)
        {
            if (ajaxLoading.Opacity != 1)
            {
                AjaxLoadingStart();
            }

            mainWindow.Bar.Text = Loading;

            BitmapSource pic;

            try
            {
                pic = await LoadImageWebAsync(path).ConfigureAwait(true);
            }
#if DEBUG
            catch (Exception e)
            {
                Trace.WriteLine("PicWeb caught exception, message = " + e.Message);
                pic = null;
            }
#else
            catch (Exception) { pic = null; }
#endif
            if (pic == null)
            {
                Reload(true);
                ToolTipStyle("Unable to load image");
                AjaxLoadingEnd();
                return;
            }

            Pic(pic, path);
            RecentFiles.Add(path);
            canNavigate = false;
        }
Esempio n. 3
0
        private void MainWindow_ContentRendered(object sender, EventArgs e)
        {
            // Update values
            AllowDrop       = true;
            IsScrollEnabled = Properties.Settings.Default.ScrollEnabled;
            Pics            = new List <string>();
            //DataContext = this;
            MonitorInfo = MonitorSize.GetMonitorSize();

            // Load image if possible
            if (Application.Current.Properties["ArbitraryArgName"] == null)
            {
                Unload();
                UpdateColor();
            }
            else
            {
                Pic(Application.Current.Properties["ArbitraryArgName"].ToString());

                if (Properties.Settings.Default.Fullscreen)
                {
                    Fullscreen_Restore(true);
                }
                else
                {
                    UpdateColor();
                }
            }

            LoadClickArrow(true);
            LoadClickArrow(false);
            Loadx2();
            LoadMinus();

            // Update WindowStyle
            if (!Properties.Settings.Default.ShowInterface)
            {
                clickArrowLeft.Opacity      =
                    clickArrowRight.Opacity =
                        x2.Opacity          =
                            minus.Opacity   =
                                0;

                clickArrowLeft.Visibility      =
                    clickArrowRight.Visibility =
                        x2.Visibility          =
                            minus.Visibility   =
                                Visibility.Visible;
            }

            mainColor = (Color)Application.Current.Resources["MainColor"];
            if (!Properties.Settings.Default.BgColorWhite)
            {
                imgBorder.Background = new SolidColorBrush(Colors.Transparent);
            }

            backgroundBorderColor = (Color)Application.Current.Resources["BackgroundColorAlt"];

            // Load PicGallery, if needed
            if (Properties.Settings.Default.PicGallery > 0)
            {
                picGallery = new PicGallery
                {
                    Opacity    = 0,
                    Visibility = Visibility.Collapsed
                };

                bg.Children.Add(picGallery);
                Panel.SetZIndex(picGallery, 999);

                if (Properties.Settings.Default.PicGallery == 2 && freshStartup)
                {
                    PicGalleryToggle.ToggleGallery();
                }
            }

            // Add UserControls :)
            LoadTooltipStyle();
            LoadFileMenu();
            LoadImageSettingsMenu();
            LoadQuickSettingsMenu();
            LoadFunctionsMenu();
            LoadAutoScrollSign();

            // Update UserControl values
            quickSettingsMenu.ToggleScroll.IsChecked = IsScrollEnabled;
            if (FitToWindow)
            {
                quickSettingsMenu.SetFit.IsChecked    = true;
                quickSettingsMenu.SetCenter.IsChecked = false;
            }

            else
            {
                quickSettingsMenu.SetCenter.IsChecked = true;
                quickSettingsMenu.SetFit.IsChecked    = false;
            }

            // Initilize Things!
            RecentFiles.Initialize();
            InitializeZoom();

            // Add things!
            AddEvents();
            AddTimers();
            AddContextMenus();

            // Updates settings from older version to newer version
            if (Properties.Settings.Default.CallUpgrade)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.CallUpgrade = false;
            }

            AjaxLoadingEnd();
        }
Esempio n. 4
0
        /// <summary>
        /// Loads image based on overloaded int.
        /// </summary>
        /// <param name="x">The index of file to load from Pics</param>
        internal static async void Pic(int x)
        {
            BitmapSource pic;

            // Additional error checking
            if (Pics.Count <= x)
            {
                if (x == 0)
                {
                    var recovery = await RecoverFailedArchiveAsync().ConfigureAwait(true);

                    if (!recovery)
                    {
                        ToolTipStyle("Archive could not be processed");
                        Reload(true);
                        return;
                    }
                }

                // Untested code
                pic = await PicErrorFix(x).ConfigureAwait(true);

                if (pic == null)
                {
                    Reload(true);
                    return;
                }
            }
            if (x < 0)
            {
                pic = await PicErrorFix(x).ConfigureAwait(true);
            }
            //if (!canNavigate)
            //{
            //    Reload(true);
            //    return;
            //}
            else
            {
                /// Add "pic" as local variable used for the image.
                /// Use the Load() function load image from memory if available
                /// if not, it will be null
                pic = Preloader.Load(Pics[x]);
            }


            if (pic == null)
            {
                mainWindow.Title       = Loading;
                mainWindow.Bar.Text    = Loading;
                mainWindow.Bar.ToolTip = Loading;

                TryZoomFit(Pics[x]);

                var thumb = GetThumb();

                if (thumb != null)
                {
                    mainWindow.img.Source = thumb;
                }

                // Dissallow changing image while loading
                canNavigate = false;

                if (freshStartup)
                {
                    // Load new value manually
                    await Task.Run(() => pic = RenderToBitmapSource(Pics[x])).ConfigureAwait(true);
                }
                else
                {
                    do
                    {
                        // Try again while loading?
                        await Task.Delay(20).ConfigureAwait(true);

                        if (x < Pics.Count)
                        {
                            pic = Preloader.Load(Pics[x]);
                        }
                    } while (Preloader.IsLoading);
                }

                // If pic is still null, image can't be rendered
                if (pic == null)
                {
                    // Attempt to load new image
                    pic = await PicErrorFix(x).ConfigureAwait(true);

                    if (pic == null)
                    {
                        if (Pics.Count <= 1)
                        {
                            Unload();
                            return;
                        }

                        DisplayBrokenImage();
                        canNavigate = true;
                        return;
                    }
                }
            }

            // Clear unsupported image window, if shown
            if (mainWindow.img.Source == null && !freshStartup)
            {
                if (mainWindow.topLayer.Children.Count > 0)
                {
                    mainWindow.topLayer.Children.Clear();
                }
            }

            // Show the image! :)
            mainWindow.img.Source = pic;

            ZoomFit(pic.PixelWidth, pic.PixelHeight);

            // Scroll to top if scroll enabled
            if (IsScrollEnabled)
            {
                mainWindow.Scroller.ScrollToTop();
            }

            /// TODO Make it staying flipped a user preference
            //// Prevent picture from being flipped if previous is
            //if (Flipped)
            //    Flip();

            // Update values
            canNavigate = true;
            SetTitleString(pic.PixelWidth, pic.PixelHeight, x);
            FolderIndex = x;
            AjaxLoadingEnd();

            if (Pics.Count > 0)
            {
                Progress(x, Pics.Count);

                // Preload images \\
                if (Preloader.StartPreload())
                {
                    Preloader.Add(pic, Pics[FolderIndex]);
                    await Preloader.PreLoad(x).ConfigureAwait(false);
                }
            }

            if (!freshStartup)
            {
                RecentFiles.Add(Pics[x]);
            }

            freshStartup = false;
        }
Esempio n. 5
0
        /// <summary>
        /// Adds events and submenu items to recent items in the context menu
        /// </summary>
        /// <param name="sender"></param>
        internal static void Recentcm_MouseEnter(object sender)
        {
            // Need to register the object as a MenuItem to use it
            var RecentFilesMenuItem = (MenuItem)sender;

            // Load values and check if succeeded
            var fileNames = RecentFiles.LoadValues();

            if (fileNames == null)
            {
                return;
            }

            /// Update old values
            /// If items exist: replace them, else add them
            /// TODO Improve how this is handled and make it more user friendly
            if (RecentFilesMenuItem.Items.Count >= fileNames.Length)
            {
                for (int i = fileNames.Length - 1; i >= 0; i--)
                {
                    // Don't add the same item more than once
                    var item = fileNames[i];
                    if (i != 0 && fileNames[i - 1] == item)
                    {
                        continue;
                    }

                    // Change values
                    var menuItem = (MenuItem)RecentFilesMenuItem.Items[i];
                    var header   = Path.GetFileNameWithoutExtension(item);
                    header           = header.Length > 30 ? Shorten(header, 30) : header;
                    menuItem.Header  = header;
                    menuItem.ToolTip = item;
                    var ext  = Path.GetExtension(item);
                    var ext5 = !string.IsNullOrWhiteSpace(ext) && ext.Length >= 5 ? ext.Substring(0, 5) : ext;
                    //ext5 = ext5.Length == 5 ? ext.Replace("?", string.Empty) : ext5;
                    menuItem.InputGestureText = ext5;
                }
                return;
            }

            // Add if not exist
            for (int i = fileNames.Length - 1; i >= 0; i--)
            {
                // Don't add the same item more than once
                var item = fileNames[i];
                if (i != 0 && fileNames[i - 1] == item)
                {
                    continue;
                }

                var cmIcon = new System.Windows.Shapes.Path
                {
                    Data    = Geometry.Parse(SVGiconCamera),
                    Stretch = Stretch.Fill,
                    Width   = 12,
                    Height  = 12,
                    Fill    = (SolidColorBrush)Application.Current.Resources["MainColorFadedBrush"]
                };

                var header = Path.GetFileNameWithoutExtension(item);
                header = header.Length > 30 ? Shorten(header, 30) : header;
                // Add items
                var menuItem = new MenuItem()
                {
                    Header  = header,
                    ToolTip = item
                };
                // Set tooltip as argument to avoid subscribing and unsubscribing to events
                menuItem.Click += (x, xx) => Pic(menuItem.ToolTip.ToString());
                menuItem.Icon   = cmIcon;
                var ext  = Path.GetExtension(item);
                var ext5 = !string.IsNullOrWhiteSpace(ext) && ext.Length >= 5 ? ext.Substring(0, 5) : ext;
                //ext5 = ext5.Length == 5 ? ext.Replace("?", string.Empty) : ext5;
                menuItem.InputGestureText = ext5;
                RecentFilesMenuItem.Items.Add(menuItem);
            }
        }