Esempio n. 1
0
        private void StartPart2(string mutexName, string[] remainingArgs)
        {
            IAnimationService animationService;

            Memory.Initialize();
            CultureInfo info = AppSettings.Instance.UI.Language.Value;

            Thread.CurrentThread.CurrentUICulture     = info;
            CultureInfo.DefaultThreadCurrentUICulture = info;
            AppSettings.Instance.UI.Language.Value    = info;
            PdnResources.Culture = info;
            AppSettings.Instance.UI.ErrorFlagsAtStartup.Value = AppSettings.Instance.UI.ErrorFlags.Value;
            UIUtil.IsGetMouseMoveScreenPointsEnabled          = AppSettings.Instance.UI.EnableSmoothMouseInput.Value;
            if (!OS.VerifyFrameworkVersion(4, 6, 0, OS.FrameworkProfile.Full))
            {
                string message = PdnResources.GetString("Error.FXRequirement");
                MessageBoxUtil.ErrorBox(null, message);
                string fxurl = "http://www.microsoft.com/en-us/download/details.aspx?id=40773";
                () => ShellUtil.LaunchUrl2(null, fxurl).Eval <bool>().Observe();
            }
            else if (!OS.VerifyWindowsVersion(6, 1, 1))
            {
                string str4 = PdnResources.GetString("Error.OSRequirement");
                MessageBoxUtil.ErrorBox(null, str4);
            }
            else if (!Processor.IsFeaturePresent(ProcessorFeature.SSE))
            {
                string str5 = PdnResources.GetString("Error.SSERequirement");
                MessageBoxUtil.ErrorBox(null, str5);
            }
            else
            {
                string str;
                if (MultithreadedWorkItemDispatcher.IsSingleThreadForced && PdnInfo.IsFinalBuild)
                {
                    throw new PaintDotNet.InternalErrorException("MultithreadedWorkItemDispatcher.IsSingleThreadForced shouldn't be true for Final builds!");
                }
                if (RefTrackedObject.IsFullRefTrackingEnabled && PdnInfo.IsFinalBuild)
                {
                    throw new PaintDotNet.InternalErrorException("Full ref tracking should not be enabled for non-expiring builds!");
                }
                PaintDotNet.Base.AssemblyServices.RegisterProxies();
                PaintDotNet.Core.AssemblyServices.RegisterProxies();
                PaintDotNet.Framework.AssemblyServices.RegisterProxies();
                ObjectRefProxy.CloseRegistration();
                remainingArgs = TryRemoveArg(remainingArgs, "/showCrashLog=", out str);
                if (!string.IsNullOrWhiteSpace(str))
                {
                    DialogResult?nullable = null;
                    try
                    {
                        string fullPath = Path.GetFullPath(str);
                        if (File.Exists(fullPath))
                        {
                            nullable = new DialogResult?(CrashManager.ShowCrashLogDialog(fullPath));
                        }
                    }
                    catch (Exception exception)
                    {
                        try
                        {
                            MessageBox.Show(exception.ToString(), null, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        catch (Exception exception2)
                        {
                            Environment.FailFast(null, exception2);
                        }
                    }
                    DialogResult?nullable2 = nullable;
                    DialogResult oK        = DialogResult.OK;
                    if ((((DialogResult)nullable2.GetValueOrDefault()) == oK) ? nullable2.HasValue : false)
                    {
                        string[] args = new string[] { "/sleep=1000" };
                        StartNewInstance(null, false, args);
                    }
                }
                else
                {
                    string str2;
                    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Startup.OnCurrentDomainUnhandledException);
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, true);
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, false);
                    Application.ThreadException += new ThreadExceptionEventHandler(Startup.OnApplicationThreadException);
                    this.canUseCrashDialog       = true;
                    remainingArgs = TryRemoveArg(remainingArgs, "/test", out str2);
                    if (str2 != null)
                    {
                        PdnInfo.IsTestMode = true;
                    }
                    SingleInstanceManager disposeMe = new SingleInstanceManager(mutexName);
                    animationService = null;
                    try
                    {
                        DirectWriteFactory.DefaultDirectWriteSettingsController defaultDirectWriteSettingsController;
                        DrawingContext.DefaultDrawingContextSettingsController  defaultDrawingContextSettingsController;
                        IDisposable               updatesServiceShutdown;
                        IUpdatesServiceHost       updatesServiceHost;
                        PdnSynchronizationContext pdnSyncContext;
                        if (!disposeMe.IsFirstInstance)
                        {
                            disposeMe.FocusFirstInstance();
                            foreach (string str7 in remainingArgs)
                            {
                                disposeMe.SendInstanceMessage(str7, 30);
                            }
                            disposeMe.Dispose();
                            disposeMe = null;
                        }
                        else
                        {
                            CleanupService.Initialize();
                            ResourcesService.Initialize();
                            UserFilesService.Initialize();
                            UserPalettesService.Initialize();
                            animationService           = AnimationService.Initialize();
                            animationService.IsEnabled = true;
                            Document.Initialize(PdnInfo.Version);
                            Layer.Initialize(PdnResources.GetString("Layer.BackgroundLayer.DefaultName"));
                            Effect.SetDefaultServiceProviderValueFactory(effect => new ServiceProviderForEffects());
                            defaultDirectWriteSettingsController = DirectWriteFactory.GetDefaultSettingsController();
                            defaultDirectWriteSettingsController.DefaultCulture = AppSettings.Instance.UI.Language.Value;
                            AppSettings.Instance.UI.Language.ValueChangedT     += (sender, e) => (defaultDirectWriteSettingsController.DefaultCulture = e.NewValue);
                            AeroColors.CurrentScheme = AppSettings.Instance.UI.AeroColorScheme.Value;
                            AppSettings.Instance.UI.AeroColorScheme.ValueChangedT += (sender, e) => (AeroColors.CurrentScheme = e.NewValue);
                            defaultDrawingContextSettingsController = DrawingContext.GetDefaultSettingsController();
                            defaultDrawingContextSettingsController.DefaultTextAntialiasMode = AppSettings.Instance.UI.DefaultTextAntialiasMode.Value;
                            AppSettings.Instance.UI.DefaultTextAntialiasMode.ValueChangedT  += delegate(object sender, ValueChangedEventArgs <TextAntialiasMode> e) {
                                defaultDrawingContextSettingsController.DefaultTextAntialiasMode = e.NewValue;
                                foreach (Form form in Application.OpenForms)
                                {
                                    form.PerformLayoutRecursiveDepthFirst("TextAntialiasMode");
                                    form.Invalidate(true);
                                }
                            };
                            defaultDrawingContextSettingsController.DefaultTextRenderingMode = AppSettings.Instance.UI.DefaultTextRenderingMode.Value;
                            AppSettings.Instance.UI.DefaultTextRenderingMode.ValueChangedT  += delegate(object sender, ValueChangedEventArgs <TextRenderingMode> e) {
                                defaultDrawingContextSettingsController.DefaultTextRenderingMode = e.NewValue;
                                foreach (Form form in Application.OpenForms)
                                {
                                    form.PerformLayoutRecursiveDepthFirst("TextRenderingMode");
                                    form.Invalidate(true);
                                }
                            };
                            PaintDotNet.IndirectUI.ControlInfo.Initialize(Assembly.GetExecutingAssembly());
                            PdnBaseForm.SetStaticHelpRequestedHandler(delegate(object sender, HelpEventArgs e) {
                                HelpService.Instance.ShowHelp(sender as IWin32Window);
                                e.Handled = true;
                            });
                            Control control = new Control();
                            SynchronizationContext current = SynchronizationContext.Current;
                            PdnSynchronizationContextController controller = PdnSynchronizationContext.Install(new WaitForMultipleObjectsExDelegate(WaitHelper.WaitForMultipleObjectsEx), new SleepExDelegate(WaitHelper.SleepEx));
                            pdnSyncContext         = controller.Instance;
                            this.mainForm          = new MainForm(remainingArgs);
                            updatesServiceHost     = this.mainForm.CreateUpdatesServiceHost();
                            updatesServiceShutdown = null;
                            EventHandler initUpdatesOnShown = null;
                            initUpdatesOnShown = delegate(object sender, EventArgs e) {
                                this.mainForm.Shown   -= initUpdatesOnShown;
                                updatesServiceShutdown = UpdatesService.Initialize(updatesServiceHost);
                            };
                            this.mainForm.Shown += initUpdatesOnShown;
                            this.mainForm.SingleInstanceManager = disposeMe;
                            disposeMe = null;
                            int num        = (int)Math.Floor((double)8.3333333333333339);
                            int intervalMs = (int)Math.Floor((double)50.0);
                            using (AnimationTimerUpdateThread timerThread = new AnimationTimerUpdateThread(intervalMs, false))
                            {
                                < > c__DisplayClass20_1 class_3;
Esempio n. 2
0
 public override void LoadResources()
 {
     this.cancelButton.Text = PdnResources.GetString("Form.CancelButton.Text");
     base.LoadResources();
 }
Esempio n. 3
0
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            Activate();

            if (!IsCurrentModalForm || !Enabled)
            {
                // do nothing
            }
            else if (drgevent.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] allFiles = (string[])drgevent.Data.GetData(DataFormats.FileDrop);

                if (allFiles == null)
                {
                    return;
                }

                string[] files = PruneDirectories(allFiles);

                bool importAsLayers = true;

                if (files.Length == 0)
                {
                    return;
                }
                else
                {
                    Icon   formIcon = Utility.ImageToIcon(PdnResources.GetImageResource("Icons.DragDrop.OpenOrImport.FormIcon.png").Reference);
                    string title    = PdnResources.GetString("DragDrop.OpenOrImport.Title");
                    string infoText = PdnResources.GetString("DragDrop.OpenOrImport.InfoText");

                    TaskButton openTB = new TaskButton(
                        PdnResources.GetImageResource("Icons.MenuFileOpenIcon.png").Reference,
                        PdnResources.GetString("DragDrop.OpenOrImport.OpenButton.ActionText"),
                        PdnResources.GetString("DragDrop.OpenOrImport.OpenButton.ExplanationText"));

                    string importLayersExplanation;
                    if (this.appWorkspace.DocumentWorkspaces.Length == 0)
                    {
                        importLayersExplanation = PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ExplanationText.NoImagesYet");
                    }
                    else
                    {
                        importLayersExplanation = PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ExplanationText");
                    }

                    TaskButton importLayersTB = new TaskButton(
                        PdnResources.GetImageResource("Icons.MenuLayersImportFromFileIcon.png").Reference,
                        PdnResources.GetString("DragDrop.OpenOrImport.ImportLayers.ActionText"),
                        importLayersExplanation);

                    TaskButton clickedTB = TaskDialog.Show(
                        this,
                        formIcon,
                        title,
                        null,
                        false,
                        infoText,
                        new TaskButton[] { openTB, importLayersTB, TaskButton.Cancel },
                        null,
                        TaskButton.Cancel);

                    if (clickedTB == openTB)
                    {
                        importAsLayers = false;
                    }
                    else if (clickedTB == importLayersTB)
                    {
                        importAsLayers = true;
                    }
                    else
                    {
                        return;
                    }
                }

                if (!importAsLayers)
                {
                    // open files into new tabs
                    this.appWorkspace.OpenFilesInNewWorkspace(files);
                }
                else
                {
                    // no image open? we will have to create one
                    if (this.appWorkspace.ActiveDocumentWorkspace == null)
                    {
                        Size newSize = this.appWorkspace.GetNewDocumentSize();

                        this.appWorkspace.CreateBlankDocumentInNewWorkspace(
                            newSize,
                            Document.DefaultDpuUnit,
                            Document.GetDefaultDpu(Document.DefaultDpuUnit),
                            false);
                    }

                    ImportFromFileAction action = new ImportFromFileAction();
                    HistoryMemento       ha     = action.ImportMultipleFiles(this.appWorkspace.ActiveDocumentWorkspace, files);

                    if (ha != null)
                    {
                        this.appWorkspace.ActiveDocumentWorkspace.History.PushNewMemento(ha);
                    }
                }
            }

            base.OnDragDrop(drgevent);
        }
Esempio n. 4
0
        private void ZoomComboBox_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                int val = 1;
                e.Cancel = false;

                if (zoomComboBox.Text == this.windowText)
                {
                    ZoomBasis = ZoomBasis.FitToWindow;
                }
                else
                {
                    try
                    {
                        string text = zoomComboBox.Text;

                        if (text.Length == 0)
                        {
                            e.Cancel = true;
                        }
                        else
                        {
                            if (text[text.Length - 1] == '%')
                            {
                                text = text.Substring(0, text.Length - 1);
                            }
                            else if (text[0] == '%')
                            {
                                text = text.Substring(1);
                            }

                            val       = (int)Math.Round(double.Parse(text));
                            ZoomBasis = ZoomBasis.ScaleFactor;
                        }
                    }

                    catch (FormatException)
                    {
                        e.Cancel = true;
                    }

                    catch (OverflowException)
                    {
                        e.Cancel = true;
                    }

                    if (e.Cancel)
                    {
                        this.zoomComboBox.BackColor   = Color.Red;
                        this.zoomComboBox.ToolTipText = PdnResources.GetString("ZoomConfigWidget.Error.InvalidNumber");
                    }
                    else
                    {
                        if (val < 1)
                        {
                            e.Cancel = true;
                            this.zoomComboBox.BackColor   = Color.Red;
                            this.zoomComboBox.ToolTipText = PdnResources.GetString("ZoomConfigWidget.Error.TooSmall");
                        }
                        else if (val > 3200)
                        {
                            e.Cancel = true;
                            this.zoomComboBox.BackColor   = Color.Red;
                            this.zoomComboBox.ToolTipText = PdnResources.GetString("ZoomConfigWidget.Error.TooLarge");
                        }
                        else
                        {
                            // Clear the error
                            e.Cancel = false;
                            this.zoomComboBox.ToolTipText = string.Empty;
                            this.zoomComboBox.BackColor   = SystemColors.Window;
                            ScaleFactor = new ScaleFactor(val, 100);
                            SuspendEvents();
                            ZoomBasis = ZoomBasis.ScaleFactor;
                            ResumeEvents();
                        }
                    }
                }
            }

            catch (FormatException)
            {
            }
        }
Esempio n. 5
0
 protected override Image Load()
 {
     return(PdnResources.GetImage(this.Name));
 }
Esempio n. 6
0
        private void StartPart2()
        {
            // Set up locale / resource details
            string locale = Settings.CurrentUser.GetString(PdnSettings.LanguageName, null);

            if (locale == null)
            {
                locale = Settings.SystemWide.GetString(PdnSettings.LanguageName, null);
            }

            if (locale != null)
            {
                CultureInfo ci = new CultureInfo(locale, true);
                Thread.CurrentThread.CurrentUICulture = ci;
            }

            // Check system requirements
            if (!OS.CheckOSRequirement())
            {
                string message = PdnResources.GetString("Error.OSRequirement");
                Utility.ErrorBox(null, message);
                return;
            }

            // Parse command-line arguments
            if (this.args.Length == 1 &&
                this.args[0] == Updates.UpdatesOptionsDialog.CommandLineParameter)
            {
                Updates.UpdatesOptionsDialog.ShowUpdateOptionsDialog(null, false);
            }
            else
            {
                SingleInstanceManager singleInstanceManager = new SingleInstanceManager("PaintDotNet");

                // If this is not the first instance of PDN.exe, then forward the command-line
                // parameters over to the first instance.
                if (!singleInstanceManager.IsFirstInstance)
                {
                    singleInstanceManager.FocusFirstInstance();

                    foreach (string arg in this.args)
                    {
                        singleInstanceManager.SendInstanceMessage(arg, 30);
                    }

                    singleInstanceManager.Dispose();
                    singleInstanceManager = null;

                    return;
                }

                // Create main window
                this.mainForm = new MainForm(this.args);

                // if the display is set to a portrait mode (tall), then orient the PDN window the same way
                if (this.mainForm.ScreenAspect < 1.0)
                {
                    int width  = mainForm.Width;
                    int height = mainForm.Height;

                    this.mainForm.Width  = height;
                    this.mainForm.Height = width;
                }

                // if the window opens and part of it is off screen, correct this
                Screen screen = Screen.FromControl(this.mainForm);

                Rectangle intersect = Rectangle.Intersect(screen.Bounds, mainForm.Bounds);
                if (intersect.Width == 0 || intersect.Height == 0)
                {
                    mainForm.Location = new Point(screen.Bounds.Left + 16, screen.Bounds.Top + 16);
                }

                // if the window is not big enough, correct this
                if (this.mainForm.Width < 200)
                {
                    this.mainForm.Width = 200; // this value was chosen arbitrarily
                }

                if (this.mainForm.Height < 200)
                {
                    this.mainForm.Height = 200; // this value was chosen arbitrarily
                }

                this.mainForm.SingleInstanceManager = singleInstanceManager;
                singleInstanceManager = null; // mainForm owns it now

                // 3 2 1 go
                Application.Run(this.mainForm);

                this.mainForm.Dispose();
                this.mainForm = null;
            }
        }
Esempio n. 7
0
        private static void UnhandledException(Exception ex)
        {
            string       dir      = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            const string fileName = "pdncrash.log";
            string       fullName = Path.Combine(dir, fileName);

            using (StreamWriter stream = new System.IO.StreamWriter(fullName, true))
            {
                stream.AutoFlush = true;

                string headerFormat;

                try
                {
                    headerFormat = PdnResources.GetString("CrashLog.HeaderText.Format");
                }

                catch (Exception ex13)
                {
                    headerFormat =
                        InvariantStrings.CrashLogHeaderTextFormatFallback +
                        ", --- Exception while calling PdnResources.GetString(\"CrashLog.HeaderText.Format\"): " +
                        ex13.ToString() +
                        Environment.NewLine;
                }

                string header;

                try
                {
                    header = string.Format(headerFormat, InvariantStrings.FeedbackEmail);
                }

                catch
                {
                    header = string.Empty;
                }

                stream.WriteLine(header);

                const string noInfoString = "err";

                string fullAppName = noInfoString;
                string timeOfCrash = noInfoString;
                string appUptime   = noInfoString;
                string osVersion   = noInfoString;
                string osRevision  = noInfoString;
                string osType      = noInfoString;
                string processorNativeArchitecture = noInfoString;
                string fxVersion             = noInfoString;
                string processorArchitecture = noInfoString;
                string cpuName            = noInfoString;
                string cpuCount           = noInfoString;
                string totalPhysicalBytes = noInfoString;
                string localeName         = noInfoString;
                string inkInfo            = noInfoString;

                try
                {
                    try
                    {
                        fullAppName = PdnInfo.GetFullAppName();
                    }

                    catch (Exception ex1)
                    {
                        fullAppName = Application.ProductVersion + ", --- Exception while calling PdnInfo.GetFullAppName(): " + ex1.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        timeOfCrash = DateTime.Now.ToString();
                    }

                    catch (Exception ex2)
                    {
                        timeOfCrash = "--- Exception while populating timeOfCrash: " + ex2.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        appUptime = (DateTime.Now - startupTime).ToString();
                    }

                    catch (Exception ex13)
                    {
                        appUptime = "--- Exception while populating appUptime: " + ex13.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        osVersion = System.Environment.OSVersion.Version.ToString();
                    }

                    catch (Exception ex3)
                    {
                        osVersion = "--- Exception while populating osVersion: " + ex3.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        osRevision = OS.Revision;
                    }

                    catch (Exception ex4)
                    {
                        osRevision = "--- Exception while populating osRevision: " + ex4.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        osType = OS.Type.ToString();
                    }

                    catch (Exception ex5)
                    {
                        osType = "--- Exception while populating osType: " + ex5.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        processorNativeArchitecture = Processor.NativeArchitecture.ToString().ToLower();
                    }

                    catch (Exception ex6)
                    {
                        processorNativeArchitecture = "--- Exception while populating processorNativeArchitecture: " + ex6.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        fxVersion = System.Environment.Version.ToString();
                    }

                    catch (Exception ex7)
                    {
                        fxVersion = "--- Exception while populating fxVersion: " + ex7.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        processorArchitecture = Processor.Architecture.ToString().ToLower();
                    }

                    catch (Exception ex8)
                    {
                        processorArchitecture = "--- Exception while populating processorArchitecture: " + ex8.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        cpuName = SystemLayer.Processor.CpuName;
                    }

                    catch (Exception ex9)
                    {
                        cpuName = "--- Exception while populating cpuName: " + ex9.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        cpuCount = SystemLayer.Processor.LogicalCpuCount.ToString() + "x";
                    }

                    catch (Exception ex10)
                    {
                        cpuCount = "--- Exception while populating cpuCount: " + ex10.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        totalPhysicalBytes = ((SystemLayer.Memory.TotalPhysicalBytes / 1024) / 1024) + " MB";
                    }

                    catch (Exception ex11)
                    {
                        totalPhysicalBytes = "--- Exception while populating totalPhysicalBytes: " + ex11.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        localeName =
                            "pdnr.c: " + PdnResources.Culture.Name +
                            ", hklm: " + Settings.SystemWide.GetString(PdnSettings.LanguageName, "n/a") +
                            ", hkcu: " + Settings.CurrentUser.GetString(PdnSettings.LanguageName, "n/a") +
                            ", cc: " + CultureInfo.CurrentCulture.Name +
                            ", cuic: " + CultureInfo.CurrentUICulture.Name;
                    }

                    catch (Exception ex14)
                    {
                        localeName = "--- Exception while populating localeName: " + ex14.ToString() + Environment.NewLine;
                    }

                    try
                    {
                        inkInfo = Ink.IsAvailable() ? "yes" : "no";
                    }

                    catch (Exception ex15)
                    {
                        inkInfo = "--- Exception while populating inkInfo: " + ex15.ToString() + Environment.NewLine;
                    }
                }

                catch (Exception ex12)
                {
                    stream.WriteLine("Exception while gathering app and system info: " + ex12.ToString());
                }

                stream.WriteLine("Application version: " + fullAppName);
                stream.WriteLine("Time of crash: " + timeOfCrash);
                stream.WriteLine("Application uptime: " + appUptime);

                stream.WriteLine("OS Version: " + osVersion + " " + osRevision + " " + osType + " " + processorNativeArchitecture);
                stream.WriteLine(".NET Framework version: " + fxVersion + " " + processorArchitecture);
                stream.WriteLine("Processor: " + cpuCount + " " + cpuName);
                stream.WriteLine("Physical memory: " + totalPhysicalBytes);
                stream.WriteLine("Tablet PC: " + inkInfo);
                stream.WriteLine("Locale: " + localeName);
                stream.WriteLine();

                stream.WriteLine("Exception details:");
                stream.WriteLine(ex.ToString());

                // Determine if there is any 'secondary' exception to report
                Exception[] otherEx = null;

                if (ex is System.Reflection.ReflectionTypeLoadException)
                {
                    otherEx = ((System.Reflection.ReflectionTypeLoadException)ex).LoaderExceptions;
                }

                if (otherEx != null)
                {
                    for (int i = 0; i < otherEx.Length; ++i)
                    {
                        stream.WriteLine();
                        stream.WriteLine("Secondary exception details:");

                        if (otherEx[i] == null)
                        {
                            stream.WriteLine("(null)");
                        }
                        else
                        {
                            stream.WriteLine(otherEx[i].ToString());
                        }
                    }
                }

                stream.WriteLine("------------------------------------------------------------------------------");
            }

            string errorFormat;
            string errorText;

            try
            {
                errorFormat = PdnResources.GetString("Startup.UnhandledError.Format");
            }

            catch (Exception)
            {
                errorFormat = InvariantStrings.StartupUnhandledErrorFormatFallback;
            }

            errorText = string.Format(errorFormat, fileName);
            Utility.ErrorBox(null, errorText);
        }
Esempio n. 8
0
        private void ReloadItems()
        {
            string suffix;

            switch (this.unitsDisplayType)
            {
            case UnitsDisplayType.Plural:
                suffix = ".Plural";
                break;

            case UnitsDisplayType.Singular:
                suffix = string.Empty;
                break;

            case UnitsDisplayType.Ratio:
                suffix = ".Ratio";
                break;

            default:
                throw new InvalidEnumArgumentException("UnitsDisplayType");
            }

            InitMeasurementItems();

            MeasurementUnit oldUnits;

            if (this.unitsToString == null)
            {
                oldUnits = MeasurementUnit.Pixel;
            }
            else
            {
                oldUnits = this.Units;
            }

            ComboBox.Items.Clear();

            string pixelsString      = PdnResources.GetString("MeasurementUnit.Pixel" + suffix);
            string inchesString      = PdnResources.GetString("MeasurementUnit.Inch" + suffix);
            string centimetersString = PdnResources.GetString("MeasurementUnit.Centimeter" + suffix);

            if (lowercase)
            {
                // TODO: we shouldn't really be using ToLower() here, these should be separately localizable strings

                pixelsString      = pixelsString.ToLower();
                inchesString      = inchesString.ToLower();
                centimetersString = centimetersString.ToLower();
            }

            this.unitsToString = new Hashtable
            {
                { MeasurementUnit.Pixel, pixelsString },
                { MeasurementUnit.Inch, inchesString },
                { MeasurementUnit.Centimeter, centimetersString }
            };

            this.stringToUnits = new Hashtable();

            if ((bool)this.measurementItems[MeasurementUnit.Pixel])
            {
                this.stringToUnits.Add(pixelsString, MeasurementUnit.Pixel);
                ComboBox.Items.Add(pixelsString);
            }

            if ((bool)this.measurementItems[MeasurementUnit.Inch])
            {
                this.stringToUnits.Add(inchesString, MeasurementUnit.Inch);
                ComboBox.Items.Add(inchesString);
            }

            if ((bool)this.measurementItems[MeasurementUnit.Centimeter])
            {
                this.stringToUnits.Add(centimetersString, MeasurementUnit.Centimeter);
                ComboBox.Items.Add(centimetersString);
            }

            if (!(bool)this.measurementItems[oldUnits])
            {
                if (ComboBox.Items.Count == 0)
                {
                    ComboBox.SelectedItem = null;
                }
                else
                {
                    ComboBox.SelectedIndex = 0;
                }
            }
            else
            {
                this.Units = oldUnits;
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Returns the bare product name, e.g. "Paint.NET"
 /// </summary>
 public static string GetBareProductName()
 {
     return(PdnResources.GetString("Application.ProductName.Bare"));
 }
Esempio n. 10
0
        private void UpdateFileSizeAndPreview(string tempFileName)
        {
            if (this.IsDisposed)
            {
                return;
            }

            if (tempFileName == null)
            {
                string error = PdnResources.GetString("SaveConfigDialog.FileSizeText.Text.Error");
                this.previewHeader.Text = string.Format(this.fileSizeTextFormat, error);
            }
            else
            {
                FileInfo fi       = new FileInfo(tempFileName);
                long     fileSize = fi.Length;
                this.previewHeader.Text   = string.Format(fileSizeTextFormat, Utility.SizeStringFromBytes(fileSize));
                this.documentView.Visible = true;

                // note: see comments for DocumentView.SuspendRefresh() for why we do these two backwards
                this.documentView.ResumeRefresh();

                Document disposeMe = null;
                try
                {
                    if (this.disposeDocument && this.documentView.Document != null)
                    {
                        disposeMe = this.documentView.Document;
                    }

                    if (this.fileType.IsReflexive(this.SaveConfigToken))
                    {
                        this.documentView.Document = this.Document;
                        this.documentView.Document.Invalidate();
                        this.disposeDocument = false;
                    }
                    else
                    {
                        FileStream stream = new FileStream(tempFileName, FileMode.Open, FileAccess.Read, FileShare.Read);

                        Document previewDoc;

                        try
                        {
                            Utility.GCFullCollect();
                            previewDoc = fileType.Load(stream);
                        }

                        catch
                        {
                            previewDoc = null;
                            TokenChangedHandler(this, EventArgs.Empty);
                        }

                        stream.Close();

                        if (previewDoc != null)
                        {
                            this.documentView.Document = previewDoc;
                            this.disposeDocument       = true;
                        }

                        Utility.GCFullCollect();
                    }

                    try
                    {
                        fi.Delete();
                    }

                    catch
                    {
                    }
                }

                finally
                {
                    this.documentView.SuspendRefresh();

                    if (disposeMe != null)
                    {
                        disposeMe.Dispose();
                    }
                }
            }
        }
Esempio n. 11
0
 public ToolChooserStrip()
 {
     this.chooseToolLabelText = PdnResources.GetString("ToolStripChooser.ChooseToolButton.Text");
     InitializeComponent();
 }
Esempio n. 12
0
        protected override void OnPaint(PaintEventArgs e)
        {
            float valueStart       = this.scaleFactor.ScaleScalar(this.rulerValue - offset);
            float valueEnd         = this.scaleFactor.ScaleScalar(this.rulerValue + 1.0f - offset);
            float highlightStartPx = this.scaleFactor.ScaleScalar(this.highlightStart - offset);
            float highlightEndPx   = this.scaleFactor.ScaleScalar(this.highlightStart + this.highlightLength - offset);

            RectangleF highlightRect;
            RectangleF valueRect;

            if (this.orientation == Orientation.Horizontal)
            {
                valueRect     = new RectangleF(valueStart, this.ClientRectangle.Top, valueEnd - valueStart, this.ClientRectangle.Height);
                highlightRect = new RectangleF(highlightStartPx, this.ClientRectangle.Top, highlightEndPx - highlightStartPx, this.ClientRectangle.Height);
            }
            else // if (this.orientation == Orientation.Vertical)
            {
                valueRect     = new RectangleF(this.ClientRectangle.Left, valueStart, this.ClientRectangle.Width, valueEnd - valueStart);
                highlightRect = new RectangleF(this.ClientRectangle.Left, highlightStartPx, this.ClientRectangle.Width, highlightEndPx - highlightStartPx);
            }

            if (!this.highlightEnabled)
            {
                highlightRect = RectangleF.Empty;
            }

            if (this.orientation == Orientation.Horizontal)
            {
                e.Graphics.DrawLine(
                    SystemPens.WindowText,
                    UI.ScaleWidth(15),
                    ClientRectangle.Top,
                    UI.ScaleWidth(15),
                    ClientRectangle.Bottom);

                string abbStringName = "MeasurementUnit." + this.MeasurementUnit.ToString() + ".Abbreviation";
                string abbString     = PdnResources.GetString(abbStringName);
                e.Graphics.DrawString(abbString, Font, SystemBrushes.WindowText, UI.ScaleWidth(-2), 0);
            }

            Region clipRegion = new Region(highlightRect);

            clipRegion.Xor(valueRect);

            if (this.orientation == Orientation.Horizontal)
            {
                clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, true);

            clipRegion.Xor(this.ClientRectangle);

            if (this.orientation == Orientation.Horizontal)
            {
                clipRegion.Exclude(new Rectangle(0, 0, UI.ScaleWidth(16), ClientRectangle.Height - 1));
            }

            e.Graphics.SetClip(clipRegion, CombineMode.Replace);
            DrawRuler(e, false);
            clipRegion.Dispose();
        }