Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor the base completion text in the config model

 * modify config.py, completion.py and __init__.py to support the new features
  • Loading branch information...
commit 3e4ccc7df99120d5734e43dee12e8e08fd367ffe 1 parent 93b0775
lunar-dev authored
View
26 autocomplete/__init__.py
@@ -1,3 +1,24 @@
+"""
+ __init__.py
+ This file is part of "Gedit Autocomplete"
+ Copyright (C) 2009 - Vincent Petithory, Fabio Zendhi Nagao
+
+ "Gedit Autocomplete" is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ "Gedit Autocomplete" is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with "Gedit Autocomplete"; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor,
+ Boston, MA 02110-1301 USA
+"""
+
import gedit
from completion import AutoCompleteEngine
@@ -15,7 +36,6 @@ def __init__(self):
self.dictionary_words = []
self.filepath = '~/.gnome2/gedit/autocomplete_settings.xml'
- self.base_text = "bonjour magalie"
self.config = ConfigModel(self.filepath)
self.config.load()
@@ -28,13 +48,13 @@ def activate(self, window):
def activate_with_local_scope(self,window):
# Create autocomplete engine in local scope mode
- engine = AutoCompleteEngine(str(self.windows_count), {}, [], self.base_text)
+ engine = AutoCompleteEngine(str(self.windows_count), self.config, {}, [])
engine.activate(window)
self.eng_map[window] = engine
def activate_with_global_scope(self,window):
# Create autocomplete engine in global scope mode
- engine = AutoCompleteEngine(str(self.windows_count), self.words, self.dictionary_words, self.base_text)
+ engine = AutoCompleteEngine(str(self.windows_count), self.config, self.words, self.dictionary_words)
engine.activate(window)
self.eng_map[window] = engine
View
29 autocomplete/completion.py
@@ -1,3 +1,24 @@
+"""
+ completion.py
+ This file is part of "Gedit Autocomplete"
+ Copyright (C) 2009 - Vincent Petithory, Fabio Zendhi Nagao
+
+ "Gedit Autocomplete" is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ "Gedit Autocomplete" is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with "Gedit Autocomplete"; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor,
+ Boston, MA 02110-1301 USA
+"""
+
import gedit
import gtk
import re
@@ -56,9 +77,8 @@ def get_text(self):
class AutoCompleteEngine():
"""Automatically complete words with the Return key."""
- def __init__(self, id, words = None,dictionary_words = None, base_text = ""):
- self.base_text = base_text
-
+ def __init__(self, id, config, words = None,dictionary_words = None):
+ self.config = config
self.completion = None
self.id_name = 'AutoCompletePluginID_'+id
self.tip = None
@@ -92,7 +112,6 @@ def activate(self, window):
self.connect_document(doc)
self.scan(doc)
-
def configure_tab(self, window, tab):
"""Connect the document and view in tab."""
context = tab.get_view().get_pango_context()
@@ -554,7 +573,7 @@ def scan(self, doc, what_to_scan='ALL_WORDS'):
"""Scan document for new words."""
self.dictionary_words = set([])
self.scan_doc(doc,what_to_scan)
- self.scan_text(self.base_text,what_to_scan)
+ self.scan_text(self.config.get_base_words(),what_to_scan)
self.dictionary_words = list(self.dictionary_words)
self.dictionary_words.sort()
View
42 autocomplete/config.py
@@ -1,3 +1,24 @@
+"""
+ config.py
+ This file is part of "Gedit Autocomplete"
+ Copyright (C) 2009 - Vincent Petithory, Fabio Zendhi Nagao
+
+ "Gedit Autocomplete" is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ "Gedit Autocomplete" is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with "Gedit Autocomplete"; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor,
+ Boston, MA 02110-1301 USA
+"""
+
import pygtk
pygtk.require('2.0')
import gtk
@@ -9,7 +30,7 @@ class ConfigModel():
def __init__(self, filepath):
# init default values
self.scope = "global"
-
+ self.base_words = ""
self.filepath = filepath
self.sv = ConfigService(self, filepath)
@@ -19,11 +40,17 @@ def load(self):
def save(self):
self.sv.save()
+ def get_scope(self):
+ return self.scope
+
def set_scope(self,value):
self.scope = value
- def get_scope(self):
- return self.scope
+ def get_base_words(self):
+ return self.base_words
+
+ def set_base_words(self,value):
+ self.base_words = value
class ConfigService():
def __init__(self, config, filepath):
@@ -53,7 +80,8 @@ def save(self):
fp = file(self.file, "wb")
fp.write('<?xml version="1.0" encoding="UTF-8"?>\n')
scope_dump = ' <scope>%s</scope>\n' % self._escape(self.config.get_scope())
- settings = '<autocomplete>\n%s</autocomplete>\n' % scope_dump;
+ base_words_dump = ' <words>%s</words>\n' % self._escape(self.config.get_base_words())
+ settings = '<autocomplete>\n%s</autocomplete>\n' % scope_dump+base_words_dump;
fp.write(settings)
fp.close()
@@ -66,11 +94,15 @@ def _escape(self, xml):
def __start_element(self, tag, attrs):
if tag == 'scope':
self.current_tag = 'scope'
+ elif tag == 'words':
+ self.current_tag = 'words'
def __end_element(self, tag):
self.current_tag = None
def __character_data(self, data):
if self.current_tag == 'scope':
self.config.set_scope(data)
+ elif self.current_tag == 'words':
+ self.config.set_base_words(data)
class ConfigurationDialog(gtk.Dialog):
def __init__(self,config,callback):
@@ -110,6 +142,8 @@ def __init__(self,config,callback):
scope_box.add(global_scope_button)
scope_box.add(local_scope_button)
+ # TODO make entry for base_words
+
self.vbox.pack_start(scope_box, True, True, 0)
scope_box.show_all()
View
1  autocomplete_settings-base.xml
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<autocomplete>
<scope>global</scope>
+ <words></words>
</autocomplete>
Please sign in to comment.
Something went wrong with that request. Please try again.