Esempio n. 1
0
        /// <summary>
        /// Shows dialog asking user to select one of the items; returns index of -1 if canceled
        /// </summary>
        public static int SelectFromList(List <string> items)
        {
            //build vm and add accelerator keys 1..9
            var vm = items.Select(s => new ItemVM {
                Text = s
            }).ToArray();

            for (int i = 0; i < vm.Length; ++i)
            {
                vm[i].Index = i;
                if (i < 9)
                {
                    vm[i].Text = $"_{i + 1} {items[i]}";
                }
            }

            var dlg = new SelectDialog
            {
                Owner = App.Current.MainWindow
            };

            dlg.eList.ItemsSource = vm;
            dlg.ShowDialog();
            return(dlg.SelectedIndex);
        }
Esempio n. 2
0
        void HandleClassifyCommand()
        {
            //get the box to classify; abort if already classified
            var box = VM.Persistent.Box;

            if (box.IsUnclass == 0)
            {
                return;
            }

            //build presets list (BoxCreator values are offset by 1 in the options list)
            var options = new List <string>
            {
                "Note"
            };

            if (Globals.AllowTasks)
            {
                options.AddRange(BoxCreator.NAMES);
            }

            //ask which preset to use
            int selectedPreset = SelectDialog.SelectFromList(options);

            if (selectedPreset < 0)
            {
                return;
            }

            //note we save the VM, edit the persistent object, then reload the VM; but nothing is actually saved to db
            VM.WriteToPersistent();
            box.IsUnclass = 0;

            //if classifying as note, just clear IsUnclass
            //else copy from BoxCreator's template
            if (selectedPreset > 0)
            {
                var templateBox = BoxCreator.GetPreset(selectedPreset - 1);
                box.BoxTime      = DateUtil.ToYMD(DateTime.Today) + "0900";
                box.Visibility   = templateBox.Visibility;
                box.TimeType     = templateBox.TimeType;
                box.Importance   = templateBox.Importance;
                box.Duration     = templateBox.Duration;
                box.PrepDuration = templateBox.PrepDuration;
            }
            VM.InitializeFromPersistent();
            VM.IsDirty = true;
        }
Esempio n. 3
0
        void HandleCreateFileCommand()
        {
            //if no template folder or if it's empty, explain to user how to use the command and abort
            bool found = false;

            string[] templateNames = null;
            string   templatePath  = Path.Combine(Globals.UI.GetExeDirectory(), "templates");

            if (Directory.Exists(templatePath))
            {
                var fullNames = Directory.GetFiles(templatePath);
                if (fullNames.Any())
                {
                    found         = true;
                    templateNames = fullNames.Select(s => Path.GetFileName(s)).ToArray();
                }
            }
            if (!found)
            {
                VisualUtils.ShowMessageDialog("To use this feature, create a folder called 'Templates' in the application folder, and manually copy your templates into that folder.");
                return;
            }

            //get user choice, or if just 1, use that
            string templateName = templateNames[0]; //without path

            if (templateNames.Length > 1)
            {
                int idx = SelectDialog.SelectFromList(templateNames.ToList());
                if (idx < 0)
                {
                    return;
                }
                templateName = templateNames[idx];
            }

            //find default starting path for target file
            string defaultPath = GetDefaultFolderPath();

            //choose destination folder and name
            var saveDlg = new SaveFileDialog();

            if (defaultPath != null)
            {
                saveDlg.InitialDirectory = defaultPath;
            }
            string ext = Path.GetExtension(templateName);

            saveDlg.Filter = ext + "|" + ext;
            if (saveDlg.ShowDialog(App.Current.MainWindow) != true)
            {
                return;
            }
            string targetName = saveDlg.FileName; //with path

            //copy file then open it
            File.Copy(Path.Combine(templatePath, templateName), targetName);
            VisualUtils.OpenWithWithDefaultApp(targetName);

            VM.NotifyVisibilityDetails();
        }