Skip to content

Commit

Permalink
Merge pull request #3 from Xrayez/reselect-recent
Browse files Browse the repository at this point in the history
Save and reselect recently refreshed plugin
  • Loading branch information
willnationsdev authored Jul 28, 2019
2 parents 09c4032 + f42cb6a commit 47faab6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon_reload_small.svg-2fb3864c9ab2acd4651c8b485b98ddf5.stex"
metadata={
"vram_texture": false
}

[deps]

Expand All @@ -14,6 +17,7 @@ dest_files=[ "res://.import/icon_reload_small.svg-2fb3864c9ab2acd4651c8b485b98dd
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
Expand All @@ -23,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
Expand Down
2 changes: 1 addition & 1 deletion addons/godot-plugin-refresher/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ name="Godot Plugin Refresher"
description="A toolbar addition to facilitate toggling off/on a selected plugin."
author="willnationsdev"
version="1.0"
script="plugin_refresher_plugin.gd"
script="plugin_refresher_plugin.gd"
25 changes: 21 additions & 4 deletions addons/godot-plugin-refresher/plugin_refresher.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
tool
extends HBoxContainer

const ADDONS_PATH = "res://addons/"
const PLUGIN_PATH = "godot-plugin-refresher"

signal request_refresh_plugin(p_name)

onready var options = $OptionButton
Expand All @@ -12,17 +15,31 @@ func reload_items():
if not options:
return
var dir = Directory.new()
dir.change_dir("res://addons/")
dir.change_dir(ADDONS_PATH)
dir.list_dir_begin(true, true)
var file = dir.get_next()
options.clear()
while file:
if dir.dir_exists("res://addons/" + file) and file != "godot-plugin-refresher":
if dir.dir_exists(ADDONS_PATH.plus_file(file)) and file != PLUGIN_PATH:
options.add_item(file)
file = dir.get_next()

func select_plugin(p_name):
if not options:
return
if p_name == null or p_name.empty():
return

for idx in options.get_item_count():
var plugin = options.get_item_text(idx)
if plugin == p_name:
options.selected = options.get_item_id(idx)

func _on_RefreshButton_pressed():
if options.selected == -1:
return # nothing selected

var plugin = options.get_item_text(options.selected)
if not plugin:
if not plugin or plugin.empty():
return
emit_signal("request_refresh_plugin", plugin)
emit_signal("request_refresh_plugin", plugin)
51 changes: 48 additions & 3 deletions addons/godot-plugin-refresher/plugin_refresher_plugin.gd
Original file line number Diff line number Diff line change
@@ -1,28 +1,73 @@
tool
extends EditorPlugin

const PLUGIN_CONFIG_DIR = 'plugins/plugin_refresher'
const PLUGIN_CONFIG = 'settings.cfg'
const SETTINGS = 'settings'
const SETTING_RECENT = 'recently_used'

var plugin_config = ConfigFile.new()

const PluginRefresherScn = preload("plugin_refresher.tscn")

var refresher

func _enter_tree():
refresher = PluginRefresherScn.instance()
add_control_to_container(CONTAINER_TOOLBAR, refresher)

var efs = get_editor_interface().get_resource_filesystem()
efs.connect("filesystem_changed", self, "_on_filesystem_changed")

refresher.connect("request_refresh_plugin", self, "_on_request_refresh_plugin")

_load_settings()

func _exit_tree():
remove_control_from_container(CONTAINER_TOOLBAR, refresher)
refresher.free()

func _load_settings():
var path = get_config_path()

var fs = Directory.new()
if not fs.file_exists(path):
# Create new if running for the first time
var config = ConfigFile.new()
fs.make_dir_recursive(path.get_base_dir())
config.save(path)
else:
plugin_config.load(path)

func _save_settings():
plugin_config.save(get_config_path())

func get_config_path():
var dir = get_editor_interface().get_editor_settings().get_project_settings_dir()
var home = dir.plus_file(PLUGIN_CONFIG_DIR)
var path = home.plus_file(PLUGIN_CONFIG)

return path

func _on_filesystem_changed():
if refresher:
refresher.reload_items()
refresher.select_plugin(get_recent_plugin())

func get_recent_plugin():
if not plugin_config.has_section_key(SETTINGS, SETTING_RECENT):
return null # not saved yet

var recent = plugin_config.get_value(SETTINGS, SETTING_RECENT)
return recent

func _on_request_refresh_plugin(p_name):
print("Refreshing plugin: ", p_name)

assert(not p_name.empty())

get_editor_interface().set_plugin_enabled(p_name, false)
get_editor_interface().set_plugin_enabled(p_name, true)
get_editor_interface().set_plugin_enabled(p_name, true)

plugin_config.set_value(SETTINGS, SETTING_RECENT, p_name)
_save_settings()
5 changes: 5 additions & 0 deletions icon.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}

[deps]

Expand All @@ -14,6 +17,7 @@ dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
Expand All @@ -23,6 +27,7 @@ flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
Expand Down
7 changes: 6 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@

config_version=4

_global_script_classes=[ ]
_global_script_class_icons={

}

[application]

config/name="Godot Plugin Refresher"
config/icon="res://icon.png"

[editor_plugins]

enabled=PoolStringArray( "godot-plugin", "godot-plugin-refresher" )
enabled=PoolStringArray( "godot-plugin-refresher" )

[input]

Expand Down

0 comments on commit 47faab6

Please sign in to comment.