示例#1
0
        /// <summary>
        /// Run main program in default mode to save clipboard contents
        /// </summary>
        /// <param name="args">Command line arguments</param>
        /// <returns>Exit code</returns>
        static int RunPaste(ArgsPaste args)
        {
            ApplyCommonArgs(args);

            var directory       = args.Directory ?? args.DirectoryFallback;
            var forceShowDialog = directory == null;

            if (Settings.Default.firstLaunch)
            {
                RunWizard();
                forceShowDialog = true;
            }


            var location = (directory ??
                            ExplorerUtil.GetActiveExplorerPath() ??
                            Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
                           .Trim().Trim("\"".ToCharArray()); // remove trailing " fixes paste in root dir

            Application.Run(new Dialog(location, forceShowDialog));
            return(0);
        }
示例#2
0
        public Dialog(string location, bool forceShowDialog = false)
        {
            // always show GUI if shift pressed during start
            forceShowDialog |= ModifierKeys == Keys.Shift;

            // Setup GUI
            InitializeComponent();

            foreach (Control element in GetAllChild(this))
            {
                if (element is WebBrowser)
                {
                    continue;
                }
                // ReSharper disable once UnusedVariable (to convince IDE that these resource strings are actually used)
                string[] usedResourceStrings = { Resources.str_filename, Resources.str_extension, Resources.str_location, Resources.str_clear_clipboard, Resources.str_save, Resources.str_preview, Resources.str_main_info, Resources.str_autosave_checkbox, Resources.str_contextentry_checkbox, Resources.str_continuous_mode };
                element.Text = Resources.ResourceManager.GetString(element.Text) ?? element.Text;
            }

            Icon           = Resources.icon;
            Text           = Resources.str_main_window_title;
            infoLabel.Text = string.Format(Resources.str_version, ProductVersion);


            // Dark theme
            if (RegistryUtil.IsDarkMode())
            {
                foreach (Control element in GetAllChild(this))
                {
                    element.ForeColor = Color.White;
                    element.BackColor = Color.FromArgb(53, 53, 53);
                }

                BackColor = Color.FromArgb(24, 24, 24);
            }

            // read clipboard and populate GUI
            comExt.Text = "*"; // force to use extension based on format type
            var clipRead = readClipboard();

            updateFilename();
            txtCurrentLocation.Text   = Path.GetFullPath(location);
            chkClrClipboard.Checked   = Settings.Default.clrClipboard;
            chkContinuousMode.Checked = continuousMode;
            updateSavebutton();
            chkAutoSave.Checked     = Settings.Default.autoSave;
            chkContextEntry.Checked = RegistryUtil.IsAppRegistered();


            txtFilename.Select();

            // show dialog or autosave option
            if (forceShowDialog)
            {
                // Make sure to bring window to foreground (holding shift will open window in background)
                WindowState = FormWindowState.Minimized;
                Show();
                BringToFront();
                WindowState = FormWindowState.Normal;
            }
            // otherwise perform autosave if enabled
            else if (Settings.Default.autoSave)
            {
                var file = clipRead ? save() : null;
                if (file != null)
                {
                    ExplorerUtil.RequestFilenameEdit(file);

                    var message = string.Format(Resources.str_autosave_balloontext, file);
                    Program.ShowBalloon(Resources.str_autosave_balloontitle, message, 10_000);

                    Environment.Exit(0);
                }
                else
                {
                    Environment.Exit(1);
                }
            }

            // register clipboard monitor
            clipMonitor.ClipboardChanged += ClipboardChanged;
        }