Skip to content

A visual git client, simple to use yet powerful. Light, fast and debloated.

Rust

feat: gitcraft 0.2.2 - .deb and .rpm packages, AppImage menu entry, restyled menus

Iván21ea18d6044b
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index ff4c52e..697ea59 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -81,6 +81,26 @@ jobs:
sudo chmod +x /usr/local/bin/appimagetool
sh packaging/linux/build-appimage.sh "gitcraft-${{ github.ref_name }}-${{ matrix.name }}.AppImage"
+ - uses: taiki-e/install-action@v2
+ if: runner.os == 'Linux'
+ with:
+ tool: cargo-deb,cargo-generate-rpm
+
+ - name: deb and rpm (Linux)
+ if: runner.os == 'Linux'
+ run: |
+ name="gitcraft-${{ github.ref_name }}-${{ matrix.name }}"
+ strip target/release/gitcraft
+ cargo deb --no-build --output "$name.deb"
+ cargo generate-rpm --output "$name.rpm"
+ # The .deb installs, with its menu entry and icon; the .rpm holds the same files.
+ sudo apt-get install -y desktop-file-utils rpm "./$name.deb"
+ desktop-file-validate /usr/share/applications/gitcraft.desktop
+ test -x /usr/bin/gitcraft
+ test -f /usr/share/icons/hicolor/256x256/apps/gitcraft.png
+ rpm -qp --requires "$name.rpm"
+ rpm -qlp "$name.rpm"
+
- uses: actions/upload-artifact@v4
with:
name: gitcraft-${{ matrix.name }}
@@ -89,6 +109,8 @@ jobs:
gitcraft-*.tar.gz
gitcraft-*-setup.exe
gitcraft-*.AppImage
+ gitcraft-*.deb
+ gitcraft-*.rpm
release:
needs: build
diff --git a/Cargo.lock b/Cargo.lock
index 4583ed2..4507100 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1447,7 +1447,7 @@ dependencies = [
[[package]]
name = "gitcraft"
-version = "0.2.1"
+version = "0.2.2"
dependencies = [
"eframe",
"egui",
diff --git a/Cargo.toml b/Cargo.toml
index 6fa0bf0..d752242 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,11 +1,13 @@
[package]
name = "gitcraft"
-version = "0.2.1"
+version = "0.2.2"
edition = "2024"
rust-version = "1.95"
license = "MIT OR Apache-2.0"
description = "A small, personal visual git client"
publish = false
+repository = "https://github.com/Vancete/gitcraft"
+readme = "README.md"
[dependencies]
eframe = { version = "0.36", default-features = false, features = ["default_fonts", "wgpu", "accesskit", "wayland", "x11", "persistence"] }
@@ -39,6 +41,32 @@ opt-level = 2
opt-level = 3
lto = "thin"
+# Linux packages, built by the release workflow (`cargo deb`, `cargo generate-rpm`).
+[package.metadata.deb]
+maintainer = "Iván <[email protected]>"
+section = "devel"
+depends = "$auto, git"
+extended-description = "A visual git client: commit graph with branch pills, diffs, blame, stashes, interactive rebase, conflicts and a built-in terminal. Drives the installed git command line."
+assets = [
+ ["target/release/gitcraft", "usr/bin/", "755"],
+ ["packaging/gitcraft.desktop", "usr/share/applications/", "644"],
+ ["assets/app-icon/gitcraft-256.png", "usr/share/icons/hicolor/256x256/apps/gitcraft.png", "644"],
+ ["README.md", "usr/share/doc/gitcraft/", "644"],
+]
+
+[package.metadata.generate-rpm]
+assets = [
+ { source = "target/release/gitcraft", dest = "/usr/bin/gitcraft", mode = "755" },
+ { source = "packaging/gitcraft.desktop", dest = "/usr/share/applications/gitcraft.desktop", mode = "644" },
+ { source = "assets/app-icon/gitcraft-256.png", dest = "/usr/share/icons/hicolor/256x256/apps/gitcraft.png", mode = "644" },
+ { source = "README.md", dest = "/usr/share/doc/gitcraft/README.md", mode = "644", doc = true },
+ { source = "LICENSE-MIT", dest = "/usr/share/licenses/gitcraft/LICENSE-MIT", mode = "644", doc = true },
+ { source = "LICENSE-APACHE", dest = "/usr/share/licenses/gitcraft/LICENSE-APACHE", mode = "644", doc = true },
+]
+
+[package.metadata.generate-rpm.requires]
+git = "*"
+
[build-dependencies]
# Icon and version info for gitcraft.exe; build.rs only uses it when targeting Windows.
winresource = "0.1"
diff --git a/README.md b/README.md
index 3945e72..b5c4872 100644
--- a/README.md
+++ b/README.md
@@ -104,12 +104,18 @@ Ready-made builds for Windows and Linux (x86-64) are on the
- **Windows:** `gitcraft-…-setup.exe` installs it for your user (no administrator rights), with a
Start menu entry, an optional desktop icon, *Open in gitcraft* on folders and an uninstaller.
The `.zip` is the same program without installing.
-- **Linux:** `gitcraft-….AppImage` runs on most distributions: make it executable
- (`chmod +x`) and run it. The `.tar.gz` holds the bare binary and a `.desktop` file.
+- **Linux:** `gitcraft-….deb` (Debian, Ubuntu, Mint…) and `gitcraft-….rpm` (Fedora, openSUSE…)
+ install it with its applications menu entry, from the software centre or with
+ `sudo apt install ./gitcraft-….deb` / `sudo dnf install ./gitcraft-….rpm`.
+ `gitcraft-….AppImage` runs on any distribution: make it executable (`chmod +x`) and run it;
+ *Add gitcraft to the applications menu* on its start page (or in Settings) adds a menu entry,
+ which follows the AppImage when you replace it with a newer one. The `.tar.gz` holds the bare
+ binary and a `.desktop` file.
A release is built by `.github/workflows/release.yml` whenever a `v*` tag is pushed
(`packaging/windows/gitcraft.iss` for the installer, `packaging/linux/build-appimage.sh` for the
-AppImage).
+AppImage, `[package.metadata.deb]` / `[package.metadata.generate-rpm]` in `Cargo.toml` for the
+packages).
## Build and run
@@ -144,6 +150,7 @@ was made this way, on a demo repository.
| `src/forge.rs` | pull / merge requests through `gh` and `glab` |
| `src/avatars.rs` | avatars from GitHub, GitLab or Gravatar, cached on disk |
| `src/update.rs` | new-release check |
+| `src/desktop_entry.rs` | applications menu entry for the AppImage |
| `src/settings.rs` | user settings and their form |
| `src/theme.rs` | colour tokens, fonts, egui style (PhotoCraft's Pro themes) |
| `src/icons.rs` | embedded Lucide SVG icons, tinted |
diff --git a/packaging/gitcraft.desktop b/packaging/gitcraft.desktop
index 03f6fd6..486a86d 100644
--- a/packaging/gitcraft.desktop
+++ b/packaging/gitcraft.desktop
@@ -6,3 +6,4 @@ Exec=gitcraft %f
Terminal=false
Categories=Development;RevisionControl;
Icon=gitcraft
+StartupWMClass=gitcraft
diff --git a/src/app.rs b/src/app.rs
index 8928acf..faeb80d 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -124,6 +124,7 @@ impl App {
theme::install_fonts(ctx);
theme::apply(ctx, saved.theme);
saved.settings.set(ctx);
+ crate::desktop_entry::refresh();
let mut app = Self {
git_version: git::version(),
@@ -408,40 +409,44 @@ impl App {
.fill(t.accent)
.corner_radius(10.0),
);
- egui::Popup::menu(&pill).show(|ui| {
- ui.label(
- RichText::new(format!(
- "gitcraft {} is out (you have {}).",
- release.version,
- update::CURRENT
- ))
- .color(t.text_dim),
- );
- if ui.button("Open the release page").clicked() {
- let _ = open::that_detached(&release.url);
- }
- if ui.button("Skip this version").clicked() {
- self.skipped_version = release.version.clone();
- self.update = None;
- }
- });
+ egui::Popup::menu(&pill)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ ui.label(
+ RichText::new(format!(
+ "gitcraft {} is out (you have {}).",
+ release.version,
+ update::CURRENT
+ ))
+ .color(t.text_dim),
+ );
+ if ui.button("Open the release page").clicked() {
+ let _ = open::that_detached(&release.url);
+ }
+ if ui.button("Skip this version").clicked() {
+ self.skipped_version = release.version.clone();
+ self.update = None;
+ }
+ });
}
if icons::small_button(ui, "command", "Command palette (Ctrl+P)").clicked() {
self.open_palette();
}
let resp = icons::small_button(ui, "palette", "Theme");
- egui::Popup::menu(&resp).show(|ui| {
- ui.label(
- RichText::new("THEME")
- .font(theme::semibold(10.5))
- .color(t.text_faint),
- );
- for kind in ThemeKind::ALL {
- if ui.radio(self.theme == kind, kind.label()).clicked() {
- self.set_theme(ui.ctx(), kind);
+ egui::Popup::menu(&resp)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ ui.label(
+ RichText::new("THEME")
+ .font(theme::semibold(10.5))
+ .color(t.text_faint),
+ );
+ for kind in ThemeKind::ALL {
+ if ui.radio(self.theme == kind, kind.label()).clicked() {
+ self.set_theme(ui.ctx(), kind);
+ }
}
- }
- });
+ });
});
});
if let Some(i) = select {
@@ -479,6 +484,17 @@ impl App {
ui.label(RichText::new(v).color(t.text_dim));
});
}
+ if let Some(appimage) = crate::desktop_entry::appimage()
+ && !crate::desktop_entry::installed()
+ {
+ ui.add_space(4.0);
+ let link = ui
+ .link("Add gitcraft to the applications menu")
+ .on_hover_text(appimage.display().to_string());
+ if link.clicked() {
+ self.error = crate::desktop_entry::install(&appimage).err();
+ }
+ }
ui.add_space(26.0);
ui.horizontal(|ui| {
diff --git a/src/desktop_entry.rs b/src/desktop_entry.rs
new file mode 100644
index 0000000..e0369f9
--- /dev/null
+++ b/src/desktop_entry.rs
@@ -0,0 +1,158 @@
+//! Running from an AppImage on Linux: an entry in the user's applications menu that starts this
+//! AppImage file (the .deb and .rpm packages install their own).
+
+use std::path::{Path, PathBuf};
+
+/// File name of the entry, apart from the `gitcraft.desktop` a package installs.
+const ENTRY: &str = "gitcraft-appimage.desktop";
+const ICON: &[u8] = include_bytes!("../assets/app-icon/gitcraft-256.png");
+
+/// The AppImage file gitcraft runs from (its runtime sets `APPIMAGE`), on Linux.
+pub fn appimage() -> Option<PathBuf> {
+ if !cfg!(target_os = "linux") {
+ return None;
+ }
+ std::env::var_os("APPIMAGE")
+ .map(PathBuf::from)
+ .filter(|p| p.is_file())
+}
+
+fn data_home() -> Option<PathBuf> {
+ std::env::var_os("XDG_DATA_HOME")
+ .map(PathBuf::from)
+ .filter(|p| p.is_absolute())
+ .or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".local/share")))
+}
+
+fn entry_path(data: &Path) -> PathBuf {
+ data.join("applications").join(ENTRY)
+}
+
+fn icon_path(data: &Path) -> PathBuf {
+ data.join("icons/hicolor/256x256/apps/gitcraft.png")
+}
+
+/// Whether the menu entry exists.
+pub fn installed() -> bool {
+ data_home().is_some_and(|d| entry_path(&d).is_file())
+}
+
+/// Adds (or rewrites) the menu entry for `appimage`.
+pub fn install(appimage: &Path) -> Result<(), String> {
+ let data = data_home().ok_or("No home folder")?;
+ write_entry(&data, appimage).map_err(|e| e.to_string())
+}
+
+/// Removes the menu entry and its icon.
+pub fn uninstall() -> Result<(), String> {
+ let data = data_home().ok_or("No home folder")?;
+ for path in [entry_path(&data), icon_path(&data)] {
+ match std::fs::remove_file(&path) {
+ Ok(()) => {}
+ Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
+ Err(e) => return Err(format!("{}: {e}", path.display())),
+ }
+ }
+ Ok(())
+}
+
+/// At startup: an AppImage that was moved or replaced by a newer file keeps its menu entry
+/// pointing at the file running now.
+pub fn refresh() {
+ let (Some(appimage), Some(data)) = (appimage(), data_home()) else {
+ return;
+ };
+ let path = entry_path(&data);
+ let Ok(current) = std::fs::read_to_string(&path) else {
+ return;
+ };
+ if current != entry(&appimage) {
+ let _ = write_entry(&data, &appimage);
+ }
+}
+
+fn write_entry(data: &Path, appimage: &Path) -> std::io::Result<()> {
+ let icon = icon_path(data);
+ if let Some(dir) = icon.parent() {
+ std::fs::create_dir_all(dir)?;
+ }
+ std::fs::write(&icon, ICON)?;
+ let path = entry_path(data);
+ if let Some(dir) = path.parent() {
+ std::fs::create_dir_all(dir)?;
+ }
+ std::fs::write(&path, entry(appimage))
+}
+
+fn entry(appimage: &Path) -> String {
+ let exec = quote_exec(&appimage.to_string_lossy());
+ format!(
+ "[Desktop Entry]\n\
+ Type=Application\n\
+ Name=gitcraft\n\
+ Comment=A small visual git client\n\
+ Exec={exec} %f\n\
+ TryExec={}\n\
+ Terminal=false\n\
+ Categories=Development;RevisionControl;\n\
+ Icon=gitcraft\n\
+ StartupWMClass=gitcraft\n",
+ escape_value(&appimage.to_string_lossy())
+ )
+}
+
+/// A program path as the quoted first word of `Exec` (Desktop Entry spec: `"`, `` ` ``, `$` and
+/// `\` escaped inside the quotes, then the value's own escaping, `%` doubled).
+fn quote_exec(path: &str) -> String {
+ let mut quoted = String::from("\"");
+ for c in path.chars() {
+ if matches!(c, '"' | '`' | '$' | '\\') {
+ quoted.push('\\');
+ }
+ quoted.push(c);
+ }
+ quoted.push('"');
+ escape_value(&quoted).replace('%', "%%")
+}
+
+/// A string value of a desktop file: backslashes and line breaks escaped.
+fn escape_value(s: &str) -> String {
+ s.replace('\\', "\\\\")
+ .replace('\n', "\\n")
+ .replace('\r', "\\r")
+ .replace('\t', "\\t")
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn quotes_the_appimage_path() {
+ assert_eq!(
+ quote_exec("/home/me/Apps/gitcraft.AppImage"),
+ "\"/home/me/Apps/gitcraft.AppImage\""
+ );
+ assert_eq!(
+ quote_exec("/home/me/My Apps/$x 100%/a\"b"),
+ "\"/home/me/My Apps/\\\\$x 100%%/a\\\\\"b\""
+ );
+ }
+
+ #[test]
+ fn writes_and_refreshes_the_entry() {
+ let data = std::env::temp_dir().join(format!("gitcraft-desktop-{}", std::process::id()));
+ let old = Path::new("/opt/gitcraft-v0.2.0.AppImage");
+ let ok = write_entry(&data, old).is_ok();
+ let text = std::fs::read_to_string(entry_path(&data)).unwrap_or_default();
+ let icon = std::fs::metadata(icon_path(&data))
+ .map(|m| m.len())
+ .unwrap_or(0);
+ let _ = std::fs::remove_dir_all(&data);
+ assert!(ok);
+ assert!(text.contains("Exec=\"/opt/gitcraft-v0.2.0.AppImage\" %f\n"));
+ assert!(text.contains("TryExec=/opt/gitcraft-v0.2.0.AppImage\n"));
+ assert_eq!(icon, ICON.len() as u64);
+ assert_ne!(text, entry(Path::new("/opt/gitcraft-v0.2.1.AppImage")));
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index a445980..55d26ef 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,6 +2,7 @@
pub mod app;
mod avatars;
+mod desktop_entry;
mod forge;
mod git;
mod graph;
diff --git a/src/main.rs b/src/main.rs
index bbef710..2969929 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,8 @@ fn main() -> eframe::Result {
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_title("gitcraft")
+ // Matches gitcraft.desktop, so Linux desktops show its icon and group its windows.
+ .with_app_id("gitcraft")
.with_inner_size([1400.0, 860.0])
.with_min_inner_size([800.0, 500.0])
.with_icon(app::window_icon()),
diff --git a/src/repo/detail.rs b/src/repo/detail.rs
index 0b62b05..6a20bb2 100644
--- a/src/repo/detail.rs
+++ b/src/repo/detail.rs
@@ -31,9 +31,11 @@ impl RepoTab {
widgets::panel_header(ui, title, |ui| {
if let Some(stash) = &stash {
let more = icons::small_button(ui, "chevron-down", "Apply, pop or drop");
- egui::Popup::menu(&more).show(|ui| {
- super::sidebar::stash_menu_items(ui, acts, &stash.name, idle);
- });
+ egui::Popup::menu(&more)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ super::sidebar::stash_menu_items(ui, acts, &stash.name, idle);
+ });
}
});
if let Some(stash) = &stash {
@@ -508,17 +510,21 @@ impl RepoTab {
let profiles = crate::settings::Settings::get(ui.ctx()).profiles;
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let b = icons::small_button(ui, "user-round", "Commit as…");
- egui::Popup::menu(&b).show(|ui| {
- if profiles.is_empty() {
- ui.label(RichText::new("Add identities in Settings").color(t.text_faint));
- }
- for p in &profiles {
- let label = format!("{} — {} <{}>", p.label, p.name, p.email);
- if ui.add_enabled(idle, egui::Button::new(label)).clicked() {
- acts.push(Action::SetIdentity(p.name.clone(), p.email.clone()));
+ egui::Popup::menu(&b)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ if profiles.is_empty() {
+ ui.label(
+ RichText::new("Add identities in Settings").color(t.text_faint),
+ );
}
- }
- });
+ for p in &profiles {
+ let label = format!("{} — {} <{}>", p.label, p.name, p.email);
+ if ui.add_enabled(idle, egui::Button::new(label)).clicked() {
+ acts.push(Action::SetIdentity(p.name.clone(), p.email.clone()));
+ }
+ }
+ });
});
});
}
diff --git a/src/repo/graph_view.rs b/src/repo/graph_view.rs
index 0e28d21..bfe6c47 100644
--- a/src/repo/graph_view.rs
+++ b/src/repo/graph_view.rs
@@ -181,24 +181,26 @@ impl RepoTab {
continue;
};
if commit.hash == WIP_HASH {
- resp.context_menu(|ui| {
- if ui
- .add_enabled(idle, egui::Button::new("Stage all changes"))
- .clicked()
- {
- acts.push(Action::Ops {
- label: "Stage all".into(),
- ops: ops(&[&["add", "-A"]]),
- refresh: Refresh::Status,
- });
- }
- if ui
- .add_enabled(idle, egui::Button::new("Stash changes…"))
- .clicked()
- {
- acts.push(Action::Dialog(Dialog::stash()));
- }
- });
+ egui::Popup::context_menu(&resp)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ if ui
+ .add_enabled(idle, egui::Button::new("Stage all changes"))
+ .clicked()
+ {
+ acts.push(Action::Ops {
+ label: "Stage all".into(),
+ ops: ops(&[&["add", "-A"]]),
+ refresh: Refresh::Status,
+ });
+ }
+ if ui
+ .add_enabled(idle, egui::Button::new("Stash changes…"))
+ .clicked()
+ {
+ acts.push(Action::Dialog(Dialog::stash()));
+ }
+ });
continue;
}
self.commit_menu(&resp, i, idle, acts);
@@ -239,7 +241,7 @@ impl RepoTab {
.current
.clone()
.unwrap_or_else(|| "HEAD".to_owned());
- resp.context_menu(|ui| {
+ egui::Popup::context_menu(resp).style(crate::theme::menu_style).show(|ui| {
if let Some(branch) = &pill
&& self.refs.current.as_deref() != Some(branch.as_str())
{
diff --git a/src/repo/mod.rs b/src/repo/mod.rs
index 42c940a..9533aec 100644
--- a/src/repo/mod.rs
+++ b/src/repo/mod.rs
@@ -1821,17 +1821,19 @@ impl RepoTab {
}
let open =
icons::tool_button(ui, "external-link", "", true).on_hover_text("Open the folder…");
- egui::Popup::menu(&open).show(|ui| {
- if ui.button(reveal_label()).clicked() {
- acts.push(Action::OpenPath(PathBuf::new()));
- }
- if ui.button("Open in editor").clicked() {
- acts.push(Action::OpenInEditor(PathBuf::new()));
- }
- if ui.button("Copy path").clicked() {
- ui.ctx().copy_text(self.path.display().to_string());
- }
- });
+ egui::Popup::menu(&open)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ if ui.button(reveal_label()).clicked() {
+ acts.push(Action::OpenPath(PathBuf::new()));
+ }
+ if ui.button("Open in editor").clicked() {
+ acts.push(Action::OpenInEditor(PathBuf::new()));
+ }
+ if ui.button("Copy path").clicked() {
+ ui.ctx().copy_text(self.path.display().to_string());
+ }
+ });
widgets::toolbar_separator(ui);
if icons::tool_button(ui, "refresh-cw", "", !self.loading)
.on_hover_text("Reload (F5)")
diff --git a/src/repo/sidebar.rs b/src/repo/sidebar.rs
index 82ab8a0..1ba4a07 100644
--- a/src/repo/sidebar.rs
+++ b/src/repo/sidebar.rs
@@ -15,17 +15,19 @@ impl RepoTab {
pub(super) fn sidebar(&mut self, ui: &mut Ui, acts: &mut Vec<Action>) {
let t = Tokens::get(ui.ctx());
widgets::panel_header(ui, "Branches", |_| {});
- ui.add_space(6.0);
+ // Sized like the commit search bar (Ctrl+F).
+ ui.add_space(8.0);
ui.horizontal(|ui| {
- ui.add_space(8.0);
- icons::inline(ui, "search", 14.0, t.text_faint);
+ ui.add_space(10.0);
+ icons::inline(ui, "search", 15.0, t.text_faint);
ui.add(
egui::TextEdit::singleline(&mut self.branch_filter)
- .hint_text("Filter")
- .desired_width(ui.available_width() - 8.0),
+ .hint_text("Filter branches and tags")
+ .desired_width(ui.available_width() - 10.0)
+ .margin(egui::Margin::symmetric(8, 4)),
);
});
- ui.add_space(4.0);
+ ui.add_space(8.0);
let filter = self.branch_filter.to_lowercase();
let matches = |b: &&Branch| filter.is_empty() || b.name.to_lowercase().contains(&filter);
@@ -73,69 +75,73 @@ impl RepoTab {
if r.clicked() {
acts.push(Action::SelectHash(tag.target.clone()));
}
- r.context_menu(|ui| {
- if ui.button("Copy name").clicked() {
- ui.ctx().copy_text(tag.name.clone());
- }
- if let Some(remote) = self.default_remote() {
- if ui
- .add_enabled(
- idle,
- egui::Button::new(format!("Push to {remote}")),
- )
- .clicked()
- {
- acts.push(Action::Ops {
- label: format!("Push tag {}", tag.name),
- ops: ops(&[&[
- "push",
- &remote,
- &format!("refs/tags/{}", tag.name),
- ]]),
- refresh: Refresh::All,
- });
+ egui::Popup::context_menu(&r)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ if ui.button("Copy name").clicked() {
+ ui.ctx().copy_text(tag.name.clone());
}
+ if let Some(remote) = self.default_remote() {
+ if ui
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Push to {remote}")),
+ )
+ .clicked()
+ {
+ acts.push(Action::Ops {
+ label: format!("Push tag {}", tag.name),
+ ops: ops(&[&[
+ "push",
+ &remote,
+ &format!("refs/tags/{}", tag.name),
+ ]]),
+ refresh: Refresh::All,
+ });
+ }
+ if ui
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Delete from {remote}…")),
+ )
+ .clicked()
+ {
+ acts.push(Action::Dialog(Dialog::confirm(
+ "Delete remote tag",
+ format!("Delete the tag “{}” from {remote}?", tag.name),
+ "Delete",
+ ops(&[&[
+ "push",
+ &remote,
+ "--delete",
+ &format!("refs/tags/{}", tag.name),
+ ]]),
+ None,
+ )));
+ }
+ }
+ ui.separator();
if ui
- .add_enabled(
- idle,
- egui::Button::new(format!("Delete from {remote}…")),
- )
+ .add_enabled(idle, egui::Button::new("Delete tag…"))
.clicked()
{
- acts.push(Action::Dialog(Dialog::confirm(
- "Delete remote tag",
- format!("Delete the tag “{}” from {remote}?", tag.name),
- "Delete",
- ops(&[&[
- "push",
- &remote,
- "--delete",
- &format!("refs/tags/{}", tag.name),
- ]]),
- None,
- )));
+ acts.push(Action::Dialog(
+ Dialog::confirm(
+ "Delete tag",
+ format!("Delete the local tag “{}”?", tag.name),
+ "Delete",
+ ops(&[&["tag", "-d", &tag.name]]),
+ None,
+ )
+ .undo(
+ Undo::Custom {
+ undo: ops(&[&["tag", &tag.name, &tag.target]]),
+ redo: ops(&[&["tag", "-d", &tag.name]]),
+ },
+ ),
+ ));
}
- }
- ui.separator();
- if ui
- .add_enabled(idle, egui::Button::new("Delete tag…"))
- .clicked()
- {
- acts.push(Action::Dialog(
- Dialog::confirm(
- "Delete tag",
- format!("Delete the local tag “{}”?", tag.name),
- "Delete",
- ops(&[&["tag", "-d", &tag.name]]),
- None,
- )
- .undo(Undo::Custom {
- undo: ops(&[&["tag", &tag.name, &tag.target]]),
- redo: ops(&[&["tag", "-d", &tag.name]]),
- }),
- ));
- }
- });
+ });
}
}
});
@@ -180,7 +186,9 @@ impl RepoTab {
} else if r.clicked() {
acts.push(Action::SelectHash(b.target.clone()));
}
- r.context_menu(|ui| self.branch_menu_items(ui, acts, b, idle));
+ egui::Popup::context_menu(&r)
+ .style(crate::theme::menu_style)
+ .show(|ui| self.branch_menu_items(ui, acts, b, idle));
}
/// The menu of a local branch: in the sidebar and in the graph's commit menu.
@@ -443,7 +451,7 @@ impl RepoTab {
t.text_faint,
);
let r = r.on_hover_text(&remote.url);
- r.context_menu(|ui| {
+ egui::Popup::context_menu(&r).style(crate::theme::menu_style).show(|ui| {
if ui.add_enabled(idle, egui::Button::new(format!("Fetch {}", remote.name))).clicked() {
acts.push(Action::Ops {
label: format!("Fetch {}", remote.name),
@@ -487,52 +495,57 @@ impl RepoTab {
} else if r.clicked() {
acts.push(Action::SelectHash(b.target.clone()));
}
- r.context_menu(|ui| {
- if ui
- .add_enabled(idle, egui::Button::new("Check out as local branch"))
- .clicked()
- {
- acts.push(Action::CheckoutRemote(b.name.clone()));
- }
- if let Some(current) = current.as_deref() {
+ egui::Popup::context_menu(&r)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
if ui
- .add_enabled(
- idle,
- egui::Button::new(format!("Fast-forward {current} to it")),
- )
+ .add_enabled(idle, egui::Button::new("Check out as local branch"))
.clicked()
{
- acts.push(fast_forward_action(&b.name, current));
+ acts.push(Action::CheckoutRemote(b.name.clone()));
}
- if ui
- .add_enabled(idle, egui::Button::new(format!("Merge into {current}")))
- .clicked()
- {
- acts.push(merge_action(&b.name, current));
+ if let Some(current) = current.as_deref() {
+ if ui
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Fast-forward {current} to it")),
+ )
+ .clicked()
+ {
+ acts.push(fast_forward_action(&b.name, current));
+ }
+ if ui
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Merge into {current}")),
+ )
+ .clicked()
+ {
+ acts.push(merge_action(&b.name, current));
+ }
+ if ui
+ .add_enabled(
+ idle,
+ egui::Button::new(format!("Rebase {current} onto it")),
+ )
+ .clicked()
+ {
+ acts.push(rebase_action(&b.name, current));
+ }
+ }
+ if ui.button("Create branch here…").clicked() {
+ acts.push(Action::Dialog(Dialog::create_branch(&b.target, &b.name)));
+ }
+ ui.separator();
+ if ui.button("Copy name").clicked() {
+ ui.ctx().copy_text(b.name.clone());
}
+ ui.separator();
if ui
- .add_enabled(
- idle,
- egui::Button::new(format!("Rebase {current} onto it")),
- )
+ .add_enabled(idle, egui::Button::new("Delete from remote…"))
.clicked()
{
- acts.push(rebase_action(&b.name, current));
- }
- }
- if ui.button("Create branch here…").clicked() {
- acts.push(Action::Dialog(Dialog::create_branch(&b.target, &b.name)));
- }
- ui.separator();
- if ui.button("Copy name").clicked() {
- ui.ctx().copy_text(b.name.clone());
- }
- ui.separator();
- if ui
- .add_enabled(idle, egui::Button::new("Delete from remote…"))
- .clicked()
- {
- acts.push(Action::Dialog(Dialog::confirm(
+ acts.push(Action::Dialog(Dialog::confirm(
"Delete remote branch",
format!(
"Delete “{short}” from {}? This changes the remote for everyone.",
@@ -542,8 +555,8 @@ impl RepoTab {
ops(&[&["push", &remote.name, "--delete", short]]),
None,
)));
- }
- });
+ }
+ });
}
}
}
@@ -600,7 +613,9 @@ impl RepoTab {
if r.clicked() {
acts.push(Action::SelectStash(i));
}
- r.context_menu(|ui| stash_menu_items(ui, acts, &stash.name, idle));
+ egui::Popup::context_menu(&r)
+ .style(crate::theme::menu_style)
+ .show(|ui| stash_menu_items(ui, acts, &stash.name, idle));
}
}
@@ -686,25 +701,28 @@ impl RepoTab {
{
acts.push(Action::SelectHash(target.clone()));
}
- r.context_menu(|ui| {
- if ui.button("Open in the browser").clicked() {
- acts.push(Action::OpenUrl(pr.url.clone()));
- }
- if ui
- .add_enabled(idle, egui::Button::new(format!("Check out {}", pr.branch)))
- .clicked()
- {
- if self.refs.local.iter().any(|b| b.name == pr.branch) {
- acts.push(Action::Checkout(pr.branch.clone()));
- } else {
- let remote = self.default_remote().unwrap_or_else(|| "origin".to_owned());
- acts.push(Action::CheckoutRemote(format!("{remote}/{}", pr.branch)));
+ egui::Popup::context_menu(&r)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ if ui.button("Open in the browser").clicked() {
+ acts.push(Action::OpenUrl(pr.url.clone()));
}
- }
- if ui.button("Copy URL").clicked() {
- ui.ctx().copy_text(pr.url.clone());
- }
- });
+ if ui
+ .add_enabled(idle, egui::Button::new(format!("Check out {}", pr.branch)))
+ .clicked()
+ {
+ if self.refs.local.iter().any(|b| b.name == pr.branch) {
+ acts.push(Action::Checkout(pr.branch.clone()));
+ } else {
+ let remote =
+ self.default_remote().unwrap_or_else(|| "origin".to_owned());
+ acts.push(Action::CheckoutRemote(format!("{remote}/{}", pr.branch)));
+ }
+ }
+ if ui.button("Copy URL").clicked() {
+ ui.ctx().copy_text(pr.url.clone());
+ }
+ });
}
}
}
@@ -848,7 +866,7 @@ impl RepoTab {
acts.push(Action::SelectHash(wt.head.clone()));
}
let path = wt.path.display().to_string();
- r.context_menu(|ui| {
+ egui::Popup::context_menu(&r).style(crate::theme::menu_style).show(|ui| {
if ui
.add_enabled(!wt.current && wt.prunable.is_none(), egui::Button::new("Open in a tab"))
.clicked()
diff --git a/src/repo/widgets.rs b/src/repo/widgets.rs
index 6a0d379..44336fe 100644
--- a/src/repo/widgets.rs
+++ b/src/repo/widgets.rs
@@ -455,27 +455,31 @@ pub fn terminal_tabs(
cwd: None,
});
}
- egui::Popup::context_menu(&plus).show(|ui| {
- for shell in crate::terminal::available_shells() {
- if ui.button(&shell.label).clicked() {
- acts.push(super::Action::NewTerminal {
- shell: Some(shell),
- cwd: None,
- });
+ egui::Popup::context_menu(&plus)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ for shell in crate::terminal::available_shells() {
+ if ui.button(&shell.label).clicked() {
+ acts.push(super::Action::NewTerminal {
+ shell: Some(shell),
+ cwd: None,
+ });
+ }
}
- }
- });
+ });
let more = icons::small_button(ui, "chevron-down", "New terminal with…");
- egui::Popup::menu(&more).show(|ui| {
- for shell in crate::terminal::available_shells() {
- if ui.button(&shell.label).clicked() {
- acts.push(super::Action::NewTerminal {
- shell: Some(shell),
- cwd: None,
- });
+ egui::Popup::menu(&more)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ for shell in crate::terminal::available_shells() {
+ if ui.button(&shell.label).clicked() {
+ acts.push(super::Action::NewTerminal {
+ shell: Some(shell),
+ cwd: None,
+ });
+ }
}
- }
- });
+ });
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
ui.add_space(4.0);
if icons::small_button(ui, "x", "Hide the panel (shells keep running)").clicked() {
@@ -496,51 +500,53 @@ pub fn file_menu(
) {
use super::Action;
use super::file_view::FileTab;
- resp.context_menu(|ui| {
- let rel = std::path::PathBuf::from(path);
- if ui.button("Open file").clicked() {
- acts.push(Action::OpenPath(rel.clone()));
- }
- if ui.button("Open in editor").clicked() {
- acts.push(Action::OpenInEditor(rel.clone()));
- }
- if ui.button(super::reveal_label()).clicked() {
- acts.push(Action::OpenPath(
- rel.parent().map(|p| p.to_path_buf()).unwrap_or_default(),
- ));
- }
- ui.separator();
- if ui.button("File history").clicked() {
- acts.push(Action::FileView {
- path: path.to_owned(),
- rev: rev.map(str::to_owned),
- tab: FileTab::History,
- });
- }
- if ui.button("Blame").clicked() {
- acts.push(Action::FileView {
- path: path.to_owned(),
- rev: rev.map(str::to_owned),
- tab: FileTab::Blame,
- });
- }
- if ignorable {
- ui.menu_button("Ignore", |ui| {
- for (label, pattern, untrack) in ignore_patterns(path) {
- if ui.button(label).clicked() {
- acts.push(Action::Ignore {
- pattern,
- path: untrack,
- });
+ egui::Popup::context_menu(resp)
+ .style(crate::theme::menu_style)
+ .show(|ui| {
+ let rel = std::path::PathBuf::from(path);
+ if ui.button("Open file").clicked() {
+ acts.push(Action::OpenPath(rel.clone()));
+ }
+ if ui.button("Open in editor").clicked() {
+ acts.push(Action::OpenInEditor(rel.clone()));
+ }
+ if ui.button(super::reveal_label()).clicked() {
+ acts.push(Action::OpenPath(
+ rel.parent().map(|p| p.to_path_buf()).unwrap_or_default(),
+ ));
+ }
+ ui.separator();
+ if ui.button("File history").clicked() {
+ acts.push(Action::FileView {
+ path: path.to_owned(),
+ rev: rev.map(str::to_owned),
+ tab: FileTab::History,
+ });
+ }
+ if ui.button("Blame").clicked() {
+ acts.push(Action::FileView {
+ path: path.to_owned(),
+ rev: rev.map(str::to_owned),
+ tab: FileTab::Blame,
+ });
+ }
+ if ignorable {
+ ui.menu_button("Ignore", |ui| {
+ for (label, pattern, untrack) in ignore_patterns(path) {
+ if ui.button(label).clicked() {
+ acts.push(Action::Ignore {
+ pattern,
+ path: untrack,
+ });
+ }
}
- }
- });
- }
- ui.separator();
- if ui.button("Copy path").clicked() {
- ui.ctx().copy_text(path.to_owned());
- }
- });
+ });
+ }
+ ui.separator();
+ if ui.button("Copy path").clicked() {
+ ui.ctx().copy_text(path.to_owned());
+ }
+ });
}
/// The ways to ignore `path`: (menu label, `.gitignore` line, what to stop tracking).
diff --git a/src/settings.rs b/src/settings.rs
index a872c8e..6185f75 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -133,6 +133,24 @@ impl Settings {
ui.label("Notifications");
ui.checkbox(&mut self.notifications, "When a long operation ends in the background");
ui.end_row();
+ if let Some(appimage) = crate::desktop_entry::appimage() {
+ ui.label("Applications menu");
+ ui.horizontal(|ui| {
+ if crate::desktop_entry::installed() {
+ if ui.button("Remove gitcraft").clicked() {
+ let _ = crate::desktop_entry::uninstall();
+ }
+ } else if ui.button("Add gitcraft").clicked() {
+ let _ = crate::desktop_entry::install(&appimage);
+ }
+ ui.label(
+ RichText::new("Starts this AppImage; follows it when you replace it")
+ .color(t.text_faint)
+ .small(),
+ );
+ });
+ ui.end_row();
+ }
ui.label("Updates");
ui.checkbox(&mut self.check_updates, "Check GitHub for a new version once a day");
ui.end_row();
diff --git a/src/theme.rs b/src/theme.rs
index 86846f8..ad37307 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -242,6 +242,32 @@ pub fn install_fonts(ctx: &egui::Context) {
ctx.set_fonts(fonts);
}
+/// Menus and context menus: no border, rows highlighted from edge to edge with room for the
+/// text, a margin only above and below (where the menu's corners are rounded).
+pub fn menu_style(s: &mut egui::Style) {
+ s.spacing.menu_margin = egui::Margin::symmetric(0, 6);
+ s.spacing.button_padding = egui::vec2(16.0, 7.0);
+ s.spacing.item_spacing.y = 0.0;
+ s.visuals.window_stroke = Stroke::NONE;
+ // A shade darker than cards on dark themes, with lighter separators.
+ let fill = s.visuals.window_fill;
+ let (fill, line) = if s.visuals.dark_mode {
+ let fill = fill.lerp_to_gamma(Color32::BLACK, 0.3);
+ (fill, fill.lerp_to_gamma(Color32::WHITE, 0.2))
+ } else {
+ (fill, fill.lerp_to_gamma(Color32::BLACK, 0.15))
+ };
+ s.visuals.window_fill = fill;
+ s.visuals.popup_shadow.color = s.visuals.popup_shadow.color.gamma_multiply(0.6);
+ s.visuals.widgets.noninteractive.bg_stroke = Stroke::new(1.0, line);
+ let w = &mut s.visuals.widgets;
+ w.inactive.weak_bg_fill = Color32::TRANSPARENT;
+ for wv in [&mut w.inactive, &mut w.hovered, &mut w.active, &mut w.open] {
+ wv.bg_stroke = Stroke::NONE;
+ wv.corner_radius = CornerRadius::ZERO;
+ }
+}
+
pub fn apply(ctx: &egui::Context, kind: ThemeKind) {
let t = Tokens::for_kind(kind);
ctx.data_mut(|d| d.insert_temp(tokens_id(), t));
@@ -261,7 +287,7 @@ pub fn apply(ctx: &egui::Context, kind: ThemeKind) {
v.warn_fg_color = t.warning;
v.error_fg_color = t.danger;
v.window_corner_radius = CornerRadius::same(t.radius_lg as u8);
- v.menu_corner_radius = CornerRadius::same(t.radius as u8);
+ v.menu_corner_radius = CornerRadius::same(t.radius_lg as u8);
v.window_shadow = egui::Shadow {
offset: [0, 10],
blur: 32,