diff --git a/data/xyz.trollcall.Beekeeper.gschema.xml b/data/xyz.trollcall.Beekeeper.gschema.xml index bd98d09..0bd0d47 100644 --- a/data/xyz.trollcall.Beekeeper.gschema.xml +++ b/data/xyz.trollcall.Beekeeper.gschema.xml @@ -1,5 +1,10 @@ - + + + "/" + Current path + The current path Beekeeper looks in. + diff --git a/src/folders.js b/src/folders.js index ee6ad4a..023710e 100644 --- a/src/folders.js +++ b/src/folders.js @@ -1,9 +1,21 @@ import Gtk from 'gi://Gtk'; import Gio from 'gi://Gio'; import GLib from 'gi://GLib'; +import Pango from 'gi://Pango'; + +export function isSamePath(p1, p2) { + const file1 = Gio.File.new_for_path(p1); + const file2 = Gio.File.new_for_path(p2); + return file1.equal(file2); +} export function getFilesInFolder(folderPath) { let folder = Gio.File.new_for_path(folderPath); + while (folder && !folder.query_exists(null)) { + folder = folder.get_parent(); + } + if (folder === null) folder = Gio.File.new_for_path("/"); + settings.set("pathname", "s", folder.get_path()); let files = folder.enumerate_children( "*", Gio.FileQueryInfoFlags.NONE, @@ -14,11 +26,13 @@ export function getFilesInFolder(folderPath) { let fileNames = []; while (file !== null) { - if (file.get_file_type() === Gio.FileType.DIRECTORY) + // if (file.get_file_type() === Gio.FileType.DIRECTORY) fileNames.push({ name: file.get_name(), icon: file.get_icon(), + type: file.get_content_type(), hidden: file.get_is_hidden(), + path: GLib.build_filenamev([folder.get_path(), file.get_name()]), time: (file.get_modification_date_time() ?? file.get_creation_date_time() ?? @@ -64,6 +78,7 @@ export function indexObjects(array) { ellipsize: "end", label: item.name, valign: "baseline", + ellipsize: Pango.EllipsizeMode.END, xalign: 0.0, }); @@ -72,7 +87,7 @@ export function indexObjects(array) { const path = new Gtk.Label({ cssClasses: ["dim-label"], ellipsize: "end", - label: GLib.DateTime.new_from_unix_utc(item.time).format("%x, %X"), + label: `${GLib.DateTime.new_from_unix_utc(item.time).format("%x, %X")} | ${item.type}`, valign: "baseline", xalign: 0.0, }); diff --git a/src/gtk/modal.ui b/src/gtk/modal.ui deleted file mode 100644 index 3c27891..0000000 --- a/src/gtk/modal.ui +++ /dev/null @@ -1,61 +0,0 @@ - - - - - note - True - Cum Balance - header_bar - - - :close - - - - - - 16 - 16 - 16 - 16 - vertical - 8 - center - - - folder - large - - - - - title-2 - Cambalache - - - - - 8 - 8 - - - - - center - 8 - - - circular - center - accessories-calculator - center - - - - - - - - diff --git a/src/main.js b/src/main.js index 20d501f..93e468b 100644 --- a/src/main.js +++ b/src/main.js @@ -32,29 +32,31 @@ export const BeekeeperApplication = GObject.registerClass( super({application_id: 'xyz.trollcall.Beekeeper', flags: Gio.ApplicationFlags.FLAGS_NONE}); const quit_action = new Gio.SimpleAction({name: 'quit'}); - quit_action.connect('activate', action => { + quit_action.connect('activate', action => { this.quit(); }); this.add_action(quit_action); - this.set_accels_for_action('app.quit', ['q']); + this.set_accels_for_action('app.quit', ['q', 'Escape']); const show_about_action = new Gio.SimpleAction({name: 'about'}); show_about_action.connect('activate', action => { - let aboutParams = { - authors: [ - 'MeowcaTheoRange' - ], + const aboutDialog = new Adw.AboutWindow({ + developer_name: 'MeowcaTheoRange', + copyright: '\u00A9 2023 MeowcaTheoRange', version: '0.1.0', - logo_icon_name: 'xyz.trollcall.Beekeeper', + application_icon: 'xyz.trollcall.Beekeeper', license_type: Gtk.License.APACHE_2_0, - program_name: 'Beekeeper', + application_name: 'Beekeeper', transient_for: this.active_window, + website: 'https://trollcall.xyz/', modal: true, - }; - const aboutDialog = new Gtk.AboutDialog(aboutParams); + comments: `Beekeeper is a productive project manager made for easy access to your project directories.` + }); aboutDialog.present(); }); this.add_action(show_about_action); + + this.#loadSettings(); } vfunc_activate() { @@ -65,6 +67,10 @@ export const BeekeeperApplication = GObject.registerClass( active_window.present(); } + + #loadSettings() { + globalThis.settings = new Gio.Settings({ schemaId: this.applicationId }); + } } ); diff --git a/src/style.css b/src/style.css index b3271e3..e656f16 100644 --- a/src/style.css +++ b/src/style.css @@ -1,3 +1,14 @@ #main-button { background-color: @accent_bg_color; + color: @accent_fg_color; +} + +#entry-box { + font-weight: bold; + border-radius: 32px; + transition: background-color 0.25s; +} + +#entry-box:not(:focus-within) { + background-color: transparent; } diff --git a/src/window.js b/src/window.js index a9461c1..9cd1390 100644 --- a/src/window.js +++ b/src/window.js @@ -17,44 +17,114 @@ import GObject from 'gi://GObject'; import Gtk from 'gi://Gtk'; +import Gdk from 'gi://Gdk'; import Gio from 'gi://Gio'; import GLib from 'gi://GLib'; -import { getFilesInFolder, indexObjects } from './folders.js'; +import { getFilesInFolder, indexObjects, isSamePath } from './folders.js'; export const BeekeeperWindow = GObject.registerClass({ GTypeName: 'BeekeeperWindow', Template: 'resource:///xyz/trollcall/Beekeeper/window.ui', - InternalChildren: ['label', 'folders', 'bigBox', 'userName', 'timeThingy'], + InternalChildren: [ + 'userName', + 'timeThingy', + 'holderBox', + 'entryBox', + 'emergencyProp' + ], }, class BeekeeperWindow extends Gtk.ApplicationWindow { - #_folders; - #_bigBox; #_userName; #_timeThingy; + #_entryBox; + #_emergencyProp; + + #bigBox; + #continueLabel; + #folders; + #earlierLabel; _init(application) { super._init({application}) - this._userName.set_text(`Welcome, ${GLib.get_real_name().split(" ")[0]}!`); + this._userName.set_text(`Welcome, ${GLib.get_real_name()}!`); this._timeThingy.set_text(`It is ${GLib.DateTime.new_now_local().format("%X")}.`); setInterval(() => this._timeThingy.set_text(`It is ${GLib.DateTime.new_now_local().format("%X")}.`), 500); - const getModal = (row) => { - let builder = Gtk.Builder.new_from_resource("/xyz/trollcall/Beekeeper/gtk/modal.ui"); - let modalWindow = builder.get_object("modalWindow"); - modalWindow.set_modal(true); - modalWindow.set_transient_for(this); - print(row); - const recommendedTypes = Gio.AppInfo.get_recommended_for_type(row.get_child().get_child_at_index(0).icon_name); - modalWindow.present(); + + settings.bind('pathname', this._entryBox, 'text', Gio.SettingsBindFlags.BIND_SET << Gio.SettingsBindFlags.BIND_GET); + let prev = this._entryBox.text; + this._entryBox.connect("activate", () => { + this.make_window(false, this._entryBox.text, prev); + prev = this._entryBox.text; + }); + this.make_window(true, prev); + } + + make_window(immune, now, prev) { + if (!immune && isSamePath(now, prev)) return; + if (this.bigBox) this._holderBox.remove(this.bigBox); + if (this.continueLabel) this._holderBox.remove(this.continueLabel); + if (this.folders) this._holderBox.remove(this.folders); + if (this.earlierLabel) this._holderBox.remove(this.earlierLabel); + + const launch_shit = (row, offset) => { + console.log(row); + if (row.get_selected_row) row = row.get_selected_row(); + const file = files[row.get_index() + offset]; + + const filetype = Gio.AppInfo.get_default_for_type(file.type, false); + const path = GLib.filename_to_uri(file.path, null); + + if (filetype) filetype.launch_default_for_uri(path); + else Gio.AppInfo.launch_default_for_uri(path, null); } - this._bigBox.connect("row_activated", getModal); - this._folders.connect("row_activated", getModal); + const offset = 3; - let folderPath = "Documents/github/"; - let files = getFilesInFolder(folderPath); - let GtkBoxThings = indexObjects(files); - GtkBoxThings.splice(0, 3).map(x => this._bigBox.append(x)); - GtkBoxThings.map(x => this._folders.append(x)); + const folderPath = now || ""; + const files = getFilesInFolder(folderPath); + const GtkBoxThings = indexObjects(files); + if (GtkBoxThings.length > 0) { + this.continueLabel = new Gtk.Label({ + label: "Continue", + xalign: "0", + css_classes: [ + "heading" + ] + }); + this._holderBox.append(this.continueLabel); + this.bigBox = new Gtk.ListBox({ + name: "main-button", + selection_mode: "single", + css_classes: [ + "boxed-list" + ] + }) + this._holderBox.append(this.bigBox); + this.bigBox.connect("row-activated", (l, r) => launch_shit(r, 0)); + GtkBoxThings.splice(0, offset).map(x => this.bigBox.append(x)); + } + if (GtkBoxThings.length > 0) { + this.earlierLabel = new Gtk.Label({ + label: "Earlier", + xalign: "0", + css_classes: [ + "heading" + ] + }); + this._holderBox.append(this.earlierLabel); + this.folders = new Gtk.ListBox({ + margin_start: 8, + margin_end: 8, + selection_mode: "single", + css_classes: [ + "boxed-list" + ] + }) + this._holderBox.append(this.folders); + this.folders.connect("row-activated", (l, r) => launch_shit(r, offset)); + GtkBoxThings.map(x => this.folders.append(x)); + } + this._emergencyProp.set_propagate_natural_height(true); } }); diff --git a/src/window.ui b/src/window.ui index 0c82c2e..ff422f0 100644 --- a/src/window.ui +++ b/src/window.ui @@ -3,17 +3,31 @@