Ejemplo n.º 1
0
    public static void ExportModules(string filePath, bool showQuickTip = false)
    {
        if (string.IsNullOrWhiteSpace(filePath))
        {
            return;
        }
        ContainerManager.UpdateCurrentDisplayObjectData();
        List <Module> modules = new List <Module>();
        int           count   = GlobalData.Modules.Count;

        for (int idx = 0; idx < count; ++idx)
        {
            Module module = new Module {
                Name = GlobalData.Modules[idx]
            };
            module.Elements = GlobalData.ModuleDic[module.Name];
            Rectangle rect = DisplayObjectUtil.GetMinRectangleContainsDisplayObjects(module.Elements);
            if (rect != null)
            {
                module.X      = rect.X;
                module.Y      = rect.Y;
                module.Width  = rect.Width;
                module.Height = rect.Height;
            }

            modules.Add(module);
        }

        string jsonString = JsonConvert.SerializeObject(modules, Formatting.Indented);
        bool   result     = Utils.WriteFile(filePath, Encoding.UTF8.GetBytes(jsonString));

        if (result)
        {
            string message = $"成功导出到 {filePath}";
            if (showQuickTip)
            {
                QuickTipManager.ShowQuickTip(message);
            }
            else
            {
                DialogManager.ShowInfo(message);
            }
            GlobalData.CurrentFilePath = filePath;
            GlobalData.ModifyCount     = 0;
        }
        else
        {
            const string message = "导出失败";
            if (showQuickTip)
            {
                QuickTipManager.ShowQuickTip(message);
            }
            else
            {
                DialogManager.ShowError(message, 0, 0);
            }
        }
    }