Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearrange Plugin Loading and SDL Initialization #1881

Open
wants to merge 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d5940b6
Initial commit to clean up projects; spun off find-file to its own pl…
adamharrison Apr 1, 2023
2f4aff1
Bump modversion.
adamharrison Jun 22, 2024
a716131
Bumped modversion and changed a few minor things.
adamharrison Jun 22, 2024
f2fd9ba
Added in handling of ignored files.
adamharrison Jun 22, 2024
0350614
Fixed small issue.
adamharrison Jun 27, 2024
3cc4543
Fixed issue with absolute arguments.
adamharrison Jul 5, 2024
9e2ec1b
Removed home encoding; may revert this if I can find out why it was d…
adamharrison Jul 7, 2024
9c05676
Fixed minor issue with file suggestions.
adamharrison Aug 22, 2024
0303199
Cleaned up treeview.
adamharrison Aug 22, 2024
41f8206
Typo.
adamharrison Aug 22, 2024
59650ec
Added in visible.
adamharrison Aug 23, 2024
056a2cb
Ensured that the appropriate project module is loaded.
adamharrison Sep 10, 2024
975e416
Fixed improper rebase.
adamharrison Sep 10, 2024
17a3503
Abstracted out the storage system of the workspace plugin so other pl…
adamharrison Mar 6, 2024
3de9036
Fixed double return.
adamharrison Mar 6, 2024
a8fce83
Fixed functional issue.
adamharrison Mar 6, 2024
11af515
Added documentation.
adamharrison Apr 3, 2024
b84738f
Sumenko reports duplicate function definitions, unsure why.
adamharrison Apr 3, 2024
d5dbfad
Fixed minor bug with workspace.
adamharrison Sep 28, 2024
7be990f
Fixed switching projects on restart.
adamharrison Oct 9, 2024
f2a66b4
Merge branch 'master' into PR/project-rework
adamharrison Oct 22, 2024
00d708c
Harmonized spacing around asserts, and fixed an issue forgetting to s…
adamharrison Nov 3, 2024
86388a6
Made project an object.
adamharrison Nov 3, 2024
62bc82e
Removing unecessary yields.
adamharrison Nov 3, 2024
28b7029
Removed unecessary fallback.
adamharrison Nov 3, 2024
fed7967
Removed unecessary line.
adamharrison Nov 3, 2024
64b5f57
Reveted backslash handling, as it doesn't seem to make any difference.
adamharrison Nov 3, 2024
8e0ae38
Spacing.
adamharrison Nov 3, 2024
320695c
Only stonks.
adamharrison Nov 3, 2024
19046d0
Removed uneeded error handling.
adamharrison Nov 3, 2024
fef8f81
Added in function to determine project by path, and added in deprecat…
adamharrison Nov 3, 2024
dcb0ee6
Merge branch 'master' into PR/project-rework
adamharrison Nov 3, 2024
0bb8d7e
Removed storage module.
adamharrison Nov 3, 2024
283b0ae
Typo.
adamharrison Nov 3, 2024
0a3b440
Changed to use deprecation log instead of regular warn so as to not s…
adamharrison Nov 27, 2024
10f2ab9
Fixed small bug with saving workspaces on project change.
adamharrison Nov 27, 2024
b20a85c
Revert "Removed storage module."
adamharrison Nov 3, 2024
84d62d2
Initial commit.
adamharrison Sep 15, 2024
2b2a009
Moved around plugin initialization.
adamharrison Sep 16, 2024
9491db9
Fixing restarting when changing projects.
adamharrison Sep 16, 2024
e1f5d69
Added in autorestart plugin.
adamharrison Sep 16, 2024
dbb75bf
Moved screensaver call to after video subsystem init.
adamharrison Sep 16, 2024
cc1d209
Fixed minor issue.
adamharrison Sep 16, 2024
154d1d1
Missing extension.
adamharrison Sep 16, 2024
0f7c3dc
Kept initailization of previous_find and previous_replace.
adamharrison Sep 16, 2024
d7b15e8
Allowed priority regex to take a decimal place.
adamharrison Sep 16, 2024
a2ac9f6
Fixed priority regex.
adamharrison Sep 16, 2024
18382f6
Fixed version mismatch error.
adamharrison Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Abstracted out the storage system of the workspace plugin so other pl…
…ugins can use it.
  • Loading branch information
adamharrison committed Sep 16, 2024
commit 17a3503e7161173f00926722b1de4bc07e301e01
51 changes: 51 additions & 0 deletions data/core/storage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- Provides persistent storage between restarts of the application.
local common = require "core.common"
local storage = {}

local function module_key_to_path(module, key)
return USERDIR .. PATHSEP .. "storage" .. (module and (PATHSEP .. module .. (key and (PATHSEP .. key:gsub("[\\/]", "-")) or "")) or "")
end

