Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj">Object the node is for</param>
        /// <param name="text">Desired text, not required to use</param>
        /// <param name="isSelected">Selection status of the node</param>
        protected virtual void DrawNodeObject(object obj, string text, bool isSelected)
        {
            // Insert an image here, preceded by an ImGuiCli.Sameline
            ImGuiCli.SameLine();
            ImGuiCli.Selectable(text, isSelected);
            if (Selection != null && ImGuiCli.IsItemClicked(0))
            {
                if (ImGuiIO.KeyCtrl)
                {
                    if (isSelected)
                    {
                        Selection.Deselect(obj);
                    }
                    else
                    {
                        Selection.Select(obj, true);
                    }
                }
                else
                {
                    Selection.Select(obj, false);
                }
            }
            else if (ImGuiCli.IsItemClicked(1) && ContextMenu != null)
            {
                ImGuiCli.OpenPopup("###tree_ctx");
            }

            if (ImGuiCli.BeginPopup("###tree_ctx", ImGuiWindowFlags_.None))
            {
                ContextMenu(obj);
                ImGuiCli.EndPopup();
            }

            if (DragConverter != null)
            {
                if (!ImGuiCli.IsPopupOpen() && ImGuiCli.BeginDragDropSource())
                {
                    ImGuiCli.SetDragDropPayload("U_TREE", DragConverter(obj));
                    ImGuiCli.Text(text);
                    ImGuiCli.EndDragDropSource();
                }
                else if (ImGuiCli.BeginDragDropTarget())
                {
                    string data = null;
                    if (ImGuiCli.AcceptDragDropPayload("U_TREE", ref data))
                    {
                        Selection.Drop(obj, data);
                    }
                }
            }
        }
