Skip to content

Commit

Permalink
Add ability to save terminal text to file
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunn1 committed Feb 10, 2016
1 parent 285dbab commit 0c72c14
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
6 changes: 4 additions & 2 deletions data/gsettings/com.gexperts.Terminix.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,9 @@
<default>'&lt;Ctrl&gt;0'</default>
<summary>Keyboard shortcut to make font normal-size</summary>
</key>


<key name="terminal-save" type="s">
<default>'disabled'</default>
<summary>Keyboard shortcut to save terminal contents</summary>
</key>
</schema>
</schemalist>
3 changes: 2 additions & 1 deletion source/gx/terminix/terminal/actions.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ enum ACTION_PASTE = "paste";
enum ACTION_SELECT_ALL = "select-all";
enum ACTION_ZOOM_IN = "zoom-in";
enum ACTION_ZOOM_OUT = "zoom-out";
enum ACTION_ZOOM_NORMAL = "zoom-normal";
enum ACTION_ZOOM_NORMAL = "zoom-normal";
enum ACTION_SAVE = "save";
57 changes: 55 additions & 2 deletions source/gx/terminix/terminal/terminal.d
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import gtk.Clipboard;
import gtk.Dialog;
import gtk.DragAndDrop;
import gtk.EventBox;
import gtk.FileChooserDialog;
import gtk.FileFilter;
import gtk.Frame;
import gtk.Image;
import gtk.InfoBar;
Expand Down Expand Up @@ -447,13 +449,17 @@ private:
notifyTerminalClose();
});

//Edit Profile Preference
//Read Only
registerActionWithSettings(group, ACTION_PREFIX, ACTION_READ_ONLY, gsShortcuts, delegate(GVariant state, SimpleAction sa) {
bool newState = !sa.getState().getBoolean();
sa.setState(new GVariant(newState));
vte.setInputEnabled(!newState);
}, null, new GVariant(false));


//SaveAs
registerActionWithSettings(group, ACTION_PREFIX, ACTION_SAVE, gsShortcuts, delegate(GVariant state, SimpleAction sa) {
saveTerminalOutput();
}, null, null);

//Edit Profile Preference
registerActionWithSettings(group, ACTION_PREFIX, ACTION_PROFILE_PREFERENCE, gsShortcuts, delegate(GVariant, SimpleAction) {
Expand Down Expand Up @@ -507,6 +513,7 @@ private:
model.appendItem(splits);

GMenu menuSection = new GMenu();
menuSection.append(_("Save") ~ "...", getActionDetailedName(ACTION_PREFIX, ACTION_SAVE));
menuSection.append(_("Find") ~ "...", getActionDetailedName(ACTION_PREFIX, ACTION_FIND));
menuSection.append(_("Title") ~ "...", getActionDetailedName(ACTION_PREFIX, ACTION_TITLE));
model.appendSection(null, menuSection);
Expand Down Expand Up @@ -1252,6 +1259,52 @@ private:
cr.fill();
return false;
}

//Save terminal output functionality
private:
string outputFilename;

/**
* Saves terminal output to a file
*
* Params:
* showSaveAsDialog = Determines if save as dialog is shown. Note dialog may be shown even if false is passed if the session filename is not set
*/
void saveTerminalOutput(bool showSaveAsDialog = true) {
if (outputFilename.length == 0 || showSaveAsDialog) {
Window window = cast(Window) getToplevel();
FileChooserDialog fcd = new FileChooserDialog(_("Save Terminal Output"), window, FileChooserAction.SAVE);
scope (exit)
fcd.destroy();

FileFilter ff = new FileFilter();
ff.addPattern("*.txt");
ff.setName(_("All Text Files"));
fcd.addFilter(ff);
ff = new FileFilter();
ff.addPattern("*");
ff.setName(_("All Files"));
fcd.addFilter(ff);

fcd.setDoOverwriteConfirmation(true);
fcd.setDefaultResponse(ResponseType.OK);
if (outputFilename.length == 0) {
} else {
fcd.setCurrentName("output.txt");
}

if (fcd.run() == ResponseType.OK) {
outputFilename = fcd.getFilename();
} else {
return;
}
}
//Do work here
gio.FileIF.FileIF file = gio.File.File.parseName(outputFilename);
gio.OutputStream.OutputStream stream = file.create(GFileCreateFlags.NONE, null);
scope(exit) {stream.close(null);}
vte.writeContentsSync(stream, VteWriteFlags.DEFAULT, null);
}

public:

Expand Down

0 comments on commit 0c72c14

Please sign in to comment.