Ejemplo n.º 1
0
        private void SaveFile(object sender, RoutedEventArgs e)
        {
            if (Tabs.Items.Count < 1)
            {
                return;
            }

            try
            {
                var currentEditor = Monad <TabControl> .Of(Tabs)
                                    .Bind(x => x.Items[Tabs.SelectedIndex] as TabItem)
                                    .Bind(x => x.Content as CodeEditor)
                                    .Value;

                if (currentEditor.FilePath == null &&
                    fileService.TryGetSaveFileName(out string fileName))
                {
                    currentEditor.FilePath = fileName;
                }

                currentEditor.Save();
                // MessageBox.Show(currentEditor.FilePath, "Info");
                Monad <TabControl> .Of(Tabs)
                .Bind(x => x.Items[Tabs.SelectedIndex] as TabItem)
                .Pipe(x => x.Header = new TextBlock {
                    Text = $"{currentEditor.FilePath.Split(Path.DirectorySeparatorChar).Last()}"
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Could not save file: {ex.Message}", "Error");
            }
        }
Ejemplo n.º 2
0
        private void CloseFile(object sender, RoutedEventArgs e)
        {
            if (Tabs.Items.Count < 1)
            {
                return;
            }

            var currentEditor = new Monad <TabControl>(Tabs)
                                .Bind(x => x.Items[Tabs.SelectedIndex] as TabItem)
                                .Bind(x => x.Content as CodeEditor)
                                .Value;

            if (!currentEditor.Saved &&
                MessageBox.Show(
                    "File not saved, save it?",
                    "Save", MessageBoxButton.YesNo,
                    MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                SaveFile(sender, e);
            }

            int selectedIndex = Tabs.SelectedIndex;

            Tabs.Items.RemoveAt(selectedIndex);
            if (Tabs.Items.Count >= 1)
            {
                Tabs.SelectedIndex = Math.Max(Tabs.Items.Count - 1, selectedIndex);
            }
        }