/// <summary>
        /// Create a new tabs list
        /// </summary>
        /// <param name="new_name">Name of your tabs list</param>
        /// <returns>ID of the new tabs list created</returns>
        public static async Task <int> CreateTabsListAsync(string new_name, int TabsListTypeID = 48)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                int id = new Random().Next(999999);

                TabsDataCache.TabsListDeserialized.Add(new TabsList {
                    ID = id, name = new_name, tabs = new List <InfosTab>(), TabsListProjectTypeID = TabsListTypeID
                });
                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.NewList, ID = new TabID {
                                ID_TabsList = id
                            }
                        });
                    });
                }

                return(id);
            }
            catch
            {
                return(0);
            }
        }
        /// <summary>
        /// Delete a tab who was selected by his ID and tabs list ID
        /// </summary>
        /// <param name="ids">ID of the tab and tabs list where is the tab</param>
        /// <returns></returns>
        public static async Task <bool> DeleteTabAsync(TabID ids)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == ids.ID_TabsList);
                InfosTab tab       = list_tabs.tabs.First(m => m.ID == ids.ID_Tab);
                list_tabs.tabs.Remove(tab);
                StorageFile delete_file = await TabsDataCache.TabsListFolder.CreateFileAsync(ids.ID_TabsList + "_" + ids.ID_Tab + ".json", CreationCollisionOption.ReplaceExisting); await delete_file.DeleteAsync();

                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.TabDeleted, ID = new TabID {
                                ID_Tab = ids.ID_Tab, ID_TabsList = ids.ID_TabsList
                            }
                        });
                    });
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Update tab informations (please use PushTabContentViaIDAsync() for set tab content)
        /// </summary>
        /// <param name="tab">Tab infos you want to update</param>
        /// <param name="id_list">ID of the tabs list where is the tab</param>
        /// <returns></returns>
        public static async Task <bool> PushUpdateTabAsync(InfosTab tab, int id_list, bool UpdateMonacoID)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == id_list);
                InfosTab _tab = list_tabs.tabs.First(m => m.ID == tab.ID);
                int      index_list = TabsDataCache.TabsListDeserialized.IndexOf(list_tabs), index_tab = list_tabs.tabs.IndexOf(_tab);

                if (UpdateMonacoID)
                {
                    tab.TabMonacoModelID = Guid.NewGuid().ToString();
                }

                TabsDataCache.TabsListDeserialized[index_list].tabs[index_tab] = tab;

                StorageFile data_tab = await TabsDataCache.TabsListFolder.CreateFileAsync(id_list + "_" + tab.ID + ".json", CreationCollisionOption.OpenIfExists);

                if (tab.TabContentTemporary != null)
                {
                    await FileIO.WriteTextAsync(data_tab, JsonConvert.SerializeObject(new ContentTab {
                        ID = tab.ID, Content = tab.TabContentTemporary
                    }, Formatting.Indented));
                }

                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.TabUpdated, ID = new TabID {
                                ID_Tab = tab.ID, ID_TabsList = id_list
                            }
                        });
                    });
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Create a tab in a tabs list who was selected by his ID
        /// </summary>
        /// <param name="tab">Tab you want to create</param>
        /// <param name="id_list">ID of the tabs list</param>
        /// <returns>ID of the new tab</returns>
        public static async Task <int> CreateTabAsync(InfosTab tab, int id_list, bool SendNotification)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                tab.ID = new Random().Next(999999);
                tab.TabMonacoModelID = Guid.NewGuid().ToString();
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == id_list);

                if (list_tabs.tabs == null)
                {
                    list_tabs.tabs = new List <InfosTab>();
                }

                list_tabs.tabs.Add(tab);
                StorageFile data_tab = await TabsDataCache.TabsListFolder.CreateFileAsync(id_list + "_" + tab.ID + ".json", CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteTextAsync(data_tab, JsonConvert.SerializeObject(new ContentTab {
                    ID = tab.ID, Content = ""
                }, Formatting.Indented));

                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        if (SendNotification)
                        {
                            Messenger.Default.Send(new STSNotification {
                                Type = TypeUpdateTab.NewTab, ID = new TabID {
                                    ID_Tab = tab.ID, ID_TabsList = id_list
                                }
                            });
                        }
                    });
                }
                return(tab.ID);
            }
            catch
            {
                return(0);
            }
        }
        /// <summary>
        /// Delete tabs list and the tabs content of the list
        /// </summary>
        /// <param name="id">ID of the tabs list</param>
        /// <returns></returns>
        public static async Task <bool> DeleteTabsListAsync(int id)
        {
            TabsDataCache.LoadTabsData();

            try
            {
                TabsList list_tabs = TabsDataCache.TabsListDeserialized.First(m => m.ID == id);

                foreach (InfosTab tab in list_tabs.tabs)
                {
                    try
                    {
                        await TabsDataCache.TabsListFolder.GetFileAsync(id + "_" + tab.ID + ".json").GetResults().DeleteAsync();
                    }
                    catch { }
                }

                TabsDataCache.TabsListDeserialized.Remove(list_tabs);
                TabsDataCache.WriteTabsListContentFile();

                foreach (CoreApplicationView view in CoreApplication.Views)
                {
                    await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        Messenger.Default.Send(new STSNotification {
                            Type = TypeUpdateTab.ListDeleted, ID = new TabID {
                                ID_TabsList = id
                            }
                        });
                    });
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }