Browse Source

Merge pull request #132 from rsredsq/RED-EDITOR-WORK

Editor Recent Projects, Button Hyperlinking
JoshEngebretson 10 years ago
parent
commit
0b331e60d3

+ 1 - 2
Resources/EditorData/AtomicEditor/editor/ui/welcomeframe.tb.txt

@@ -7,9 +7,8 @@ TBLayout: distribution: gravity, size: available, axis: y, id: welcomelayout, po
 					text Open Project
 				TBButton: id: new project
 					text New Project
-			TBLayout: distribution: gravity, axis: y, position: left
+			TBLayout: distribution: gravity, axis: y, position: left, id: recentprojects
 				TBEditField: text: "<color #76D6FF>Recent Projects:</color>", styling: 1, readonly: 1, adapt-to-content: 1, skin: 0
-				TBSelectList: gravity: all, id: recentprojects
 	TBLayout: distribution: gravity, size: available
 		TBLayout: distribution: gravity, axis: y, position: left
 			TBEditField: text: "<color #76D6FF>Welcome:</color>", styling: 1, readonly: 1, adapt-to-content: 1, skin: 0

+ 38 - 26
Script/AtomicEditor/ui/WelcomeFrame.ts

@@ -11,38 +11,37 @@ class WelcomeFrame extends ScriptWidget {
 
         this.load("AtomicEditor/editor/ui/welcomeframe.tb.txt");
 
-        this.recentProjects = <Atomic.UISelectList> this.getWidget("recentprojects");
-        this.recentSource = new Atomic.UISelectItemSource();
+        var recentProjects = <Atomic.UILayout> this.getWidget("recentprojects");
         this.gravity = Atomic.UI_GRAVITY_ALL;
 
+        this.recentList = new Atomic.UIListView();
+        this.recentList.rootList.id = "recentList";
+
+        recentProjects.addChild(this.recentList);
+
         var container = <Atomic.UILayout> parent.getWidget("resourceviewcontainer");
 
         container.addChild(this);
 
         this.updateRecentProjects();
 
+        this.subscribeToEvent(EditorEvents.CloseProject, () => {
+            this.updateRecentProjects();
+        });
+
     }
 
     handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
+        if (ev.type == Atomic.UI_EVENT_TYPE_RIGHT_POINTER_UP) {
+            if (ev.target.id == "recentList") {
+                this.openFrameMenu(ev.x, ev.y);
+            }
+        }
 
         if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
 
             var id = ev.target.id;
 
-            if (id == "recentprojects") {
-
-                var itemID = Number(this.recentProjects.selectedItemID);
-
-                if (itemID >= 0 && itemID < this.recent.length) {
-
-                    this.sendEvent(EditorEvents.LoadProject, { path: this.recent[itemID] });
-
-                }
-
-                return true;
-
-            }
-
             if (id == "open project") {
 
                 var utils = new Editor.FileUtils();
@@ -64,32 +63,45 @@ class WelcomeFrame extends ScriptWidget {
 
             }
 
-        }
+            if (id == "recentList") {
+                var path: string = this.recent[this.recentList.getSelectedItemID()];
+                this.sendEvent(EditorEvents.LoadProject, { path: path });
+            }
 
+            if (id == "recentProjectsContextMenu") {
+                var pref = Atomic.editorMode.getPreferences();
+                if (ev.refid == "clear recent projects") {
+                    pref.deleteRecentProjects();
+                    this.updateRecentProjects();
+                }
+            }
+        }
     }
 
     updateRecentProjects() {
 
-        this.recentSource.clear();
-
+        this.recentList.deleteAllItems();
+        
         // prune any that don't exist
         Atomic.editorMode.preferences.updateRecentFiles();
 
-        this.recent = Atomic.editorMode.preferences.recentProjects;
+        this.recent = Atomic.editorMode.getPreferences().getRecentProjects();
 
         for (var i in this.recent) {
-
-            this.recentSource.addItem(new Atomic.UISelectItem(this.recent[i], i))
-
+            this.recentList.addRootItem(this.recent[i], "Folder.icon", i);
         }
 
-        this.recentProjects.source = this.recentSource;
+    }
 
+    private openFrameMenu(x: number, y: number) {
+        var menu = new Atomic.UIMenuWindow(this, "recentProjectsContextMenu");
+        var menuButtons = new Atomic.UISelectItemSource();
+        menuButtons.addItem(new Atomic.UISelectItem("Clear Recent Projects", "clear recent projects"));
+        menu.show(menuButtons, x, y);
     }
 
     recent: string[] = [];
-    recentProjects: Atomic.UISelectList;
-    recentSource: Atomic.UISelectItemSource;
+    recentList: Atomic.UIListView;
 
 }
 

+ 1 - 0
Script/TypeScript/Editor.d.ts

@@ -47,6 +47,7 @@ declare module Editor {
 
       registerRecentProject(fullpath: string): void;
       getRecentProjects(): string[];
+      deleteRecentProjects(): void;
       setAndroidSDKPath(path: string): void;
       setAntPath(path: string): void;
       setJDKRootPath(path: string): void;

+ 10 - 0
Source/Atomic/UI/UIButton.cpp

@@ -3,6 +3,7 @@
 #include <TurboBadger/tb_widgets_common.h>
 
 #include <Atomic/IO/Log.h>
+#include <Atomic/IO/FileSystem.h>
 
 #include "UIEvents.h"
 #include "UI.h"
@@ -38,6 +39,15 @@ void UIButton::SetSqueezable(bool value)
 
 bool UIButton::OnEvent(const tb::TBWidgetEvent &ev)
 {
+    if (ev.type == EVENT_TYPE_CLICK) 
+	{
+        String text = GetText();
+        if (text.StartsWith("http://") || text.StartsWith("https://")) 
+		{
+            FileSystem* fileSystem = GetSubsystem<FileSystem>();
+            fileSystem->SystemOpen(text);
+        }
+    }
     return UIWidget::OnEvent(ev);
 }
 

+ 7 - 0
Source/AtomicEditor/Application/AEPreferences.cpp

@@ -200,6 +200,13 @@ void AEPreferences::RegisterRecentProject(const String& fullpath)
 
 }
 
+void AEPreferences::DeleteRecentProjects() 
+{
+    if (recentProjects_.Size() <= 0) return;
+    recentProjects_.Clear();
+    UpdateRecentFiles(true);
+}
+
 bool AEPreferences::ReadStartupPrefs(Context *context, StartupPreferences& prefs)
 {
 

+ 1 - 0
Source/AtomicEditor/Application/AEPreferences.h

@@ -33,6 +33,7 @@ public:
 
     void RegisterRecentProject(const String& fullpath);
     const Vector<String>& GetRecentProjects() { return recentProjects_; }
+    void DeleteRecentProjects();
 
     void SetAndroidSDKPath(const String& path) { androidSDKPath_ = path; Write(); }
     void SetAntPath(const String& path) { antPath_ = path; Write(); }