<commit_before>---@module fimbul.gtk.mainwindow

local mainwindow = {}

local base = _G
local table = require("table")

local lgi = require("lgi")
local Gtk = lgi.require("Gtk", "3.0")

local console_page = require("fimbul.gtk.mainwindow.console_page")
local party_page = require("fimbul.gtk.mainwindow.party_page")

function mainwindow:_emit(f)
   for _, p in base.pairs(self.pages) do
      local event = p["on_" .. f]
      if event ~= nil and type(event) == 'function' then
         event(p)
      end
   end
end

function mainwindow:_file_open()
   dlg = Gtk.FileChooserDialog(
      { title = "Open repository...",
        action = Gtk.FileChooserAction.SELECT_FOLDER,
        transient_for = self.wnd,
        destroy_with_parent = true,
        buttons = {
           { "Open", Gtk.ResponseType.ACCEPT },
           { Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL },
        },
   })

   res = dlg:run()
   if res == Gtk.ResponseType.ACCEPT then
      ok, err = pcall(self.repository.open, self.repository, dlg:get_filename())

      if not ok then
         self.console:error(err);
      else
         self:_emit("repository_open")
      end
   end
   dlg:destroy()
end

function mainwindow:_setup()
   self.wnd = Gtk.Window({
         title = 'Fimbul',
         on_destroy = Gtk.main_quit
   })
   self.wnd:set_size_request(600, 400)

   self.menubar = Gtk.MenuBar(
      {
         id = "menubar",
         Gtk.MenuItem {
            label = "File",
            visible = true,
            submenu = Gtk.Menu {
               Gtk.MenuItem {
                  label = "Open...",
                  id = "file_open",
                  on_activate = function () self:_file_open() end
               },
               Gtk.SeparatorMenuItem(),
               Gtk.MenuItem {
                  label = "Quit",<commit_msg>Load repository too instead of just opening it.<commit_after>---@module fimbul.gtk.mainwindow

local mainwindow = {}

local base = _G
local table = require("table")

local lgi = require("lgi")
local Gtk = lgi.require("Gtk", "3.0")

local console_page = require("fimbul.gtk.mainwindow.console_page")
local party_page = require("fimbul.gtk.mainwindow.party_page")

function mainwindow:_emit(f)
   for _, p in base.pairs(self.pages) do
      local event = p["on_" .. f]
      if event ~= nil and type(event) == 'function' then
         event(p)
      end
   end
end

function mainwindow:_file_open()
   dlg = Gtk.FileChooserDialog(
      { title = "Open repository...",
        action = Gtk.FileChooserAction.SELECT_FOLDER,
        transient_for = self.wnd,
        destroy_with_parent = true,
        buttons = {
           { "Open", Gtk.ResponseType.ACCEPT },
           { Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL },
        },
   })

   res = dlg:run()
   if res == Gtk.ResponseType.ACCEPT then
      ok, err = pcall(self.repository.open, self.repository, dlg:get_filename())

      if not ok then
         self.console:error(err);
      else
         -- Load repository
         ok, err = pcall(self.repository.load, self.repository)
         if not ok then
            self.console:error(err)
         else
            self:_emit("repository_open")
         end
      end
   end
   dlg:destroy()
end

function mainwindow:_setup()
   self.wnd = Gtk.Window({
         title = 'Fimbul',
         on_destroy = Gtk.main_quit
   })
   self.wnd:set_size_request(600, 400)

   self.menubar = Gtk.MenuBar(
      {
         id = "menubar",
         Gtk.MenuItem {
            label = "File",
            visible = true,
            submenu = Gtk.Menu {
               Gtk.MenuItem {
                  label = "Open...",
                  id = "file_open",
                  on_activate = function () self:_file_open() end
               },
               Gtk.SeparatorMenuItem(),
               Gtk.MenuItem {
                  label = "Quit",
{'fraction_non_alphanumeric': 0.1195539419087137, 'fraction_numerical': 0.004149377593360996, 'mean_word_length': 1.9442748091603053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2327742', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1213, 'n_words': 257}