Beispiel #2
0
        public void Draw()
        {
            if (newDirectory_ != null && newDirectory_ != CurrentDirectory)
            {
                CurrentDirectory = newDirectory_;
                UpdateItems();
            }

            // Left hand side, draw the local roots, favorites and recent
            float totalWidth = ImGuiCli.GetContentRegionAvailWidth();
            float w          = totalWidth;
            float fontHeight = ImGuiCli.GetFontSize();
            float fSize      = fontHeight * 16;

            w = Math.Min(w * 0.33f, fSize);

            float yAvail = ImGuiCli.GetContentRegionAvail().Y;

            ImGuiCli.BeginChild("##folder_tree", new Vector2(w, yAvail), true);
            //ImGuiEx.PushBoldFont();
            bool localOpen = ImGuiCli.CollapsingHeader(ICON_FA.FOLDER + " LOCAL");

            //ImGuiEx.PopFont();
            if (localOpen)
            {
                DrawTree(rootEntry_);
            }

            //ImGuiEx.PushBoldFont();
            bool favoritesOpen = ImGuiCli.CollapsingHeader(ICON_FA.STAR + " FAVORITES");

            //ImGuiEx.PopFont();
            if (favoritesOpen)
            {
                ImGuiCli.Indent();
                for (int i = 0; i < Favorites.Count; ++i)
                {
                    ImGuiCli.PushID(i + 1);

                    Texture2D thumbnail = thumbCache_.GetOrCreateThumbnail(Favorites[i]);
                    if (thumbnail != null)
                    {
                        ImGuiCli.Image(thumbnail, new Vector2(fontHeight, fontHeight));
                        ImGuiCli.SameLine();
                    }
                    string dispValue = Favorites[i].Substring(Favorites[i].Substring(0, Favorites[i].LastIndexOf("\\")).LastIndexOf("\\") + 1);
                    ImGuiCli.Text(dispValue);
                    if (ImGuiCli.IsItemClicked(0))
                    {
                        CurrentDirectory = Favorites[i];
                        UpdateItems();
                    }
                    else if (ImGuiCli.IsItemClicked(1))
                    {
                        ImGuiCli.OpenPopup("#favorite_ctx");
                    }
                    if (ImGuiCli.BeginPopup("#favorite_ctx", ImGuiWindowFlags_.None))
                    {
                        if (ImGuiCli.MenuItem(ICON_FA.MINUS + " Remove"))
                        {
                            Favorites.RemoveAt(i);
                            --i;
                        }
                        ImGuiCli.EndPopup();
                    }
                    ImGuiCli.PopID();
                }
                ImGuiCli.Unindent();
            }

            //ImGuiEx.PushBoldFont();
            bool recentOpen = ImGuiCli.CollapsingHeader(ICON_FA.CLOCK + " RECENT");

            //ImGuiEx.PopFont();
            if (recentOpen)
            {
                ImGuiCli.Indent();
                for (int i = 0; i < Recents.Count; ++i)
                {
                    ImGuiCli.PushID(i + 1);

                    Texture2D thumbnail = thumbCache_.GetOrCreateThumbnail(Recents[i]);
                    if (thumbnail != null)
                    {
                        ImGuiCli.Image(thumbnail, new Vector2(fontHeight, fontHeight));
                        ImGuiCli.SameLine();
                    }
                    string dispValue = Recents[i].Substring(Recents[i].Substring(0, Recents[i].LastIndexOf("\\")).LastIndexOf("\\") + 1);
                    ImGuiCli.Text(dispValue);
                    if (ImGuiCli.IsItemClicked(0))
                    {
                        CurrentDirectory = Recents[i];
                        UpdateItems();
                    }
                    else if (ImGuiCli.IsItemClicked(1))
                    {
                        ImGuiCli.OpenPopup("#Recents_ctx");
                    }
                    if (ImGuiCli.BeginPopup("#Recents_ctx", ImGuiWindowFlags_.None))
                    {
                        if (ImGuiCli.MenuItem(ICON_FA.MINUS + " Remove"))
                        {
                            Recents.RemoveAt(i);
                            --i;
                        }
                        ImGuiCli.EndPopup();
                    }
                    ImGuiCli.PopID();
                }
                ImGuiCli.Unindent();
            }

            ImGuiCli.EndChild();

            ImGuiCli.SameLine();

            // Right hand side, list the current items
            float contentWidth = totalWidth - w - ImGuiStyle.WindowPadding.X;

            ImGuiCli.BeginChild("##dir_content_region", new Vector2(contentWidth, yAvail), true);

            float itemSize = asDetail_ ? 48 : 128;

            int columns = (int)(contentWidth / (asDetail_ ? 256.0f : 128.0f));

            columns = columns < 1 ? 1 : columns;

            ImGuiCli.Columns(columns, false);

            for (int i = 0; i < currentItems_.Count; ++i)
            {
                string item = currentItems_[i];
                if (item == "." || item == "..")
                {
                    continue;
                }
                if (ExcludeFilesystemItem(item))
                {
                    continue;
                }

                string displayName = item.Substring(item.LastIndexOf('\\') + 1);
                if (filter_.IsActive && !filter_.PassFilter(displayName))
                {
                    continue;
                }

                ImGuiCli.PushID(i);

                ImGuiCli.BeginGroup();

                Texture2D thumbnail = thumbCache_.GetOrCreateThumbnail(item);
                if (thumbnail != null)
                {
                    ImGuiCli.ImageButton(thumbnail, new Vector2(itemSize - 20, itemSize - 16));
                }
                else
                {
                    ImGuiCli.Button("???", new Vector2(itemSize - 20, itemSize - 16));
                }
                if (!ImGuiCli.IsPopupOpen() && ImGuiCli.BeginDragDropSource())
                {
                    if (Recents.Contains(CurrentDirectory))
                    {
                        Recents.Remove(CurrentDirectory);
                    }
                    Recents.Insert(0, CurrentDirectory);

                    ImGuiCli.SetDragDropPayload("U_ASSET", item);
                    if (thumbnail != null)
                    {
                        ImGuiCli.Image(thumbnail, new Vector2(128, 128));
                    }
                    ImGuiCli.Text(displayName);
                    ImGuiCli.EndDragDropSource();
                }

                if (ImGuiCli.IsItemDoubleClicked(0))
                {
                    System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(item);
                    if (dirInfo.Exists)
                    {
                        newDirectory_ = dirInfo.FullName;
                    }
                }
                else if (ImGuiCli.IsItemClicked(1))
                {
                    ImGuiCli.OpenPopup("##asset_browser_popup");
                }

                if (ImGuiCli.BeginPopup("##asset_browser_popup", ImGuiWindowFlags_.None))
                {
                    string ext = System.IO.Path.GetExtension(item);
                    if (ImGuiCli.MenuItem("Open (system)"))
                    {
                        System.Diagnostics.Process.Start(item);
                    }
                    //TODO: custom handlers
                    ImGuiCli.EndPopup();
                }

                if (asDetail_)
                {
                    ImGuiCli.SameLine();
                }
                ImGuiCli.TextWrapped(displayName);
                if (!asDetail_ && ImGuiCli.IsItemHovered())
                {
                    ImGuiCli.SetTooltip(item);
                }
                ImGuiCli.EndGroup();

                ImGuiCli.PopID();
                ImGuiCli.NextColumn();
            }

            ImGuiCli.EndChild();
        }