Skip to content

Commit

Permalink
Fix #34, fix disabling of delete button on profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunn1 committed Jan 19, 2016
1 parent 9d3c9c1 commit 2e8e4db
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 25 deletions.
5 changes: 5 additions & 0 deletions data/gsettings/com.gexperts.Terminix.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
to appear there.
</description>
</key>
<key name="warn-vte-config-issue" type="b">
<default>true</default>
<summary>Whether to warn if the VTE configuration issue is detected</summary>
<description>If true, a dialog will be displayed warning the user that VTE is not configured correctly.</description>
</key>
</schema>

<!-- SettingsList base schema -->
Expand Down
4 changes: 3 additions & 1 deletion source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -40,13 +40,15 @@ int main(string[] args) {
return 1;
}

trace("Reading command parameters...");
CommandParameters cp = CommandParameters(args);
if (!cp.exit) {
auto terminixApp = new Terminix(cp);
//Bypass GTK command line handling since we handle it ourselves
string[] tempArgs;
int result;
try {
trace("Running application...");
result = terminixApp.run(tempArgs);
} catch (Exception e) {
error("Unexpected exception occurred");
Expand Down
46 changes: 45 additions & 1 deletion source/gx/terminix/application.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = "<span weight='bold' size='larger'>" ~ _("Configuration Issue Detected") ~ "</span>";
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);
}
}
}
}
}
1 change: 1 addition & 0 deletions source/gx/terminix/preferences.d
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 1 addition & 2 deletions source/gx/terminix/prefwindow.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion source/gx/terminix/session.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
62 changes: 42 additions & 20 deletions source/gx/terminix/terminal/terminal.d
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private:
Scrollbar sb;

GPid gpid = 0;
bool titleInitialized = false;
bool _terminalInitialized = false;

Label lblTitle;

Expand Down Expand Up @@ -214,7 +214,7 @@ private:
GSettings gsProfile;
GSettings gsShortcuts;
GSettings gsDesktop;

/**
* Create the user interface of the TerminalPane
*/
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e8e4db

Please sign in to comment.