Permalink
Browse files

Added Rename command for host connections.

  • Loading branch information...
1 parent 5be69ad commit 052e0e616905a25549183049bf72490a4220a6aa @alamaison committed Aug 7, 2015
View
@@ -73,7 +73,7 @@ b816a87f-5022-11dc-9153-0090f5284f85
b816a880-5022-11dc-9153-0090f5284f85 Add SFTP command ID
b816a881-5022-11dc-9153-0090f5284f85 Remove SFTP command ID
b816a882-5022-11dc-9153-0090f5284f85 New folder commmand ID
-b816a883-5022-11dc-9153-0090f5284f85
+b816a883-5022-11dc-9153-0090f5284f85 Rename SFTP host command ID
b816a884-5022-11dc-9153-0090f5284f85 Launch key agent command ID
b816a885-5022-11dc-9153-0090f5284f85 About box command ID
b816a886-5022-11dc-9153-0090f5284f85 Close session command ID
@@ -23,7 +23,9 @@ set(COMMAND_SOURCES
commands/LaunchAgent.cpp
commands/LaunchAgent.hpp
commands/Remove.cpp
- commands/Remove.hpp)
+ commands/Remove.hpp
+ commands/Rename.cpp
+ commands/Rename.hpp)
set(SOURCES
columns.cpp
@@ -0,0 +1,114 @@
+/* Copyright (C) 2015 Alexander Lamaison <swish@lammy.co.uk>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "Rename.hpp"
+
+#include "swish/shell_folder/data_object/ShellDataObject.hpp" // PidlFormat
+#include "swish/shell_folder/shell.hpp" // put_view_item_into_rename_mode
+
+#include <washer/shell/services.hpp> // shell_browser, shell_view
+
+#include <comet/error.h> // com_error
+#include <comet/ptr.h> // com_ptr
+#include <comet/uuid_fwd.h> // uuid_t
+
+#include <boost/locale.hpp> // translate
+#include <boost/throw_exception.hpp> // BOOST_THROW_EXCEPTION
+
+#include <cassert> // assert
+#include <string>
+
+using swish::nse::Command;
+using swish::shell_folder::data_object::PidlFormat;
+using swish::shell_folder::put_view_item_into_rename_mode;
+
+using washer::shell::pidl::apidl_t;
+using washer::shell::shell_browser;
+using washer::shell::shell_view;
+
+using comet::com_error;
+using comet::com_ptr;
+using comet::uuid_t;
+
+using boost::locale::translate;
+
+using std::wstring;
+
+namespace swish {
+namespace host_folder {
+namespace commands {
+
+namespace {
+ const uuid_t RENAME_COMMAND_ID("b816a883-5022-11dc-9153-0090f5284f85");
+}
+
+Rename::Rename(HWND hwnd, const apidl_t& folder_pidl) :
+ Command(
+ translate(L"&Rename SFTP Connection"), RENAME_COMMAND_ID,
+ translate(L"Rename an SFTP connection created with Swish."),
+ L"shell32.dll,133", translate(L"&Rename SFTP Connection..."),
+ translate(L"Rename Connection")),
+ m_hwnd(hwnd), m_folder_pidl(folder_pidl) {}
+
+BOOST_SCOPED_ENUM(Command::state) Rename::state(
+ const comet::com_ptr<IDataObject>& data_object, bool /*ok_to_be_slow*/)
+const
+{
+ if (!data_object)
+ {
+ // Selection unknown.
+ return state::hidden;
+ }
+
+ PidlFormat format(data_object);
+ switch (format.pidl_count())
+ {
+ case 1:
+ return state::enabled;
+ case 0:
+ return state::hidden;
+ default:
+ // This means multiple items are selected. We disable rather than
+ // hide the buttons to let the user know the option exists but that
+ // we don't support multi-host renaming.
+ return state::disabled;
+ }
+}
+
+// This command just puts the item into rename (edit) mode. When the user
+// finishes typing the new name, the shell takes care of performing the rest of
+// the renaming process by calling SetNameOf() on the HostFolder
+void Rename::operator()(
+ const com_ptr<IDataObject>& data_object, const com_ptr<IBindCtx>&)
+const
+{
+ PidlFormat format(data_object);
+ if (format.pidl_count() != 1)
+ BOOST_THROW_EXCEPTION(com_error(E_FAIL));
+
+ com_ptr<IShellView> view = shell_view(shell_browser(m_site));
+
+ apidl_t pidl_selected = format.file(0);
+
+ put_view_item_into_rename_mode(view, pidl_selected.last_item());
+}
+
+void Rename::set_site(com_ptr<IUnknown> ole_site)
+{
+ m_site = ole_site;
+}
+
+}}} // namespace swish::host_folder::commands
@@ -0,0 +1,56 @@
+/* Copyright (C) 2015 Alexander Lamaison <swish@lammy.co.uk>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by the
+ Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SWISH_HOST_FOLDER_COMMANDS_RENAME_HPP
+#define SWISH_HOST_FOLDER_COMMANDS_RENAME_HPP
+
+#include "swish/nse/Command.hpp" // Command
+
+#include <washer/shell/pidl.hpp> // apidl_t
+
+#include <comet/ptr.h> // com_ptr
+
+#include <ObjIdl.h> // IDataObject, IBindCtx
+
+namespace swish {
+namespace host_folder {
+namespace commands {
+
+class Rename : public swish::nse::Command
+{
+public:
+ Rename(HWND hwnd, const washer::shell::pidl::apidl_t& folder_pidl);
+
+ virtual BOOST_SCOPED_ENUM(state) state(
+ const comet::com_ptr<IDataObject>& data_object,
+ bool ok_to_be_slow) const;
+
+ void operator()(
+ const comet::com_ptr<IDataObject>& data_object,
+ const comet::com_ptr<IBindCtx>& bind_ctx) const;
+
+ void set_site(comet::com_ptr<IUnknown> ole_site);
+
+private:
+ HWND m_hwnd;
+ washer::shell::pidl::apidl_t m_folder_pidl;
+ comet::com_ptr<IUnknown> m_site;
+};
+
+}}} // namespace swish::host_folder::commands
+
+
+#endif
@@ -5,7 +5,7 @@
@if license
- Copyright (C) 2010, 2011, 2012 Alexander Lamaison <awl03@doc.ic.ac.uk>
+ Copyright (C) 2010, 2011, 2012, 2015 Alexander Lamaison <swish@lammy.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@
#include "swish/host_folder/commands/CloseSession.hpp"
#include "swish/host_folder/commands/LaunchAgent.hpp"
#include "swish/host_folder/commands/Remove.hpp"
+#include "swish/host_folder/commands/Rename.hpp"
#include "swish/nse/explorer_command.hpp" // CExplorerCommand*
#include "swish/nse/task_pane.hpp" // CUIElementErrorAdapter
@@ -45,6 +46,7 @@
#include <vector>
using swish::nse::CExplorerCommand;
+using swish::nse::CExplorerCommandWithSite;
using swish::nse::CExplorerCommandProvider;
using swish::nse::CUICommand;
using swish::nse::CUIElementErrorAdapter;
@@ -78,6 +80,7 @@ com_ptr<IExplorerCommandProvider> host_folder_command_provider(
CExplorerCommandProvider::ordered_commands commands;
commands.push_back(new CExplorerCommand<Add>(hwnd, folder_pidl));
commands.push_back(new CExplorerCommand<Remove>(hwnd, folder_pidl));
+ commands.push_back(new CExplorerCommandWithSite<Rename>(hwnd, folder_pidl));
commands.push_back(new CExplorerCommand<CloseSession>(hwnd, folder_pidl));
commands.push_back(new CExplorerCommand<LaunchAgent>(hwnd, folder_pidl));
return new CExplorerCommandProvider(commands);
@@ -125,12 +128,14 @@ host_folder_task_pane_tasks(HWND hwnd, const apidl_t& folder_pidl)
commands->push_back(
new CUICommand< WebtaskCommandTitleAdapter<Remove> >(hwnd, folder_pidl));
commands->push_back(
+ new CUICommand< WebtaskCommandTitleAdapter<Rename> >(hwnd, folder_pidl));
+ commands->push_back(
new CUICommand< WebtaskCommandTitleAdapter<CloseSession> >(hwnd, folder_pidl));
commands->push_back(
new CUICommand< WebtaskCommandTitleAdapter<LaunchAgent> >(
hwnd, folder_pidl));
- com_ptr<IEnumUICommand> e =
+ com_ptr<IEnumUICommand> e =
make_smart_enumeration<IEnumUICommand>(commands);
return make_pair(e, com_ptr<IEnumUICommand>());
@@ -42,6 +42,8 @@ using washer::shell::pidl::cpidl_t;
using comet::regkey;
+using boost::optional;
+
using std::runtime_error;
using std::transform;
using std::wstring;
@@ -63,40 +65,49 @@ namespace { // private
return swish_connections.open(label);
}
+}
- /**
- * Get a single connection from the registry as a PIDL.
- *
- * @pre The @c Software\\Swish\\Connections registry key exists.
- * @pre The connection is present as a subkey of the
- * @c Software\\Swish\\Connections registry key whose name is given
- * by @p label.
- *
- * @param label Friendly name of the connection to load.
- *
- * @returns A host PIDL holding the connection details.
- * @throws com_error if the connection does not exist in the
- * or is corrupted.
- */
- cpidl_t GetConnectionDetailsFromRegistry(wstring label)
- {
- regkey swish_connections = regkey(HKEY_CURRENT_USER).open(
- CONNECTIONS_REGISTRY_KEY_NAME);
+namespace swish {
+namespace host_folder {
+namespace host_management {
+
+/**
+ * Get a single connection from the registry as a PIDL.
+ *
+ * @pre The connection, if present, is a subkey of the
+ * @c Software\\Swish\\Connections registry key whose name is given
+ * by @p label.
+ *
+ * @param label Friendly name of the connection to load.
+ *
+ * @returns A host PIDL holding the connection details.
+ */
+optional<cpidl_t> FindConnectionInRegistry(const wstring& label)
+{
+ regkey swish_connections = regkey(HKEY_CURRENT_USER).open_nothrow(
+ CONNECTIONS_REGISTRY_KEY_NAME);
+ // Legal to fail here - may be first ever connection
+ if(!swish_connections)
+ return optional<cpidl_t>();
- regkey connection = swish_connections.open(label);
+ regkey connection = swish_connections.open(label);
+ if(!connection)
+ return optional<cpidl_t>();
- wstring host = connection[HOST_VALUE_NAME];
- int port = connection[PORT_VALUE_NAME];
- wstring user = connection[USER_VALUE_NAME];
- wstring path = connection[PATH_VALUE_NAME];
+ wstring host = connection[HOST_VALUE_NAME];
+ int port = connection[PORT_VALUE_NAME];
+ wstring user = connection[USER_VALUE_NAME];
+ wstring path = connection[PATH_VALUE_NAME];
- return create_host_itemid(host, user, path, port, label);
- }
+ return create_host_itemid(host, user, path, port, label);
}
-namespace swish {
-namespace host_folder {
-namespace host_management {
+namespace {
+
+ cpidl_t GetConnectionDetailsFromRegistry(const wstring& label) {
+ return *FindConnectionInRegistry(label);
+ }
+}
/**
* Load all the connections stored in the registry into PIDLs.
@@ -30,6 +30,8 @@
#include <washer/shell/pidl.hpp> // cpidl_t
+#include <boost/optional/optional.hpp>
+
#include <string>
#include <vector>
@@ -43,6 +45,9 @@ void AddConnectionToRegistry(
std::wstring label, std::wstring host, int port,
std::wstring username, std::wstring path);
+boost::optional<washer::shell::pidl::cpidl_t> FindConnectionInRegistry(
+ const std::wstring& label);
+
void RemoveConnectionFromRegistry(std::wstring label);
void RenameConnectionInRegistry(
Oops, something went wrong.

0 comments on commit 052e0e6

Please sign in to comment.