public static ImporterRule OpenWindow(ImporterRule rule = null)
 {
     activeRule = rule;
     wnd        = GetWindow <ImporterRulesEditorWindow>(false, "Rules Editor", true);
     tempRule   = new ImporterRule();
     if (rule != null)
     {
         tempRule.CopyFrom(rule);
     }
     return(tempRule);
 }
    private void OnGUI()
    {
        if (tempRule == null)
        {
            return;
        }

        tempRule.DrawEditor();

        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Save"))
        {
            if (tempRule.pathComparer == ImporterRulesPathComparer.regex && !string.IsNullOrEmpty(tempRule.pattern))
            {
                try
                {
                    new Regex(tempRule.pattern);
                }
                catch (Exception)
                {
                    Debug.LogWarning("Regex pattern contains an error.");
                    return;
                }
            }

            if (activeRule != null)
            {
                activeRule.CopyFrom(tempRule);
            }
            else
            {
                ImporterRulesWindow.AddRule(tempRule);
            }
            ImporterRulesWindow.Save();
            ImporterRulesWindow.RedrawWindow();
            Close();
        }

        if (GUILayout.Button("Cancel"))
        {
            activeRule = null;
            Close();
        }

        GUILayout.EndHorizontal();
    }
    public static void DuplicateRule(ImporterRule rule)
    {
        ImporterRule newRule = ImporterRulesEditorWindow.OpenWindow();

        newRule.CopyFrom(rule);
        string name  = newRule.name;
        Regex  regex = new Regex(@"\d+$", RegexOptions.IgnoreCase);

        if (regex.IsMatch(name))
        {
            newRule.name = regex.Replace(name, match => (int.Parse(match.Value) + 1).ToString());
        }
        else
        {
            newRule.name += " 2";
        }
    }