mirror of
https://github.com/Relintai/pandemonium_cms.git
synced 2024-11-12 09:35:02 +01:00
Page entry editing setup.
This commit is contained in:
parent
714b0ab370
commit
b156d2722a
@ -1,7 +1,23 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://Main.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/web_pages/classes/WebPage.gd" type="Script" id=2]
|
||||
[ext_resource path="res://addons/web_pages/classes/post_entries/WebPageEntryTitleText.gd" type="Script" id=3]
|
||||
|
||||
[sub_resource type="Resource" id=1]
|
||||
script = ExtResource( 3 )
|
||||
text = ""
|
||||
hsize = 1
|
||||
|
||||
[sub_resource type="Resource" id=2]
|
||||
script = ExtResource( 3 )
|
||||
text = ""
|
||||
hsize = 1
|
||||
|
||||
[sub_resource type="Resource" id=3]
|
||||
script = ExtResource( 3 )
|
||||
text = ""
|
||||
hsize = 1
|
||||
|
||||
[node name="WebServer" type="WebServerSimple"]
|
||||
script = ExtResource( 1 )
|
||||
@ -15,3 +31,4 @@ data = "<a href=\"/blog\">Blog</a>"
|
||||
[node name="Asdasd" type="WebNode" parent="WebRoot"]
|
||||
uri_segment = "asda"
|
||||
script = ExtResource( 2 )
|
||||
entries = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ) ]
|
||||
|
@ -3,3 +3,52 @@ extends WebNode
|
||||
class_name WebPage, "res://addons/web_pages/icons/icon_web_page.svg"
|
||||
|
||||
export(Array, Resource) var entries : Array
|
||||
|
||||
signal entries_changed()
|
||||
|
||||
func add_entry(var entry : WebPageEntry, var after : WebPageEntry = null) -> void:
|
||||
if after != null:
|
||||
for i in range(entries.size()):
|
||||
if entries[i] == after:
|
||||
entries.insert(i + 1, entry)
|
||||
break
|
||||
else:
|
||||
entries.push_back(entry)
|
||||
|
||||
emit_signal("entries_changed")
|
||||
|
||||
func remove_entry(var entry : WebPageEntry) -> void:
|
||||
entries.erase(entry)
|
||||
|
||||
emit_signal("entries_changed")
|
||||
|
||||
func move_entry_up(var entry : WebPageEntry) -> void:
|
||||
# Skips checking the first entry (1, entries.size())
|
||||
for i in range(1, entries.size()):
|
||||
if entries[i] == entry:
|
||||
entries[i] = entries[i - 1]
|
||||
entries[i - 1] = entry
|
||||
emit_signal("entries_changed")
|
||||
return
|
||||
|
||||
func move_entry_down(var entry : WebPageEntry) -> void:
|
||||
# Skips checking the last entry (size() - 1)
|
||||
for i in range(entries.size() - 1):
|
||||
if entries[i] == entry:
|
||||
entries[i] = entries[i + 1]
|
||||
entries[i + 1] = entry
|
||||
emit_signal("entries_changed")
|
||||
return
|
||||
|
||||
func get_entry_before(var entry : WebPageEntry) -> WebPageEntry:
|
||||
if entries.size() < 2:
|
||||
return null
|
||||
|
||||
if entries[0] == entry:
|
||||
return null
|
||||
|
||||
for i in range(1, entries.size()):
|
||||
if entries[i] == entry:
|
||||
return entries[i - 1]
|
||||
|
||||
return null
|
||||
|
@ -2,5 +2,5 @@ tool
|
||||
extends "res://addons/web_pages/classes/WebPageEntry.gd"
|
||||
class_name WebPageEntryTitleText, "res://addons/web_pages/icons/icon_web_page_entry_title_text.svg"
|
||||
|
||||
export(String) var title_text : String
|
||||
export(String) var text : String
|
||||
export(int) var hsize : int = 1
|
||||
|
@ -3,11 +3,16 @@ extends AcceptDialog
|
||||
|
||||
signal on_entry_class_selected(entry_class)
|
||||
|
||||
var _init : bool = false
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_INSTANCED:
|
||||
get_ok().set_text("Close")
|
||||
|
||||
get_node("HFlowContainer/AddTitleTextButton").connect("pressed", self, "_add_title_text_button_pressed")
|
||||
if what == NOTIFICATION_ENTER_TREE:
|
||||
if !_init:
|
||||
_init = true
|
||||
|
||||
get_ok().set_text("Close")
|
||||
get_node("VBC/AddTitleTextButton").connect("pressed", self, "_add_title_text_button_pressed")
|
||||
|
||||
func _add_title_text_button_pressed() -> void:
|
||||
emit_signal("on_entry_class_selected" , "WebPageEntryTitleText")
|
||||
hide()
|
||||
|
@ -1,7 +1,7 @@
|
||||
tool
|
||||
extends PanelContainer
|
||||
|
||||
var PageEditor : PackedScene = null
|
||||
var WebPageEntryEditor : PackedScene = null
|
||||
|
||||
var _wne_tool_bar_button : Button = null
|
||||
|
||||
@ -11,11 +11,70 @@ var undo_redo : UndoRedo = null
|
||||
var _entry_name_line_edit : LineEdit = null
|
||||
var _uri_segment_line_edit : LineEdit = null
|
||||
var _add_entry_popup : AcceptDialog = null
|
||||
var _entries_container : Control = null
|
||||
|
||||
var _entry_add_after : WebPageEntry = null
|
||||
|
||||
func set_page(page : WebPage):
|
||||
if _page:
|
||||
_page.disconnect("entries_changed", self, "on_page_entries_changed")
|
||||
|
||||
_page = page
|
||||
|
||||
if _page:
|
||||
_page.connect("entries_changed", self, "on_page_entries_changed")
|
||||
|
||||
_entry_name_line_edit.text = page.name
|
||||
_uri_segment_line_edit.text = page.uri_segment
|
||||
|
||||
recreate()
|
||||
|
||||
func recreate() -> void:
|
||||
clear()
|
||||
create_editors()
|
||||
|
||||
func create_editors() -> void:
|
||||
for i in range(_page.entries.size()):
|
||||
var e : WebPageEntry = _page.entries[i]
|
||||
|
||||
if e:
|
||||
var ee : Control = create_editor_for_entry(e)
|
||||
_entries_container.add_child(ee)
|
||||
|
||||
func create_editor_for_entry(entry : WebPageEntry) -> Control:
|
||||
var c : Control = WebPageEntryEditor.instance() as Control
|
||||
c.set_entry(entry, undo_redo)
|
||||
return c
|
||||
|
||||
func clear() -> void:
|
||||
for i in range(_entries_container.get_child_count()):
|
||||
_entries_container.get_child(i).queue_free()
|
||||
|
||||
func add_entry(entry : WebPageEntry, after : WebPageEntry = null) -> void:
|
||||
undo_redo.create_action("Added web page entry")
|
||||
undo_redo.add_do_method(_page, "add_entry", entry, after)
|
||||
undo_redo.add_undo_method(_page, "remove_entry", entry)
|
||||
undo_redo.commit_action()
|
||||
|
||||
func remove_entry(entry : WebPageEntry) -> void:
|
||||
var after : WebPageEntry = _page.get_entry_before(entry)
|
||||
|
||||
undo_redo.create_action("Added web page entry")
|
||||
undo_redo.add_do_method(_page, "remove_entry", entry)
|
||||
undo_redo.add_undo_method(_page, "add_entry", entry, after)
|
||||
undo_redo.commit_action()
|
||||
|
||||
func move_entry_up(entry : WebPageEntry) -> void:
|
||||
undo_redo.create_action("Added web page entry")
|
||||
undo_redo.add_do_method(_page, "move_entry_up", entry)
|
||||
undo_redo.add_undo_method(_page, "move_entry_down", entry)
|
||||
undo_redo.commit_action()
|
||||
|
||||
func move_entry_down(entry : WebPageEntry) -> void:
|
||||
undo_redo.create_action("Added web page entry")
|
||||
undo_redo.add_do_method(_page, "move_entry_down", entry)
|
||||
undo_redo.add_undo_method(_page, "move_entry_up", entry)
|
||||
undo_redo.commit_action()
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_INSTANCED:
|
||||
@ -28,7 +87,12 @@ func _notification(what):
|
||||
_add_entry_popup = get_node("Popups/AddEntryPopup")
|
||||
_add_entry_popup.connect("on_entry_class_selected", self, "_on_add_entry_class_selected")
|
||||
|
||||
PageEditor = ResourceLoader.load("res://addons/web_pages/editor/PageEditor.tscn", "PackedScene") as PackedScene
|
||||
_entries_container = get_node("MC/EntriesContainer/MainVB/Entries")
|
||||
|
||||
var main_add_button : Button = get_node("MC/EntriesContainer/MainVB/MainAddButton")
|
||||
main_add_button.connect("pressed", self, "_on_entry_add_requested")
|
||||
|
||||
WebPageEntryEditor = ResourceLoader.load("res://addons/web_pages/editor/WebPageEntryEditor.tscn", "PackedScene") as PackedScene
|
||||
elif what == NOTIFICATION_ENTER_TREE:
|
||||
var wne : Control = Engine.get_global("WebNodeEditor")
|
||||
if wne:
|
||||
@ -93,5 +157,34 @@ func _edited_node_changed(web_node : WebNode):
|
||||
#add method to switch off to the prev screen
|
||||
#wne.switch_to_main_screen_tab(self)
|
||||
|
||||
func on_page_entries_changed() -> void:
|
||||
recreate()
|
||||
|
||||
func _on_add_entry_class_selected(cls_name : String) -> void:
|
||||
print(cls_name)
|
||||
var entry : WebPageEntry = null
|
||||
|
||||
if cls_name == "WebPageEntryTitleText":
|
||||
entry = WebPageEntryTitleText.new()
|
||||
|
||||
if !entry:
|
||||
PLogger.log_error("PageEditor: Couldn't create entry for: " + cls_name)
|
||||
return
|
||||
|
||||
add_entry(entry, _entry_add_after)
|
||||
|
||||
func _on_entry_add_requested() -> void:
|
||||
_entry_add_after = null
|
||||
_add_entry_popup.popup_centered()
|
||||
|
||||
func _on_entry_add_requested_after(entry) -> void:
|
||||
_entry_add_after = entry
|
||||
_add_entry_popup.popup_centered()
|
||||
|
||||
func _on_entry_move_up_requested(entry) -> void:
|
||||
move_entry_up(entry)
|
||||
|
||||
func _on_entry_move_down_requested(entry) -> void:
|
||||
move_entry_down(entry)
|
||||
|
||||
func _on_entry_delete_requested(entry) -> void:
|
||||
remove_entry(entry)
|
||||
|
@ -61,10 +61,21 @@ margin_bottom = 586.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Entries" type="VBoxContainer" parent="MC/EntriesContainer"]
|
||||
[node name="MainVB" type="VBoxContainer" parent="MC/EntriesContainer"]
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 24.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="MainAddButton" type="Button" parent="MC/EntriesContainer/MainVB"]
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 20.0
|
||||
text = "Add (Bottom)"
|
||||
|
||||
[node name="Entries" type="VBoxContainer" parent="MC/EntriesContainer/MainVB"]
|
||||
margin_top = 24.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 24.0
|
||||
|
||||
[node name="Popups" type="Control" parent="."]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
@ -80,20 +91,20 @@ anchor_bottom = 0.5
|
||||
margin_left = -100.0
|
||||
margin_top = -35.0
|
||||
margin_right = 100.0
|
||||
margin_bottom = 35.0
|
||||
margin_bottom = 31.0
|
||||
window_title = "Add"
|
||||
script = ExtResource( 3 )
|
||||
|
||||
[node name="HFlowContainer" type="HFlowContainer" parent="Popups/AddEntryPopup"]
|
||||
[node name="VBC" type="VBoxContainer" parent="Popups/AddEntryPopup"]
|
||||
margin_left = 8.0
|
||||
margin_top = 8.0
|
||||
margin_right = 192.0
|
||||
margin_bottom = 34.0
|
||||
margin_bottom = 30.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="AddTitleTextButton" type="Button" parent="Popups/AddEntryPopup/HFlowContainer"]
|
||||
margin_right = 89.0
|
||||
[node name="AddTitleTextButton" type="Button" parent="Popups/AddEntryPopup/VBC"]
|
||||
margin_right = 184.0
|
||||
margin_bottom = 22.0
|
||||
text = "Title Text"
|
||||
icon = ExtResource( 2 )
|
||||
|
@ -4,16 +4,30 @@ extends VBoxContainer
|
||||
var _entry : WebPageEntry = null
|
||||
|
||||
var _entry_type_label : Label = null
|
||||
var _main_container : Control = null
|
||||
|
||||
var _editor : Control = null
|
||||
|
||||
var WebPageEntryTitleTextEditor : PackedScene = null
|
||||
|
||||
signal entry_add_requested_after(entry)
|
||||
signal entry_move_up_requested(entry)
|
||||
signal entry_move_down_requested(entry)
|
||||
signal entry_delete_requested(entry)
|
||||
|
||||
func set_entry(entry : WebPageEntry) -> void:
|
||||
func set_entry(entry : WebPageEntry, undo_redo : UndoRedo) -> void:
|
||||
_entry = entry
|
||||
|
||||
_entry_type_label.text = entry.get_class()
|
||||
var cls : String = entry.get_class()
|
||||
_entry_type_label.text = cls
|
||||
|
||||
if cls == "WebPageEntryTitleText":
|
||||
_editor = WebPageEntryTitleTextEditor.instance()
|
||||
|
||||
if _editor:
|
||||
_editor.undo_redo = undo_redo
|
||||
_editor.set_entry(entry)
|
||||
_main_container.add_child(_editor)
|
||||
|
||||
func _on_add_button_pressed():
|
||||
emit_signal("entry_add_requested_after", _entry)
|
||||
@ -29,7 +43,10 @@ func _on_delete_button_pressed():
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_INSTANCED:
|
||||
WebPageEntryTitleTextEditor = ResourceLoader.load("res://addons/web_pages/editor/post_entries/WebPageEntryTitleTextEditor.tscn", "PackedScene")
|
||||
|
||||
_entry_type_label = get_node("PC/VBC/TopBar/EntryTypeLabel")
|
||||
_main_container = get_node("PC/VBC/MainContainer")
|
||||
|
||||
get_node("AddButton").connect("pressed", self, "_on_add_button_pressed")
|
||||
get_node("PC/VBC/TopBar/UpButton").connect("pressed", self, "_on_up_button_pressed")
|
@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/web_pages/editor/PageEntryEditor.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/web_pages/editor/WebPageEntryEditor.gd" type="Script" id=1]
|
||||
|
||||
[node name="Entry" type="VBoxContainer"]
|
||||
margin_right = 1024.0
|
||||
@ -10,13 +10,13 @@ script = ExtResource( 1 )
|
||||
|
||||
[node name="PC" type="PanelContainer" parent="."]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 46.0
|
||||
margin_bottom = 60.0
|
||||
|
||||
[node name="VBC" type="VBoxContainer" parent="PC"]
|
||||
margin_left = 7.0
|
||||
margin_top = 7.0
|
||||
margin_right = 1017.0
|
||||
margin_bottom = 39.0
|
||||
margin_bottom = 53.0
|
||||
|
||||
[node name="TopBar" type="HBoxContainer" parent="PC/VBC"]
|
||||
margin_right = 1010.0
|
||||
@ -51,13 +51,13 @@ margin_top = 24.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 28.0
|
||||
|
||||
[node name="MainContainer" type="MarginContainer" parent="PC/VBC"]
|
||||
[node name="MainContainer" type="PanelContainer" parent="PC/VBC"]
|
||||
margin_top = 32.0
|
||||
margin_right = 1010.0
|
||||
margin_bottom = 32.0
|
||||
margin_bottom = 46.0
|
||||
|
||||
[node name="AddButton" type="Button" parent="."]
|
||||
margin_top = 50.0
|
||||
margin_top = 64.0
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 70.0
|
||||
text = "Add"
|
||||
margin_bottom = 84.0
|
||||
text = "Add Here"
|
@ -0,0 +1,28 @@
|
||||
tool
|
||||
extends MarginContainer
|
||||
|
||||
var _entry : WebPageEntryTitleText = null
|
||||
var undo_redo : UndoRedo = null
|
||||
|
||||
var _line_edit : LineEdit = null
|
||||
|
||||
func set_entry(entry : WebPageEntryTitleText, pundo_redo : UndoRedo) -> void:
|
||||
undo_redo = pundo_redo
|
||||
|
||||
_entry = entry
|
||||
|
||||
_line_edit.text = _entry.text
|
||||
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_INSTANCED:
|
||||
_line_edit = get_node("LineEdit")
|
||||
|
||||
_line_edit.connect("text_entered", self, "_on_line_edit")
|
||||
|
||||
func _on_line_edit(text : String) -> void:
|
||||
undo_redo.create_action("Page title text changed")
|
||||
undo_redo.add_do_property(_entry, "text", text)
|
||||
undo_redo.add_undo_property(_entry, "text", _entry.text)
|
||||
undo_redo.add_do_property(_line_edit, "text", text)
|
||||
undo_redo.add_undo_property(_line_edit, "text", _entry.text)
|
||||
undo_redo.commit_action()
|
@ -0,0 +1,12 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/web_pages/editor/post_entries/WebPageEntryTitleTextEditor.gd" type="Script" id=1]
|
||||
|
||||
[node name="WebPageEntryTitleTextEditor" type="MarginContainer"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="."]
|
||||
margin_right = 1024.0
|
||||
margin_bottom = 600.0
|
Loading…
Reference in New Issue
Block a user