function storage.load(module, key)
local path = module_key_to_path(module, key)
if system.get_file_info(path) then
local func, err = loadfile(path)
if func then
return func()
else
core.error("error loading storage file for %s[%s]: %s", module, key, err)
end
end
return nil
end

function storage.save(module, key, t)
local path = module_key_to_path(module, key)
local dir = common.dirname(path)
if not system.get_file_info(dir) then
local status, err = common.mkdirp(dir)
if not status then
core.error("error creating storage directory for %s at %s: %s", module, dir, err)
end
end
local f, err = io.open(path, "wb")
if f then
f:write("return " .. common.serialize(t))
f:flush()
else
core.error("error opening storage file %s for writing: %s", path, err)
end
end

function storage.keys(module)
return system.list_dir(module_key_to_path(module))
end

function storage.clear(module, key)
local path = module_key_to_path(module, key)
if system.get_file_info(path) then
common.rm(path, true)
end
end

return storage
69 changes: 26 additions & 43 deletions data/plugins/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,37 @@ local core = require "core"
local common = require "core.common"
local DocView = require "core.docview"
local LogView = require "core.logview"
local storage = require "core.storage"

local STORAGE_MODULE = "ws"

local function workspace_files_for(project_dir)
local function workspace_keys_for(project_dir)
local basename = common.basename(project_dir)
local workspace_dir = USERDIR .. PATHSEP .. "ws"
local info_wsdir = system.get_file_info(workspace_dir)
if not info_wsdir then
local ok, err = system.mkdir(workspace_dir)
if not ok then
error("cannot create workspace directory: \"" .. err .. "\"")
end
end
return coroutine.wrap(function()
local files = system.list_dir(workspace_dir) or {}
local n = #basename
for _, file in ipairs(files) do
if file:sub(1, n) == basename then
local id = tonumber(file:sub(n + 1):match("^-(%d+)$"))
for _, key in ipairs(storage.keys(STORAGE_MODULE) or {}) do
if key:sub(1, #basename) == basename then
local id = tonumber(key:sub(#basename + 1):match("^-(%d+)$"))
if id then
coroutine.yield(workspace_dir .. PATHSEP .. file, id)
coroutine.yield(key, id)
end
end
end
end)
end


local function consume_workspace_file(project_dir)
for filename, id in workspace_files_for(project_dir) do
local load_f = loadfile(filename)
local function consume_workspace(project_dir)
for key, id in workspace_keys_for(project_dir) do
local load_f = load(storage.load(STORAGE_MODULE, key))
local workspace = load_f and load_f()
if workspace and workspace.path == project_dir then
os.remove(filename)
storage.clear(STORAGE_MODULE, key)
return workspace
end
end
end


local function get_workspace_filename(project_dir)
local id_list = {}
for filename, id in workspace_files_for(project_dir) do
id_list[id] = true
end
local id = 1
while id_list[id] do
id = id + 1
end
local basename = common.basename(project_dir)
return USERDIR .. PATHSEP .. "ws" .. PATHSEP .. basename .. "-" .. tostring(id)
end


local function has_no_locked_children(node)
if node.locked then return false end
if node.type == "leaf" then return true end
Expand Down Expand Up @@ -166,7 +144,7 @@ local function load_node(node, t)
active_view = view
end
if not view:is(DocView) then
view.scroll = v.scroll
view.scroll = v.scroll
end
end
end
Expand Down Expand Up @@ -195,20 +173,25 @@ end


local function save_workspace()
local root = get_unlocked_root(core.root_view.root_node)
local workspace_filename = get_workspace_filename(core.root_project().path)
local fp = io.open(workspace_filename, "w")
if fp then
local node_text = common.serialize(save_node(root))
local dir_text = common.serialize(save_directories())
fp:write(string.format("return { path = %q, documents = %s, directories = %s }\n", core.root_project().path, node_text, dir_text))
fp:close()
local project_dir = common.basename(core.root_project().path)
local id_list = {}
for filename, id in workspace_keys_for(project_dir) do
id_list[id] = true
end
local id = 1
while id_list[id] do
id = id + 1
end
local root = get_unlocked_root(core.root_view.root_node)
local node_text = common.serialize(save_node(root))
local dir_text = common.serialize(save_directories())

storage.save(STORAGE_MODULE, project_dir .. "-" .. id, string.format("return { path = %q, documents = %s, directories = %s }\n", core.project_dir, node_text, dir_text))
end


local function load_workspace()
local workspace = consume_workspace_file(core.root_project().path)
local workspace = consume_workspace(core.root_project().path)
if workspace then
local root = get_unlocked_root(core.root_view.root_node)
local active_view = load_node(root, workspace.documents)
Expand Down