~quequotion/glippy/glippy

« back to all changes in this revision

Viewing changes to src/actions/EditActionWindow.cs

  • Committer: Que Quotion
  • Date: 2018-07-01 13:34:36 UTC
  • Revision ID: quequotion@bugmenot.com-20180701133436-usy073goo274fh6a
Glippy: Simple, powerful clipboard manager

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Glippy
 
3
 * Copyright © 2010, 2011, 2012 Wojciech Kowalczyk
 
4
 * The program is distributed under the terms of the GNU General Public License Version 3.
 
5
 * See LICENCE for details.
 
6
 */
 
7
 
 
8
using System;
 
9
using Gtk;
 
10
using Mono.Unix;
 
11
 
 
12
namespace Glippy.Actions
 
13
{
 
14
        /// <summary>
 
15
        /// Edit action window.
 
16
        /// </summary>
 
17
        internal partial class EditActionWindow : Window
 
18
        {
 
19
                /// <summary>
 
20
                /// Edited action.
 
21
                /// </summary>
 
22
                private Action action;
 
23
                
 
24
                /// <summary>
 
25
                /// Tree iterator.
 
26
                /// </summary>
 
27
                private TreeIter iter;
 
28
                
 
29
                /// <summary>
 
30
                /// Tree path.
 
31
                /// </summary>
 
32
                private TreePath path;
 
33
                
 
34
                /// <summary>
 
35
                /// List of actions.
 
36
                /// </summary>
 
37
                private ListStore list;
 
38
                
 
39
                /// <summary>
 
40
                /// Plugin.
 
41
                /// </summary>
 
42
                private Actions plugin;
 
43
                
 
44
                /// <summary>
 
45
                /// Initializes a new instance of class.
 
46
                /// </summary>
 
47
                /// <param name="plugin">Plugin.</param>
 
48
                /// <param name="list">List of actions.</param>
 
49
                public EditActionWindow(Actions plugin, ListStore list) : base(WindowType.Toplevel)
 
50
                {
 
51
                        this.Build();
 
52
                        this.list = list;
 
53
                        this.plugin = plugin;
 
54
                        
 
55
                        try
 
56
                        {
 
57
                                this.Icon = IconTheme.Default.LoadIcon("glippy", 128, IconLookupFlags.GenericFallback);
 
58
                        }
 
59
                        catch (Exception ex)
 
60
                        {
 
61
                                Core.Tools.PrintInfo(ex, this.GetType());
 
62
                        }                       
 
63
                        
 
64
                        this.Destroyed += (s, e) => this.Purge();
 
65
                }
 
66
                
 
67
                /// <summary>
 
68
                /// Initializes a new instance of class.
 
69
                /// </summary>
 
70
                /// <param name="plugin">Plugin.</param>
 
71
                /// <param name="list">List of plugins.</param>
 
72
                /// <param name="action">Edited action.</param>
 
73
                /// <param name="path">Tree path of edited element.</param>
 
74
                /// <param name="iter">Tree iterator of edited element.</param>
 
75
                public EditActionWindow(Actions plugin, ListStore list, Action action, TreePath path, TreeIter iter) : this(plugin, list)
 
76
                {
 
77
                        this.action = action;
 
78
                        this.iter = iter;
 
79
                        this.path = path;
 
80
                        this.label.Text = action.Label;
 
81
                        this.content.Buffer.Text = action.Content;
 
82
                        this.Title = Catalog.GetString("Edit action");                                          
 
83
                }
 
84
                
 
85
                /// <summary>
 
86
                /// Cleans window.
 
87
                /// </summary>
 
88
                public void Purge()
 
89
                {
 
90
                        this.plugin.EditActionWindow = null;
 
91
                        this.Dispose();
 
92
                }
 
93
                
 
94
                /// <summary>
 
95
                /// Handles key press event event.
 
96
                /// </summary>
 
97
                /// <param name="sender">Sender.</param>
 
98
                /// <param name="args">Event arguments.</param>
 
99
                private void OnKeyPressEvent(object sender, KeyPressEventArgs args)
 
100
                {
 
101
                        if (args.Event.Key == Gdk.Key.Escape)
 
102
                                this.Destroy();
 
103
                }                                               
 
104
                
 
105
                /// <summary>
 
106
                /// Handles button cancel clicked event.
 
107
                /// </summary>
 
108
                /// <param name="sender">Sender.</param>
 
109
                /// <param name="args">Event arguments.</param>
 
110
                private void OnButtonCancelClicked(object sender, EventArgs args)
 
111
                {
 
112
                        this.Destroy();
 
113
                }
 
114
                
 
115
                /// <summary>
 
116
                /// Handles button apply clicked event.
 
117
                /// </summary>
 
118
                /// <param name="sender">Sender.</param>
 
119
                /// <param name="args">Event arguments.</param>
 
120
                private void OnButtonApplyClicked(object sender, EventArgs args)
 
121
                {
 
122
                        MessageDialog dialog;
 
123
                        
 
124
                        if (this.label.Text.Length == 0)                        
 
125
                        {
 
126
                                dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, Catalog.GetString("Label is required."));
 
127
                                dialog.Run();
 
128
                                dialog.Destroy();
 
129
                                dialog.Dispose();
 
130
                        }
 
131
                        else if (this.content.Buffer.Text.Length == 0)
 
132
                        {
 
133
                                dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, false, Catalog.GetString("Content is required."));
 
134
                                dialog.Run();
 
135
                                dialog.Destroy();
 
136
                                dialog.Dispose();
 
137
                        }
 
138
                        else
 
139
                        {
 
140
                                if (this.action != null)
 
141
                                {
 
142
                                        this.action.Label = this.label.Text;
 
143
                                        this.action.Content = this.content.Buffer.Text;                                 
 
144
                                        this.list.EmitRowChanged(this.path, this.iter);
 
145
                                }
 
146
                                else
 
147
                                {
 
148
                                        this.action = new Action();
 
149
                                        this.action.Label = this.label.Text;
 
150
                                        this.action.Content = this.content.Buffer.Text;                                 
 
151
                                        this.list.AppendValues(action);
 
152
                                }
 
153
                                
 
154
                                this.Destroy();
 
155
                        }                       
 
156
                }
 
157
        }
 
158
}