예제 #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string apiKey = txtAPIKey.Text.Trim();

                //if (true)
                //{
                _CodeStatsConfigFile.ApiKey = apiKey;
                _CodeStatsConfigFile.Proxy  = txtProxy.Text.Trim();
                _CodeStatsConfigFile.Debug  = chkDebugMode.Checked;
                _CodeStatsConfigFile.Stats  = chkStats.Checked;

                if (String.IsNullOrWhiteSpace(txtAPIURL.Text) || txtAPIURL.Text == Constants.ApiMyPulsesEndpoint)
                {
                    //_CodeStatsConfigFile.ApiUrl = Constants.ApiMyPulsesEndpoint;
                    _CodeStatsConfigFile.ApiUrl = string.Empty;
                }
                else
                {
                    _CodeStatsConfigFile.ApiUrl = txtAPIURL.Text;
                }

                _CodeStatsConfigFile.Save();

                if (chkStats.Checked && !CodeStatsPackage._reportedStats)
                {
                    CodeStatsPackage.ReportStats();
                }

                OnConfigSaved();

                /*}
                 * else // - kept in case we check API tokens in future
                 * {
                 *  MessageBox.Show(@"Please enter valid API token.");
                 *  DialogResult = DialogResult.None; // do not close dialog box
                 * }*/
            }
            catch (Exception ex)
            {
                Logger.Error("Error when saving data from SettingsForm", ex);
                MessageBox.Show(ex.Message);
            }
        }
        static void beNotified(IntPtr notifyCode)
        {
            ScNotification notification = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));

            if (notification.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
            {
                PluginBase._funcItems.RefreshItems();
                CodeStatsPackage.SetToolBarIcon();
            }
            else if (notification.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
            {
                CodeStatsPackage.PluginCleanUp();
                Marshal.FreeHGlobal(_ptrPluginName);
            }
            else
            {
                CodeStatsPackage.OnNotification(notification);
            }
        }
예제 #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                if (CodeStatsPackage._apikeyForm != null && CodeStatsPackage._apikeyForm.Visible)
                {
                    CodeStatsPackage._apikeyForm.Close();
                }
            }
            finally { }

            try
            {
                string apiKey = txtAPIKey.Text.Trim();

                //if (true)
                //{
                if (String.IsNullOrWhiteSpace(txtAPIURL.Text) || txtAPIURL.Text == Constants.ApiMyPulsesEndpoint)
                {
                    //_CodeStatsConfigFile.ApiUrl = Constants.ApiMyPulsesEndpoint;
                    _CodeStatsConfigFile.ApiUrl = string.Empty;
                }
                else
                {
                    // API URL was changed, previous one was default
                    if (_CodeStatsConfigFile.ApiUrl != txtAPIURL.Text && String.IsNullOrWhiteSpace(_CodeStatsConfigFile.ApiUrl))
                    {
                        // Show confirmation
                        if ((MessageBox.Show("API URL should only be changed if you intend to use another instance of Code::Stats service, for example beta or private, unpublic one.\nIt should normally be kept to default. If you put wrong URL here, no pulses will be registered and all your recorded XP will be lost.\n\n" + txtAPIURL.Text + "\nDo you still want to save this API URL?", "Are you sure?",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                             MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes))
                        {
                            _CodeStatsConfigFile.ApiUrl = txtAPIURL.Text;
                        }
                        else
                        {
                            this.FocusTxtAPIURL();
                            this.ShowAPIURLTooltip();
                            this.DialogResult = DialogResult.None;
                            return;
                        }
                    }
                    else
                    {
                        _CodeStatsConfigFile.ApiUrl = txtAPIURL.Text;
                    }
                }

                _CodeStatsConfigFile.ApiKey = apiKey;
                _CodeStatsConfigFile.Proxy  = txtProxy.Text.Trim();
                _CodeStatsConfigFile.Debug  = chkDebugMode.Checked;
                _CodeStatsConfigFile.Stats  = chkStats.Checked;

                LanguageDetectionUIRefresh();
                _CodeStatsConfigFile.UseExtensionMapping = chkUseExtensionMapping.Checked;
                _CodeStatsConfigFile.UseLexerLanguage    = chkUseExtensionMapping.Checked;
                _CodeStatsConfigFile.DetectionPriority   = !radioDetectionPriority_extensionMapping.Checked ? Constants.DetectionType.LEXER_LANGUAGE : Constants.DetectionType.EXTENSION_MAPPING;
                _CodeStatsConfigFile.UseCustomMapping    = chkUseCustomMapping.Checked;

                _CodeStatsConfigFile.Save();

                OnConfigSaved();
                //CodeStatsPackage.GetSettings(); // reload settings in main class

                CodeStatsPackage._hasAlreadyShownInvalidApiTokenMessage = false;

                if (chkStats.Checked && !CodeStatsPackage._reportedStats)
                {
                    CodeStatsPackage.ReportStats();
                }

                /*}
                 * else // - kept in case we check API tokens in future
                 * {
                 *  MessageBox.Show(@"Please enter valid API token.");
                 *  DialogResult = DialogResult.None; // do not close dialog box
                 * }*/
            }
            catch (Exception ex)
            {
                Logger.Error("Error when saving data from SettingsForm", ex);
                MessageBox.Show(ex.Message);
            }
        }
 static void setInfo(NppData notepadPlusData)
 {
     PluginBase.nppData = notepadPlusData;
     CodeStatsPackage.CommandMenuInit();
 }