Exemplo n.º 1
0
        public MainView()
        {
            ProcessStartInfo mongoDbProcessInfo = new ProcessStartInfo();

            mongoDbProcessInfo.FileName  = "/usr/local/Cellar/mongodb-community/4.2.1/bin/mongod";
            mongoDbProcessInfo.Arguments = "--config /usr/local/etc/mongod.conf";

            //mongoDbProcessInfo.FileName = "/opt/local/bin/mongod";
            //mongoDbProcessInfo.Arguments = "--config /usr/local/etc/mongod.conf";

            mongoDbProcessInfo.UseShellExecute = false;
            mongoDbProcessInfo.CreateNoWindow  = true;
            mongoDbProcess = Process.Start(mongoDbProcessInfo);
            //p.WaitForExit();

            MainViewModel = new MainViewModel();

            this.DataContext = MainViewModel;

            Title      = "iTrip";
            ClientSize = new Size(1200, 600);

            var gridView = new GridView();

            JourneyList         = new SelectableFilterCollection <JourneyViewModel>(gridView, MainViewModel.Journeys);
            gridView.ShowHeader = false;
            gridView.DataStore  = JourneyList;
            gridView.SelectedItemBinding.BindDataContext((MainViewModel m) => m.SelectedJourney);
            gridView.ContextMenu            = CreateContextMenu();
            gridView.AllowMultipleSelection = true;
            gridView.Style = "journeyList";

            gridView.Columns.Add(new GridColumn
            {
                DataCell = new TextBoxCell {
                    Binding = Binding.Property <JourneyViewModel, string>(r => r.Text)
                },
                HeaderText = "Name",
                Editable   = false,
                Resizable  = false,
                Sortable   = false,
            });

            var searchBox = CreateSearchBox(JourneyList);

            var addButton = new Label();

            addButton.Text       = "+";
            addButton.Font       = new Font(FontFamilies.SansFamilyName, 30);
            addButton.TextColor  = Colors.DarkGray;
            addButton.MouseUp   += (sender, e) => { AddNewJourney(); ((Label)sender).TextColor = Colors.DarkGray; };
            addButton.MouseDown += (sender, e) => ((Label)sender).TextColor = Colors.Black;

            var deleteButton = new Label();

            deleteButton.Text       = "–";
            deleteButton.Font       = new Font(FontFamilies.SansFamilyName, 32);
            deleteButton.TextColor  = Colors.DarkGray;
            deleteButton.MouseUp   += (sender, e) => { DeleteSelectedJourney(); ((Label)sender).TextColor = Colors.DarkGray; };
            deleteButton.MouseDown += (sender, e) => ((Label)sender).TextColor = Colors.Black;

            TableLayout bottomBar = ViewHelper.AppendH(addButton, deleteButton) as TableLayout;

            bottomBar.Padding = new Padding(5, 0);

            var layout = new TableLayout
            {
                Rows =
                {
                    new TableRow(searchBox)
                    {
                        ScaleHeight = false
                    },
                    new TableRow(gridView)
                    {
                        ScaleHeight = true
                    },
                    new TableRow(bottomBar)
                    {
                        ScaleHeight = false
                    },
                    //new TableRow(new TableLayout { Rows = { new TableRow(addButton, deleteButton, null) } } ) { ScaleHeight = false }
                },
                Padding = new Padding(0, 20, 0, 0)
            };

            var splitter = new Splitter
            {
                Orientation = Orientation.Horizontal,
                Position    = 200,
                FixedPanel  = SplitterFixedPanel.Panel1,
                Panel1      = layout,
            };

            splitter.BindDataContext(c => c.Panel2, (MainViewModel m) => m.SelectedJourneyControl);


            var mainLayout = new TableLayout
            {
                Rows =
                {
                    new TableRow(splitter)
                    {
                        ScaleHeight = true
                    },
                    //new TableRow(GetStatusBar()) { ScaleHeight = false }
                },
                Padding = new Padding(0, 0, 0, 0),
            };


            Content = mainLayout;


            Style = "main";

            var addJourneyCommand = new Command {
                MenuText = "New Journey", Image = Icon.FromResource("iTrip.Images.AddIcon.png"), ToolBarText = "New Journey", Shortcut = Keys.Application | Keys.N
            };

            addJourneyCommand.Executed += (sender, e) => AddNewJourney();

            var saveJourneyCommand = new Command {
                MenuText = "Save Journey", ToolBarText = "Save Journey", Shortcut = Keys.Application | Keys.S
            };

            saveJourneyCommand.Executed += (sender, e) => MainViewModel.Save();

            var addEventCommand = new Command {
                MenuText = "Add Event", ToolBarText = "Add Event"
            };

            addEventCommand.Executed += (sender, e) => MainViewModel.SelectedJourney?.AddEvent();

            var addExpenseCommand = new Command {
                MenuText = "Add Expense", Image = Icon.FromResource("iTrip.Images.AddExpenseIcon.png"), ToolBarText = "Add Event"
            };

            addExpenseCommand.Executed += (sender, e) => MainViewModel.SelectedJourney?.AddSpending();

            var displayMapCommand = new Command {
                MenuText = "Map", ToolBarText = "Map"
            };

            displayMapCommand.Executed += (sender, e) => DisplayMap();

            var displayReporting = new Command {
                MenuText = "Reporting", ToolBarText = "Reporting"
            };

            displayReporting.Executed += (sender, e) => DisplaySummary();

            //var quitCommand = new Command { MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q };
            //quitCommand.Executed += (sender, e) => Quit();

            var aboutCommand = new Command {
                MenuText = "About..."
            };

            aboutCommand.Executed += (sender, e) => MessageBox.Show(this, "iTrip v1.5");

            // create menu
            Menu = new MenuBar
            {
                Items =
                {
                    // File submenu
                    new ButtonMenuItem {
                        Text = "&File", Items ={ addJourneyCommand,          saveJourneyCommand, addEventCommand, addExpenseCommand }
                    },
                    new ButtonMenuItem {
                        Text = "&View", Items ={ displayMapCommand,          displayReporting }
                    }
                    // new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } },
                    // new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } },
                },
                ApplicationItems =
                {
                    // application (OS X) or file menu (others)
                    new ButtonMenuItem {
                        Text = "&Preferences..."
                    },
                },
                //QuitItem = quitCommand,
                AboutItem = aboutCommand
            };

            // create toolbar
            //ToolBar = new ToolBar { Items = { addJourneyCommand, new SeparatorToolItem() { Type = SeparatorToolItemType.FlexibleSpace }, saveJourneyCommand, addEventCommand, addExpenseCommand } };
        }