From: <nic...@us...> - 2014-05-18 19:03:51
|
Revision: 4807 http://sourceforge.net/p/mp-plugins/code/4807 Author: nicsergio Date: 2014-05-18 19:03:47 +0000 (Sun, 18 May 2014) Log Message: ----------- Modified Paths: -------------- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultConfig.xml trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs Removed Paths: ------------- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultNavigatorConfig.xml Modified: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultConfig.xml =================================================================== --- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultConfig.xml 2014-05-18 16:40:08 UTC (rev 4806) +++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultConfig.xml 2014-05-18 19:03:47 UTC (rev 4807) @@ -182,4 +182,56 @@ <SoundEffect>click.wav</SoundEffect> </Item> </Items> + <Navigator> + <General> + <MenuHeader>Skin Navigator</MenuHeader> + <ShowSeparator>1</ShowSeparator> + <Separator>--------------------------------</Separator> + <ShowNumbers>1</ShowNumbers> + <RemoveDuplicates>1</RemoveDuplicates> + </General> + <Items> + <Item> + <Caption>Always</Caption> + <Windows /> + <Destinations> + <Destination> + <Caption>Basic Home</Caption> + <WindowID>35</WindowID> + <LoadParameter /> + <Force>0</Force> + </Destination> + <Destination> + <Caption>Movies</Caption> + <WindowID>96742</WindowID> + <LoadParameter /> + <Force>0</Force> + </Destination> + </Destinations> + </Item> + <Item> + <Caption>Music</Caption> + <Windows> + <Window> + <Caption>TV</Caption> + <WindowID>1</WindowID> + </Window> + </Windows> + <Destinations> + <Destination> + <Caption>Music</Caption> + <WindowID>502</WindowID> + <LoadParameter /> + <Force>0</Force> + </Destination> + <Destination> + <Caption>Movies</Caption> + <WindowID>96742</WindowID> + <LoadParameter /> + <Force>0</Force> + </Destination> + </Destinations> + </Item> + </Items> + </Navigator> </ShortCuter> \ No newline at end of file Deleted: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultNavigatorConfig.xml =================================================================== --- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultNavigatorConfig.xml 2014-05-18 16:40:08 UTC (rev 4806) +++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/Resources/XmlFiles/DefaultNavigatorConfig.xml 2014-05-18 19:03:47 UTC (rev 4807) @@ -1,53 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Navigator> - <General> - <MenuHeader>Skin Navigator</MenuHeader> - <ShowSeparator>1</ShowSeparator> - <Separator>--------------------------------</Separator> - <ShowNumbers>1</ShowNumbers> - <RemoveDuplicates>1</RemoveDuplicates> - </General> - <Items> - <Item> - <Caption>Always</Caption> - <Windows /> - <Destinations> - <Destination> - <Caption>Basic Home</Caption> - <WindowID>35</WindowID> - <LoadParameter /> - <Force>0</Force> - </Destination> - <Destination> - <Caption>Movies</Caption> - <WindowID>96742</WindowID> - <LoadParameter /> - <Force>0</Force> - </Destination> - </Destinations> - </Item> - <Item> - <Caption>Music</Caption> - <Windows> - <Window> - <Caption>TV</Caption> - <WindowID>1</WindowID> - </Window> - </Windows> - <Destinations> - <Destination> - <Caption>Music</Caption> - <WindowID>502</WindowID> - <LoadParameter /> - <Force>0</Force> - </Destination> - <Destination> - <Caption>Movies</Caption> - <WindowID>96742</WindowID> - <LoadParameter /> - <Force>0</Force> - </Destination> - </Destinations> - </Item> - </Items> -</Navigator> \ No newline at end of file Modified: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj =================================================================== --- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj 2014-05-18 16:40:08 UTC (rev 4806) +++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuter.csproj 2014-05-18 19:03:47 UTC (rev 4807) @@ -183,9 +183,6 @@ <Content Include="ExternalResources\Dialogs.dll" /> <Content Include="Resources\Images\SkinNav.png" /> <Content Include="Resources\Images\SkinNavAdd.png" /> - <EmbeddedResource Include="Resources\XmlFiles\DefaultNavigatorConfig.xml"> - <SubType>Designer</SubType> - </EmbeddedResource> <Content Include="..\Common\Resources\Images\ArrowDown.png"> <Link>Resources\Images\ArrowDown.png</Link> </Content> Modified: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs =================================================================== --- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs 2014-05-18 16:40:08 UTC (rev 4806) +++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs 2014-05-18 19:03:47 UTC (rev 4807) @@ -508,35 +508,18 @@ #endregion #region Metodi Pubblici - public bool LoadConfig() { return LoadConfig(string.Empty); } //Caricamento configurazione predefinita - public bool LoadConfig(string settingsFile) //Caricamento configurazione + //public bool LoadConfig() { return LoadConfig(string.Empty); } //Caricamento configurazione predefinita + public void LoadConfig(XmlDocument xmlFile) //Caricamento configurazione { _items.Clear(); //--> pulizia lista elementi di navigazione - string nodeHeader; - FileStream userConfig = null; - try + + XmlNode innerNode; + XmlNode navigatorNode = xmlFile.DocumentElement.SelectSingleNode("/ShortCuter/Navigator"); + if (navigatorNode != null) //Se presenti impostazioni di navigazione { - XmlDocument xmlFile = new XmlDocument(); - if (settingsFile.Length > 0) + XmlNode generalNode = navigatorNode.SelectSingleNode("General"); + if (generalNode != null) //Se presenti impostazioni generali { - userConfig = new FileStream(settingsFile, FileMode.Open, FileAccess.Read); - xmlFile.Load(userConfig); //Lettura file xml delle ultime impostazioni - userConfig.Close(); //--> chiusura file - nodeHeader = "/ShortCuter/Navigator/"; - } - else - { - using (Stream defaultConfig = Assembly.GetExecutingAssembly().GetManifestResourceStream("ProcessPlugins.ShortCuter.Resources.XmlFiles.DefaultNavigatorConfig.xml")) - { - xmlFile.Load(defaultConfig); //Configurazione predefinita --> lettura file xml incapsulato - } - nodeHeader = "/Navigator/"; - } - - XmlNode innerNode; - XmlNode generalNode = xmlFile.DocumentElement.SelectSingleNode(nodeHeader + "General"); - if (generalNode != null) //Se presente sezione "General" - { innerNode = generalNode.SelectSingleNode("MenuHeader"); if (innerNode != null) _general.MenuHeader = innerNode.InnerText; @@ -553,23 +536,7 @@ if (innerNode != null) _general.RemoveDuplicates = Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText)); } - else - { - if (settingsFile.Length > 0) - { - if (Log != null) //Se impostazioni non trovate --> si carica la configurazione predefinita - Log(this, new LogEventArgs(LogEventArgs.LogLevels.Debug, "Navigator settings not found: default config will be loaded..")); - return LoadConfig(); //--> caricamento configurazione predefinita - } - else - { - if (Log != null) //Se impostazioni non trovate nella configurazione predefinita - Log(this, new LogEventArgs(LogEventArgs.LogLevels.Info, "Navigator settings not found loading DefaultNavigatorConfig.xml.")); - return false; - } - } - - XmlNodeList nodeList = xmlFile.DocumentElement.SelectNodes(nodeHeader + "Items/Item"); + XmlNodeList nodeList = navigatorNode.SelectNodes("Items/Item"); foreach (XmlNode node in nodeList) //Iterazione per memorizzazione elementi di navigazione { Item navItem = new Item(); @@ -586,7 +553,7 @@ innerNode = wndNode.SelectSingleNode("WindowID"); if (innerNode != null) wnd.WindowID = Convert.ToInt32(innerNode.InnerText); - navItem.Windows.Add(wnd); //--> + navItem.Windows.Add(wnd); //--> aggiunta finestra di abilitazione } XmlNodeList dstList = node.SelectNodes("Destinations/Destination"); foreach (XmlNode dstNode in dstList) //Iterazione per memorizzazione destinazioni @@ -605,33 +572,53 @@ if (innerNode != null) dst.Force = Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText)); if (dst.IsValid) - navItem.Destinations.Add(dst); + navItem.Destinations.Add(dst); //--> aggiunta destinazione } _items.Add(navItem); //--> aggiunta elemento di navigazione } - - - if (_items.Count > 0) - return true; //--> lettura configurazione effettuata - else - { - if (defaultSettings && Log != null) //Se nessun shortcut trovato nella configurazione predefinita: emissione messaggio - Log(this, new LogEventArgs(LogEventArgs.LogLevels.Info, "No shortcuts found loading DefaultConfig.xml.")); - return false; - } } - catch (Exception e) - { - if (defaultSettings && Log != null) //Se lettura configurazione predefinita fallita: emissione messaggio di errore - Log(this, new LogEventArgs(LogEventArgs.LogLevels.Error, "Error loading DefaultConfig.xml.", e)); - return false; - } - finally - { - if (userConfig != null) - userConfig.Close(); //--> eventuale chiusura oggetto FileStream - } } + public void SaveConfig(XmlTextWriter xmlSettings) //Salvataggio configurazione + { + xmlSettings.WriteStartElement("Navigator"); + xmlSettings.WriteStartElement("General"); + xmlSettings.WriteElementString("MenuHeader", _general.MenuHeader); + xmlSettings.WriteElementString("ShowSeparator", Convert.ToInt16(_general.ShowSeparator).ToString()); + xmlSettings.WriteElementString("Separator", _general.Separator); + xmlSettings.WriteElementString("ShowNumbers", Convert.ToInt16(_general.ShowNumbers).ToString()); + xmlSettings.WriteElementString("RemoveDuplicates", Convert.ToInt16(_general.RemoveDuplicates).ToString()); + xmlSettings.WriteEndElement(); + + xmlSettings.WriteStartElement("Items"); + foreach (Item navItem in _items) //Iterazione per salvataggio elementi di navigazione + { + xmlSettings.WriteStartElement("Item"); + xmlSettings.WriteElementString("Caption", navItem.Caption); + xmlSettings.WriteStartElement("Windows"); + foreach (Item.Window wnd in navItem.Windows) //Iterazione per salvataggio finestre di abilitazione + { + xmlSettings.WriteStartElement("Window"); + xmlSettings.WriteElementString("Caption", wnd.Caption); + xmlSettings.WriteElementString("WindowID", wnd.WindowID.ToString()); + xmlSettings.WriteEndElement(); + } + xmlSettings.WriteEndElement(); + xmlSettings.WriteStartElement("Destinations"); + foreach (Item.Destination dst in navItem.Destinations) //Iterazione per salvataggio destinazioni + { + xmlSettings.WriteStartElement("Destination"); + xmlSettings.WriteElementString("Caption", dst.Caption); + xmlSettings.WriteElementString("WindowID", dst.WindowID.ToString()); + xmlSettings.WriteElementString("LoadParameter", dst.LoadParameter); + xmlSettings.WriteElementString("Force", Convert.ToInt16(dst.Force).ToString()); + xmlSettings.WriteEndElement(); + } + xmlSettings.WriteEndElement(); + xmlSettings.WriteEndElement(); + } + xmlSettings.WriteEndElement(); + xmlSettings.WriteEndElement(); + } public WindowLink Go() //Gestione finestra di dialogo e navigazione alla destinazione selezionata { if (Log != null) @@ -897,7 +884,7 @@ } if (_items.Count > 0) { - _navigator.LoadConfig(defaultSettings ? null : SettingsFile); //--> caricamento configurazione Skin Navigator + _navigator.LoadConfig(xmlFile); //--> caricamento configurazione Skin Navigator return true; //--> lettura configurazione effettuata } else @@ -957,6 +944,8 @@ xmlSettings.WriteEndElement(); xmlSettings.WriteEndElement(); + _navigator.SaveConfig(xmlSettings); //--> salvataggio configurazione Skin Navigator + xmlSettings.Flush(); xmlSettings.Close(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |