Пример #1
0
 public static void SavePersonalTools(PersonalToolStrip ts)
 {
     IniConfigSource source = CreatePersonalToolsSource(ts);
     source.Save(IniFile);
 }
Пример #2
0
 public static void LoadPersonalTools(PersonalToolStrip ts)
 {
     IConfigSource source;
     if (File.Exists(IniFile))
         source = new IniConfigSource(IniFile);
     else
         source = new IniConfigSource();
     LoadPersonalToolsFromSource(ts, source);
 }
Пример #3
0
 public static void LoadPersonalToolsFromSource(PersonalToolStrip ts, IConfigSource source)
 {
     ts.Clear();
     foreach (IConfig config in source.Configs)
         if (config.Contains(TYPE_OPT))
         {
             PersonalToolButtonType type = (PersonalToolButtonType)Enum.Parse(
                 typeof(PersonalToolButtonType), config.Get(TYPE_OPT), true);
             string label = config.Get(LABEL_OPT, "");
             bool showLabel = config.GetBoolean(SHOWLABEL_OPT, false);
             switch (type)
             {
                 case PersonalToolButtonType.CustomFigure:
                     Type figureClass = Type.GetType(config.Get(FIGURECLASS_OPT));
                     if (figureClass != null)
                     {
                         DAuthorProperties dap = new DAuthorProperties();
                         WorkBookUtils.ReadConfigToDap(config, dap);
                         string base64Icon = config.Get(BASE64ICON_OPT);
                         ts.Items.Add(new CustomFigureToolButton(new CustomFigureTool(label, showLabel, figureClass, dap, base64Icon)));
                     }
                     break;
                 case PersonalToolButtonType.RunCmd:
                     ts.Items.Add(new RunCmdToolButton(new RunCmdTool(label, showLabel, config.Get(RUNCMD_OPT),
                         config.Get(ARGS_OPT))));
                     break;
                 case PersonalToolButtonType.ShowDir:
                     ts.Items.Add(new ShowDirToolButton(new ShowDirTool(label, showLabel, config.Get(DIR_OPT))));
                     break;
                 case PersonalToolButtonType.WebLink:
                     ts.Items.Add(new WebLinkToolButton(new WebLinkTool(label, showLabel, config.Get(WEBLINK_OPT))));
                     break;
                 case PersonalToolButtonType.ModeSelect:
                     ts.Items.Add(new ModeSelectToolButton(new ModeSelectTool(label, showLabel,
                         (ModeSelectType)Enum.Parse(typeof(ModeSelectType), config.Get(MODESELECT_OPT), true))));
                     break;
             }
         }
 }
Пример #4
0
 public static IniConfigSource CreatePersonalToolsSource(PersonalToolStrip ts)
 {
     IniConfigSource source = new IniConfigSource();
     for (int i = 1; i < ts.Items.Count; i++)
     {
         IConfig config = source.AddConfig(i.ToString());
         ToolStripItem b = ts.Items[i];
         if (b is PersonalToolButton)
         {
             config.Set(LABEL_OPT, ((PersonalToolButton)b).Label);
             config.Set(SHOWLABEL_OPT, ((PersonalToolButton)b).ShowLabel);
             if (b is CustomFigureToolButton)
             {
                 CustomFigureTool t = ((CustomFigureToolButton)b).CustomFigure;
                 config.Set(TYPE_OPT, PersonalToolButtonType.CustomFigure);
                 config.Set(FIGURECLASS_OPT, t.FigureClass.AssemblyQualifiedName);
                 WorkBookUtils.WriteDapToConfig(t.Dap, config);
                 config.Set(BASE64ICON_OPT, t.Base64Icon);
             }
             else if (b is RunCmdToolButton)
             {
                 RunCmdTool t = ((RunCmdToolButton)b).RunCmd;
                 if (t.Command != null && t.Arguments != null)
                 {
                     config.Set(TYPE_OPT, PersonalToolButtonType.RunCmd);
                     config.Set(RUNCMD_OPT, t.Command);
                     config.Set(ARGS_OPT, t.Arguments);
                 }
             }
             else if (b is ShowDirToolButton)
             {
                 ShowDirTool t = ((ShowDirToolButton)b).ShowDir;
                 if (t.Dir != null)
                 {
                     config.Set(TYPE_OPT, PersonalToolButtonType.ShowDir);
                     config.Set(DIR_OPT, t.Dir);
                 }
             }
             else if (b is WebLinkToolButton)
             {
                 WebLinkTool t = ((WebLinkToolButton)b).WebLink;
                 if (t.Link != null)
                 {
                     config.Set(TYPE_OPT, PersonalToolButtonType.WebLink);
                     config.Set(WEBLINK_OPT, t.Link);
                 }
             }
             else if (b is ModeSelectToolButton)
             {
                 config.Set(TYPE_OPT, PersonalToolButtonType.ModeSelect);
                 ModeSelectTool t = ((ModeSelectToolButton)b).ModeSelect;
                 config.Set(MODESELECT_OPT, ((ModeSelectToolButton)b).ModeSelectType);
             }
         }
     }
     return source;
 }