Example #1
0
        public async Task <bool> CreateFile()
        {
            bool result = false;

            await DispatcherHelper.ExecuteOnUIThreadAsync(async() =>
            {
                FileSavePicker filePicker         = new FileSavePicker();
                filePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                filePicker.SuggestedFileName      = Path.GetFileNameWithoutExtension(Tab.TabName);

                string Extension = Path.GetExtension(Tab.TabName);
                if (Extension != "")
                {
                    filePicker.FileTypeChoices.Add("File", new List <string> {
                        Extension
                    });
                }

                foreach (string name in LanguagesHelper.GetLanguagesNames())
                {
                    List <string> Types = LanguagesHelper.GetLanguageExtensions(LanguagesHelper.GetLanguageTypeViaName(name));

                    if (Types.Count == 0)
                    {
                        Types.Add(".txt");
                    }

                    filePicker.FileTypeChoices.Add(name, Types);
                }

                StorageFile file = await filePicker.PickSaveFileAsync();
                if (file != null)
                {
                    Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                    Windows.Storage.FileProperties.BasicProperties date = await file.GetBasicPropertiesAsync();

                    Tab.TabDateModified        = date.DateModified.ToString();
                    Tab.TabType                = LanguagesHelper.GetLanguageType(file.FileType);
                    Tab.TabOriginalPathContent = file.Path;
                    Tab.TabName                = file.Name;

                    await TabsWriteManager.PushUpdateTabAsync(Tab, ListTabsID, true);

                    result = true;
                }
            });

            return(result);
        }
        private async void list_types_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (list_types.SelectedIndex != -1)
            {
                string LanguageType = LanguagesHelper.GetLanguageTypeViaName((string)list_types.SelectedItem);

                if (LanguageType != current_tab.TabType)
                {
                    current_tab.TabType = LanguageType;
                    await TabsWriteManager.PushUpdateTabAsync(current_tab, current_list, false);

                    if (current_tab != null && GlobalVariables.CurrentIDs.ID_Tab == current_tab.ID && GlobalVariables.CurrentIDs.ID_TabsList == current_list)
                    {
                        Messenger.Default.Send(new TabSelectedNotification {
                            tabID = current_tab.ID, tabsListID = current_list, contactType = ContactTypeSCEE.ReloadLanguage, typeLanguage = current_tab.TabType
                        });
                    }
                }
            }
        }