public void Multi_Thread_Toplevels() { Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true))); var t = Application.Top; var w = new Window(); t.Add(w); int count = 0, count1 = 0, count2 = 0; bool log = false, log1 = false, log2 = false; bool fromTopStillKnowFirstIsRunning = false; bool fromTopStillKnowSecondIsRunning = false; bool fromFirstStillKnowSecondIsRunning = false; Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), (_) => { count++; if (count1 == 5) { log1 = true; } if (count1 > 13 && count < 15) { fromTopStillKnowFirstIsRunning = true; } if (count2 > 6 && count2 < 8) { fromTopStillKnowSecondIsRunning = true; } if (count == 30) { Assert.Equal(30, count); Assert.Equal(20, count1); Assert.Equal(10, count2); Assert.True(log); Assert.True(log1); Assert.True(log2); Assert.True(fromTopStillKnowFirstIsRunning); Assert.True(fromTopStillKnowSecondIsRunning); Assert.True(fromFirstStillKnowSecondIsRunning); Application.RequestStop(); return(false); } return(true); }); t.Ready = () => { FirstDialogToplevel(); }; void FirstDialogToplevel() { var od = new OpenDialog { Ready = () => { SecoundDialogToplevel(); } }; Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), (_) => { count1++; if (count2 == 5) { log2 = true; } if (count2 > 3 && count2 < 5) { fromFirstStillKnowSecondIsRunning = true; } if (count1 == 20) { Assert.Equal(20, count1); Application.RequestStop(); return(false); } return(true); }); Application.Run(od); } void SecoundDialogToplevel() { var d = new Dialog(); Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), (_) => { count2++; if (count < 30) { log = true; } if (count2 == 10) { Assert.Equal(10, count2); Application.RequestStop(); return(false); } return(true); }); Application.Run(d); } Application.Run(); Application.Shutdown(); }
static int QueryFull(bool useErrorColors, int width, int height, ustring title, ustring message, int defaultButton = 0, Border border = null, params ustring [] buttons) { const int defaultWidth = 50; int textWidth = TextFormatter.MaxWidth(message, width == 0 ? defaultWidth : width); int textHeight = TextFormatter.MaxLines(message, textWidth); // message.Count (ustring.Make ('\n')) + 1; int msgboxHeight = Math.Max(1, textHeight) + 3; // textHeight + (top + top padding + buttons + bottom) // Create button array for Dialog int count = 0; List <Button> buttonList = new List <Button> (); if (buttons != null && defaultButton > buttons.Length - 1) { defaultButton = buttons.Length - 1; } foreach (var s in buttons) { var b = new Button(s); if (count == defaultButton) { b.IsDefault = true; } buttonList.Add(b); count++; } // Create Dialog (retain backwards compat by supporting specifying height/width) Dialog d; if (width == 0 & height == 0) { d = new Dialog(title, buttonList.ToArray()); d.Height = msgboxHeight; } else { d = new Dialog(title, Math.Max(width, textWidth) + 4, height, buttonList.ToArray()); } if (border != null) { d.Border = border; } if (useErrorColors) { d.ColorScheme = Colors.Error; } if (message != null) { var l = new Label(textWidth > width ? 0 : (width - 4 - textWidth) / 2, 1, message); l.LayoutStyle = LayoutStyle.Computed; l.TextAlignment = TextAlignment.Centered; l.X = Pos.Center(); l.Y = Pos.Center(); l.Width = Dim.Fill(2); l.Height = Dim.Fill(1); d.Add(l); } // Dynamically size Width int msgboxWidth = Math.Max(defaultWidth, Math.Max(title.RuneCount + 8, Math.Max(textWidth + 4, d.GetButtonsWidth()) + 8)); // textWidth + (left + padding + padding + right) d.Width = msgboxWidth; // Setup actions int clicked = -1; for (int n = 0; n < buttonList.Count; n++) { int buttonId = n; var b = buttonList [n]; b.Clicked += () => { clicked = buttonId; Application.RequestStop(); }; if (b.IsDefault) { b.SetFocus(); } } // Run the modal; do not shutdown the mainloop driver when done Application.Run(d); return(clicked); }
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(); }