Skip to content

Commit

Permalink
[icon_explorer] Update icon explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Jan 5, 2024
1 parent 51e2db0 commit 8f942f4
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 349 deletions.
26 changes: 21 additions & 5 deletions addons/icon_explorer/internal/scripts/collection.gd
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
extends RefCounted

const Io := preload("res://addons/icon_explorer/internal/scripts/io.gd")
const Icon := preload("res://addons/icon_explorer/internal/scripts/icon.gd")

enum Id {
MATERIAL_DESIGN,
}

signal install_finished(status: Error)
signal remove_finished(status: Error)

var id: Id
var name: String
var version: String
Expand All @@ -14,20 +18,32 @@ var license: String
var license_text: String
var web: String

var __remove_thread: Thread

# VIRTUAL
func load() -> Array[Icon]:
assert(false, "virtual function")
return []

# VIRTUAL
func add(version: String) -> bool:
func install(http: HTTPRequest, version: String) -> void:
assert(false, "virtual function")
return false

# VIRTUAL
func remove() -> bool:
assert(false, "virtual function")
return false
func remove() -> void:
if self.__remove_thread != null && self.__remove_thread.is_alive():
return
if self.__remove_thread != null:
self.__remove_thread.wait_to_finish()

self.__remove_thread = Thread.new()
self.__remove_thread.start(self.__remove)

func __remove() -> void:
if Io.rrm_dir(self.directory()):
self.remove_finished.emit(Error.OK)
else:
self.remove_finished.emit(Error.FAILED)

# VIRTUAL
func icon_directory() -> String:
Expand Down
21 changes: 15 additions & 6 deletions addons/icon_explorer/internal/scripts/collection_mdi.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,23 @@ func load() -> Array[Icon]:
return icons

# OVERRIDE
func add(version: String) -> bool:
assert(false, "virtual function")
return false
func install(http: HTTPRequest, version: String) -> void:
if !http.request_completed.is_connected(self._on_request_completed):
http.request_completed.connect(_on_request_completed)

self.install_finished.emit(Error.FAILED)

func _on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void:
if result != HTTPRequest.RESULT_SUCCESS:
self.install_finished.emit(Error.FAILED)
return


self.install_finished.emit(Error.OK)

# OVERRIDE
func remove() -> bool:
assert(false, "virtual function")
return false
func remove() -> void:
super.remove()

# OVERRIDE
func icon_directory() -> String:
Expand Down
17 changes: 17 additions & 0 deletions addons/icon_explorer/internal/scripts/io.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
static func rrm_dir(dir_path: String) -> bool:
var dir: DirAccess = DirAccess.open(dir_path)
if !dir:
return false

dir.list_dir_begin()
var file_name: String = dir.get_next()
while file_name != "":
if dir.current_is_dir():
if !rrm_dir(dir_path.path_join(file_name)):
return false
else:
if dir.remove(file_name) != Error.OK:
return false
file_name = dir.get_next()
DirAccess.remove_absolute(dir_path)
return true
47 changes: 0 additions & 47 deletions addons/icon_explorer/internal/ui/explorer.gd

This file was deleted.

69 changes: 0 additions & 69 deletions addons/icon_explorer/internal/ui/explorer.tscn

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,67 @@
extends VBoxContainer

const Collection := preload("res://addons/icon_explorer/internal/scripts/collection.gd")
const FilterOptions := preload("res://addons/icon_explorer/internal/ui/icon_viewer/filter_options.gd")
const FilterOptions := preload("res://addons/icon_explorer/internal/ui/explorer/filter_options.gd")
const Icon := preload("res://addons/icon_explorer/internal/scripts/icon.gd")
const IconDatabase := preload("res://addons/icon_explorer/internal/scripts/icon_database.gd")
const DetailPanel := preload("res://addons/icon_explorer/internal/ui/detail_panel/detail_panel.gd")

const Options := preload("res://addons/icon_explorer/internal/ui/options/options.gd")

@export var _filter_icon: TextureRect
@export var _filter: LineEdit
@export var _filter_options_path: NodePath
@onready var _filter_options: FilterOptions = self.get_node(self._filter_options_path)
@export var _icon_list: ItemList
@export var _options_button: Button
@export var _options_popup: Window
@export var _options_path: NodePath
@onready var _options: Options = self.get_node(self._options_path)

@export var _status_bar: ProgressBar

@export var _detail_panel_path: NodePath
@onready var _detail_panel: DetailPanel = self.get_node(self._detail_panel_path)

var _db: IconDatabase:
set = set_db
var _db: IconDatabase = IconDatabase.new()

func _ready() -> void:
self.get_viewport().gui_embed_subwindows = false
self._filter_icon.texture = self.get_theme_icon("Search", "EditorIcons")
self._filter_options.icon = self.get_theme_icon("AnimationFilter", "EditorIcons")
self._filter_options.options_changed.connect(self.update)
self._icon_list.item_selected.connect(self._on_icon_selected)
self._filter.text_changed.connect(self._on_filter_changed)
self._options_button.icon = self.get_theme_icon("Tools", "EditorIcons")
self._options_button.pressed.connect(self._on_option_pressed)

func set_db(new_db: IconDatabase) -> void:
_db = new_db
# load in main thread: https://github.com/godotengine/godot/issues/86796
# self._db.load()
# self.set_process(true)
self._db._load()
self._status_bar.value = 100.0

var filter_popup: PopupMenu = self._filter_options.get_popup()
for coll: Collection in self._db.installed_collections():
filter_popup.add_check_item(coll.name, int(coll.id))
for idx: int in range(filter_popup.item_count):
filter_popup.set_item_checked(idx, true)
self._options.db = self._db
self.update()

func _ready() -> void:
self._filter_icon.texture = self.get_theme_icon("Search", "EditorIcons")
self._filter_options.icon = self.get_theme_icon("AnimationFilter", "EditorIcons")
self._filter_options.options_changed.connect(self.update)
self._icon_list.item_selected.connect(self._on_icon_selected)
self._filter.text_changed.connect(self._on_filter_changed)
func _process(_delta: float) -> void:
return
if self._db.is_loaded():
self.set_process(false)
var filter_popup: PopupMenu = self._filter_options.get_popup()
for coll: Collection in self._db.installed_collections():
filter_popup.add_check_item(coll.name, int(coll.id))
for idx: int in range(filter_popup.item_count):
filter_popup.set_item_checked(idx, true)
self.update()
return

self._status_bar.value = self._db.load_progress()

func clear() -> void:
self._icon_list.clear()
Expand All @@ -56,3 +84,6 @@ func _on_icon_selected(idx: int) -> void:

func _on_filter_changed(text: String) -> void:
self.update(text)

func _on_option_pressed() -> void:
self._options_popup.popup_centered_ratio(0.35)
Loading

0 comments on commit 8f942f4

Please sign in to comment.