[moserial] Save and restore selected notebook tabs from profile.



commit f0da48fbde6493ab0074a860a570f03c6a80fe50
Author: Mictronics <github mictronics de>
Date:   Mon Apr 27 20:33:50 2020 +0200

    Save and restore selected notebook tabs from profile.

 src/MainWindow.vala  | 31 ++++++++++++++++++++++++-------
 src/Preferences.vala |  2 +-
 src/Profile.vala     | 29 +++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 8 deletions(-)
---
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index 5af08f9..aea0975 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -131,8 +131,9 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
         int width = profile.getWindowWidth ();
         int height = profile.getWindowHeight ();
         int panedPosition = profile.getWindowPanedPosition ();
-        if ((width > 0) && (height > 0))
+        if ((width > 0) && (height > 0)) {
             gtkWindow.resize (width, height);
+        }
 
         // setup paned
         paned = (Paned) builder.get_object ("vpaned");
@@ -239,9 +240,13 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
 
         // setup incoming notebook
         incoming_notebook = (Notebook) builder.get_object ("incoming_notebook");
+        incoming_notebook.set_current_page (profile.getNotebookTab (false));
+        incoming_notebook.switch_page.connect (onIncomingNotebookSwitchPage);
 
         // setup outgoing notebook
         outgoing_notebook = (Notebook) builder.get_object ("outgoing_notebook");
+        outgoing_notebook.set_current_page (profile.getNotebookTab (true));
+        outgoing_notebook.switch_page.connect (onOutgoingNotebookSwitchPage);
 
         // setup textBuffers;
         incomingHexTextBuffer = new HexTextBuffer ();
@@ -343,8 +348,8 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
         outgoingClearButton.clicked.connect (clearOutgoing);
         outgoingClearButton.set_tooltip_text (_("Clear outgoing text box."));
 
-        //take currentSettings into account for outgoing input area
-        updateOutgoingInputArea();
+        // take currentSettings into account for outgoing input area
+        updateOutgoingInputArea ();
 
         // load and apply preferences
         currentPreferences = Preferences.loadFromProfile (profile);
@@ -356,6 +361,14 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
         currentPaths = DefaultPaths.loadFromProfile (profile);
     }
 
+    private void onIncomingNotebookSwitchPage (Widget page, uint page_num) {
+        profile.setNotebookTab (false, page_num);
+    }
+
+    private void onOutgoingNotebookSwitchPage (Widget page, uint page_num) {
+        profile.setNotebookTab (true, page_num);
+    }
+
     private void toggleRTS (ToggleButton button) {
         // Toogle only when connected
         if (!serialConnection.isConnected ()) {
@@ -399,7 +412,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
             currentSettings = Settings.loadFromProfile (profile);
             currentPreferences = Preferences.loadFromProfile (profile);
             currentPaths = DefaultPaths.loadFromProfile (profile);
-            updateOutgoingInputArea();
+            updateOutgoingInputArea ();
             updatePreferences (null, currentPreferences);
             statusbar.pop (statusbarContext);
             statusbar.push (statusbarContext, currentSettings.getStatusbarString (false));
@@ -652,7 +665,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
         currentSettings = newSettings;
         statusbar.pop (statusbarContext);
         statusbar.push (statusbarContext, currentSettings.getStatusbarString (false));
-        updateOutgoingInputArea();
+        updateOutgoingInputArea ();
         profileChanged = true;
     }
 
@@ -855,6 +868,7 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
                 if ((sc.rx > 32) && (sc.nonprintable > 0) && (sc.rx / sc.nonprintable < 4) && 
!sc.forced_hex_view) {
                     sc.forced_hex_view = true;
                     incoming_notebook.set_current_page (1);
+                    profile.setNotebookTab (false, 1);
                 }
 
                 if (currentPreferences.enableTimeout && recordButton.get_active ()) {
@@ -873,10 +887,13 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
     }
 
     private void inputModeChanged (ComboBox inputModeCombo) {
-        if (inputModeCombo.get_active () == inputModeValues.HEX)
+        if (inputModeCombo.get_active () == inputModeValues.HEX) {
             outgoing_notebook.set_current_page (1);
-        else
+            profile.setNotebookTab (true, 1);
+        } else {
             outgoing_notebook.set_current_page (0);
+            profile.setNotebookTab (true, 0);
+        }
     }
 
     private void showHelpButton (ToolButton button) {
diff --git a/src/Preferences.vala b/src/Preferences.vala
index 3d8b9d5..1480fff 100644
--- a/src/Preferences.vala
+++ b/src/Preferences.vala
@@ -71,7 +71,7 @@ public class Preferences : GLib.Object {
 
     public static Gdk.RGBA getGdkRGBA (string color) {
         Gdk.RGBA c = Gdk.RGBA ();
-        c.parse(color);
+        c.parse (color);
         return c;
     }
 
diff --git a/src/Profile.vala b/src/Profile.vala
index 52d4b8f..5f845aa 100644
--- a/src/Profile.vala
+++ b/src/Profile.vala
@@ -59,6 +59,35 @@ public class Profile : GLib.Object {
         }
     }
 
+    public void setNotebookTab (bool outgoing, uint tab) {
+        string n = "incoming_tab";
+        if (outgoing) {
+            n = "outgoing_tab";
+        }
+
+        if (tab != 0) {
+            keyFile.set_integer ("window", n, 1);
+        } else {
+            keyFile.set_integer ("window", n, 0);
+        }
+    }
+
+    public int getNotebookTab (bool outgoing) {
+        string n = "incoming_tab";
+        if (outgoing) {
+            n = "outgoing_tab";
+        }
+
+        try {
+            if (keyFile.get_integer ("window", n) != 0) {
+                return 1;
+            }
+            return 0;
+        } catch (GLib.KeyFileError e) {
+            return 0;
+        }
+    }
+
     public bool load (string ? filename, Gtk.Window window) {
         string f;
         bool default_profile = false;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]