Example #1
0
        static void LoadFile()
        {
            OpenDialog openFileDialog = new OpenDialog("Select File", "Select a *.cdb file to open");

            openFileDialog.Height                  = Dim.Percent(70f);
            openFileDialog.Width                   = Dim.Percent(70f);
            openFileDialog.AllowedFileTypes        = new string[] { ".cdb" };
            openFileDialog.AllowsMultipleSelection = false;
            openFileDialog.CanChooseDirectories    = false;
            openFileDialog.CanChooseFiles          = true;
            Application.Run(openFileDialog);

            List <string> files = new List <string>(openFileDialog.FilePaths);

            if (files.Count < 1)
            {
                PrintStatus("No file was selected to open.", StatusLevel.Error);
                return;
            }
            RookDB loadedDB = new RookDB(System.IO.File.ReadAllText(files[0]), files[0]);

            if (loadedDB.IsValid())
            {
                currDB = loadedDB;
                currTableView.Source = new EditorListRenderer(currDB.tables.First().Value);
                columnHeaders.UpdateColumns(currDB.tables.First().Value.columns.ToArray());
                UpdateWindowName();
                UpdateTableDisplay();
                PrintStatus("Loaded database: " + loadedDB.filename, StatusLevel.Default);
            }
            else
            {
                PrintStatus("Could not load database, file was invalid.", StatusLevel.Error);
            }
        }
Example #2
0
        static void CreateNew()
        {
            string    dbName        = "temp.cdb";
            Dialog    getNameDialog = new Dialog("Enter new database name", 60, 10);
            TextField nameField     = new TextField("")
            {
                X = 1, Y = 1, Width = Dim.Fill(), Height = 1
            };
            Button confirmBtn = new Button("Confirm")
            {
                Clicked = () =>
                {
                    if (nameField.Text.Length > 5 && nameField.Text.EndsWith(".cdb"))
                    {
                        dbName = dbName = nameField.Text.ToString();
                        Application.RequestStop();
                    }
                }
            };

            getNameDialog.AddButton(confirmBtn);
            getNameDialog.Add(nameField);
            Application.Run(getNameDialog);

            currDB = new RookDB(dbName);
            PrintStatus("Created new database, unsaved.", StatusLevel.Warning);
            UpdateWindowName();
        }
Example #3
0
        public void Render(ListView container, ConsoleDriver driver, bool selected, int item, int col, int line, int width)
        {
            List <DBRecord> records = new List <DBRecord>(currTable.records.Values);
            int             hOffset = EditorProgram.columnHeaders.hOffset;

            if (hOffset > currTable.columns.Count)
            {
                hOffset = currTable.columns.Count - 1;
            }
            if (hOffset < 0)
            {
                hOffset = 0;
            }

            string dispStr = records[item].identifier.PadRight(ColumnHeaderControl.COLUMN_WIDTH);

            for (int i = hOffset; i < currTable.columns.Count; i++)
            {
                if (dispStr.Length + ColumnHeaderControl.COLUMN_WIDTH >= width)
                {
                    break;
                }
                dispStr += StringHelper.LimitLength(
                    RookDB.PrettyPrintFieldValue(records[item], i),
                    ColumnHeaderControl.COLUMN_WIDTH,
                    " .. ").PadRight(ColumnHeaderControl.COLUMN_WIDTH);
            }

            driver.AddStr(dispStr);
        }
Example #4
0
 static void SaveFile()
 {
     if (currDB == null)
     {
         PrintStatus("Couldn't save database, nothing loaded in memory.", StatusLevel.Error);
         return;
     }
     RookDB.WriteFile(currDB, currDB.filename, true);
     PrintStatus("Database saved successfully.", StatusLevel.Default);
 }
