Exemplo n.º 1
0
        static int QueryFull(bool useErrorColors, int width, int height, string title, string message, params string [] buttons)
        {
            int lines = Label.MeasureLines(message, width);
            int clicked = -1, count = 0;

            var d = new Dialog(title, width, height);

            if (useErrorColors)
            {
                d.ColorScheme = Colors.Error;
            }

            foreach (var s in buttons)
            {
                int n = count++;
                var b = new Button(s);
                b.Clicked += delegate {
                    clicked   = n;
                    d.Running = false;
                };
                d.AddButton(b);
            }
            if (message != null)
            {
                var l = new Label((width - 4 - message.Length) / 2, 0, message);
                d.Add(l);
            }

            Application.Run(d);
            return(clicked);
        }
Exemplo n.º 2
0
        public void AddControls()
        {

            MusicView = new ListView(musicFiles);
            PlayListView = new ListView(playList);

            MusicView.Width = Dim.Fill() - 1;
            MusicView.Height = Dim.Fill();

            PlayListView.Width = Dim.Fill() - 1;
            PlayListView.Height = Dim.Fill();

            Button playButton = new Button(1, 8, "Play");

            Button set_button = new Button(5, 5, "Ok");
            Button set_url_button = new Button(5, 5, "Ok");


            Button bookMarkButton = new Button(30, 8, "Bookmark");
            Button skipButton = new Button(20, 8, "Skip");

            skipButton.Clicked += () => {

                if(playList.Count > 0)
                nextTrack();
            
            };
            dirText = new Label(new Rect(1, 1, 256, 20), "Current Directory");
            var sItemPause = new StatusItem(Key.Space, "SPACE - Pause/Resume", ()=> {
                
                if(mp.IsPlaying)
                {
                    mp.SetPause(true);
                    pauseButton.Text = "Resume";
                }
                else
                {
                    mp.SetPause(false);
                    pauseButton.Text = "Pause";
                }

            });

            var sItemFastForward = new StatusItem(Key.ControlF, "Ctrl + F - Fast Forward", () => {
                mp.Position += 0.01F;
            });

            var sItemSkipTrack = new StatusItem(Key.ControlS, "Ctrl + S - Skip Track", () => {
                nextTrack();

            });

            StatusItem[] statusItems = {sItemPause, sItemFastForward, sItemSkipTrack};
            var statusBar = new StatusBar(statusItems);


            playButton.Clicked += () => {
                if(playList.Count > 0)
                playTrack();
                else
                    MessageBox.ErrorQuery("Playlist Empty", "Press Escape to continue");
            };

            bookMarkButton.Clicked += () => {
                mp.SetPause(true);
                lastPlayedTrack.write(playListTable, mp.Time, currentTrack, musicDir);
            };

            pauseButton.Clicked += () => {

                if(pauseButton.Text == "Resume")
                {
                    mp.SetPause(false);
                    pauseButton.Text = "Pause";
                }
                else
                {
                    mp.SetPause(true);
                    pauseButton.Text = "Resume";
                }
            };

            MusicView.OpenSelectedItem += openDialogClicked;
            MusicView.SelectedItemChanged += musicViewSelect;
            PlayListView.OpenSelectedItem += playListClicked;

            dialog = new Terminal.Gui.Dialog("Enter Music Directory", 50, 10, set_button);
            url_dialog = new Terminal.Gui.Dialog("Enter URL", 50, 10, set_url_button);
            url_dialog.Visible = false;

            entry = new TextField()
            {
                X = 1,
                Y = 1,
                Width = Dim.Fill(),
                Height = 1
            };

            var url_entry = new TextField()
            {
                X = 1,
                Y = 1,
                Width = Dim.Fill(),
                Height = 1
            };

            url_dialog.Add(url_entry);
            dialog.Add(entry);

            var menu = new MenuBar(new MenuBarItem[] {
            new MenuBarItem ("_File", new MenuItem [] {
                new MenuItem ("_Open Music DIR", "", () => {
                    dialog.Visible = true;
                    entry.SetFocus();
                }),

                  new MenuItem ("_Add All", "", () => {
                       
                    foreach(string filename in filelist)
                    {
                        playList.Add(Path.GetFileName(filename));
                        var track = new Track();
                        track.title = Path.GetFileName(filename);
                        track.directory = filename;
                        playListTable.Add(track);
                    }
                    PlayListView.SetSource(playList);
                    
                }),

                   new MenuItem ("_Open URL", "", () => {
                    url_dialog.Visible = true;
                    url_entry.SetFocus();

                }),

                  new MenuItem ("_Exit","", () => {
                      mp.SetPause(true);
                      lastPlayedTrack.write(playListTable, mp.Time, currentTrack, musicDir);
                      top.Running = false;

                      cleanUp();

                      
                      
                })
            }),

            new MenuBarItem ("_Playlist", new MenuItem [] {
                new MenuItem ("_Play","", () => {
                    if(playList.Count >= 1 && PlayListView.SelectedItem > 0)
                    {
                        currentTrack = PlayListView.SelectedItem;
                    }
                    else
                    {
                        currentTrack = 0;
                    }
                    if(playList.Count != 0)
                    playTrack();

                }),
                new MenuItem("_Clear","", () => {
                    mp.Stop();
                    playList.Clear();
                    playListTable.Clear();
                    PlayListView.SetSource(playList);
                    currentTrack = 0;


                }),

            }),

            new MenuBarItem ("_Mode", new MenuItem [] {
                new MenuItem ("_Shuffle","", () => {
                    shuffle = true;
                    modeText.Text = modes[1].ToString();
                    nextTrack();

                }),
                new MenuItem("_Continuous","", () =>
                {
                    shuffle = false;
                    modeText.Text = modes[0].ToString();
                }),

            }),
        });

            top.Add(menu);


            set_button.Clicked += buttonClicked;
            set_url_button.Clicked += () => {

                
            if(url_entry.Text.Length <= 0)
            {

                url_dialog.Visible = false;
                MessageBox.ErrorQuery("Invalid URL", "Press Escape to continue");
                PlayListView.SetFocus();
                return;
            }
            playList.Add(url_entry.Text.ToString());
            var track = new Track();
            track.title = url_entry.Text.ToString();
            track.directory = url_entry.Text.ToString();

            playListTable.Add(track);
            url_dialog.Visible = false;
            };
            
            if(!dirSet)
            {
                dialog.Visible = false;
                listDirContents();
            }


            trackPlaying = new FrameView("Current Track")
            {
                X = 0,
                Y = 1,

                Height = Dim.Percent(40, true),
                Width = Dim.Percent(48, true)

            };

           
                      
            var PlayListWindow = new FrameView("PlayList")
            {
                X = 0,
                Y = Pos.Bottom(trackPlaying),
                Height = Dim.Percent(80, true),
                Width = Dim.Percent(48, true)
            };

          
            var progressFrame = new FrameView()
            {
                X = 0,
                Y = 5,
                Width = Dim.Fill(),
                Height = 3,
                CanFocus = false
            };




            progress = new ProgressBar() {
                X = 0,
                Y = 0,
                Width = Dim.Fill() + 1,
                Height = 1,
            };
	        progress.Fraction = 0F;
            PlayListWindow.Add(PlayListView);


            progressFrame.Add(progress);
            trackPlaying.Add(
                selectedTrackTitle,
                selectedTrackArtist,
                timerText,
                modeText
                );
            var win = new FrameView("Music Files")
            {
                X = Pos.Right(trackPlaying),
                Y = 1,
                Width = Dim.Fill(),
                Height = Dim.Percent(88, true)

            };
            win.Add(   
                      MusicView

                        );

            var currentDirWindow = new FrameView("Currently Browsing")
            {
                X = 0,
                Y = Pos.Bottom(win),
                Width = Dim.Percent(100, true),
                Height = Dim.Percent(90, true)
                
            };
            entry.SetFocus();

            top.Add(trackPlaying);
            top.Add(win);
            top.Add(PlayListWindow, dialog, statusBar, url_dialog);
            trackPlaying.Add(bookMarkButton, progressFrame, playButton, pauseButton, skipButton);
            timerText.Text = "";

            currentDirWindow.Add(dirText);
            top.Add(currentDirWindow);

            top.Width = Dim.Percent(100, true);
            top.Height = Dim.Percent(100, true);
            lastPlayedTrack.load();
            if(lastPlayedTrack.playlist_exists)
            {
                playList.Clear();

                playListTable = lastPlayedTrack.getPlayListFiles();
                foreach(Track t in playListTable) {
                    playList.Add(t.title);
                }
                PlayListView.SetSource(playList);

                if(playList.Count > 0)
                {
                    currentTrack = lastPlayedTrack.getPlaylistPosition();
                    playTrack();
                    
                    mp.Time = lastPlayedTrack.getTrackTime();
                    
                }
                if(lastPlayedTrack.file_exists)
                musicDir = lastPlayedTrack.getLastDirectory();
                listDirContents();

            }

            Application.Resized += windowResized;

            Application.Run();

        }