Exemple #1
0
        /// <summary>
        /// Show main UI with filter and map list
        /// </summary>
        /// <returns></returns>
        void ShowMainUi()
        {
            var mainRect = new Rect(Screen.width / 3, 100, Screen.width / 3, Screen.height - 200);

            mainRect.width = Math.Max(Screen.width / 3, 600);             //force width to not be less than the minimum size to show all controls

            //fixed positioning

            //simple box
            GUI.Box(mainRect, "");

            //patchamak trail logo
            GUI.Label(new Rect(mainRect.x - 50, mainRect.y - 40, 128, 128), new GUIContent(_logoPatcha));

            //main content
            using (new GUILayout.AreaScope(new Rect(mainRect.x + 25, mainRect.y + 30, mainRect.width - 50, mainRect.height - 40))) {
                using (new GUILayout.VerticalScope()) {
                    new TitleWidget("Patcha'Map Importer", 30);

                    GUILayout.Space(30);

                    using (new DisableAllButtons(_editUiVisible)) {
                        //show filter and ordering widget
                        var filter = new FilterWidget(_mapManager.CurrentFilter).Value;
                        if (filter.ToString() != _mapManager.CurrentFilter.ToString())                         //todo : make operator Equals instead of comparing strings
                        {
                            Log.Write("MI: Applying new filter !");
                            _mapManager.Filter(filter);
                            _mainUiScrollPos = Vector2.zero;
                        }

                        GUILayout.Space(5);

                        //show map list and wire button actions
                        new MapListWidget(ref _mainUiScrollPos, _mapManager.Maps, _loadedMap,
                                          map => {
                            if (map == _loadedMap)
                            {
                                return;                                                        //map already loaded, do nothing
                            }
                            Log.Write($"MI: Load map '{map.Filename}'");
                            _loadedMap = map;
                            _editedMap = map;
                            _mapLoader.Load(map);
                            _mainUiVisible = false;
                        },
                                          map => {
                            Log.Write($"MI: Edit map '{map.Filename}'");
                            _editedMap     = map;
                            _editUiVisible = true;
                        }
                                          );

                        GUILayout.Space(5);

                        //save on bottom (todo:remove it when editmap ui is done)
                        using (new GUILayout.HorizontalScope()) {
                            GUILayout.FlexibleSpace();

                            if (GUILayout.Button("Save"))
                            {
                                _mapManager.Save();
                            }
                            if (GUILayout.Button("Reload"))
                            {
                                _mapManager.Load();
                            }
                            if (GUILayout.Button("Close"))
                            {
                                _mainUiVisible = false;
                                _editUiVisible = false;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
		public SearchResultsPage (FileSearch search)
		{
			VPaned         paned;
			TreeViewColumn column;
			ToolItem       spacerItem;
			ToolItem       filterItem;
			Alignment      filterAlignment;
			ToolButton     searchAgainToolButton;
			
			this.search = search;
	
			downloadToolButton = new ToolButton(new Image("gtk-save", IconSize.LargeToolbar), "Download");
			downloadToolButton.IsImportant = true;
			downloadToolButton.Sensitive = false;
			downloadToolButton.Clicked += DownloadToolButtonClicked;
			
			searchAgainToolButton = new ToolButton(new Image("gtk-refresh", IconSize.LargeToolbar), "Search Again");
			searchAgainToolButton.IsImportant = true;
			searchAgainToolButton.Clicked += SearchAgainToolButtonClicked;		
			
			spacerItem = new ToolItem();
			spacerItem.Expand = true;

			filterButton = new ToggleButton("Filter Results");
			filterButton.Image = new Image(Gui.LoadIcon(16, "application-x-executable"));
			filterButton.Toggled += delegate (object o, EventArgs args) {
				this.ShowFilter = filterButton.Active;
			};

			filterAlignment = new Alignment(0.5f, 0.5f, 0, 0);
			filterAlignment.Add(filterButton);

			filterItem = new ToolItem();
			filterItem.Add(filterAlignment);

			browseToolButton = new ToolButton(new Image("gtk-open", IconSize.LargeToolbar), "Browse");
			browseToolButton.IsImportant = true;
			browseToolButton.Sensitive = false;
			browseToolButton.Clicked += BrowseToolButtonClicked;

			toolbar = new Toolbar();
			toolbar.ToolbarStyle = ToolbarStyle.BothHoriz;
			toolbar.Insert(downloadToolButton, -1);
			toolbar.Insert(browseToolButton, -1);
			toolbar.Insert(spacerItem, -1);
			toolbar.Insert(filterItem, -1);
			toolbar.Insert(new SeparatorToolItem(), -1);
			toolbar.Insert(searchAgainToolButton, -1);
			toolbar.ShowAll();

			this.PackStart(toolbar, false, false, 0);

			resultCountByTypeCache = new Dictionary<FilterType, int>();

			Gdk.Pixbuf audioPixbuf = Gui.LoadIcon(16, "audio-x-generic");
			Gdk.Pixbuf videoPixbuf = Gui.LoadIcon(16, "video-x-generic");
			Gdk.Pixbuf imagePixbuf = Gui.LoadIcon(16, "image-x-generic");
			Gdk.Pixbuf docPixbuf = Gui.LoadIcon(16, "x-office-document");
			unknownPixbuf = Gui.LoadIcon(16, "text-x-generic");
			folderPixbuf = Gui.LoadIcon(16, "folder");
			
			typeStore = new ListStore(typeof(Gdk.Pixbuf), typeof(string), typeof(FilterType));
			typeStore.AppendValues(null, "All Results", FilterType.All);
			typeStore.AppendValues(null, "-");
			typeStore.AppendValues(audioPixbuf, "Audio", FilterType.Audio);
			typeStore.AppendValues(videoPixbuf, "Video", FilterType.Video);
			typeStore.AppendValues(imagePixbuf, "Images", FilterType.Image);
			typeStore.AppendValues(docPixbuf, "Documents", FilterType.Document);
			typeStore.AppendValues(folderPixbuf, "Folders", FilterType.Folder);
			typeStore.AppendValues(unknownPixbuf, "Other", FilterType.Other);
			
			typeTree = new TreeView();
			typeTree.HeadersVisible = false;
			typeTree.RowSeparatorFunc = delegate (TreeModel m, TreeIter i) {
				string text = (string)m.GetValue(i, 1);
				return (text == "-");
			};
			typeTree.Selection.Changed += TypeSelectionChanged;

			typeTree.Model = typeStore;
			
			CellRendererPixbuf pixbufCell = new CellRendererPixbuf();
			CellRendererText textCell = new CellRendererText();
			CellRendererText countTextCell = new CellRendererText();
			countTextCell.Sensitive = false;
			countTextCell.Alignment = Pango.Alignment.Right;
			countTextCell.Xalign = 1;

			column = new TreeViewColumn();
			column.PackStart(pixbufCell, false);
			column.PackStart(textCell, true);
			column.PackStart(countTextCell, false);
			column.AddAttribute(pixbufCell, "pixbuf", 0);
			column.AddAttribute(textCell, "text", 1);
			column.SetCellDataFunc(countTextCell, new TreeCellDataFunc(TypeCountCellFunc));

			typeTree.AppendColumn(column);

			TreeView artistTree = new TreeView();
			artistTree.HeadersVisible = false;

			TreeView albumTree = new TreeView();
			albumTree.HeadersVisible = false;

			HBox topBox = new HBox();
			topBox.PackStart(Gui.AddScrolledWindow(typeTree), true, true, 0);
			topBox.PackStart(Gui.AddScrolledWindow(artistTree), true, true, 1);
			topBox.PackStart(Gui.AddScrolledWindow(albumTree), true, true, 0);
			topBox.Homogeneous = true;

			resultsStore = new ListStore(typeof(SearchResult));
			resultsStore.RowInserted += delegate {
				Refilter();
			};
			resultsStore.RowDeleted += delegate {
				Refilter();
			};
			resultsTree = new TreeView();
			resultsTree.RowActivated += resultsTree_RowActivated;
			resultsTree.ButtonPressEvent += resultsTree_ButtonPressEvent;
			resultsTree.Selection.Changed += ResultsTreeSelectionChanged;

			imageColumns = new List<TreeViewColumn>();
			audioColumns = new List<TreeViewColumn>();
			videoColumns = new List<TreeViewColumn>();
			fileOnlyColumns = new List<TreeViewColumn>();
			folderOnlyColumns = new List<TreeViewColumn>();

			column = new TreeViewColumn();
			column.Title = "File Name";
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Autosize;
			column.Resizable = true;
			column.SortColumnId = 0;
			//resultsTree.ExpanderColumn = column;

			CellRenderer cell = new CellRendererPixbuf();
			column.PackStart(cell, false);
			column.SetCellDataFunc(cell, new TreeCellDataFunc(IconFunc));

			cell = new CellRendererText();
			column.PackStart(cell, true);
			column.SetCellDataFunc(cell, new TreeCellDataFunc(FileNameFunc));

			resultsTree.AppendColumn(column);

			column = resultsTree.AppendColumn("Codec", new CellRendererText(), new TreeCellDataFunc(CodecFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 120;
			column.Resizable = true;
			column.SortColumnId = 1;
			videoColumns.Add(column);

			column = resultsTree.AppendColumn("Format", new CellRendererText(), new TreeCellDataFunc(FormatFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 90;
			column.Resizable = true;
			column.SortColumnId = 2;
			imageColumns.Add(column);

			column = resultsTree.AppendColumn("Resolution", new CellRendererText(), new TreeCellDataFunc(ResolutionFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 90;
			column.Resizable = true;
			column.SortColumnId = 3;
			videoColumns.Add(column);
			imageColumns.Add(column);

			column = resultsTree.AppendColumn("Artist", new CellRendererText(), new TreeCellDataFunc(ArtistFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 110;
			column.Resizable = true;
			column.SortColumnId = 4;
			audioColumns.Add(column);

			column = resultsTree.AppendColumn("Album", new CellRendererText(), new TreeCellDataFunc(AlbumFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 110;
			column.Resizable = true;
			column.SortColumnId = 5;
			audioColumns.Add(column);
		
			column = resultsTree.AppendColumn("Bitrate", new CellRendererText(), new TreeCellDataFunc(BitrateFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 70;
			column.Resizable = true;
			column.SortColumnId = 6;
			audioColumns.Add(column);

			column = resultsTree.AppendColumn("Size", new CellRendererText(), new TreeCellDataFunc(SizeFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 70;
			column.SortColumnId = 7;
			column.Resizable = true;
			fileOnlyColumns.Add(column);

			column = resultsTree.AppendColumn("Sources", new CellRendererText(), new TreeCellDataFunc(SourcesFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 85;
			column.SortColumnId = 8;
			column.Resizable = true;
			fileOnlyColumns.Add(column);
			
			column = resultsTree.AppendColumn("User", new CellRendererText(), new TreeCellDataFunc(UserFunc));
			column.Clickable = true;
			column.Sizing = TreeViewColumnSizing.Fixed;
			column.FixedWidth = 85;
			column.SortColumnId = 8;
			column.Resizable = true;
			folderOnlyColumns.Add(column);
			
			column = resultsTree.AppendColumn("Full Path", new CellRendererText(), new TreeCellDataFunc(FullPathFunc));
			column.Clickable = true;
			column.Resizable = true;
			column.SortColumnId = 9;

			column = resultsTree.AppendColumn("Info Hash", new CellRendererText(), new TreeCellDataFunc(InfoHashFunc));
			column.Clickable = true;
			column.Resizable = true;
			column.SortColumnId = 10;
			fileOnlyColumns.Add(column);

			resultsFilter = new TreeModelFilter(resultsStore, null);
			resultsFilter.VisibleFunc = resultsFilterFunc;

			resultsSort = new TreeModelSort(resultsFilter);
			for (int x = 0; x < resultsTree.Columns.Length; x++) {
				resultsSort.SetSortFunc(x, resultsSortFunc);
			}
			resultsTree.Model = resultsSort;

			ScrolledWindow resultsTreeSW = new ScrolledWindow();
			resultsTreeSW.Add(resultsTree);

			paned = new VPaned();
			paned.Add1(topBox);
			paned.Add2(resultsTreeSW);
			paned.Position = 160;
			paned.ShowAll();

			filterWidget = new FilterWidget(search);
			filterWidget.FiltersChanged += filterWidget_FiltersChanged;
			filterWidget.Hidden += filterWidget_Hidden;
		
			this.PackStart(filterWidget, false, false, 0);
			this.PackStart(paned, true, true, 0);

			TypeSelectionChanged(typeTree, EventArgs.Empty);

			search.NewResults += (NewResultsEventHandler)DispatchService.GuiDispatch(new NewResultsEventHandler(search_NewResults));
			search.ClearedResults += (EventHandler)DispatchService.GuiDispatch(new EventHandler(search_ClearedResults));

			resultPopupMenu = new Menu();
			
			browseResultMenuItem = new ImageMenuItem("Browse");
			browseResultMenuItem.Image = new Image(Gui.LoadIcon(16, "document-open"));
			browseResultMenuItem.Activated += BrowseToolButtonClicked;
			resultPopupMenu.Append(browseResultMenuItem);
			
			downloadResultMenuItem = new ImageMenuItem("Download");
			downloadResultMenuItem.Image = new Image(Gui.LoadIcon(16, "go-down"));
			downloadResultMenuItem.Activated += DownloadToolButtonClicked;
			resultPopupMenu.Append(downloadResultMenuItem);

			resultPropertiesMenuItem = new ImageMenuItem(Gtk.Stock.Properties, null);
			resultPropertiesMenuItem.Activated += FilePropertiesButtonClicked;
			resultPopupMenu.Append(resultPropertiesMenuItem);
		}