Example #5
0
        static void SaveFileAs()
        {
            SaveDialog saveDialog = new SaveDialog("Select save location", "Select location and filename to save database as.");

            saveDialog.IsExtensionHidden = false;
            saveDialog.AllowedFileTypes  = new string[] { "*.cdb" };
            Application.Run(saveDialog);
            if (saveDialog.FileName == null)
            {
                PrintStatus("Save As was cancelled by user.", StatusLevel.Warning);
                return;
            }
            string selPath = saveDialog.FilePath.ToString();

            if (!selPath.EndsWith(".cdb"))
            {
                selPath += ".cdb";
            }
            if (System.IO.File.Exists(selPath))
            {
                bool   overwriteConfirmed = false;
                Dialog overwriteDialog    = new Dialog("Confirm Overwrite", 20, 25);
                Label  overwriteLabel     = new Label("You are about to overwrite an existing file.\nContinue?");
                Button okBtn = new Button("Overwrite", true)
                {
                    Clicked = () => { overwriteConfirmed = true; Application.RequestStop(); }
                };
                Button cancelBtn = new Button("Cancel")
                {
                    Clicked = () => { Application.RequestStop(); }
                };
                overwriteDialog.AddButton(okBtn);
                overwriteDialog.AddButton(cancelBtn);
                overwriteDialog.Add(overwriteLabel);
                Application.Run(overwriteDialog);
                if (!overwriteConfirmed)
                {
                    return;
                }
            }
            RookDB.WriteFile(currDB, selPath, true);
            PrintStatus("Saved under alt file name: " + StringHelper.LimitLengthInverse(selPath, 50), StatusLevel.Default);
        }
Example #6
0
        //https://github.com/migueldeicaza/gui.cs
        public static void RunEditor(string initialFile = null)
        {
            Application.Init();
            mainWin = new Window("RookDB Terminal Editor - empty")
            {
                X      = 0,
                Y      = 1,
                Width  = Dim.Fill(),
                Height = Dim.Fill(1),
            };
            Application.Top.Add(mainWin);
            currTableView = new ListView(new EditorListRenderer(null))
            {
                Y      = 1,
                Width  = Dim.Fill(),
                Height = Dim.Fill(1),
            };
            mainWin.Add(currTableView);
            columnHeaders = new ColumnHeaderControl()
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Fill(),
                Height = 1,
            };
            mainWin.Add(columnHeaders);
            tablesLine = new Label("Example Text")
            {
                X      = 1,
                Y      = Pos.AnchorEnd(1),
                Width  = Dim.Fill(2),
                Height = 1,
            };
            mainWin.Add(tablesLine);

            statusLine = new Label("")
            {
                X         = 0,
                Y         = Pos.Bottom(Application.Top) - 1,
                Width     = Dim.Fill(),
                Height    = 1,
                TextColor = new Terminal.Gui.Attribute(Color.BrightYellow, Color.Black),
                Text      = "Loading..."
            };
            Application.Top.Add(new HotInputHook()); //input hook for scrolling column headers without them being focused
            Application.Top.Add(statusLine);

            MenuBar mainMenu = new MenuBar(new MenuBarItem[]
            {
                new MenuBarItem("_File", new MenuItem[]
                {
                    new MenuItem("_New", "", CreateNew),
                    new MenuItem("_Load", "", LoadFile),
                    new MenuItem("_Save", "", SaveFile),
                    new MenuItem("S_ave As", "", SaveFileAs),
                    new MenuItem("_Quit", "", Quit),
                }),
                new MenuBarItem("_Add/Delete", new MenuItem[]
                {
                    new MenuItem("Add Table", "", AddTable),
                    new MenuItem("Delete Table", "", DeleteTable),
                    new MenuItem("Add Column", "", AddColumn),
                    new MenuItem("Delete Column", "", DeleteColumn),
                    new MenuItem("Add Record", "", AddRecord),
                    new MenuItem("Delete Record", "", DeleteRecord),
                }),
                new MenuBarItem("_Edit", new MenuItem[]
                {
                    new MenuItem("Rename Table", "", RenameTable),
                    new MenuItem("Edit Column", "", EditColumn),
                    new MenuItem("Change Column Order", "", ChangeColumnOrder)
                }),
                new MenuBarItem("_Options", new MenuItem[]
                {
                    new MenuItem("_Settings", "", null),
                    new MenuItem("_Help", "", ShowHelp),
                    new MenuItem("_About", "", ShowAbout),
                }),
            });

            Application.Top.Add(mainMenu);
            if (initialFile != null && System.IO.File.Exists(initialFile))
            {
                currDB = new RookDB(System.IO.File.ReadAllText(initialFile), initialFile);
                if (!currDB.IsValid())
                {
                    currDB = null;
                }
            }

            PrintStatus("Editor loaded", StatusLevel.Default);
            Application.Run();
        }