Skip to content

Commit

Permalink
Broken attempt to progress regarding shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
maoschanz committed May 7, 2019
1 parent ef5c4d5 commit d959f3b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 10 deletions.
57 changes: 48 additions & 9 deletions markdown_preview/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
LOCALE_PATH = os.path.join(BASE_PATH, 'locale')

MD_PREVIEW_KEY_BASE = 'org.gnome.gedit.plugins.markdown_preview'
BASE_TEMP_NAME = '/tmp/gedit_plugin_markdown_preview'

try:
import gettext
gettext.bindtextdomain('gedit-plugin-markdown-preview', LOCALE_PATH)
gettext.textdomain('gedit-plugin-markdown-preview')
_ = gettext.gettext
import gettext
gettext.bindtextdomain('gedit-plugin-markdown-preview', LOCALE_PATH)
gettext.textdomain('gedit-plugin-markdown-preview')
_ = gettext.gettext
except:
_ = lambda s: s
_ = lambda s: s

class MdConfigWidget(Gtk.Box):
__gtype_name__ = 'MdConfigWidget'

Expand Down Expand Up @@ -82,18 +81,58 @@ def __init__(self, datadir, **kwargs):
styleButton.connect('clicked', self.on_choose_css)

### SHORTCUTS ###
# TODO
shortcuts_treeview = builder.get_object('shortcuts_treeview')
#--------
renderer1 = Gtk.CellRendererText()
column1 = Gtk.TreeViewColumn()
column1.set_expand(True)
column1.pack_start(renderer1, True)
column1.add_attribute(renderer1, 'text', 1);
shortcuts_treeview.append_column(column1)
#--------
renderer2 = Gtk.CellRendererAccel(editable=True, \
accel_mode=Gtk.CellRendererAccelMode.GTK)
renderer2.connect('accel-edited', self.on_accel_edited)
renderer2.connect('accel-cleared', self.on_accel_cleared)
column2 = Gtk.TreeViewColumn()
column2.pack_end(renderer2, False)
shortcuts_treeview.append_column(column2)
#--------
self.add_keybinding(shortcuts_treeview.get_model(), 'kb-italic', _("Italic"))
self.add_keybinding(shortcuts_treeview.get_model(), 'kb-bold', _("Bold"))

# shortcuts_treeview.show_all()

# https://github.com/GNOME/gtk/blob/master/gdk/keynames.txt


self.add(switcher)
self.add(stack)

self.connect('notify::visible', self.set_options_visibility)

def add_keybinding(self, model, setting_id, description):
# accelerator = self._settings.get_strv(setting_id)[0]
# if accelerator is None:
# [key, mods] = [0, 0]
# else:
# [key, mods] = Gtk.accelerator_parse(self._settings.get_strv(setting_id)[0])
key = 0
mods = 0

row = model.insert(0, row=[setting_id, description, key, mods])

# row = model.insert(100)
# model.set(row, \
# [COLUMN_ID, COLUMN_DESCRIPTION, COLUMN_KEY, COLUMN_MODS],
# [setting_id, description, key, mods])

def on_accel_edited(self, *args):
pass # TODO

def on_accel_cleared(self, *args):
pass # TODO

def on_backend_changed(self, w):
self._settings.set_string('backend', w.get_active_id())
self.set_options_visibility()
Expand Down
43 changes: 42 additions & 1 deletion markdown_preview/prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,31 @@
<property name="orientation">vertical</property>
<child>
<object class="GtkTreeView" id="shortcuts_treeview">
<property name="enable-grid-lines">True</property>
<property name="headers-visible">False</property>
<property name="model">list_store</property>


<!-- <child>-->
<!-- <object class="GtkTreeViewColumn">-->
<!-- <property name="title">Description</property>-->
<!-- <child>-->
<!-- <object class="GtkCellRendererText"/>-->
<!-- <attributes>-->
<!-- <attribute name="text">1</attribute>-->
<!-- </attributes>-->
<!-- </child>-->
<!-- </object>-->
<!-- </child>-->
<!-- <child>-->
<!-- <object class="GtkTreeViewColumn">-->
<!-- <property name="title">Shortcut</property>-->
<!-- <child>-->
<!-- <object class="GtkCellRendererAccel"/>-->
<!-- TODO-->
<!-- </child>-->
<!-- </object>-->
<!-- </child>-->

</object>
</child>
</object>
Expand All @@ -259,5 +282,23 @@
</packing>
</child>
</object>

<object class="GtkListStore" id="list_store">
<columns>
<column type="gchararray"/>
<column type="gchararray"/>
<column type="gint"/>
<column type="gint"/>
</columns>
<data>
<!-- <row>-->
<!-- <col id="0">John</col>-->
<!-- <col id="1">Doe</col>-->
<!-- <col id="2">25</col>-->
<!-- <col id="3">25</col>-->
<!-- </row>-->
</data>
</object>

</interface>

13 changes: 13 additions & 0 deletions org.gnome.gedit.plugins.markdown_preview.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,18 @@
<summary></summary>
<description></description>
</key>

<key name="kb-italic" type="as">
<default><![CDATA[['<Primary>slash']]]></default>
<summary>Add italic markup</summary>
<description></description>
</key>
<key name="kb-bold" type="as">
<default><![CDATA[['<Primary><Shift>B']]]></default>
<summary>Add bold markup</summary>
<description></description>
</key>
</schema>
</schemalist>


0 comments on commit d959f3b

Please sign in to comment.