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

Implement module add operation #337

Closed
github-actions bot opened this issue Oct 12, 2021 · 0 comments
Closed

Implement module add operation #337

github-actions bot opened this issue Oct 12, 2021 · 0 comments
Labels

Comments

@github-actions
Copy link

Implement module add operation

; TODO: Implement module add operation

class ManageModulesWindow extends ManageWindowBase {
    listViewColumns := Array("NAME", "ENABLED", "SOURCE", "VERSION")
    moduleManager := ""
    needsRestart := false

    __New(container, themeObj, config) {
        this.moduleManager := container.Get("ModuleManager")
        this.lvCount := this.moduleManager.Count(true)
        Debugger().Inspect(container.GetParameter("module"))
        super.__New(container, themeObj, config)
    }

    GetDefaultConfig(container, config) {
        defaults := super.GetDefaultConfig(container, config)
        defaults["title"] := "Manage Modules"
        defaults["modules_file"] := container.Get("Config")["modules_file"]
        return defaults
    }

    AddBottomControls(y) {
        position := "x" . this.margin . " y" . y
        this.AddManageButton("AddButton", position, "add", true)
    }

    GetListViewData(lv) {
        data := Map()

        for name, module in this.moduleManager.All("", false, true) {
            enabledText := module.IsEnabled() ? "Yes" : "No"
            data[name] := [name, enabledText, module.GetVersion()]
        }

        return data
    }

    ShouldHighlightRow(key, data) {
        return false
    }

    GetViewMode() {
        return this.app.Config["modules_view_mode"]
    }

    GetListViewImgList(lv, large := false) {
        IL := IL_Create(this.lvCount, 1, large)
        defaultIcon := this.themeObj.GetIconPath("Module")
        iconNum := 1

        for key, module in this.moduleManager.All("", false, true) {
            iconSrc := module.GetModuleIcon()

            if (!iconSrc or !FileExist(iconSrc)) {
                iconSrc := defaultIcon
            }

            IL_Add(IL, iconSrc)
            iconNum++
        }

        return IL
    }

    OnDoubleClick(LV, rowNum) {
        key := this.listView.GetRowKey(rowNum)
        this.ConfigureModule(key)
    }

    EnableModule(key) {
        this.moduleManager.EnableModule(key)
        this.needsRestart := true
        this.UpdateListView()
    }

    DisableModule(key) {
        this.moduleManager.DisableModule(key)
        this.needsRestart := true
        this.UpdateListView()
    }

    ConfigureModule(key) {
        modified := false
        obj := this.moduleManager[key]

        ; TODO: Implement module edit operation here

        if (modified) {
            this.needsRestart := true
            this.UpdateListView()
        }
    }

    DeleteModule(key) {
        if (this.moduleManager.DeleteModule(key)) {
            this.needsRestart := true
            this.UpdateListView()
        }
    }

    OnAddButton(btn, info) {
        this.AddModule()
    }

    AddModule() {
        ; TODO: Implement module add operation
        Run("https://github.com/topics/launchpad-module")
    }

    OnSize(guiObj, minMax, width, height) {
        super.OnSize(guiObj, minMax, width, height)
        
        if (minMax == -1) {
            return
        }

        this.AutoXYWH("y", ["AddButton"])
    }

    ShowListViewContextMenu(lv, item, isRightClick, X, Y) {
        key := this.listView.GetRowKey(item)
        module := this.moduleManager[key]

        menuItems := []

        if (module.IsEnabled()) {
            menuItems.Push(Map("label", "Disable", "name", "DisableModule"))
        } else {
            menuItems.Push(Map("label", "Enable", "name", "EnableModule"))
        }

        menuItems.Push(Map("label", "Configure", "name", "ConfigureModule"))

        if (!module.IsCore()) {
            menuItems.Push(Map("label", "Delete", "name", "DeleteModule"))
        }

        result := this.app.Service("GuiManager").Menu(menuItems, this)

        if (result == "EnableModule") {
            this.EnableModule(key)
        } else if (result == "DisableModule") {
            this.DisableModule(key)
        } else if (result == "ConfigureModule") {
            this.ConfigureModule(key)
        } else if (result == "DeleteModule") {
            this.DeleteModule(key)
        }
    }
}

ed83ae6aac6dc81f6c2caeee1d47dc238f19a531

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant