Lines 52-57
Link Here
|
52 |
import org.netbeans.modules.mercurial.HgFileNode; |
52 |
import org.netbeans.modules.mercurial.HgFileNode; |
53 |
import org.netbeans.modules.mercurial.HgModuleConfig; |
53 |
import org.netbeans.modules.mercurial.HgModuleConfig; |
54 |
import org.netbeans.modules.mercurial.ui.actions.ContextAction; |
54 |
import org.netbeans.modules.mercurial.ui.actions.ContextAction; |
|
|
55 |
import org.netbeans.modules.mercurial.ui.status.StatusAction; |
55 |
import org.netbeans.modules.mercurial.util.HgUtils; |
56 |
import org.netbeans.modules.mercurial.util.HgUtils; |
56 |
import org.netbeans.modules.mercurial.util.HgRepositoryContextCache; |
57 |
import org.netbeans.modules.mercurial.util.HgRepositoryContextCache; |
57 |
import org.netbeans.modules.mercurial.util.HgProjectUtils; |
58 |
import org.netbeans.modules.mercurial.util.HgProjectUtils; |
Lines 63-70
Link Here
|
63 |
import javax.swing.*; |
64 |
import javax.swing.*; |
64 |
import java.awt.*; |
65 |
import java.awt.*; |
65 |
import java.io.File; |
66 |
import java.io.File; |
|
|
67 |
import java.util.logging.Level; |
66 |
import java.util.ArrayList; |
68 |
import java.util.ArrayList; |
67 |
import java.util.List; |
69 |
import java.util.List; |
|
|
70 |
import java.util.Set; |
68 |
import java.util.Iterator; |
71 |
import java.util.Iterator; |
69 |
import java.util.Map; |
72 |
import java.util.Map; |
70 |
import javax.swing.event.TableModelEvent; |
73 |
import javax.swing.event.TableModelEvent; |
Lines 99-106
Link Here
|
99 |
} |
102 |
} |
100 |
|
103 |
|
101 |
public boolean isEnabled () { |
104 |
public boolean isEnabled () { |
102 |
FileStatusCache cache = Mercurial.getInstance().getFileStatusCache(); |
105 |
Set<File> ctxFiles = context != null? context.getRootFiles(): null; |
103 |
return cache.containsFileOfStatus(context, FileInformation.STATUS_LOCAL_CHANGE); |
106 |
if(HgUtils.getRootFile(context) == null || ctxFiles == null || ctxFiles.size() == 0) |
|
|
107 |
return false; |
108 |
return true; |
104 |
} |
109 |
} |
105 |
|
110 |
|
106 |
public void performAction(ActionEvent e) { |
111 |
public void performAction(ActionEvent e) { |
Lines 125-136
Link Here
|
125 |
} |
130 |
} |
126 |
|
131 |
|
127 |
public static void commit(String contentTitle, final VCSContext ctx) { |
132 |
public static void commit(String contentTitle, final VCSContext ctx) { |
128 |
FileStatusCache cache = Mercurial.getInstance().getFileStatusCache(); |
|
|
129 |
File[] roots = ctx.getRootFiles().toArray(new File[ctx.getRootFiles().size()]); |
130 |
if (roots == null || roots.length == 0) { |
131 |
return; |
132 |
} |
133 |
|
134 |
final File repository = HgUtils.getRootFile(ctx); |
133 |
final File repository = HgUtils.getRootFile(ctx); |
135 |
if (repository == null) return; |
134 |
if (repository == null) return; |
136 |
String projName = HgProjectUtils.getProjectName(repository); |
135 |
String projName = HgProjectUtils.getProjectName(repository); |
Lines 140-192
Link Here
|
140 |
} |
139 |
} |
141 |
final String prjName = projName; |
140 |
final String prjName = projName; |
142 |
|
141 |
|
143 |
File[][] split = Utils.splitFlatOthers(roots); |
|
|
144 |
List<File> fileList = new ArrayList<File>(); |
145 |
for (int c = 0; c < split.length; c++) { |
146 |
roots = split[c]; |
147 |
boolean recursive = c == 1; |
148 |
if (recursive) { |
149 |
File[] files = cache.listFiles(ctx, FileInformation.STATUS_LOCAL_CHANGE); |
150 |
for (int i= 0; i < files.length; i++) { |
151 |
for(int r = 0; r < roots.length; r++) { |
152 |
if( HgUtils.isParentOrEqual(roots[r], files[i]) ) { |
153 |
if(!fileList.contains(files[i])) { |
154 |
fileList.add(files[i]); |
155 |
} |
156 |
} |
157 |
} |
158 |
} |
159 |
} else { |
160 |
File[] files = HgUtils.flatten(roots, FileInformation.STATUS_LOCAL_CHANGE); |
161 |
for (int i= 0; i<files.length; i++) { |
162 |
if(!fileList.contains(files[i])) { |
163 |
fileList.add(files[i]); |
164 |
} |
165 |
} |
166 |
} |
167 |
} |
168 |
|
169 |
if(fileList.size()==0) { |
170 |
return; |
171 |
} |
172 |
|
173 |
// show commit dialog |
142 |
// show commit dialog |
174 |
final CommitPanel panel = new CommitPanel(); |
143 |
final CommitPanel panel = new CommitPanel(); |
175 |
final CommitTable data = new CommitTable(panel.filesLabel, CommitTable.COMMIT_COLUMNS, new String[] {CommitTableModel.COLUMN_NAME_PATH }); |
144 |
final CommitTable data = new CommitTable(panel.filesLabel, CommitTable.COMMIT_COLUMNS, new String[] {CommitTableModel.COLUMN_NAME_PATH }); |
176 |
|
145 |
|
177 |
panel.setCommitTable(data); |
146 |
panel.setCommitTable(data); |
178 |
|
147 |
|
179 |
HgFileNode[] nodes; |
|
|
180 |
ArrayList<HgFileNode> nodesList = new ArrayList<HgFileNode>(fileList.size()); |
181 |
|
182 |
for (Iterator<File> it = fileList.iterator(); it.hasNext();) { |
183 |
File file = it.next(); |
184 |
HgFileNode node = new HgFileNode(file); |
185 |
nodesList.add(node); |
186 |
} |
187 |
nodes = nodesList.toArray(new HgFileNode[fileList.size()]); |
188 |
data.setNodes(nodes); |
189 |
|
190 |
JComponent component = data.getComponent(); |
148 |
JComponent component = data.getComponent(); |
191 |
panel.filesPanel.setLayout(new BorderLayout()); |
149 |
panel.filesPanel.setLayout(new BorderLayout()); |
192 |
panel.filesPanel.add(component, BorderLayout.CENTER); |
150 |
panel.filesPanel.add(component, BorderLayout.CENTER); |
Lines 202-207
Link Here
|
202 |
cancelButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CommitAction.class, "ACSN_Commit_Action_Cancel")); |
160 |
cancelButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CommitAction.class, "ACSN_Commit_Action_Cancel")); |
203 |
cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CommitAction.class, "ACSD_Commit_Action_Cancel")); |
161 |
cancelButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CommitAction.class, "ACSD_Commit_Action_Cancel")); |
204 |
|
162 |
|
|
|
163 |
computeNodes(data, panel, ctx, repository, cancelButton); |
205 |
commitButton.setEnabled(false); |
164 |
commitButton.setEnabled(false); |
206 |
dd.setOptions(new Object[] {commitButton, cancelButton}); |
165 |
dd.setOptions(new Object[] {commitButton, cancelButton}); |
207 |
dd.setHelpCtx(new HelpCtx(CommitAction.class)); |
166 |
dd.setHelpCtx(new HelpCtx(CommitAction.class)); |
Lines 241-246
Link Here
|
241 |
} |
200 |
} |
242 |
} |
201 |
} |
243 |
|
202 |
|
|
|
203 |
private static void computeNodes(final CommitTable table, final CommitPanel panel, final VCSContext ctx, final File repository, JButton cancel) { |
204 |
RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(repository); |
205 |
final HgProgressSupport support = new HgProgressSupport(NbBundle.getMessage(CommitAction.class, "Progress_Preparing_Commit"), cancel) { |
206 |
public void perform() { |
207 |
try { |
208 |
panel.progressPanel.setVisible(true); |
209 |
// Ensure that cache is uptodate |
210 |
StatusAction.executeStatus(ctx, this); |
211 |
|
212 |
FileStatusCache cache = Mercurial.getInstance().getFileStatusCache(); |
213 |
File[] roots = ctx.getRootFiles().toArray(new File[ctx.getRootFiles().size()]); |
214 |
|
215 |
File[][] split = Utils.splitFlatOthers(roots); |
216 |
List<File> fileList = new ArrayList<File>(); |
217 |
for (int c = 0; c < split.length; c++) { |
218 |
roots = split[c]; |
219 |
boolean recursive = c == 1; |
220 |
if (recursive) { |
221 |
File[] files = cache.listFiles(ctx, FileInformation.STATUS_LOCAL_CHANGE); |
222 |
for (int i= 0; i < files.length; i++) { |
223 |
for(int r = 0; r < roots.length; r++) { |
224 |
if( HgUtils.isParentOrEqual(roots[r], files[i]) ) { |
225 |
if(!fileList.contains(files[i])) { |
226 |
fileList.add(files[i]); |
227 |
} |
228 |
} |
229 |
} |
230 |
} |
231 |
} else { |
232 |
File[] files = HgUtils.flatten(roots, FileInformation.STATUS_LOCAL_CHANGE); |
233 |
for (int i= 0; i<files.length; i++) { |
234 |
if(!fileList.contains(files[i])) { |
235 |
fileList.add(files[i]); |
236 |
} |
237 |
} |
238 |
} |
239 |
} |
240 |
if(fileList.size()==0) { |
241 |
return; |
242 |
} |
243 |
|
244 |
HgFileNode[] nodes; |
245 |
ArrayList<HgFileNode> nodesList = new ArrayList<HgFileNode>(fileList.size()); |
246 |
|
247 |
for (Iterator<File> it = fileList.iterator(); it.hasNext();) { |
248 |
File file = it.next(); |
249 |
HgFileNode node = new HgFileNode(file); |
250 |
nodesList.add(node); |
251 |
} |
252 |
nodes = nodesList.toArray(new HgFileNode[fileList.size()]); |
253 |
table.setNodes(nodes); |
254 |
} finally { |
255 |
panel.progressPanel.setVisible(false); |
256 |
} |
257 |
} |
258 |
}; |
259 |
panel.barPanel.add(support.getProgressComponent(), BorderLayout.CENTER); |
260 |
panel.barPanel.setVisible(true); |
261 |
support.start(rp); |
262 |
} |
263 |
|
244 |
private static boolean containsCommitable(CommitTable data) { |
264 |
private static boolean containsCommitable(CommitTable data) { |
245 |
Map<HgFileNode, CommitOptions> map = data.getCommitFiles(); |
265 |
Map<HgFileNode, CommitOptions> map = data.getCommitFiles(); |
246 |
for(CommitOptions co : map.values()) { |
266 |
for(CommitOptions co : map.values()) { |