コード例 #1
0
ファイル: BaseViewModel.cs プロジェクト: wxknxxzj/textFilter
        private bool SaveModifiedFile(bool noPrompt, IFile <T> item)
        {
            if (item == default(IFile <T>) || item.Modified == false)
            {
                SetStatus("SaveModifiedFile: not modified. returning");
                return(noPrompt);
            }

            // prompt for saving
            if (!TextFilterSettings.Settings.AutoSave & !noPrompt)
            {
                TimedSaveDialog dialog = new TimedSaveDialog(item.Tag);

                dialog.Enable();

                switch (dialog.WaitForResult())
                {
                case TimedSaveDialog.Results.Disable:
                    TextFilterSettings.Settings.AutoSave = true;
                    break;

                case TimedSaveDialog.Results.DontSave:
                    item.Modified = false;
                    break;

                case TimedSaveDialog.Results.DontSaveAll:
                    noPrompt      = true;
                    item.Modified = false;
                    break;

                case TimedSaveDialog.Results.Save:
                    SaveFileExecuted(item);
                    item.Modified = false;
                    break;

                case TimedSaveDialog.Results.SaveAs:
                    SaveFileAsExecuted(item);
                    item.Modified = false;
                    break;

                case TimedSaveDialog.Results.Unknown:
                    // dont worry about errors since we are closing.
                    break;
                }
            }
            else if (TextFilterSettings.Settings.AutoSave)
            {
                SaveFileExecuted(item);
                item.Modified = false;
            }

            DeleteIfTempFile(item);
            return(noPrompt);
        }
コード例 #2
0
        public void SaveModifiedFiles(object sender)
        {
            List <string> delList = new List <string>();

            try
            {
                foreach (IFile <T> item in new List <IFile <T> >(ViewManager.FileManager.Where(x => x.Modified == true)))
                {
                    // set tab index to current
                    SelectedIndex = TabItems.IndexOf(TabItems.First(x => x.Tag == item.Tag));
                    if (!IsValidTabIndex())
                    {
                        continue;
                    }

                    // prompt for saving
                    if (!TextFilterSettings.Settings.AutoSave)
                    {
                        TimedSaveDialog dialog = new TimedSaveDialog(item.Tag);

                        dialog.Enable();

                        switch (dialog.WaitForResult())
                        {
                        case TimedSaveDialog.Results.Disable:
                            TextFilterSettings.Settings.AutoSave = true;
                            break;

                        case TimedSaveDialog.Results.DontSave:
                            item.Modified = false;
                            break;

                        case TimedSaveDialog.Results.Save:
                            SaveFileExecuted(item);
                            item.Modified = false;
                            break;

                        case TimedSaveDialog.Results.SaveAs:
                            SaveFileAsExecuted(item);
                            item.Modified = false;
                            break;

                        case TimedSaveDialog.Results.Unknown:
                            // dont worry about errors since we are closing.
                            break;
                        }
                    }
                    else
                    {
                        SaveFileExecuted(item);
                        item.Modified = false;
                    }

                    DeleteIfTempFile(item);
                }
            }
            catch (Exception e)
            {
                SetStatus("SaveModifiedFiles: exception: " + e.ToString());
            }
        }