Skip to content

Commit

Permalink
Only allow user to save schemes to ~/.local/share/gedit/styles/
Browse files Browse the repository at this point in the history
  • Loading branch information
jonocodes committed Apr 8, 2013
1 parent 219d366 commit 2ff5ad1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
54 changes: 20 additions & 34 deletions schemer/schemer.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,46 +271,32 @@ def on_save_clicked(self, param):
return

nameOrIdChange = True



# attempt to save to ~/.local/share/gedit/styles/
stylesDir = os.path.join(GLib.get_user_data_dir(), "gedit", "styles")

# if the file name or ID did not change, and they are using a local file, save it there
if not nameOrIdChange and os.access(inFile, os.W_OK) and (str(os.path.dirname(inFile)) != tempDirectory):
if (not nameOrIdChange and
os.access(inFile, os.W_OK) and
os.path.dirname(inFile) == stylesDir and
(str(os.path.dirname(inFile)) != tempDirectory)):

outFile = inFile

# else, create a new file
# else, designate a new file
else:
possibleDirs = self.schemeManager.get_search_path()

# attempt to save to ~/.local/share/gedit/styles/
thisDir = os.path.join(GLib.get_user_data_dir(), "gedit", "styles")

if thisDir in possibleDirs:
if not os.path.isdir(thisDir):
try:
os.makedirs(thisDir)
except:
pass
if not os.path.isdir(stylesDir):
try:
os.makedirs(stylesDir)
except:
pass

if (os.access(stylesDir, os.W_OK)):
outFile = os.path.join(stylesDir, self.entryId.get_text() + '.xml')


if (os.access(thisDir, os.W_OK)):
outFile = os.path.join(thisDir, self.entryId.get_text() + '.xml')

# if we cant save it there, save it where ever we have permission to save it
if not outFile:
for thisDir in possibleDirs:

if thisDir == tempDirectory:
continue

# create the directory if it does not exist
if not os.path.isdir(thisDir):
try:
os.makedirs(thisDir)
except:
pass

if (os.access(thisDir, os.W_OK)):
outFile = os.path.join(thisDir, self.entryId.get_text() + '.xml')
break

if outFile:

# make sure the name/ID to not refer to a system scheme that is not writable
Expand Down
45 changes: 14 additions & 31 deletions schemer/schemer.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<!-- interface-requires gtksourceview 3.0 -->
<object class="GtkListStore" id="liststoreLanguages">
<columns>
Expand All @@ -16,7 +17,7 @@
<object class="GtkWindow" id="window">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Scheme Editor</property>
<property name="title" translatable="yes">Color Scheme Editor</property>
<property name="window_position">center</property>
<property name="default_width">700</property>
<property name="default_height">550</property>
Expand All @@ -25,6 +26,10 @@
<object class="GtkVBox" id="vbox20">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">8</property>
<property name="margin_bottom">2</property>
<property name="spacing">2</property>
<child>
<object class="GtkVBox" id="vbox21">
Expand Down Expand Up @@ -126,14 +131,12 @@
<property name="homogeneous">True</property>
<child>
<object class="GtkToggleButton" id="togglebuttonBold">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Bold</property>
<property name="tooltip_text" translatable="yes">Bold</property>
<property name="use_action_appearance">False</property>
<property name="relief">none</property>
<child>
<object class="GtkImage" id="image30">
Expand All @@ -151,14 +154,12 @@
</child>
<child>
<object class="GtkToggleButton" id="togglebuttonItalic">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Italic</property>
<property name="tooltip_text" translatable="yes">Italic</property>
<property name="use_action_appearance">False</property>
<property name="relief">none</property>
<child>
<object class="GtkImage" id="image31">
Expand All @@ -176,14 +177,12 @@
</child>
<child>
<object class="GtkToggleButton" id="togglebuttonUnderline">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Underline</property>
<property name="tooltip_text" translatable="yes">Underline</property>
<property name="use_action_appearance">False</property>
<property name="relief">none</property>
<child>
<object class="GtkImage" id="image32">
Expand All @@ -201,14 +200,12 @@
</child>
<child>
<object class="GtkToggleButton" id="togglebuttonStrikethrough">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Strikethrough</property>
<property name="tooltip_text" translatable="yes">Strikethrough</property>
<property name="use_action_appearance">False</property>
<property name="relief">none</property>
<child>
<object class="GtkImage" id="image33">
Expand Down Expand Up @@ -241,74 +238,66 @@
<property name="row_spacing">12</property>
<child>
<object class="GtkColorButton" id="colorbuttonBackground">
<property name="use_action_appearance">False</property>
<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="title" translatable="yes">Pick the background color</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
<property name="x_options"/>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkColorButton" id="colorbuttonForeground">
<property name="use_action_appearance">False</property>
<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="title" translatable="yes">Pick the foreground color</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
<property name="x_options"/>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbuttonBackground">
<property name="label" translatable="yes">_Background</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options"></property>
<property name="y_options"></property>
<property name="x_options"/>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="checkbuttonForeground">
<property name="label" translatable="yes">_Foreground</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="x_options"></property>
<property name="y_options"></property>
<property name="x_options"/>
<property name="y_options"/>
</packing>
</child>
</object>
Expand All @@ -320,11 +309,9 @@
</child>
<child>
<object class="GtkButton" id="resetButton">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<child>
<object class="GtkAlignment" id="alignment7">
<property name="visible">True</property>
Expand Down Expand Up @@ -588,11 +575,9 @@
<child>
<object class="GtkButton" id="buttonCancel">
<property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</property>
<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="use_stock">True</property>
</object>
<packing>
Expand All @@ -604,11 +589,9 @@
<child>
<object class="GtkButton" id="buttonSave">
<property name="label">gtk-save</property>
<property name="use_action_appearance">False</property>
<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="use_stock">True</property>
</object>
<packing>
Expand Down

0 comments on commit 2ff5ad1

Please sign in to comment.