[gedit-latex] Fix preferences dialog



commit 90585b33b3e9a0778023de829666c2a266d743dc
Author: John Stowers <john stowers gmail com>
Date:   Fri Jun 24 18:53:09 2011 +1200

    Fix preferences dialog
    
    	* So we can see what code to delete
    	* Wow, it is a lot

 latex/__init__.py           |   33 ++++----------
 latex/preferences.xml       |   21 ---------
 latex/preferences/dialog.py |   45 ++++++++++++++------
 latex/ui/configure.ui       |   98 +++++++------------------------------------
 4 files changed, 58 insertions(+), 139 deletions(-)
---
diff --git a/latex/__init__.py b/latex/__init__.py
index 54b505d..850a3ae 100644
--- a/latex/__init__.py
+++ b/latex/__init__.py
@@ -22,9 +22,8 @@
 This is searched by gedit for a class extending gedit.Plugin
 """
 
-from gi.repository import Gedit, GObject, Gtk
+from gi.repository import Gedit, GObject, Gtk, PeasGtk
 import logging
-#import platform
 
 logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s	%(name)s - %(message)s")
 
@@ -33,19 +32,16 @@ from util import open_error
 from preferences.dialog import PreferencesDialog
 
 
-class GeditLaTeXPlugin(GObject.Object, Gedit.WindowActivatable):
+class GeditLaTeXPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable):
 	"""
 	This controls the plugin life-cycle
 	"""
 	__gtype_name__ =  "GeditLatexWindowActivatable"
 
-        window = GObject.property(type=Gedit.Window)
-	
-	
+	window = GObject.property(type=Gedit.Window)
+
 	_log = logging.getLogger("GeditLaTeXPlugin")
-	
-	_platform_okay = True 
-	
+
 	def __init__(self):
 		GObject.Object.__init__(self)
 		self._window_decorators = {}
@@ -57,10 +53,7 @@ class GeditLaTeXPlugin(GObject.Object, Gedit.WindowActivatable):
 		
 		@param window: GeditWindow
 		"""
-		self._log.debug("activate")
-		
-		if self._platform_okay:
-			self._window_decorators[self.window] = GeditWindowDecorator(self.window)
+		self._window_decorators[self.window] = GeditWindowDecorator(self.window)
 	
 	def do_deactivate(self):
 		"""
@@ -68,14 +61,8 @@ class GeditLaTeXPlugin(GObject.Object, Gedit.WindowActivatable):
 		
 		@param window: GeditWindow
 		"""
-		self._log.debug("deactivate")
-		
-		if self._platform_okay:
-			self._window_decorators[self.window].destroy()
-			del self._window_decorators[self.window]
-	
-	def create_configure_dialog(self):
-		if self._platform_okay:
-			return PreferencesDialog().dialog
+		self._window_decorators[self.window].destroy()
+		del self._window_decorators[self.window]
 	
-		pass	
+	def do_create_configure_widget(self):
+		return PreferencesDialog().dialog
diff --git a/latex/preferences/dialog.py b/latex/preferences/dialog.py
index b4e9de8..7c49d5a 100644
--- a/latex/preferences/dialog.py
+++ b/latex/preferences/dialog.py
@@ -30,6 +30,13 @@ from ..base.resources import find_resource, MODE_READWRITE
 from ..util import GladeInterface
 from . import Preferences, IPreferencesMonitor
 
+def _insert_column_with_attributes(view, pos, title, rend, **kwargs):
+	print kwargs
+	tv = Gtk.TreeViewColumn(title)
+	tv.pack_start(rend, True)
+	for k in kwargs:
+		tv.add_attribute(rend, k, kwargs[k])
+	view.insert_column(tv, pos)
 
 class PreferencesSpinButtonProxy(object):
 	def __init__(self, widget, key, default_value):
@@ -65,7 +72,7 @@ class PreferencesColorProxy(object):
 		self._preferences = Preferences()
 		
 		# init value
-		self._widget.set_color(Gdk.color_parse(self._preferences.get(key, default_value)))
+		#self._widget.set_color(Gdk.color_parse(self._preferences.get(key, default_value)))
 		
 		# listen to change
 		self._widget.connect("color-set", self._on_color_set)
@@ -201,9 +208,9 @@ class ConfigureToolDialog(GladeInterface):
 			
 			ppRenderer.connect("edited", self._on_job_pp_edited)
 			
-			self._view_job.insert_column_with_attributes(-1, "Command", commandRenderer, text=0, editable=True)
-			self._view_job.insert_column_with_attributes(-1, "Must Succeed", mustSucceedRenderer, active=1)
-			self._view_job.insert_column_with_attributes(-1, "Post-Processor", ppRenderer, text=2)
+			_insert_column_with_attributes(self._view_job, -1, "Command", commandRenderer, text=0, editable=True)
+			_insert_column_with_attributes(self._view_job, -1, "Must Succeed", mustSucceedRenderer, active=1)
+			_insert_column_with_attributes(self._view_job, -1, "Post-Processor", ppRenderer, text=2)
 			
 			#
 			# description
@@ -219,7 +226,7 @@ class ConfigureToolDialog(GladeInterface):
 			
 			self._view_extension = self.find_widget("treeviewExtension")
 			self._view_extension.set_model(self._store_extension)
-			self._view_extension.insert_column_with_attributes(-1, "", Gtk.CellRendererText(), text=0)
+			_insert_column_with_attributes(self._view_extension, -1, "", Gtk.CellRendererText(), text=0)
 			self._view_extension.set_headers_visible(False)
 			
 			self._button_add_extension = self.find_widget("buttonAddExtension")
@@ -383,7 +390,7 @@ class ConfigureSnippetDialog(GladeInterface):
 			self._treeview_package = self.find_widget("treeviewPackage")
 			self._store_package = Gtk.ListStore(str)
 			self._treeview_package.set_model(self._store_package)
-			self._treeview_package.insert_column_with_attributes(-1, "", Gtk.CellRendererText(), text=0)
+			_insert_column_with_attributes(self._treeview_package, -1, "", Gtk.CellRendererText(), text=0)
 			self._treeview_package.set_headers_visible(False)
 			self._button_add_package = self.find_widget("buttonAddPackage")
 			self._button_remove_package = self.find_widget("buttonRemovePackage")
@@ -431,7 +438,7 @@ class PreferencesDialog(GladeInterface, IPreferencesMonitor):
 		if not self._dialog:
 			self._preferences = Preferences()
 			
-			self._dialog = self.find_widget("dialogConfigure")
+			self._dialog = self.find_widget("notebook1")
 			
 			#
 			# snippets
@@ -443,8 +450,8 @@ class PreferencesDialog(GladeInterface, IPreferencesMonitor):
 			
 			self._view_snippets = self.find_widget("treeviewTemplates")
 			self._view_snippets.set_model(self._store_snippets)
-			self._view_snippets.insert_column_with_attributes(-1, "Active", render_toggle, active=0)
-			self._view_snippets.insert_column_with_attributes(-1, "Name", Gtk.CellRendererText(), text=1)
+			_insert_column_with_attributes(self._view_snippets, -1, "Active", render_toggle, active=0)
+			_insert_column_with_attributes(self._view_snippets, -1, "Name", Gtk.CellRendererText(), text=1)
 			
 			self._entry_snippet = self.find_widget("textviewTemplate")
 			
@@ -460,7 +467,7 @@ class PreferencesDialog(GladeInterface, IPreferencesMonitor):
 				
 			self._viewBibs = self.find_widget("treeviewBibs")
 			self._viewBibs.set_model(self._storeBibs)
-			self._viewBibs.insert_column_with_attributes(-1, "Filename", Gtk.CellRendererText(), text=0)
+			_insert_column_with_attributes(self._viewBibs, -1, "Filename", Gtk.CellRendererText(), text=0)
 			
 			#
 			# tools
@@ -476,8 +483,8 @@ class PreferencesDialog(GladeInterface, IPreferencesMonitor):
 				
 			self._view_tool = self.find_widget("treeviewProfiles")
 			self._view_tool.set_model(self._store_tool)
