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

feat: enable and disable plugins at will! #243

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
dcc3a5e
feat: enable and disable plugins at will!
thennothinghappened Jan 17, 2025
66d7532
fix: de-register plugin on reload
thennothinghappened Jan 17, 2025
9c90cb3
fix(plugin): clean up prefs load listener in `docs-tooltip`
thennothinghappened Jan 17, 2025
73f43cf
fix(plugin) `docs-tooltips` restore og when cleaned up
thennothinghappened Jan 17, 2025
7d7c77f
feat: `buildPreferences` method on `PluginData`
thennothinghappened Jan 17, 2025
fb3c7cb
fix: hide disabled plugin styles instead of remove
thennothinghappened Jan 17, 2025
8470442
feat(outline-view): implement clean-up
thennothinghappened Jan 17, 2025
b0314c5
feat(docs-tooltips): implement clean-up
thennothinghappened Jan 17, 2025
6cde91c
fix(docs-tooltips): redundant `enabled` preference
thennothinghappened Jan 17, 2025
e57ce6d
refactor: `isEnabled(pluginName)` is clearer
thennothinghappened Jan 17, 2025
5a8419f
feat: way to de-register file kinds
thennothinghappened Jan 17, 2025
9358c77
fix(image-viewer): deregister image types on cleanup
thennothinghappened Jan 17, 2025
212ff7b
refactor(image-viewer): remove dependency on Haxe `$extend`
thennothinghappened Jan 17, 2025
c72ec3d
fix: close tabs of de-registered file types
thennothinghappened Jan 17, 2025
43dbe24
fix(ini-editor): deregister types on clean-up
thennothinghappened Jan 17, 2025
65e2bef
refactor: init plugin API separately to loading plugins
thennothinghappened Jan 17, 2025
97aaad0
Merge remote-tracking branch 'upstream/master' into toggle-plugins
thennothinghappened Jan 17, 2025
2738c4f
fix: ensure project exists before plugins start
thennothinghappened Jan 17, 2025
7d7eb69
feat: enable/disable dependency chains
thennothinghappened Jan 18, 2025
0f6cee5
refactor: nicer naming of vars
thennothinghappened Jan 18, 2025
ea96699
refactor: clear separation of dir & registry plugin names
thennothinghappened Jan 18, 2025
a301415
refactor: remove redundant `pluginList`
thennothinghappened Jan 18, 2025
efba7d5
refactor: make `PluginManager.load` private
thennothinghappened Jan 18, 2025
1db595b
refactor: load plugin config sep. to loading plugin itself
thennothinghappened Jan 18, 2025
b7e3be8
fix: resolve plugin deps by registry name, not dir name
thennothinghappened Jan 18, 2025
fe9b3de
fix: revert `PluginState.path` to `PluginState.dir`
thennothinghappened Jan 18, 2025
22e1a0f
fix: handle toggling of plugins in UI that cannot be cleaned up
thennothinghappened Jan 18, 2025
7382e64
fix: don't redundantly say plugin name twice in errors
thennothinghappened Jan 18, 2025
83e86dc
refactor: only call plugin start/stop in correct state
thennothinghappened Jan 18, 2025
5dd67d8
fix: stop listening to script state after promise resolves
thennothinghappened Jan 18, 2025
c7fe8a8
feat: still show plugins that completely failed to load
thennothinghappened Jan 18, 2025
9e2be8b
fix: `script.onerror` is a lie apparently?
thennothinghappened Jan 18, 2025
4861929
Revert "fix: `script.onerror` is a lie apparently?"
thennothinghappened Jan 18, 2025
2db2d53
refactor: naming consistency for `ArrayTools`
thennothinghappened Jan 18, 2025
b041b2d
refactor: don't use reflection for `ArrayTools.flatMap`
thennothinghappened Jan 18, 2025
b192f2a
style: arrow functions do exist apparently!
thennothinghappened Jan 18, 2025
cc0882b
fix: invalid json parse should not discard error
thennothinghappened Jan 18, 2025
9ffebe0
style: knew there was another pesky arrow function candidate
thennothinghappened Jan 18, 2025
dfdc923
style: and another arrow func!
thennothinghappened Jan 18, 2025
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
40 changes: 16 additions & 24 deletions bin/resources/app/plugins/docs-tooltips/docs-tooltips.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
(() => {
const Preferences = $gmedit['ui.Preferences'];

const Project = $gmedit['gml.Project'];

const state = {
enabled: true,
strictLatest: false,
keys: []
};

const ogSetText = aceEditor.tooltipManager.ttip.setText;

GMEdit.register('docs-tooltips', {
init: () => {

downloadLatestDocs();

if (!Preferences.current.docs_tooltips) Preferences.current.docs_tooltips = {
enabled: true,
strictLatest: false,
keys: []
};

state.enabled = Preferences.current.docs_tooltips.enabled;
state.strictLatest = Preferences.current.docs_tooltips.strictLatest;
state.keys = Preferences.current.docs_tooltips.keys;

const ogSetText = aceEditor.tooltipManager.ttip.setText;
aceEditor.tooltipManager.ttip.setText = function() {
if (!state.enabled
|| (state.strictLatest && $gmedit['gml.Project'].current.version.name != 'v23')
|| state.keys == null
) {
if ((state.strictLatest && !Project.current.isGMS23) || state.keys == null) {
ogSetText.apply(this, arguments);
return;
}
Expand All @@ -52,23 +49,18 @@
}
}
},
cleanup: () => {}
});

GMEdit.on('preferencesBuilt', function(e) {
var out = e.target.querySelector('.plugin-settings[for="docs-tooltips"]');
cleanup: () => {
aceEditor.tooltipManager.ttip.setText = ogSetText;
},
buildPreferences: (out) => {

Preferences.addCheckbox(out, 'Enabled', state.enabled, () => {
state.enabled = !state.enabled;
Preferences.current.docs_tooltips.enabled = state.enabled;
Preferences.save();
});
Preferences.addCheckbox(out, 'Disable for non GMS2.3+ projects', state.strictLatest, () => {
state.strictLatest = !state.strictLatest;
Preferences.current.docs_tooltips.strictLatest = state.strictLatest;
Preferences.save();
});

Preferences.addCheckbox(out, 'Disable for non GMS2.3+ projects', state.strictLatest, () => {
state.strictLatest = !state.strictLatest;
Preferences.current.docs_tooltips.strictLatest = state.strictLatest;
Preferences.save();
});
}
});

function downloadLatestDocs() {
Expand Down
91 changes: 51 additions & 40 deletions bin/resources/app/plugins/image-viewer/image-viewer.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
(function() {
//
var Panner = $gmedit["editors.Panner"];
var Editor = $gmedit["editors.Editor"];
function ImageViewer(file) {
Editor.call(this, file);
this.element = document.createElement("div");
this.element.classList.add("resinfo");
this.element.classList.add("sprite");
//
var panner = null;
var pandiv = document.createElement("div");
this.element.appendChild(pandiv);
//
var image = document.createElement("img");
image.onload = function(_) {
panner.recenter();
};
pandiv.appendChild(image);
this.image = image;
//
panner = new Panner(pandiv, image);
this.panner = panner;
}
ImageViewer.prototype = GMEdit.extend(Editor.prototype, {
load: function(data) {
const Panner = $gmedit["editors.Panner"];
const Editor = $gmedit["editors.Editor"];
const FileKind = $gmedit["file.FileKind"];

class ImageViewer extends Editor {

constructor(file) {

super(file);

this.element = document.createElement("div");
this.element.classList.add("resinfo");
this.element.classList.add("sprite");
//
var panner = null;
var pandiv = document.createElement("div");
this.element.appendChild(pandiv);
//
var image = document.createElement("img");
image.onload = function(_) {
panner.recenter();
};
pandiv.appendChild(image);
this.image = image;
//
panner = new Panner(pandiv, image);
this.panner = panner;

}

load(_) {
this.image.src = this.file.path;
}
});
//
var FileKind = $gmedit["file.FileKind"];
function KImage() {
FileKind.call(this);

}
KImage.prototype = GMEdit.extend(FileKind.prototype, {
init: function(file, data) {

class KImage extends FileKind {

static inst = new KImage();

init(file, _) {
file.editor = new ImageViewer(file);
}
});
//

}

GMEdit.register("image-viewer", {
init: function() {
var kimg = new KImage();
FileKind.register("png", kimg);
FileKind.register("jpg", kimg);
FileKind.register("jpeg", kimg);
FileKind.register("gif", kimg);
FileKind.register("bmp", kimg);
FileKind.register("png", KImage.inst);
FileKind.register("jpg", KImage.inst);
FileKind.register("jpeg", KImage.inst);
FileKind.register("gif", KImage.inst);
FileKind.register("bmp", KImage.inst);
},
cleanup: function() {
// todo
FileKind.deregister("png", KImage.inst);
FileKind.deregister("jpg", KImage.inst);
FileKind.deregister("jpeg", KImage.inst);
FileKind.deregister("gif", KImage.inst);
FileKind.deregister("bmp", KImage.inst);
}
});
})();
12 changes: 9 additions & 3 deletions bin/resources/app/plugins/ini-editor/ini-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,19 @@
KIni.prototype = GMEdit.extend(KCode.prototype, {
// we don't need to override anything if it's pure code
});
//

var kini = new KIni();

GMEdit.register("ini-editor", {
init: function() {
var kini = new KIni();
init: () => {
FileKind.register("ini", kini);
FileKind.register("cfg", kini);
FileKind.register("conf", kini);
},
cleanup: () => {
FileKind.deregister("ini", kini);
FileKind.deregister("cfg", kini);
FileKind.deregister("conf", kini);
}
});
})();
136 changes: 78 additions & 58 deletions bin/resources/app/plugins/outline-view/outline-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,55 +700,85 @@

}

function init() {
AceCommands.add({
name: "toggleOutlineView",
//bindKey: "Ctrl-Shift-O", // if you'd like
exec: function(editor) {
toggle();
var currPrefs = FileWrap.readConfigSync("config", Preferences.path);
if (currPrefs) {
var currOV = currPrefs.outlineView;
if (currOV == null) currOV = currPrefs.outlineView = {};
currOV.hide = !visible;
FileWrap.writeConfigSync("config", Preferences.path, currPrefs);
function opt(ov, name, def) {
if (!ov) return def;
var val = ov[name];
return val !== undefined ? val : def;
}

function getDisplayMode(currOV) {
var dm = opt(currOV, "displayMode", null);
if (dm == null) dm = opt(currOV, "currOnly", false) ? 0 : 1;
return dm;
}

var toggleOutlineViewCommand;
var toggleOutlineViewPaletteCommand;

var currPrefs = Preferences.current;
var currOV = currPrefs.outlineView;

function prepareOV() {
currOV = Preferences.current.outlineView;
if (!currOV) currOV = Preferences.current.outlineView = {};
return currOV;
}

GMEdit.register("outline-view", {
init: () => {

toggleOutlineViewCommand = {
name: "toggleOutlineView",
//bindKey: "Ctrl-Shift-O", // if you'd like
exec: function(editor) {
toggle();
var currPrefs = FileWrap.readConfigSync("config", Preferences.path);
if (currPrefs) {
currOV = currPrefs.outlineView;
if (currOV == null) currOV = currPrefs.outlineView = {};
currOV.hide = !visible;
FileWrap.writeConfigSync("config", Preferences.path, currPrefs);
}
}
};

toggleOutlineViewPaletteCommand = {
name: "Toggle outline view",
exec: "toggleOutlineView",
title: ""
};

AceCommands.add(toggleOutlineViewCommand);
AceCommands.addToPalette(toggleOutlineViewPaletteCommand);

setDisplayMode(getDisplayMode(currOV))
showAtTop = opt(currOV, "showAtTop", true);
showFuncArgs = opt(currOV, "showFuncArgs", true);

GMEdit.on("fileRename", onFileRename);

if (!(currOV && currOV.hide)) {
toggle();
}
});
AceCommands.addToPalette({
name: "Toggle outline view",
exec: "toggleOutlineView",
title: ""
});
//
var currPrefs = Preferences.current;
var currOV = currPrefs.outlineView;
function opt(ov, name, def) {
if (!ov) return def;
var val = ov[name];
return val !== undefined ? val : def;
}
function prepareOV() {
var currOV = Preferences.current.outlineView;
if (!currOV) currOV = Preferences.current.outlineView = {};
return currOV;
}
if (!(currOV && currOV.hide)) toggle();
function getDisplayMode(currOV) {
var dm = opt(currOV, "displayMode", null);
if (dm == null) dm = opt(currOV, "currOnly", false) ? 0 : 1;
return dm;
}
setDisplayMode(getDisplayMode(currOV))
showAtTop = opt(currOV, "showAtTop", true);
showFuncArgs = opt(currOV, "showFuncArgs", true);
//
GMEdit.on("preferencesBuilt", function(e) {
var out = e.target.querySelector('.plugin-settings[for="outline-view"]');
var currOV = Preferences.current.outlineView;

},
cleanup: function() {

AceCommands.remove(toggleOutlineViewCommand);
AceCommands.removeFromPalette(toggleOutlineViewPaletteCommand);

GMEdit.off("fileRename", onFileRename);

if (visible) {
toggle();
}

},
buildPreferences: (out) => {
currOV = Preferences.current.outlineView;
var hideCtr = Preferences.addCheckbox(out, "Hide", currOV && currOV.hide, function(val) {
toggle();
var currOV = prepareOV();
currOV = prepareOV();
currOV.hide = !visible;
Preferences.save();
});
Expand All @@ -761,37 +791,27 @@
];
Preferences.addDropdown(out, "Display mode", displayModes[getDisplayMode(currOV)], displayModes, function(val) {
var i = displayModes.indexOf(val);
var currOV = prepareOV();
currOV = prepareOV();
currOV.displayMode = i;
setDisplayMode(i);
Preferences.save();
toggle_sync();
forceRefresh();
})
Preferences.addCheckbox(out, "Show 2.3 function arguments", opt(currOV, "showFuncArgs", true), function(val) {
var currOV = prepareOV();
currOV = prepareOV();
showFuncArgs = currOV.showFuncArgs = val;
currEl = null;
Preferences.save();
forceRefresh();
});
Preferences.addCheckbox(out, "Scroll to top upon navigation", opt(currOV, "showAtTop", true), function(val) {
var currOV = prepareOV();
currOV = prepareOV();
showAtTop = currOV.showAtTop = val;
currEl = null;
Preferences.save();
forceRefresh();
});
});

GMEdit.on("fileRename", onFileRename);

}

GMEdit.register("outline-view", {
init: init,
cleanup: function() {
// todo
},
_modeMap: modeMap
});
Expand Down
9 changes: 5 additions & 4 deletions src/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,18 @@ class Main {
ProjectStyle.init();
FileDrag.init();
ChromeTabs.init();
PluginManager.initApi();
Project.init();
aceEditor.statusBar.update();
Project.nameNode.innerText = "Loading project...";
Project.openInitialProject();
Project.nameNode.innerText = "Loading plugins...";
plugins.PluginManager.init(function() {
Project.nameNode.innerText = "Loading project...";
Project.openInitialProject();
PluginManager.loadInstalledPlugins().then(function(_) {
#if lwedit
aceEditor.session = WelcomePage.init(aceEditor);
LiveWeb.init();
#end
PluginManager.dispatchInitCallbacks();
PluginManager.startPlugins();
});
Console.log("hello!");
StartupTests.main();
Expand Down
Loading