Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Last active Nov 11, 2015
Embed
What would you like to do?
Add some more open source license to Geany
diff --git a/data/geany.glade b/data/geany.glade
index 3c04578..184cce0 100644
--- a/data/geany.glade
+++ b/data/geany.glade
@@ -269,6 +269,26 @@
</object>
</child>
<child>
+ <object class="GtkMenuItem" id="insert_apache2_notice1">
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Insert _Apache 2.0 Notice</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_comments_apache2_activate" swapped="no"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="insert_bsd_notice1">
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Insert _BSD Notice</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_comments_bsd_activate" swapped="no"/>
+ </object>
+ </child>
+ <child>
<object class="GtkMenuItem" id="insert_gpl_notice1">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
diff --git a/data/templates/apache2 b/data/templates/apache2
new file mode 100644
index 0000000..df99d14
--- /dev/null
+++ b/data/templates/apache2
@@ -0,0 +1,11 @@
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+this file except in compliance with the License. You may obtain a copy of the
+License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software distributed
+under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied. See the License for the
+specific language governing permissions and limitations under the License.
+
diff --git a/data/templates/lgpl b/data/templates/lgpl
new file mode 100644
index 0000000..7741edb
--- /dev/null
+++ b/data/templates/lgpl
@@ -0,0 +1,14 @@
+This library is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free
+Software Foundation; either version 2.1 of the License, or (at your option)
+any later version.
+
+This library 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 Lesser General Public License for more
+details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this library; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
diff --git a/data/templates/mit b/data/templates/mit
new file mode 100644
index 0000000..209d778
--- /dev/null
+++ b/data/templates/mit
@@ -0,0 +1,18 @@
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
diff --git a/data/templates/wtfpl b/data/templates/wtfpl
new file mode 100644
index 0000000..dc9c179
--- /dev/null
+++ b/data/templates/wtfpl
@@ -0,0 +1,20 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+Everyone is permitted to copy and distribute verbatim or modified copies of
+this license document, and changing it is allowed as long as the name is
+changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+0. You just DO WHAT THE FUCK YOU WANT TO.
+
+This program is free software. It comes without any warranty, to the extent
+permitted by applicable law. You can redistribute it and/or modify it under
+the terms of the Do What The Fuck You Want To Public License, Version 2, as
+published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more
+details.
+
diff --git a/src/callbacks.c b/src/callbacks.c
index ece2d9d..1a2a094 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -1210,6 +1210,24 @@ G_MODULE_EXPORT void on_comments_gpl_activate(GtkMenuItem *menuitem, gpointer us
}
+G_MODULE_EXPORT void on_comments_lgpl_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GeanyDocument *doc = document_get_current();
+ gchar *text;
+
+ g_return_if_fail(doc != NULL);
+
+ text = templates_get_template_licence(doc, GEANY_TEMPLATE_LGPL);
+
+ verify_click_pos(doc); /* make sure that the click_pos is valid */
+
+ sci_start_undo_action(doc->editor->sci);
+ sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
+ sci_end_undo_action(doc->editor->sci);
+ g_free(text);
+}
+
+
G_MODULE_EXPORT void on_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
@@ -1229,6 +1247,60 @@ G_MODULE_EXPORT void on_comments_bsd_activate(GtkMenuItem *menuitem, gpointer us
}
+G_MODULE_EXPORT void on_comments_mit_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GeanyDocument *doc = document_get_current();
+ gchar *text;
+
+ g_return_if_fail(doc != NULL);
+
+ text = templates_get_template_licence(doc, GEANY_TEMPLATE_MIT);
+
+ verify_click_pos(doc); /* make sure that the click_pos is valid */
+
+ sci_start_undo_action(doc->editor->sci);
+ sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
+ sci_end_undo_action(doc->editor->sci);
+ g_free(text);
+}
+
+
+G_MODULE_EXPORT void on_comments_apache2_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GeanyDocument *doc = document_get_current();
+ gchar *text;
+
+ g_return_if_fail(doc != NULL);
+
+ text = templates_get_template_licence(doc, GEANY_TEMPLATE_APACHE2);
+
+ verify_click_pos(doc); /* make sure that the click_pos is valid */
+
+ sci_start_undo_action(doc->editor->sci);
+ sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
+ sci_end_undo_action(doc->editor->sci);
+ g_free(text);
+}
+
+
+G_MODULE_EXPORT void on_comments_wtfpl_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GeanyDocument *doc = document_get_current();
+ gchar *text;
+
+ g_return_if_fail(doc != NULL);
+
+ text = templates_get_template_licence(doc, GEANY_TEMPLATE_WTFPL);
+
+ verify_click_pos(doc); /* make sure that the click_pos is valid */
+
+ sci_start_undo_action(doc->editor->sci);
+ sci_insert_text(doc->editor->sci, editor_info.click_pos, text);
+ sci_end_undo_action(doc->editor->sci);
+ g_free(text);
+}
+
+
G_MODULE_EXPORT void on_comments_changelog_activate(GtkMenuItem *menuitem, gpointer user_data)
{
GeanyDocument *doc = document_get_current();
@@ -1543,6 +1615,13 @@ G_MODULE_EXPORT void on_menu_comments_gpl_activate(GtkMenuItem *menuitem, gpoint
}
+G_MODULE_EXPORT void on_menu_comments_lgpl_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ insert_callback_from_menu = TRUE;
+ on_comments_lgpl_activate(menuitem, user_data);
+}
+
+
G_MODULE_EXPORT void on_menu_comments_bsd_activate(GtkMenuItem *menuitem, gpointer user_data)
{
insert_callback_from_menu = TRUE;
@@ -1550,6 +1629,27 @@ G_MODULE_EXPORT void on_menu_comments_bsd_activate(GtkMenuItem *menuitem, gpoint
}
+G_MODULE_EXPORT void on_menu_comments_mit_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ insert_callback_from_menu = TRUE;
+ on_comments_mit_activate(menuitem, user_data);
+}
+
+
+G_MODULE_EXPORT void on_menu_comments_apache2_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ insert_callback_from_menu = TRUE;
+ on_comments_apache2_activate(menuitem, user_data);
+}
+
+
+G_MODULE_EXPORT void on_menu_comments_wtfpl_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ insert_callback_from_menu = TRUE;
+ on_comments_wtfpl_activate(menuitem, user_data);
+}
+
+
G_MODULE_EXPORT void on_menu_insert_include_activate(GtkMenuItem *menuitem, gpointer user_data)
{
insert_callback_from_menu = TRUE;
diff --git a/src/callbacks.h b/src/callbacks.h
index f6435cf..f91a8ab 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -420,7 +420,6 @@ G_MODULE_EXPORT void
on_next_message1_activate (GtkMenuItem *menuitem,
gpointer user_data);
-
G_MODULE_EXPORT void
on_menu_comments_multiline_activate (GtkMenuItem *menuitem,
gpointer user_data);
@@ -430,6 +429,10 @@ on_menu_comments_gpl_activate (GtkMenuItem *menuitem,
gpointer user_data);
G_MODULE_EXPORT void
+on_menu_comments_lgpl_activate (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+G_MODULE_EXPORT void
on_menu_insert_include_activate (GtkMenuItem *menuitem,
gpointer user_data);
@@ -446,6 +449,18 @@ on_comments_bsd_activate (GtkMenuItem *menuitem,
gpointer user_data);
G_MODULE_EXPORT void
+on_comments_mit_activate (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+G_MODULE_EXPORT void
+on_comments_apache2_activate (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+G_MODULE_EXPORT void
+on_comments_wtfpl_activate (GtkMenuItem *menuitem,
+ gpointer user_data);
+
+G_MODULE_EXPORT void
on_project_new1_activate (GtkMenuItem *menuitem,
gpointer user_data);
diff --git a/src/templates.c b/src/templates.c
index e77d33b..9797d40 100644
--- a/src/templates.c
+++ b/src/templates.c
@@ -121,8 +121,12 @@ static void init_general_templates(void)
{
/* read the contents */
read_template("fileheader", GEANY_TEMPLATE_FILEHEADER);
- read_template("gpl", GEANY_TEMPLATE_GPL);
+ read_template("apache2", GEANY_TEMPLATE_APACHE2);
read_template("bsd", GEANY_TEMPLATE_BSD);
+ read_template("gpl", GEANY_TEMPLATE_GPL);
+ read_template("lgpl", GEANY_TEMPLATE_LGPL);
+ read_template("mit", GEANY_TEMPLATE_MIT);
+ read_template("wtfpl", GEANY_TEMPLATE_WTFPL);
read_template("function", GEANY_TEMPLATE_FUNCTION);
read_template("changelog", GEANY_TEMPLATE_CHANGELOG);
}
@@ -432,14 +436,19 @@ static void make_comment_block(GString *comment_text, gint filetype_idx, guint i
}
-gchar *templates_get_template_licence(GeanyDocument *doc, gint licence_type)
+gchar *templates_get_template_licence(GeanyDocument *doc, gint license_type)
{
GString *template;
g_return_val_if_fail(doc != NULL, NULL);
- g_return_val_if_fail(licence_type == GEANY_TEMPLATE_GPL || licence_type == GEANY_TEMPLATE_BSD, NULL);
-
- template = g_string_new(templates[licence_type]);
+ g_return_val_if_fail(license_type == GEANY_TEMPLATE_GPL ||
+ license_type == GEANY_TEMPLATE_LGPL ||
+ license_type == GEANY_TEMPLATE_BSD ||
+ license_type == GEANY_TEMPLATE_MIT ||
+ license_type == GEANY_TEMPLATE_APACHE2 ||
+ license_type == GEANY_TEMPLATE_WTFPL, NULL);
+
+ template = g_string_new(templates[license_type]);
replace_static_values(template);
templates_replace_default_dates(template);
templates_replace_command(template, DOC_FILENAME(doc), doc->file_type->name, NULL);
@@ -458,8 +467,12 @@ static gchar *get_template_fileheader(GeanyFiletype *ft)
filetypes_load_config(ft->id, FALSE); /* load any user extension setting */
templates_replace_valist(template,
- "{gpl}", templates[GEANY_TEMPLATE_GPL],
+ "{apache2}", templates[GEANY_TEMPLATE_APACHE2],
"{bsd}", templates[GEANY_TEMPLATE_BSD],
+ "{gpl}", templates[GEANY_TEMPLATE_GPL],
+ "{lgpl}", templates[GEANY_TEMPLATE_LGPL],
+ "{mit}", templates[GEANY_TEMPLATE_MIT],
+ "{wtfpl}", templates[GEANY_TEMPLATE_WTFPL],
NULL);
/* we don't replace other wildcards here otherwise they would get done twice for files */
diff --git a/src/templates.h b/src/templates.h
index 0cf0da4..4614f4e 100644
--- a/src/templates.h
+++ b/src/templates.h
@@ -34,8 +34,12 @@ G_BEGIN_DECLS
enum
{
- GEANY_TEMPLATE_GPL = 0,
+ GEANY_TEMPLATE_APACHE2 = 0,
GEANY_TEMPLATE_BSD,
+ GEANY_TEMPLATE_GPL,
+ GEANY_TEMPLATE_LGPL,
+ GEANY_TEMPLATE_MIT,
+ GEANY_TEMPLATE_WTFPL,
GEANY_TEMPLATE_FILEHEADER,
GEANY_TEMPLATE_CHANGELOG,
GEANY_TEMPLATE_FUNCTION,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment