Beispiel #1
0
 static Settings()
 {
     LocalDomain                 = DefaultLocalDomain;
     CommonsDomain               = DefaultCommonsDomain;
     LocalUserName               = LocalPassword = CommonsPassword = CommonsUserName =
         LocalWikiData           = LocalWikiDataHosted =
             CurrentSourceOption = SourceCategory = SourceTextFile = "";
     LocalSysop = LogTransfers = OpenBrowserAutomatically = OpenBrowserLocal = false;
     SaveCreds  = AutoUpdate = true;
     UseHttps   = !PlatformSpecific.IsMono(); // default to false on Mono, as HTTPS doesn't work there
 }
        private void CoolCat_Load(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                toolTips.SetToolTip(btnAdd, Localization.GetString("AddCategory_Tooltip"));
            }

            if (PlatformSpecific.IsMono())
            {
                AutoSize = false;
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            CoolCatItem item = new CoolCatItem(this);

            Items.Add(item);
            flowLayout.Controls.Add(item);
            flowLayout.Controls.SetChildIndex(item, flowLayout.Controls.Count - 2);

            item.TabIndex         = Items.Count;
            item.RemoveClicked   += new EventHandler(item_RemoveClicked);
            item.LeftEditingMode += new EventHandler(item_LeftEditingMode);
            item.Focus();

            if (PlatformSpecific.IsMono())
            {
                item.Resize += new EventHandler(item_Resize_Mono);
                item_Resize_Mono(null, null);
            }
        }
Beispiel #4
0
        private void FinishCategoryAutoComplete(string[] results, string extraResult)
        {
            // This code causes hangs under Mono. Need to fix
            if (PlatformSpecific.IsMono())
            {
                return;
            }

            string text = cboCatName.Text;

            cboCatName.Items.Clear();
            if (results.Length > 0)
            {
                //Array.Sort(results);
                int numResultsToUse = Math.Min(results.Length, MaxAutoCompleteItems - (extraResult == null ? 1 : 0));
                for (int i = 0; i < numResultsToUse; i++)
                {
                    cboCatName.Items.Add(results[i].Substring("Category:".Length));
                }
            }
            if (extraResult != null)
            {
                cboCatName.Items.Add(CoolCat.NormalizeCatName(extraResult));
            }

            if (cboCatName.Items.Count == 0)
            {
                cboCatName.Items.Add("");
            }

            if (!cboCatName.DroppedDown && cboCatName.Visible)
            {
                cboCatName.DroppedDown = true;
                cboCatName.Text        = text;
            }
            cboCatName.SelectionStart = text.Length;
        }
Beispiel #5
0
        private void cboCatName_TextChanged(object sender, EventArgs e)
        {
            if (cboCatName.Text.Length == 0 || textUpdateTarget != cboCatName.Text)
            {
                return;
            }

            // needed to avoid overzealous mouse pointer hiding on Windows
            PlatformSpecific.FakeMouseMovement();

            DateTime now = DateTime.Now;

            latestDate = now;

            // use same queries as HotCat (via GET), to take advantage of server-side caching
            MorebitsDotNet.GetApi(Wiki.Commons,
                                  "format=json&action=opensearch&namespace=14&limit=30&search=Category:" + Uri.EscapeDataString(cboCatName.Text),
                                  now, delegate(string json, object date)
            {
                if (latestDate > ((DateTime)date))
                {
                    return;
                }

                string[] results;

                // we take advantage of the fact that [ is not a legal character in wiki page titles
                // To be honest, this whole thing is crass, but I don't want to bring in a full JSON
                // parser just for this
                string resultsPart = json.Substring(json.IndexOf('[', 2) + 1);
                // ...and taking advantage of the fact that ] is not legal either!
                if (resultsPart.IndexOf(']') > 0)
                {
                    // we have results, so trim off the trailing junk and parse out character escapes
                    resultsPart = resultsPart.Substring(1, resultsPart.IndexOf(']') - 2);
                    resultsPart.Replace("\\\\", "#");
                    int location;
                    string charValue;
                    while ((location = resultsPart.IndexOf("\\u")) != -1)
                    {
                        charValue   = resultsPart.Substring(location + 2, 4);
                        resultsPart = resultsPart.Remove(location, 6).Insert(location,
                                                                             Char.ConvertFromUtf32(int.Parse(charValue, NumberStyles.AllowHexSpecifier)));
                    }
                    resultsPart = resultsPart.Replace("\\\"", "\"").Replace("#", "\\");
                    results     = resultsPart.Split(new string[] { "\",\"" }, StringSplitOptions.None);
                }
                else
                {
                    // no results
                    results = new string[0];
                }
                //MessageBox.Show(json + "\n\n====================\n\n" + string.Join("\n", results));

                ParentCoolCat.AddCategoryExistenceRange(results, true);

                if (ParentCoolCat.DoesCategoryExist(cboCatName.Text) != true)
                {
                    // does it exist? Go looking
                    MorebitsDotNet.GetApi(Wiki.Commons,
                                          "format=json&action=query&titles=Category:" + Uri.EscapeDataString(cboCatName.Text),
                                          cboCatName.Text, delegate(string innerJson, object catName)
                    {
                        // more crassness
                        bool exists = innerJson.IndexOf("\"-1\":") == -1;
                        SetCategoryExistenceIcon(exists);
                        ParentCoolCat.AddCategoryExistence((string)catName, exists);

                        FinishCategoryAutoComplete(results, exists ? (string)catName : null);
                    }
                                          );
                }
                else
                {
                    SetCategoryExistenceIcon(true);
                    FinishCategoryAutoComplete(results, null);
                }
            }
                                  );
        }