-			self._view_tool.insert_column_with_attributes(-1, "Label", Gtk.CellRendererText(), markup=0)
-			self._view_tool.insert_column_with_attributes(-1, "File Extensions", Gtk.CellRendererText(), text=1)
+			_insert_column_with_attributes(self._view_tool, -1, "Label", Gtk.CellRendererText(), markup=0)
+			_insert_column_with_attributes(self._view_tool, -1, "File Extensions", Gtk.CellRendererText(), text=1)
 			
 			# init tool and listen to tool changes
 			self.__load_tools()
@@ -514,6 +521,9 @@ class PreferencesDialog(GladeInterface, IPreferencesMonitor):
 								   "on_treeviewTemplates_cursor_changed" : self._on_snippet_cursor_changed,
 								   "on_treeviewProfiles_cursor_changed" : self._on_tool_cursor_changed,
 								   "on_buttonNewTemplate_clicked" : self._on_new_snippet_clicked,
+								   "on_buttonDeleteTemplate_clicked" : self._on_delete_snippet_clicked,
+								   "on_buttonAddBib_clicked" : self._on_add_bib_clicked,
+								   "on_buttonRemoveBib_clicked" : self._on_delete_bib_clicked,
 								   "on_buttonNewProfile_clicked" : self._on_new_tool_clicked,
 								   "on_buttonMoveUpTool_clicked" : self._on_tool_up_clicked,
 								   "on_buttonMoveDownTool_clicked" : self._on_tool_down_clicked,
@@ -654,7 +664,16 @@ class PreferencesDialog(GladeInterface, IPreferencesMonitor):
 		snippet = ConfigureSnippetDialog().run(Snippet("Unnamed", "", True, []))
 		if not snippet is None:
 			self._preferences.save_or_update_snippet(snippet)
-	
+
+	def _on_delete_snippet_clicked(self, button):
+		pass
+
+	def _on_delete_bib_clicked(self, button):
+		pass
+
+	def _on_add_bib_clicked(self, button):
+		pass
+			
 	def _on_close_clicked(self, button):
 		self._dialog.hide()
 	
diff --git a/latex/ui/configure.ui b/latex/ui/configure.ui
index 1bdb975..cd3ecf2 100644
--- a/latex/ui/configure.ui
+++ b/latex/ui/configure.ui
@@ -1,61 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
-  <object class="GtkAdjustment" id="adjustment1">
-    <property name="lower">50</property>
-    <property name="upper">10000</property>
-    <property name="value">500</property>
-    <property name="step_increment">10</property>
-    <property name="page_increment">100</property>
-  </object>
-  <object class="GtkDialog" id="dialogConfigure">
-    <property name="can_focus">False</property>
-    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-    <property name="border_width">5</property>
-    <property name="title" translatable="yes">Configure LaTeX Plugin</property>
-    <property name="window_position">center-on-parent</property>
-    <property name="type_hint">dialog</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area1">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="buttonClose">
-                <property name="label">gtk-close</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-                <property name="use_action_appearance">False</property>
-                <property name="use_stock">True</property>
-                <signal name="clicked" handler="on_buttonClose_clicked" swapped="no"/>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
           <object class="GtkNotebook" id="notebook1">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
@@ -942,7 +887,20 @@
                   </packing>
                 </child>
                 <child>
-                  <placeholder/>
+                  <object class="GtkColorButton" id="colorWarning">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_action_appearance">False</property>
+                    <property name="color">#000000000000</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                    <property name="y_options"></property>
+                  </packing>
                 </child>
                 <child>
                   <placeholder/>
@@ -966,20 +924,7 @@
                   <placeholder/>
                 </child>
                 <child>
-                  <object class="GtkColorButton" id="colorWarning">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="use_action_appearance">False</property>
-                    <property name="color">#000000000000</property>
-                  </object>
-                  <packing>
-                    <property name="left_attach">1</property>
-                    <property name="right_attach">2</property>
-                    <property name="top_attach">3</property>
-                    <property name="bottom_attach">4</property>
-                    <property name="y_options"></property>
-                  </packing>
+                  <placeholder/>
                 </child>
               </object>
               <packing>
@@ -997,17 +942,6 @@
                 <property name="tab_fill">False</property>
               </packing>
             </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget response="0">buttonClose</action-widget>
-    </action-widgets>
+
   </object>
 </interface>



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