From 2e8e4dbac2971a572060eac7d5a7a74c49c91f06 Mon Sep 17 00:00:00 2001 From: gnunn1 Date: Mon, 18 Jan 2016 19:21:30 -0500 Subject: [PATCH] Fix #34, fix disabling of delete button on profiles --- .../com.gexperts.Terminix.gschema.xml | 5 ++ source/app.d | 4 +- source/gx/terminix/application.d | 46 +++++++++++++- source/gx/terminix/preferences.d | 1 + source/gx/terminix/prefwindow.d | 3 +- source/gx/terminix/session.d | 2 +- source/gx/terminix/terminal/terminal.d | 62 +++++++++++++------ 7 files changed, 98 insertions(+), 25 deletions(-) diff --git a/data/gsettings/com.gexperts.Terminix.gschema.xml b/data/gsettings/com.gexperts.Terminix.gschema.xml index e38f820d..1c739acf 100644 --- a/data/gsettings/com.gexperts.Terminix.gschema.xml +++ b/data/gsettings/com.gexperts.Terminix.gschema.xml @@ -126,6 +126,11 @@ to appear there. + + true + Whether to warn if the VTE configuration issue is detected + If true, a dialog will be displayed warning the user that VTE is not configured correctly. + diff --git a/source/app.d b/source/app.d index e475c328..b7736850 100644 --- a/source/app.d +++ b/source/app.d @@ -19,7 +19,7 @@ import gx.terminix.cmdparams; import gx.terminix.constants; int main(string[] args) { - + trace("Starting terminix..."); //Version checking cribbed from grestful, thanks! string gtkError = Version.checkVersion(GTK_VERSION_MAJOR, GTK_VERSION_MINOR, GTK_VERSION_PATCH); if (gtkError !is null) { @@ -40,6 +40,7 @@ int main(string[] args) { return 1; } + trace("Reading command parameters..."); CommandParameters cp = CommandParameters(args); if (!cp.exit) { auto terminixApp = new Terminix(cp); @@ -47,6 +48,7 @@ int main(string[] args) { string[] tempArgs; int result; try { + trace("Running application..."); result = terminixApp.run(tempArgs); } catch (Exception e) { error("Unexpected exception occurred"); diff --git a/source/gx/terminix/application.d b/source/gx/terminix/application.d index be107491..3e11e920 100644 --- a/source/gx/terminix/application.d +++ b/source/gx/terminix/application.d @@ -20,8 +20,13 @@ import glib.VariantType : GVariantType = VariantType; import gtk.AboutDialog; import gtk.Application; +import gtk.CheckButton; import gtk.Dialog; +import gtk.Image; +import gtk.Label; +import gtk.LinkButton; import gtk.Main; +import gtk.MessageDialog; import gtk.Settings; import gtk.Widget; import gtk.Window; @@ -62,6 +67,8 @@ private: AppWindow[] appWindows; ProfileWindow[] profileWindows; PreferenceWindow preferenceWindow; + + bool warnedVTEConfigIssue = false; /** * Load and register binary resource file and add css files as providers @@ -325,4 +332,41 @@ public: ProfileWindow window = new ProfileWindow(this, profile); window.showAll(); } -} + + bool testVTEConfig() { + return !warnedVTEConfigIssue && gsGeneral.getBoolean(SETTINGS_WARN_VTE_CONFIG_ISSUE_KEY); + } + + /** + * Shows a dialog when a VTE configuration issue is detected. + * See Issue #34 and https://github.com/gnunn1/terminix/wiki/VTE-Configuration-Issue + * for more information. + */ + void warnVTEConfigIssue() { + if (testVTEConfig()) { + warnedVTEConfigIssue = true; + string msg = _("There appears to be an issue with the configuration of the terminal.\n" ~ + "This issue is not serious, but correcting it will improve your experience\n" ~ + "Click the link below for more information:"); + string title = "" ~ _("Configuration Issue Detected") ~ ""; + MessageDialog dlg = new MessageDialog(getActiveWindow(), DialogFlags.MODAL, MessageType.WARNING, ButtonsType.OK, null, null); + scope(exit) {dlg.destroy();} + with (dlg) { + setTransientFor(getActiveWindow()); + setMarkup(title); + getMessageArea().setMarginLeft(0); + getMessageArea().setMarginRight(0); + getMessageArea().add(new Label(msg)); + getMessageArea().add(new LinkButton("https://github.com/gnunn1/terminix/wiki/VTE-Configuration-Issue")); + CheckButton cb = new CheckButton(_("Do not show this message again")); + getMessageArea().add(cb); + setImage(new Image("dialog-warning", IconSize.DIALOG)); + showAll(); + run(); + if (cb.getActive()) { + gsGeneral.setBoolean(SETTINGS_WARN_VTE_CONFIG_ISSUE_KEY, false); + } + } + } + } +} \ No newline at end of file diff --git a/source/gx/terminix/preferences.d b/source/gx/terminix/preferences.d index 4b4d5c67..61686c2d 100644 --- a/source/gx/terminix/preferences.d +++ b/source/gx/terminix/preferences.d @@ -30,6 +30,7 @@ enum SETTINGS_THEME_VARIANT_DARK_VALUE = "dark"; enum SETTINGS_PROMPT_ON_NEW_SESSION_KEY = "prompt-on-new-session"; enum SETTINGS_NOTIFY_ON_PROCESS_COMPLETE_KEY = "notify-on-process-complete"; enum SETTINGS_UNSAFE_PASTE_ALERT_KEY = "unsafe-paste-alert"; +enum SETTINGS_WARN_VTE_CONFIG_ISSUE_KEY = "warn-vte-config-issue"; enum SETTINGS_ENCODINGS_KEY = "encodings"; enum SETTINGS_SEARCH_DEFAULT_MATCH_CASE = "search-default-match-case"; diff --git a/source/gx/terminix/prefwindow.d b/source/gx/terminix/prefwindow.d index d724b154..b5558997 100644 --- a/source/gx/terminix/prefwindow.d +++ b/source/gx/terminix/prefwindow.d @@ -205,7 +205,6 @@ private: TreeView tvShortcuts = new TreeView(tsShortcuts); tvShortcuts.setActivateOnSingleClick(false); - //tvShortcuts.addOnCursorChanged(delegate(TreeView) { updateUI(); }); TreeViewColumn column = new TreeViewColumn(_("Action"), new CellRendererText(), "text", COLUMN_NAME); column.setExpand(true); @@ -388,7 +387,7 @@ private: void updateUI() { TreeIter selected = tvProfiles.getSelectedIter(); - btnDelete.setSensitive(selected !is null && lsProfiles.iterNChildren(null) > 0); + btnDelete.setSensitive(selected !is null && lsProfiles.iterNChildren(null) > 1); btnEdit.setSensitive(selected !is null); } diff --git a/source/gx/terminix/session.d b/source/gx/terminix/session.d index 3457fee2..14e6d413 100644 --- a/source/gx/terminix/session.d +++ b/source/gx/terminix/session.d @@ -249,7 +249,7 @@ private: Terminal newTerminal = createTerminal(terminal.profileUUID); trace("Inserting terminal"); insertTerminal(terminal, newTerminal, orientation, 2); - trace("Intializing terminal"); + trace("Intializing terminal with " ~ terminal.currentDirectory); newTerminal.initTerminal(terminal.currentDirectory, false); } diff --git a/source/gx/terminix/terminal/terminal.d b/source/gx/terminix/terminal/terminal.d index b4d2d5f2..316522c9 100644 --- a/source/gx/terminix/terminal/terminal.d +++ b/source/gx/terminix/terminal/terminal.d @@ -186,7 +186,7 @@ private: Scrollbar sb; GPid gpid = 0; - bool titleInitialized = false; + bool _terminalInitialized = false; Label lblTitle; @@ -214,7 +214,7 @@ private: GSettings gsProfile; GSettings gsShortcuts; GSettings gsDesktop; - + /** * Create the user interface of the TerminalPane */ @@ -481,20 +481,34 @@ private: //Event handlers vte.addOnChildExited(&onTerminalChildExited); - vte.addOnWindowTitleChanged(delegate(VTE terminal) { updateTitle(); }); - vte.addOnIconTitleChanged(delegate(VTE terminal) { updateTitle(); }); + vte.addOnWindowTitleChanged(delegate(VTE terminal) { + trace(format("Window title changed, pid=%d '%s'", gpid, vte.getWindowTitle())); + terminalInitialized = true; + updateTitle(); + }); + vte.addOnIconTitleChanged(delegate(VTE terminal) { + trace(format("Icon title changed, pid=%d '%s'", gpid, vte.getIconTitle())); + updateTitle(); + }); vte.addOnCurrentDirectoryUriChanged(delegate(VTE terminal) { - titleInitialized = true; + trace(format("Current directory changed, pid=%d '%s'", gpid, currentDirectory)); + terminalInitialized = true; updateTitle(); }); vte.addOnCurrentFileUriChanged(delegate(VTE terminal) { trace("Current file is " ~ vte.getCurrentFileUri); }); vte.addOnFocusIn(&onTerminalFocusIn); vte.addOnFocusOut(&onTerminalFocusOut); vte.addOnNotificationReceived(delegate(string summary, string _body, VTE terminal) { - if (titleInitialized && !terminal.hasFocus()) { + if (terminalInitialized && !terminal.hasFocus()) { notifyProcessNotification(summary, _body, terminalUUID); } }); + vte.addOnContentsChanged(delegate(VTE) { + // VTE configuration problem, Issue #34 + if (terminalInitialized && terminix.testVTEConfig() && currentDirectory.length == 0) { + terminix.warnVTEConfigIssue(); + } + }); vte.addOnButtonPress(&onTerminalButtonPress); vte.addOnKeyPress(delegate(Event event, Widget widget) { @@ -558,10 +572,11 @@ private: title = title.replace(TERMINAL_ICON_TITLE, vte.getIconTitle()); title = title.replace(TERMINAL_ID, to!string(terminalID)); string path; - if (titleInitialized) { + if (terminalInitialized) { path = currentDirectory; trace("Current directory is " ~ path); } else { + trace("Terminal not initialized yet, no path available"); path = ""; } title = title.replace(TERMINAL_DIR, path); @@ -772,6 +787,7 @@ private: vte.setCursorBlinkMode(getBlinkMode(gsProfile.getString(SETTINGS_PROFILE_CURSOR_BLINK_MODE_KEY))); break; case SETTINGS_PROFILE_TITLE_KEY: + trace("Applying preferences"); updateTitle(); break; case SETTINGS_PROFILE_USE_SYSTEM_FONT_KEY, SETTINGS_PROFILE_FONT_KEY: @@ -836,18 +852,18 @@ private: * command options. */ void spawnTerminalProcess(string initialPath) { - GSpawnFlags flags; + GSpawnFlags flags = GSpawnFlags.SEARCH_PATH_FROM_ENVP; string shell = vte.getUserShell(); - string[] args = [shell]; + string[] args; if (gsProfile.getBoolean(SETTINGS_PROFILE_USE_CUSTOM_COMMAND_KEY)) { - args ~= "-c"; - args ~= gsProfile.getString(SETTINGS_PROFILE_CUSTOM_COMMAND_KEY); - flags = GSpawnFlags.SEARCH_PATH; + ShellUtils.shellParseArgv(gsProfile.getString(SETTINGS_PROFILE_CUSTOM_COMMAND_KEY), args); + flags = flags | GSpawnFlags.SEARCH_PATH; } else { + args ~= shell; if (gsProfile.getBoolean(SETTINGS_PROFILE_LOGIN_SHELL_KEY)) { - args ~= "-" ~ shell; + args ~= format("-%s", shell); + flags = flags | GSpawnFlags.FILE_AND_ARGV_ZERO; } - flags = GSpawnFlags.DEFAULT; } string[] envv = [""]; foreach(arg; args) trace("Argument: " ~ arg); @@ -1173,6 +1189,7 @@ public: trace("Set VTE Size for columns " ~ to!string(gsProfile.getInt(SETTINGS_PROFILE_SIZE_COLUMNS_KEY))); vte.setSize(gsProfile.getInt(SETTINGS_PROFILE_SIZE_COLUMNS_KEY), gsProfile.getInt(SETTINGS_PROFILE_SIZE_ROWS_KEY)); } + trace("Terminal initialized"); updateTitle(); } @@ -1212,16 +1229,11 @@ public: if (gpid == 0) return null; string hostname; - //trace("Getting current directory"); string cwd = vte.getCurrentDirectoryUri(); if (cwd.length == 0) { - //trace("Whoops, current directory is empty"); return null; - } else { - //trace("Got current directory " ~ cwd); - } + } string result = URI.filenameFromUri(cwd, hostname); - //trace("Got result " ~ result); return result; } @@ -1258,6 +1270,16 @@ public: updateTitle(); } } + + @property bool terminalInitialized() { + return _terminalInitialized; + } + + @property void terminalInitialized(bool value) { + if (value != _terminalInitialized) { + _terminalInitialized = value; + } + } /** * A unique ID for the terminal, it is constant for the lifespan